[GPU] Explicitly initialize the base::ThreadPoolInstance in time for angle::InitializePlatform

This is equivalent to the ThreadPoolInstance configuration that the
GPU process was implicitly getting from ChildProcess::ChildProcess
(constructed from GPUProcess::GPUProcess). Modulo the added ability to
explicitly name this ThreadPool and have independent metrics :).

The ThreadPoolInstance is still started at virtually the same order as
before so semantics should be equivalent for the GPU process.

This is necessary otherwise etienneb's fix for crbug.com/1091259
is a no-op in production due to the early-bail if there's no
ThreadPoolInstance on init (added for tests, breaks prod).

[email protected], [email protected]

Bug: 1091259
Change-Id: I3ce25ac70bb4d1980e3d38ae6f90851041632bd7
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2255655
Commit-Queue: Zhenyao Mo <[email protected]>
Reviewed-by: Sunny Sachanandani <[email protected]>
Reviewed-by: Brian White <[email protected]>
Reviewed-by: Zhenyao Mo <[email protected]>
Auto-Submit: Gabriel Charette <[email protected]>
Cr-Commit-Position: refs/heads/master@{#781944}
diff --git a/content/gpu/gpu_main.cc b/content/gpu/gpu_main.cc
index bf8c86b0..c8024d77 100644
--- a/content/gpu/gpu_main.cc
+++ b/content/gpu/gpu_main.cc
@@ -329,10 +329,15 @@
 
   gpu_init->set_sandbox_helper(&sandbox_helper);
 
-  // Since GPU initialization calls into skia, its important to initialize skia
+  // Since GPU initialization calls into skia, it's important to initialize skia
   // before it.
   InitializeSkia();
 
+  // Create the ThreadPool before invoking |gpu_init| as it needs the ThreadPool
+  // (in angle::InitializePlatform()). Do not start it until after the sandbox
+  // is initialized however to avoid creating threads outside the sandbox.
+  base::ThreadPoolInstance::Create("GPU");
+
   // Gpu initialization may fail for various reasons, in which case we will need
   // to tear down this process. However, we can not do so safely until the IPC
   // channel is set up, because the detection of early return of a child process
@@ -347,6 +352,9 @@
 
   GetContentClient()->SetGpuInfo(gpu_init->gpu_info());
 
+  // Start the ThreadPoolInstance now that the sandbox is initialized.
+  base::ThreadPoolInstance::Get()->StartWithDefaultParams();
+
   const base::ThreadPriority io_thread_priority =
       base::FeatureList::IsEnabled(features::kGpuUseDisplayThreadPriority)
           ? base::ThreadPriority::DISPLAY