Eliminate Content's use of ServiceFactory

Content sort of repurposed Service Manager's ServiceFactory interface to
push service launching requests into child processes. ServiceFactory is
going away to simplify Service Manager APIs, so this CL moves the child
process "run a service" request into a new message on the existing
content.mojom.ChildControl interface held by all ChildProcessHosts.

Most of the CL is plumbing calls from process hosts down to their child
threads.

This also finally eliminates content::ServiceFactory which has over time
diminished into a pretty useless base class for UtilityServiceFactory
and GpuServiceFactory.

Bug: 925860
Change-Id: I451de1f6e69f36a7fcacc4712aee67a8aca569d3
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1512786
Reviewed-by: Tom Sepez <[email protected]>
Reviewed-by: Kenneth Russell <[email protected]>
Reviewed-by: Avi Drissman <[email protected]>
Reviewed-by: Sadrul Chowdhury <[email protected]>
Commit-Queue: Ken Rockot <[email protected]>
Cr-Commit-Position: refs/heads/master@{#639817}
diff --git a/content/gpu/gpu_child_thread.h b/content/gpu/gpu_child_thread.h
index f9264ba..3b40d5a5 100644
--- a/content/gpu/gpu_child_thread.h
+++ b/content/gpu/gpu_child_thread.h
@@ -10,6 +10,7 @@
 #include <memory>
 #include <queue>
 #include <string>
+#include <vector>
 
 #include "base/callback.h"
 #include "base/command_line.h"
@@ -31,9 +32,7 @@
 #include "gpu/ipc/service/x_util.h"
 #include "media/base/android_overlay_mojo_factory.h"
 #include "mojo/public/cpp/bindings/associated_binding_set.h"
-#include "mojo/public/cpp/bindings/binding_set.h"
 #include "services/service_manager/public/cpp/service_context_ref.h"
-#include "services/service_manager/public/mojom/service_factory.mojom.h"
 #include "services/viz/privileged/interfaces/viz_main.mojom.h"
 #include "third_party/blink/public/common/associated_interfaces/associated_interface_registry.h"
 #include "ui/gfx/native_widget_types.h"
@@ -68,8 +67,11 @@
 
   bool in_process_gpu() const;
 
-  // ChildThreadImpl:.
+  // ChildThreadImpl:
   bool Send(IPC::Message* msg) override;
+  void RunService(
+      const std::string& service_name,
+      mojo::PendingReceiver<service_manager::mojom::Service> receiver) override;
 
   // IPC::Listener implementation via ChildThreadImpl:
   void OnAssociatedInterfaceRequest(
@@ -86,9 +88,6 @@
   void OnMemoryPressure(
       base::MemoryPressureListener::MemoryPressureLevel level);
 
-  void BindServiceFactoryRequest(
-      service_manager::mojom::ServiceFactoryRequest request);
-
   // Returns a closure which calls into the VizMainImpl to perform shutdown
   // before quitting the main message loop. Must be called on the main thread.
   static base::RepeatingClosure MakeQuitSafelyClosure();
@@ -107,10 +106,6 @@
   // ServiceFactory for service_manager::Service hosting.
   std::unique_ptr<GpuServiceFactory> service_factory_;
 
-  // Bindings to the service_manager::mojom::ServiceFactory impl.
-  mojo::BindingSet<service_manager::mojom::ServiceFactory>
-      service_factory_bindings_;
-
   blink::AssociatedInterfaceRegistry associated_interfaces_;
 
   // Holds a closure that releases pending interface requests on the IO thread.
@@ -121,6 +116,20 @@
 
   std::unique_ptr<base::MemoryPressureListener> memory_pressure_listener_;
 
+  // Retains pending GPU-process service startup requests (i.e. RunService
+  // invocations from the browser) until the process is fully initialized.
+  struct PendingServiceRequest {
+    PendingServiceRequest(
+        const std::string& service_name,
+        mojo::PendingReceiver<service_manager::mojom::Service> receiver);
+    PendingServiceRequest(PendingServiceRequest&&);
+    ~PendingServiceRequest();
+
+    std::string service_name;
+    mojo::PendingReceiver<service_manager::mojom::Service> receiver;
+  };
+  std::vector<PendingServiceRequest> pending_service_requests_;
+
   base::WeakPtrFactory<GpuChildThread> weak_factory_;
 
   DISALLOW_COPY_AND_ASSIGN(GpuChildThread);