Reland: Shutdown ScreenAI service if it has no clients.

ScreenAI service checks periodically if there are any remotes connected
to it, and if there is none, shuts itself down to release resources.

The first patch of this CL is the last patch of the reverted one.

Cq-Include-Trybots: luci.chromium.try:linux_chromium_msan_rel_ng

AX-Relnotes: n/a
Bug: 353718857
Change-Id: I34aad66b8bfea73650f563a32c7f9bf9576551ea
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5741655
Reviewed-by: David Tseng <[email protected]>
Reviewed-by: Alex Gough <[email protected]>
Commit-Queue: Ramin Halavati <[email protected]>
Cr-Original-Commit-Position: refs/heads/main@{#1334635}
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5746964
Cr-Commit-Position: refs/heads/main@{#1335236}
diff --git a/services/screen_ai/screen_ai_service_impl.cc b/services/screen_ai/screen_ai_service_impl.cc
index cb36243..75dc8be3 100644
--- a/services/screen_ai/screen_ai_service_impl.cc
+++ b/services/screen_ai/screen_ai_service_impl.cc
@@ -459,4 +459,12 @@
   }
 }
 
+void ScreenAIService::ShutDownIfNoClients() {
+  bool no_clients = screen_ai_annotators_.empty() &&
+                    screen_2x_main_content_extractors_.empty();
+  if (no_clients) {
+    base::Process::TerminateCurrentProcessImmediately(0);
+  }
+}
+
 }  // namespace screen_ai