0

Shut down Screen AI service when idle.

If Screen AI service is connected and not used for more than 5 minutes,
shut it down.
Idle handlers from clients are removed as it is now handled centrally
in the service.

OBSOLETE_HISTOGRAMS=Patterned histogram Accessibility.ScreenAI.{Feature}.Idle.Connected is no more needed.

AX-Relnotes: n/a
Bug: 353718857
Change-Id: Ie90029d487e716e855c483dcb339e985c42d1298
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5783111
Reviewed-by: David Tseng <dtseng@chromium.org>
Reviewed-by: Mark Schillaci <mschillaci@google.com>
Auto-Submit: Ramin Halavati <rhalavati@chromium.org>
Commit-Queue: Ramin Halavati <rhalavati@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1342904}
This commit is contained in:
Ramin Halavati
2024-08-16 17:39:09 +00:00
committed by Chromium LUCI CQ
parent 221c365b20
commit dc0b2e516c
6 changed files with 10 additions and 66 deletions
chrome
browser
renderer
content/renderer/accessibility/annotations
services/screen_ai
tools/metrics/histograms/metadata/accessibility

@@ -12,12 +12,6 @@
namespace {
// The delay after which the idle connection to OCR service will be
// disconnected.
// TODO(b/353718857): Remove this when ScreenAI service is set to auto shut down
// on idle.
constexpr base::TimeDelta kIdleDisconnectDelay = base::Minutes(5);
class SequenceBoundReceiver {
public:
SequenceBoundReceiver() = default;
@@ -127,7 +121,6 @@ void OpticalCharacterRecognizer::MaybeConnectToOcrService() {
->BindScreenAIAnnotator(
screen_ai_annotator_->BindNewPipeAndPassReceiver());
screen_ai_annotator_->reset_on_disconnect();
screen_ai_annotator_->reset_on_idle_timeout(kIdleDisconnectDelay);
(*screen_ai_annotator_)->SetClientType(client_type_);
}

@@ -26,11 +26,6 @@
namespace {
// Time after which an idle connection to Screen AI service is disconnected.
// TODO(b/353718857): Remove this when ScreenAI service is set to auto shut down
// on idle.
constexpr base::TimeDelta kScreenAIIdleDisconnectDelay = base::Minutes(5);
// TODO: Consider moving this to AXNodeProperties.
static const ax::mojom::Role kContentRoles[]{
ax::mojom::Role::kHeading, ax::mojom::Role::kParagraph,
@@ -239,7 +234,6 @@ void AXTreeDistiller::DistillViaScreen2x(
render_frame()->GetBrowserInterfaceBroker().GetInterface(
main_content_extractor_.BindNewPipeAndPassReceiver());
main_content_extractor_.reset_on_disconnect();
main_content_extractor_.reset_on_idle_timeout(kScreenAIIdleDisconnectDelay);
main_content_extractor_.set_disconnect_handler(
base::BindOnce(&AXTreeDistiller::OnMainContentExtractorDisconnected,
weak_ptr_factory_.GetWeakPtr()));

@@ -17,11 +17,6 @@ using blink::WebDocument;
namespace {
// Time after which an idle connection to Screen AI service is disconnected.
// TODO(b/353718857): Remove this when ScreenAI service is set to auto shut down
// on idle.
constexpr base::TimeDelta kScreenAIIdleDisconnectDelay = base::Minutes(5);
const char kHistogramsName[] =
"Accessibility.MainNodeAnnotations.AnnotationResult";
@@ -122,7 +117,6 @@ void AXMainNodeAnnotator::Annotate(const WebDocument& document,
.GetInterface(annotator.InitWithNewPipeAndPassReceiver());
annotator_remote_.Bind(std::move(annotator));
annotator_remote_.reset_on_disconnect();
annotator_remote_.reset_on_idle_timeout(kScreenAIIdleDisconnectDelay);
}
// Identify the main node using Screen2x.

@@ -44,7 +44,7 @@ namespace screen_ai {
namespace {
// How often it would be checked that the service is idle and can be shutdown.
constexpr base::TimeDelta kIdleCheckingDelay = base::Minutes(10);
constexpr base::TimeDelta kIdleCheckingDelay = base::Minutes(5);
// How long after all clients are disconnected, it is checked if service is
// idle.
@@ -509,34 +509,17 @@ void ScreenAIService::CheckIdleStateAfterDelay() {
}
void ScreenAIService::ShutDownIfNoClients() {
bool ocr_has_clients = screen_ai_annotators_.size();
bool main_content_extraction_has_clients =
screen2x_main_content_extractors_.size();
if (!ocr_has_clients && !main_content_extraction_has_clients) {
VLOG(2) << "Shutting down since no client.";
base::Process::TerminateCurrentProcessImmediately(0);
}
// Collect data on whether each functionality of the service is idle.
// This will be used to plan further to shut down the service when idle, or
// track features which keep the service in idle state.
// TODO(b/353718857): Shut down when both features are idle, after ensuring
// all clients support reconnecting.
const base::TimeTicks kIdlenessThreshold =
base::TimeTicks::Now() - kIdleCheckingDelay;
if (!ocr_idle_reported_ && !ocr_last_used_.is_null() &&
ocr_last_used_ < kIdlenessThreshold) {
ocr_idle_reported_ = true;
base::UmaHistogramBoolean("Accessibility.ScreenAI.OCR.Idle.Connected",
ocr_has_clients);
}
if (!main_content_extraction_idle_reported_ &&
!main_content_extraction_last_used_.is_null() &&
main_content_extraction_last_used_ < kIdlenessThreshold) {
main_content_extraction_idle_reported_ = true;
base::UmaHistogramBoolean(
"Accessibility.ScreenAI.MainContentExtraction.Idle.Connected",
main_content_extraction_has_clients);
bool ocr_not_needed =
!screen_ai_annotators_.size() || ocr_last_used_ < kIdlenessThreshold;
bool main_content_extractioncan_not_needed =
!screen2x_main_content_extractors_.size() ||
main_content_extraction_last_used_ < kIdlenessThreshold;
if (ocr_not_needed && main_content_extractioncan_not_needed) {
VLOG(2) << "Shutting down since no client or idle.";
base::Process::TerminateCurrentProcessImmediately(0);
}
}

@@ -140,11 +140,6 @@ class ScreenAIService : public mojom::ScreenAIServiceFactory,
base::TimeTicks ocr_last_used_;
base::TimeTicks main_content_extraction_last_used_;
// Whether idle state for each feature is reported or not. Idle state is
// reported only once per feature during the lifetime of the service.
bool ocr_idle_reported_ = false;
bool main_content_extraction_idle_reported_ = false;
std::unique_ptr<base::RepeatingTimer> idle_checking_timer_;
mojo::Receiver<mojom::ScreenAIServiceFactory> factory_receiver_;

@@ -2783,21 +2783,6 @@ even if they fit the naming pattern. -->
</token>
</histogram>
<histogram name="Accessibility.ScreenAI.{Feature}.Idle.Connected"
enum="BooleanConnected" expires_after="2025-02-28">
<owner>rhalavati@chromium.org</owner>
<owner>chrome-a11y-core@google.com</owner>
<summary>
Records whether the {Feature} has been connected to a client or not while
being idle (initialized but not used for more than 10min). This metric is
collected only once during the life time of ScreenAI service.
</summary>
<token key="Feature">
<variant name="MainContentExtraction" summary="Main Content Extraction"/>
<variant name="OCR" summary="Optical Character Recognition"/>
</token>
</histogram>
<histogram name="Accessibility.ScreenAI.{feature}.InitializationLatency"
units="ms" expires_after="2025-02-28">
<owner>rhalavati@chromium.org</owner>