Created a basic public interface for SharedMemoryArbiter to allow public transport layers

Change-Id: I4391bdb55144998e05f1df2a29775a9725d9bd65
diff --git a/Android.bp b/Android.bp
index d77c2ed..d487b4a 100644
--- a/Android.bp
+++ b/Android.bp
@@ -56,7 +56,7 @@
     "src/tracing/core/id_allocator.cc",
     "src/tracing/core/service_impl.cc",
     "src/tracing/core/shared_memory_abi.cc",
-    "src/tracing/core/shared_memory_arbiter.cc",
+    "src/tracing/core/shared_memory_arbiter_impl.cc",
     "src/tracing/core/trace_config.cc",
     "src/tracing/core/trace_packet.cc",
     "src/tracing/core/trace_writer_impl.cc",
@@ -684,7 +684,7 @@
     "src/tracing/core/id_allocator.cc",
     "src/tracing/core/service_impl.cc",
     "src/tracing/core/shared_memory_abi.cc",
-    "src/tracing/core/shared_memory_arbiter.cc",
+    "src/tracing/core/shared_memory_arbiter_impl.cc",
     "src/tracing/core/trace_config.cc",
     "src/tracing/core/trace_packet.cc",
     "src/tracing/core/trace_writer_impl.cc",
@@ -802,8 +802,8 @@
     "src/tracing/core/service_impl_unittest.cc",
     "src/tracing/core/shared_memory_abi.cc",
     "src/tracing/core/shared_memory_abi_unittest.cc",
-    "src/tracing/core/shared_memory_arbiter.cc",
-    "src/tracing/core/shared_memory_arbiter_unittest.cc",
+    "src/tracing/core/shared_memory_arbiter_impl.cc",
+    "src/tracing/core/shared_memory_arbiter_impl_unittest.cc",
     "src/tracing/core/trace_config.cc",
     "src/tracing/core/trace_packet.cc",
     "src/tracing/core/trace_packet_unittest.cc",
diff --git a/include/perfetto/tracing/core/BUILD.gn b/include/perfetto/tracing/core/BUILD.gn
index 1f895ac..134fa0a 100644
--- a/include/perfetto/tracing/core/BUILD.gn
+++ b/include/perfetto/tracing/core/BUILD.gn
@@ -26,6 +26,7 @@
     "service.h",
     "shared_memory.h",
     "shared_memory_abi.h",
+    "shared_memory_arbiter.h",
     "trace_config.h",
     "trace_packet.h",
     "trace_writer.h",
diff --git a/include/perfetto/tracing/core/shared_memory_arbiter.h b/include/perfetto/tracing/core/shared_memory_arbiter.h
new file mode 100644
index 0000000..3bcc12d
--- /dev/null
+++ b/include/perfetto/tracing/core/shared_memory_arbiter.h
@@ -0,0 +1,64 @@
+/*
+ * Copyright (C) 2018 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef INCLUDE_PERFETTO_TRACING_CORE_SHARED_MEMORY_ARBITER_H_
+#define INCLUDE_PERFETTO_TRACING_CORE_SHARED_MEMORY_ARBITER_H_
+
+#include <stddef.h>
+
+#include <functional>
+#include <memory>
+#include <vector>
+
+#include "perfetto/tracing/core/basic_types.h"
+
+namespace perfetto {
+
+namespace base {
+class TaskRunner;
+}
+
+class SharedMemory;
+class TraceWriter;
+
+// Used by the Producer-side of the transport layer to vend TraceWriters
+// from the SharedMemory it receives from the Service-side.
+class SharedMemoryArbiter {
+ public:
+  using OnPagesCompleteCallback =
+      std::function<void(const std::vector<uint32_t>& /*page_indexes*/)>;
+
+  virtual ~SharedMemoryArbiter() = default;
+
+  // Creates a new TraceWriter and assigns it a new WriterID. The WriterID is
+  // written in each chunk header owned by a given TraceWriter and is used by
+  // the Service to reconstruct TracePackets written by the same TraceWriter.
+  // Returns nullptr if all WriterID slots are exhausted.
+  // TODO(primiano): instead of nullptr this should return a NoopWriter.
+  virtual std::unique_ptr<TraceWriter> CreateTraceWriter(
+      BufferID target_buffer) = 0;
+
+  // Implemented in src/core/shared_memory_arbiter_impl.cc .
+  static std::unique_ptr<SharedMemoryArbiter> CreateInstance(
+      SharedMemory*,
+      size_t page_size,
+      OnPagesCompleteCallback,
+      base::TaskRunner*);
+};
+
+}  // namespace perfetto
+
+#endif  // INCLUDE_PERFETTO_TRACING_CORE_SHARED_MEMORY_ARBITER_H_
diff --git a/src/tracing/BUILD.gn b/src/tracing/BUILD.gn
index a60da53..988d829 100644
--- a/src/tracing/BUILD.gn
+++ b/src/tracing/BUILD.gn
@@ -36,8 +36,8 @@
     "core/service_impl.cc",
     "core/service_impl.h",
     "core/shared_memory_abi.cc",
-    "core/shared_memory_arbiter.cc",
-    "core/shared_memory_arbiter.h",
+    "core/shared_memory_arbiter_impl.cc",
+    "core/shared_memory_arbiter_impl.h",
     "core/trace_config.cc",
     "core/trace_packet.cc",
     "core/trace_writer_impl.cc",
@@ -92,7 +92,7 @@
     "core/id_allocator_unittest.cc",
     "core/service_impl_unittest.cc",
     "core/shared_memory_abi_unittest.cc",
-    "core/shared_memory_arbiter_unittest.cc",
+    "core/shared_memory_arbiter_impl_unittest.cc",
     "core/trace_packet_unittest.cc",
     "core/trace_writer_impl_unittest.cc",
     "ipc/posix_shared_memory_unittest.cc",
diff --git a/src/tracing/core/shared_memory_arbiter.cc b/src/tracing/core/shared_memory_arbiter_impl.cc
similarity index 80%
rename from src/tracing/core/shared_memory_arbiter.cc
rename to src/tracing/core/shared_memory_arbiter_impl.cc
index de08dc0..e0b3249 100644
--- a/src/tracing/core/shared_memory_arbiter.cc
+++ b/src/tracing/core/shared_memory_arbiter_impl.cc
@@ -14,10 +14,11 @@
  * limitations under the License.
  */
 
-#include "src/tracing/core/shared_memory_arbiter.h"
+#include "src/tracing/core/shared_memory_arbiter_impl.h"
 
 #include "perfetto/base/logging.h"
 #include "perfetto/base/task_runner.h"
+#include "perfetto/tracing/core/shared_memory.h"
 #include "src/tracing/core/trace_writer_impl.h"
 
 #include <limits>
@@ -27,20 +28,31 @@
 using Chunk = SharedMemoryABI::Chunk;
 
 // static
-SharedMemoryABI::PageLayout SharedMemoryArbiter::default_page_layout =
+SharedMemoryABI::PageLayout SharedMemoryArbiterImpl::default_page_layout =
     SharedMemoryABI::PageLayout::kPageDiv1;
 
-SharedMemoryArbiter::SharedMemoryArbiter(void* start,
-                                         size_t size,
-                                         size_t page_size,
-                                         OnPagesCompleteCallback callback,
-                                         base::TaskRunner* task_runner)
+// static
+std::unique_ptr<SharedMemoryArbiter> SharedMemoryArbiter::CreateInstance(
+    SharedMemory* shared_memory,
+    size_t page_size,
+    OnPagesCompleteCallback callback,
+    base::TaskRunner* task_runner) {
+  return std::unique_ptr<SharedMemoryArbiterImpl>(
+      new SharedMemoryArbiterImpl(shared_memory->start(), shared_memory->size(),
+                                  page_size, callback, task_runner));
+}
+SharedMemoryArbiterImpl::SharedMemoryArbiterImpl(
+    void* start,
+    size_t size,
+    size_t page_size,
+    OnPagesCompleteCallback callback,
+    base::TaskRunner* task_runner)
     : task_runner_(task_runner),
       on_pages_complete_callback_(std::move(callback)),
       shmem_abi_(reinterpret_cast<uint8_t*>(start), size, page_size),
       active_writer_ids_(SharedMemoryABI::kMaxWriterID + 1) {}
 
-Chunk SharedMemoryArbiter::GetNewChunk(
+Chunk SharedMemoryArbiterImpl::GetNewChunk(
     const SharedMemoryABI::ChunkHeader& header,
     BufferID target_buffer,
     size_t size_hint) {
@@ -60,7 +72,7 @@
         bool is_new_page = false;
 
         // TODO(primiano): make the page layout dynamic.
-        auto layout = SharedMemoryArbiter::default_page_layout;
+        auto layout = SharedMemoryArbiterImpl::default_page_layout;
 
         if (shmem_abi_.is_page_free(page_idx_)) {
           // TODO(primiano): Use the |size_hint| here to decide the layout.
@@ -117,7 +129,7 @@
   }
 }
 
-void SharedMemoryArbiter::ReturnCompletedChunk(Chunk chunk) {
+void SharedMemoryArbiterImpl::ReturnCompletedChunk(Chunk chunk) {
   bool should_post_callback = false;
   {
     std::lock_guard<std::mutex> scoped_lock(lock_);
@@ -129,13 +141,13 @@
   }
   if (should_post_callback) {
     // TODO what happens if the arbiter gets destroyed?
-    task_runner_->PostTask(
-        std::bind(&SharedMemoryArbiter::InvokeOnPagesCompleteCallback, this));
+    task_runner_->PostTask(std::bind(
+        &SharedMemoryArbiterImpl::InvokeOnPagesCompleteCallback, this));
   }
 }
 
 // This is always invoked on the |task_runner_| thread.
-void SharedMemoryArbiter::InvokeOnPagesCompleteCallback() {
+void SharedMemoryArbiterImpl::InvokeOnPagesCompleteCallback() {
   std::vector<uint32_t> pages_to_notify;
   {
     std::lock_guard<std::mutex> scoped_lock(lock_);
@@ -145,7 +157,7 @@
   on_pages_complete_callback_(pages_to_notify);
 }
 
-std::unique_ptr<TraceWriter> SharedMemoryArbiter::CreateTraceWriter(
+std::unique_ptr<TraceWriter> SharedMemoryArbiterImpl::CreateTraceWriter(
     BufferID target_buffer) {
   WriterID id;
   {
@@ -156,7 +168,7 @@
       id ? new TraceWriterImpl(this, id, target_buffer) : nullptr);
 }
 
-void SharedMemoryArbiter::ReleaseWriterID(WriterID id) {
+void SharedMemoryArbiterImpl::ReleaseWriterID(WriterID id) {
   std::lock_guard<std::mutex> scoped_lock(lock_);
   active_writer_ids_.Free(id);
 }
diff --git a/src/tracing/core/shared_memory_arbiter.h b/src/tracing/core/shared_memory_arbiter_impl.h
similarity index 74%
rename from src/tracing/core/shared_memory_arbiter.h
rename to src/tracing/core/shared_memory_arbiter_impl.h
index 050f2fc..f1c4308 100644
--- a/src/tracing/core/shared_memory_arbiter.h
+++ b/src/tracing/core/shared_memory_arbiter_impl.h
@@ -14,8 +14,8 @@
  * limitations under the License.
  */
 
-#ifndef SRC_TRACING_CORE_SHARED_MEMORY_ARBITER_H_
-#define SRC_TRACING_CORE_SHARED_MEMORY_ARBITER_H_
+#ifndef SRC_TRACING_CORE_SHARED_MEMORY_ARBITER_IMPL_H_
+#define SRC_TRACING_CORE_SHARED_MEMORY_ARBITER_IMPL_H_
 
 #include <stdint.h>
 
@@ -25,6 +25,7 @@
 
 #include "perfetto/tracing/core/basic_types.h"
 #include "perfetto/tracing/core/shared_memory_abi.h"
+#include "perfetto/tracing/core/shared_memory_arbiter.h"
 #include "src/tracing/core/id_allocator.h"
 
 namespace perfetto {
@@ -41,11 +42,8 @@
 // This class is thread-safe and uses locks to do so. Data sources are supposed
 // to interact with this sporadically, only when they run out of space on their
 // current thread-local chunk.
-class SharedMemoryArbiter {
+class SharedMemoryArbiterImpl : public SharedMemoryArbiter {
  public:
-  using OnPagesCompleteCallback =
-      std::function<void(const std::vector<uint32_t>& /*page_indexes*/)>;
-
   // Args:
   // |start|,|size|: boundaries of the shared memory buffer.
   // |page_size|: a multiple of 4KB that defines the granularity of tracing
@@ -53,18 +51,11 @@
   // |OnPagesCompleteCallback|: a callback that will be posted on the passed
   // |TaskRunner| when one or more pages are complete (and hence the Producer
   // should send a NotifySharedMemoryUpdate() to the Service).
-  SharedMemoryArbiter(void* start,
-                      size_t size,
-                      size_t page_size,
-                      OnPagesCompleteCallback,
-                      base::TaskRunner*);
-
-  // Creates a new TraceWriter and assigns it a new WriterID. The WriterID is
-  // written in each chunk header owned by a given TraceWriter and is used by
-  // the Service to reconstruct TracePackets written by the same TraceWriter.
-  // Returns nullptr if all WriterID slots are exhausted.
-  // TODO(primiano): instead of nullptr this should return a NoopWriter.
-  std::unique_ptr<TraceWriter> CreateTraceWriter(BufferID target_buffer = 0);
+  SharedMemoryArbiterImpl(void* start,
+                          size_t size,
+                          size_t page_size,
+                          OnPagesCompleteCallback,
+                          base::TaskRunner*);
 
   // Returns a new Chunk to write tracing data. The call always returns a valid
   // Chunk. TODO(primiano): right now this blocks if there are no free chunks
@@ -82,13 +73,18 @@
     default_page_layout = l;
   }
 
+  // SharedMemoryArbiter implementation.
+  // See include/perfetto/tracing/core/shared_memory_arbiter.h for comments.
+  std::unique_ptr<TraceWriter> CreateTraceWriter(
+      BufferID target_buffer = 0) override;
+
  private:
   friend class TraceWriterImpl;
 
   static SharedMemoryABI::PageLayout default_page_layout;
 
-  SharedMemoryArbiter(const SharedMemoryArbiter&) = delete;
-  SharedMemoryArbiter& operator=(const SharedMemoryArbiter&) = delete;
+  SharedMemoryArbiterImpl(const SharedMemoryArbiterImpl&) = delete;
+  SharedMemoryArbiterImpl& operator=(const SharedMemoryArbiterImpl&) = delete;
 
   // Called by the TraceWriter destructor.
   void ReleaseWriterID(WriterID);
@@ -109,4 +105,4 @@
 
 }  // namespace perfetto
 
-#endif  // SRC_TRACING_CORE_SHARED_MEMORY_ARBITER_H_
+#endif  // SRC_TRACING_CORE_SHARED_MEMORY_ARBITER_IMPL_H_
diff --git a/src/tracing/core/shared_memory_arbiter_unittest.cc b/src/tracing/core/shared_memory_arbiter_impl_unittest.cc
similarity index 90%
rename from src/tracing/core/shared_memory_arbiter_unittest.cc
rename to src/tracing/core/shared_memory_arbiter_impl_unittest.cc
index 9acd260..8a437a1 100644
--- a/src/tracing/core/shared_memory_arbiter_unittest.cc
+++ b/src/tracing/core/shared_memory_arbiter_impl_unittest.cc
@@ -14,7 +14,7 @@
  * limitations under the License.
  */
 
-#include "src/tracing/core/shared_memory_arbiter.h"
+#include "src/tracing/core/shared_memory_arbiter_impl.h"
 
 #include "gtest/gtest.h"
 #include "perfetto/base/utils.h"
@@ -29,7 +29,7 @@
 
 constexpr size_t kMaxWriterID = SharedMemoryABI::kMaxWriterID;
 
-class SharedMemoryArbiterTest : public AlignedBufferTest {
+class SharedMemoryArbiterImplTest : public AlignedBufferTest {
  public:
   void SetUp() override {
     AlignedBufferTest::SetUp();
@@ -38,8 +38,8 @@
         on_pages_complete_(arg);
     };
     task_runner_.reset(new base::TestTaskRunner());
-    arbiter_.reset(new SharedMemoryArbiter(buf(), buf_size(), page_size(),
-                                           callback, task_runner_.get()));
+    arbiter_.reset(new SharedMemoryArbiterImpl(buf(), buf_size(), page_size(),
+                                               callback, task_runner_.get()));
   }
 
   void TearDown() override {
@@ -48,19 +48,19 @@
   }
 
   std::unique_ptr<base::TestTaskRunner> task_runner_;
-  std::unique_ptr<SharedMemoryArbiter> arbiter_;
+  std::unique_ptr<SharedMemoryArbiterImpl> arbiter_;
   std::function<void(const std::vector<uint32_t>&)> on_pages_complete_;
 };
 
 size_t const kPageSizes[] = {4096, 65536};
 INSTANTIATE_TEST_CASE_P(PageSize,
-                        SharedMemoryArbiterTest,
+                        SharedMemoryArbiterImplTest,
                         ::testing::ValuesIn(kPageSizes));
 
 // Checks that chunks that target different buffer IDs are placed in different
 // pages.
-TEST_P(SharedMemoryArbiterTest, ChunksAllocationByTargetBufferID) {
-  SharedMemoryArbiter::set_default_layout_for_testing(
+TEST_P(SharedMemoryArbiterImplTest, ChunksAllocationByTargetBufferID) {
+  SharedMemoryArbiterImpl::set_default_layout_for_testing(
       SharedMemoryABI::PageLayout::kPageDiv4);
   SharedMemoryABI::Chunk chunks[8];
   chunks[0] = arbiter_->GetNewChunk({}, 1 /* target buffer id */, 0);
@@ -112,8 +112,8 @@
 // Because a chunk can share a page only if all other chunks in the page have
 // the same target buffer ID, there is only one possible final distribution:
 // each page is filled with chunks that all belong to the same buffer ID.
-TEST_P(SharedMemoryArbiterTest, GetAndReturnChunks) {
-  SharedMemoryArbiter::set_default_layout_for_testing(
+TEST_P(SharedMemoryArbiterImplTest, GetAndReturnChunks) {
+  SharedMemoryArbiterImpl::set_default_layout_for_testing(
       SharedMemoryABI::PageLayout::kPageDiv14);
   static constexpr size_t kTotChunks = kNumPages * 14;
   SharedMemoryABI::Chunk chunks[kTotChunks];
@@ -155,7 +155,7 @@
 }
 
 // Check that we can actually create up to kMaxWriterID TraceWriter(s).
-TEST_P(SharedMemoryArbiterTest, WriterIDsAllocation) {
+TEST_P(SharedMemoryArbiterImplTest, WriterIDsAllocation) {
   std::map<WriterID, std::unique_ptr<TraceWriter>> writers;
   for (size_t i = 0; i < kMaxWriterID; i++) {
     std::unique_ptr<TraceWriter> writer = arbiter_->CreateTraceWriter(0);
diff --git a/src/tracing/core/trace_writer_impl.cc b/src/tracing/core/trace_writer_impl.cc
index a17e543..451e65d 100644
--- a/src/tracing/core/trace_writer_impl.cc
+++ b/src/tracing/core/trace_writer_impl.cc
@@ -23,7 +23,7 @@
 
 #include "perfetto/base/logging.h"
 #include "perfetto/protozero/proto_utils.h"
-#include "src/tracing/core/shared_memory_arbiter.h"
+#include "src/tracing/core/shared_memory_arbiter_impl.h"
 
 #include "protos/trace_packet.pbzero.h"
 
@@ -40,7 +40,7 @@
 constexpr size_t kPacketHeaderSize = SharedMemoryABI::kPacketHeaderSize;
 }  // namespace
 
-TraceWriterImpl::TraceWriterImpl(SharedMemoryArbiter* shmem_arbiter,
+TraceWriterImpl::TraceWriterImpl(SharedMemoryArbiterImpl* shmem_arbiter,
                                  WriterID id,
                                  BufferID target_buffer)
     : shmem_arbiter_(shmem_arbiter),
diff --git a/src/tracing/core/trace_writer_impl.h b/src/tracing/core/trace_writer_impl.h
index 3c7121d..1f3494f 100644
--- a/src/tracing/core/trace_writer_impl.h
+++ b/src/tracing/core/trace_writer_impl.h
@@ -27,7 +27,7 @@
 
 namespace perfetto {
 
-class SharedMemoryArbiter;
+class SharedMemoryArbiterImpl;
 
 // See //include/perfetto/tracing/core/trace_writer.h for docs.
 class TraceWriterImpl : public TraceWriter,
@@ -35,7 +35,7 @@
  public:
   // TracePacketHandle is defined in trace_writer.h
 
-  TraceWriterImpl(SharedMemoryArbiter*, WriterID, BufferID);
+  TraceWriterImpl(SharedMemoryArbiterImpl*, WriterID, BufferID);
   ~TraceWriterImpl() override;
 
   // TraceWriter implementation. See documentation in trace_writer.h .
@@ -66,7 +66,7 @@
 
   // The per-producer arbiter that coordinates access to the shared memory
   // buffer from several threads.
-  SharedMemoryArbiter* const shmem_arbiter_;
+  SharedMemoryArbiterImpl* const shmem_arbiter_;
 
   // ID of the current writer.
   const WriterID id_;
diff --git a/src/tracing/core/trace_writer_impl_unittest.cc b/src/tracing/core/trace_writer_impl_unittest.cc
index 3b86acf..655a3b2 100644
--- a/src/tracing/core/trace_writer_impl_unittest.cc
+++ b/src/tracing/core/trace_writer_impl_unittest.cc
@@ -20,7 +20,7 @@
 #include "perfetto/base/utils.h"
 #include "perfetto/tracing/core/trace_writer.h"
 #include "src/base/test/test_task_runner.h"
-#include "src/tracing/core/shared_memory_arbiter.h"
+#include "src/tracing/core/shared_memory_arbiter_impl.h"
 #include "src/tracing/test/aligned_buffer_test.h"
 
 #include "protos/trace_packet.pbzero.h"
@@ -31,13 +31,13 @@
 class TraceWriterImplTest : public AlignedBufferTest {
  public:
   void SetUp() override {
-    SharedMemoryArbiter::set_default_layout_for_testing(
+    SharedMemoryArbiterImpl::set_default_layout_for_testing(
         SharedMemoryABI::PageLayout::kPageDiv4);
     AlignedBufferTest::SetUp();
     auto callback = [](const std::vector<uint32_t>& arg) {};
     task_runner_.reset(new base::TestTaskRunner());
-    arbiter_.reset(new SharedMemoryArbiter(buf(), buf_size(), page_size(),
-                                           callback, task_runner_.get()));
+    arbiter_.reset(new SharedMemoryArbiterImpl(buf(), buf_size(), page_size(),
+                                               callback, task_runner_.get()));
   }
 
   void TearDown() override {
@@ -46,7 +46,7 @@
   }
 
   std::unique_ptr<base::TestTaskRunner> task_runner_;
-  std::unique_ptr<SharedMemoryArbiter> arbiter_;
+  std::unique_ptr<SharedMemoryArbiterImpl> arbiter_;
   std::function<void(const std::vector<uint32_t>&)> on_pages_complete_;
 };
 
diff --git a/src/tracing/ipc/producer/producer_ipc_client_impl.cc b/src/tracing/ipc/producer/producer_ipc_client_impl.cc
index 277a9b5..d62ccd9 100644
--- a/src/tracing/ipc/producer/producer_ipc_client_impl.cc
+++ b/src/tracing/ipc/producer/producer_ipc_client_impl.cc
@@ -24,8 +24,8 @@
 #include "perfetto/tracing/core/data_source_config.h"
 #include "perfetto/tracing/core/data_source_descriptor.h"
 #include "perfetto/tracing/core/producer.h"
+#include "perfetto/tracing/core/shared_memory_arbiter.h"
 #include "perfetto/tracing/core/trace_writer.h"
-#include "src/tracing/core/shared_memory_arbiter.h"
 #include "src/tracing/ipc/posix_shared_memory.h"
 
 // TODO think to what happens when ProducerIPCClientImpl gets destroyed
@@ -104,16 +104,15 @@
   auto on_pages_complete = [this](const std::vector<uint32_t>& changed_pages) {
     OnPagesComplete(changed_pages);
   };
-  shared_memory_arbiter_.reset(
-      new SharedMemoryArbiter(shared_memory_->start(), shared_memory_->size(),
-                              4096 /* TODO where does this come from? */,
-                              on_pages_complete, task_runner_));
+  shared_memory_arbiter_ = SharedMemoryArbiter::CreateInstance(
+      shared_memory_.get(), 4096 /* TODO where does this come from? */,
+      on_pages_complete, task_runner_);
 
   producer_->OnConnect();
 }
 
-// Called by SharedMemoryArbiter when some chunks are complete and we need to
-// notify the service about that.
+// Called by SharedMemoryArbiterImpl when some chunks are complete and we need
+// to notify the service about that.
 void ProducerIPCClientImpl::OnPagesComplete(
     const std::vector<uint32_t>& changed_pages) {
   PERFETTO_DCHECK_THREAD(thread_checker_);
diff --git a/src/tracing/ipc/producer/producer_ipc_client_impl.h b/src/tracing/ipc/producer/producer_ipc_client_impl.h
index 745b786..aa2bbf2 100644
--- a/src/tracing/ipc/producer/producer_ipc_client_impl.h
+++ b/src/tracing/ipc/producer/producer_ipc_client_impl.h
@@ -25,6 +25,7 @@
 #include "perfetto/ipc/service_proxy.h"
 #include "perfetto/tracing/core/basic_types.h"
 #include "perfetto/tracing/core/service.h"
+#include "perfetto/tracing/core/shared_memory.h"
 #include "perfetto/tracing/ipc/producer_ipc_client.h"
 
 #include "protos/tracing_service/producer_port.ipc.h"
@@ -81,7 +82,7 @@
   // (e.g. start/stop a data source).
   void OnServiceRequest(const GetAsyncCommandResponse&);
 
-  // Callback passed to SharedMemoryArbiter.
+  // Callback passed to SharedMemoryArbiterImpl.
   void OnPagesComplete(const std::vector<uint32_t>&);
 
   // TODO think to destruction order, do we rely on any specific dtor sequence?