Make sure to always create the SMA on the correct thread in the in-process case

Requires TracingService::ConnectProducer to be called with in_process=true
so that the SMA is automatically created when the SMB is created.

R=primiano@google.com

Bug:chromium:935550
Change-Id: Iaba045c7ad98519e53ebe09bfee99a15df194dd9
diff --git a/src/tracing/core/tracing_service_impl.h b/src/tracing/core/tracing_service_impl.h
index d8fb2af..db174ce 100644
--- a/src/tracing/core/tracing_service_impl.h
+++ b/src/tracing/core/tracing_service_impl.h
@@ -75,7 +75,8 @@
                          TracingServiceImpl*,
                          base::TaskRunner*,
                          Producer*,
-                         const std::string& producer_name);
+                         const std::string& producer_name,
+                         bool in_process);
     ~ProducerEndpointImpl() override;
 
     // TracingService::ProducerEndpoint implementation.
@@ -117,7 +118,7 @@
     friend class TracingServiceImplTest;
     ProducerEndpointImpl(const ProducerEndpointImpl&) = delete;
     ProducerEndpointImpl& operator=(const ProducerEndpointImpl&) = delete;
-    SharedMemoryArbiterImpl* GetOrCreateShmemArbiter();
+    SharedMemoryArbiterImpl* GetShmemArbiter();
 
     ProducerID const id_;
     const uid_t uid_;
@@ -129,6 +130,7 @@
     SharedMemoryABI shmem_abi_;
     size_t shmem_size_hint_bytes_ = 0;
     const std::string name_;
+    bool in_process_;
 
     // Set of the global target_buffer IDs that the producer is configured to
     // write into in any active tracing session.
@@ -144,10 +146,8 @@
     // before use.
     std::map<WriterID, BufferID> writers_;
 
-    // This is used only in in-process configurations. The mutex protects
-    // concurrent construction of |inproc_shmem_arbiter_|.
+    // This is used only in in-process configurations.
     // SharedMemoryArbiterImpl methods themselves are thread-safe.
-    std::mutex inproc_shmem_arbiter_mutex_;
     std::unique_ptr<SharedMemoryArbiterImpl> inproc_shmem_arbiter_;
 
     PERFETTO_THREAD_CHECKER(thread_checker_)
@@ -258,7 +258,8 @@
       Producer*,
       uid_t uid,
       const std::string& producer_name,
-      size_t shared_memory_size_hint_bytes = 0) override;
+      size_t shared_memory_size_hint_bytes = 0,
+      bool in_process = false) override;
 
   std::unique_ptr<TracingService::ConsumerEndpoint> ConnectConsumer(
       Consumer*,