Use viz::GpuHostImpl in OopAsh

This CL updates ws::gpu_host::GpuHost to use viz::GpuHostImpl as its
implementation for viz::mojom::GpuHost. It does not replace ws::GpuHost
completely as it still depends ws::GpuClient. A follow-up CL would
replace ws::GpuClient with viz::GpuClient. Then we can probably remove
ws::GpuHost.

BUG=841446

Cq-Include-Trybots: luci.chromium.try:android_optional_gpu_tests_rel
Change-Id: Ibec183545d235803d6206b93aac27055a72bde26
Reviewed-on: https://chromium-review.googlesource.com/c/1239336
Reviewed-by: Sadrul Chowdhury <[email protected]>
Reviewed-by: Scott Violet <[email protected]>
Reviewed-by: Antoine Labour <[email protected]>
Commit-Queue: Mohsen Izadi <[email protected]>
Cr-Commit-Position: refs/heads/master@{#597392}
diff --git a/components/viz/host/gpu_host_impl.h b/components/viz/host/gpu_host_impl.h
index 7beb4ec6..af2bebb 100644
--- a/components/viz/host/gpu_host_impl.h
+++ b/components/viz/host/gpu_host_impl.h
@@ -40,19 +40,39 @@
 class ShaderDiskCache;
 }  // namespace gpu
 
-namespace IPC {
-class Channel;
-}
-
 namespace viz {
 
+// Contains either an interface or an associated interface pointer to a
+// mojom::VizMain implementation and routes the requests appropriately.
+class VIZ_HOST_EXPORT VizMainWrapper {
+ public:
+  explicit VizMainWrapper(mojom::VizMainPtr viz_main_ptr);
+  explicit VizMainWrapper(mojom::VizMainAssociatedPtr viz_main_associated_ptr);
+  ~VizMainWrapper();
+
+  void CreateGpuService(
+      mojom::GpuServiceRequest request,
+      mojom::GpuHostPtr gpu_host,
+      discardable_memory::mojom::DiscardableSharedMemoryManagerPtr
+          discardable_memory_manager,
+      mojo::ScopedSharedBufferHandle activity_flags,
+      gfx::FontRenderParams::SubpixelRendering subpixel_rendering);
+  void CreateFrameSinkManager(mojom::FrameSinkManagerParamsPtr params);
+
+ private:
+  mojom::VizMainPtr viz_main_ptr_;
+  mojom::VizMainAssociatedPtr viz_main_associated_ptr_;
+
+  DISALLOW_COPY_AND_ASSIGN(VizMainWrapper);
+};
+
 class VIZ_HOST_EXPORT GpuHostImpl : public mojom::GpuHost {
  public:
   class VIZ_HOST_EXPORT Delegate {
    public:
     virtual gpu::GPUInfo GetGPUInfo() const = 0;
     virtual gpu::GpuFeatureInfo GetGpuFeatureInfo() const = 0;
-    virtual void UpdateGpuInfo(
+    virtual void DidInitialize(
         const gpu::GPUInfo& gpu_info,
         const gpu::GpuFeatureInfo& gpu_feature_info,
         const base::Optional<gpu::GPUInfo>& gpu_info_for_hardware_gpu,
@@ -125,10 +145,13 @@
                               const gpu::GpuFeatureInfo&,
                               EstablishChannelStatus)>;
 
-  GpuHostImpl(Delegate* delegate, IPC::Channel* channel, InitParams params);
+  GpuHostImpl(Delegate* delegate,
+              std::unique_ptr<VizMainWrapper> viz_main_ptr,
+              InitParams params);
   ~GpuHostImpl() override;
 
   static void InitFontRenderParams(const gfx::FontRenderParams& params);
+  static void ResetFontRenderParams();
 
   void OnProcessLaunched(base::ProcessId pid);
   void OnProcessCrashed();
@@ -164,6 +187,8 @@
   }
 
  private:
+  friend class GpuHostImplTestApi;
+
 #if defined(USE_OZONE)
   void InitOzone();
   void TerminateGpuProcess(const std::string& message);
@@ -208,13 +233,12 @@
                         const std::string& message) override;
 
   Delegate* const delegate_;
-  IPC::Channel* const channel_;
+  std::unique_ptr<VizMainWrapper> viz_main_ptr_;
   const InitParams params_;
 
   // Task runner corresponding to the thread |this| is created on.
   scoped_refptr<base::SingleThreadTaskRunner> host_thread_task_runner_;
 
-  mojom::VizMainAssociatedPtr viz_main_ptr_;
   mojom::GpuServicePtr gpu_service_ptr_;
   mojo::Binding<mojom::GpuHost> gpu_host_binding_;
   gpu::GpuProcessHostActivityFlags activity_flags_;