[tracing] Improve and simplify startup tracing

This CL aligns behavior across child processes,
and supports tracing earlier during startup generally.
- Only Gpu process previously implemented early initialization, this
is now implemented on all child processes.
- Logic around SetupStartupTracingBlocking is simplified
as a result, we call it directly as soon as field trials
are initialized.

Gpu process on linux/chromeos restarts the tracing thread.
For simplicity, this isn't implemented in other processes and
we fallback to "later" startup tracing (needs_startup_tracing_after_sandbox_init), which is still earlier
than what we had before.

I encountered an underlying issue where UpdateDataSource
complains about missing DataSourceDescriptor.id;
I believe this started happening because the reordering
leads us to register e.g. v8 TrackEvent after we started tracing.
The consequences are benign; we don't really rely on DataSourceDescriptor other than being informative.
The fix is simply to forward the id through mojo.

Change-Id: I7f4afc5f97956bc7f97dc00741c317482be3ab5d
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6685790
Reviewed-by: Gabriel Charette <[email protected]>
Reviewed-by: Kramer Ge <[email protected]>
Reviewed-by: Ken Buchanan <[email protected]>
Reviewed-by: Dave Tapuska <[email protected]>
Reviewed-by: Mikhail Khokhlov <[email protected]>
Commit-Queue: Etienne Pierre-Doray <[email protected]>
Cr-Commit-Position: refs/heads/main@{#1482672}
diff --git a/content/gpu/gpu_main.cc b/content/gpu/gpu_main.cc
index 620a5f2..b6403600 100644
--- a/content/gpu/gpu_main.cc
+++ b/content/gpu/gpu_main.cc
@@ -381,6 +381,16 @@
     client->PostSandboxInitialized();
   }
 
+  // Startup tracing creates a tracing thread, which is incompatible on
+  // platforms that require single-threaded sandbox initialization. In these
+  // cases, startup tracing is either initialized right after sandbox
+  // initialization, or we restart the tracing thread during sandbox
+  // initialization.
+  if (parameters.needs_startup_tracing_after_sandbox_init) {
+    tracing::InitTracingPostFeatureList(/*enable_consumer=*/false,
+                                        /*will_trace_thread_restart=*/false);
+  }
+
   GetContentClient()->SetGpuInfo(gpu_init->gpu_info());
 
   base::ThreadType io_thread_type = base::ThreadType::kDisplayCritical;
@@ -400,13 +410,6 @@
 
   gpu_process.set_main_thread(child_thread);
 
-  // Mojo IPC support is brought up by GpuChildThread, so startup tracing is
-  // enabled here if it needs to start after mojo init (normally so the mojo
-  // broker can bypass the sandbox to allocate startup tracing's SMB).
-  if (parameters.needs_startup_tracing_after_mojo_init) {
-    tracing::EnableStartupTracingIfNeeded();
-  }
-
 #if BUILDFLAG(IS_MAC)
   // A GPUEjectPolicy of 'wait' is set in the Info.plist of the browser
   // process, meaning it is "responsible" for making sure it and its