Non functional refactorings to gen classes

This CL makes a bunch of boring refactorings in the
attempt of making next CLs easier to review. No new
functionality is introduced. Major changes:

- Remove forward declaration to proto-derived core classes
  like TraceConfig. In the next CLs they will be moved to
  a different namespace which will make their forward decls
  trickier.
- Rename the ParseFromRawProto methods to ParseFromString to
  match the libprotobuf api.
- Extract a base class for .gen.h class, it will be used later
  by the IPC layer.

Bug: 132880619
Change-Id: I84f49788677002b07283f6a4602dca511c77dd11
diff --git a/Android.bp b/Android.bp
index 9ccb7eb..8a85fb7 100644
--- a/Android.bp
+++ b/Android.bp
@@ -63,6 +63,7 @@
     ":perfetto_include_perfetto_profiling_normalize",
     ":perfetto_include_perfetto_protozero_protozero",
     ":perfetto_include_perfetto_tracing_core_core",
+    ":perfetto_include_perfetto_tracing_core_forward_decls",
     ":perfetto_include_perfetto_tracing_tracing",
     ":perfetto_protos_perfetto_common_cpp_gen",
     ":perfetto_protos_perfetto_common_lite_gen",
@@ -272,6 +273,7 @@
     ":perfetto_include_perfetto_protozero_protozero",
     ":perfetto_include_perfetto_public_public",
     ":perfetto_include_perfetto_tracing_core_core",
+    ":perfetto_include_perfetto_tracing_core_forward_decls",
     ":perfetto_include_perfetto_tracing_tracing",
     ":perfetto_protos_perfetto_common_cpp_gen",
     ":perfetto_protos_perfetto_common_lite_gen",
@@ -460,6 +462,7 @@
     ":perfetto_include_perfetto_ext_tracing_ipc_ipc",
     ":perfetto_include_perfetto_protozero_protozero",
     ":perfetto_include_perfetto_tracing_core_core",
+    ":perfetto_include_perfetto_tracing_core_forward_decls",
     ":perfetto_include_perfetto_tracing_tracing",
     ":perfetto_protos_perfetto_common_cpp_gen",
     ":perfetto_protos_perfetto_common_lite_gen",
@@ -647,6 +650,7 @@
     ":perfetto_include_perfetto_ext_tracing_ipc_ipc",
     ":perfetto_include_perfetto_protozero_protozero",
     ":perfetto_include_perfetto_tracing_core_core",
+    ":perfetto_include_perfetto_tracing_core_forward_decls",
     ":perfetto_include_perfetto_tracing_tracing",
     ":perfetto_protos_perfetto_common_cpp_gen",
     ":perfetto_protos_perfetto_common_lite_gen",
@@ -886,6 +890,11 @@
   name: "perfetto_include_perfetto_tracing_core_core",
 }
 
+// GN: //include/perfetto/tracing/core:forward_decls
+filegroup {
+  name: "perfetto_include_perfetto_tracing_core_forward_decls",
+}
+
 // GN: //include/perfetto/tracing:tracing
 filegroup {
   name: "perfetto_include_perfetto_tracing_tracing",
@@ -905,6 +914,7 @@
     ":perfetto_include_perfetto_profiling_normalize",
     ":perfetto_include_perfetto_protozero_protozero",
     ":perfetto_include_perfetto_tracing_core_core",
+    ":perfetto_include_perfetto_tracing_core_forward_decls",
     ":perfetto_include_perfetto_tracing_tracing",
     ":perfetto_protos_perfetto_common_cpp_gen",
     ":perfetto_protos_perfetto_common_lite_gen",
@@ -4516,6 +4526,7 @@
     "src/protozero/scattered_stream_null_delegate.cc",
     "src/protozero/scattered_stream_writer.cc",
     "src/protozero/static_buffer.cc",
+    "src/protozero/virtual_destructors.cc",
   ],
 }
 
@@ -5498,6 +5509,7 @@
     ":perfetto_include_perfetto_trace_processor_storage",
     ":perfetto_include_perfetto_trace_processor_trace_processor",
     ":perfetto_include_perfetto_tracing_core_core",
+    ":perfetto_include_perfetto_tracing_core_forward_decls",
     ":perfetto_include_perfetto_tracing_tracing",
     ":perfetto_protos_perfetto_common_cpp_gen",
     ":perfetto_protos_perfetto_common_lite_gen",
@@ -6075,6 +6087,7 @@
     ":perfetto_include_perfetto_ext_tracing_ipc_ipc",
     ":perfetto_include_perfetto_protozero_protozero",
     ":perfetto_include_perfetto_tracing_core_core",
+    ":perfetto_include_perfetto_tracing_core_forward_decls",
     ":perfetto_include_perfetto_tracing_tracing",
     ":perfetto_protos_perfetto_common_cpp_gen",
     ":perfetto_protos_perfetto_common_lite_gen",
diff --git a/BUILD b/BUILD
index d7c5923..dae81c7 100644
--- a/BUILD
+++ b/BUILD
@@ -149,6 +149,7 @@
         ":include_perfetto_protozero_protozero",
         ":include_perfetto_public_public",
         ":include_perfetto_tracing_core_core",
+        ":include_perfetto_tracing_core_forward_decls",
         ":include_perfetto_tracing_tracing",
     ],
     deps = [
@@ -354,6 +355,7 @@
     srcs = [
         "include/perfetto/protozero/contiguous_memory_range.h",
         "include/perfetto/protozero/copyable_ptr.h",
+        "include/perfetto/protozero/cpp_message_obj.h",
         "include/perfetto/protozero/field.h",
         "include/perfetto/protozero/message.h",
         "include/perfetto/protozero/message_handle.h",
@@ -413,6 +415,14 @@
     ],
 )
 
+# GN target: //include/perfetto/tracing/core:forward_decls
+filegroup(
+    name = "include_perfetto_tracing_core_forward_decls",
+    srcs = [
+        "include/perfetto/tracing/core/forward_decls.h",
+    ],
+)
+
 # GN target: //include/perfetto/tracing:tracing
 filegroup(
     name = "include_perfetto_tracing_tracing",
@@ -555,6 +565,7 @@
         "src/protozero/scattered_stream_null_delegate.cc",
         "src/protozero/scattered_stream_writer.cc",
         "src/protozero/static_buffer.cc",
+        "src/protozero/virtual_destructors.cc",
     ],
 )
 
@@ -2350,6 +2361,7 @@
         ":include_perfetto_ext_tracing_ipc_ipc",
         ":include_perfetto_protozero_protozero",
         ":include_perfetto_tracing_core_core",
+        ":include_perfetto_tracing_core_forward_decls",
         ":include_perfetto_tracing_tracing",
     ],
     visibility = [
@@ -2420,6 +2432,7 @@
         ":include_perfetto_ext_tracing_ipc_ipc",
         ":include_perfetto_protozero_protozero",
         ":include_perfetto_tracing_core_core",
+        ":include_perfetto_tracing_core_forward_decls",
         ":include_perfetto_tracing_tracing",
         ":src_android_internal_headers",
         ":src_android_internal_lazy_library_loader",
diff --git a/BUILD.gn b/BUILD.gn
index 6e2753d..85475a9 100644
--- a/BUILD.gn
+++ b/BUILD.gn
@@ -113,7 +113,6 @@
 
     # For checking all generated xxx.gen.{cc,h} files without waiting for
     # embedders to try to use them and fail.
-    "protos/perfetto/trace:cpp",
     "protos/perfetto/config:cpp",
     "protos/perfetto/common:cpp",
 
diff --git a/include/perfetto/ext/tracing/core/commit_data_request.h b/include/perfetto/ext/tracing/core/commit_data_request.h
index baff757..f87b0d4 100644
--- a/include/perfetto/ext/tracing/core/commit_data_request.h
+++ b/include/perfetto/ext/tracing/core/commit_data_request.h
@@ -17,11 +17,12 @@
 #ifndef INCLUDE_PERFETTO_EXT_TRACING_CORE_COMMIT_DATA_REQUEST_H_
 #define INCLUDE_PERFETTO_EXT_TRACING_CORE_COMMIT_DATA_REQUEST_H_
 
-// This header exists only for legacy code that used to refer to the
-// checked-in auto-generated code, before it was moved to be a build-time gen
-// rule. DO NOT add any new includes to this header, instead directly include
-// the one below.
-// TODO(primiano): cleanup call-sites and remove this header.
+// Creates the aliases in the ::perfetto namespace, doing things like:
+// using ::perfetto::Foo = ::perfetto::protos::gen::Foo.
+// See comments in forward_decls.h for the historical reasons of this
+// indirection layer.
+#include "perfetto/tracing/core/forward_decls.h"
+
 #include "protos/perfetto/common/commit_data_request.gen.h"
 
 #endif  // INCLUDE_PERFETTO_EXT_TRACING_CORE_COMMIT_DATA_REQUEST_H_
diff --git a/include/perfetto/ext/tracing/core/consumer.h b/include/perfetto/ext/tracing/core/consumer.h
index ccbd072..0cbd158 100644
--- a/include/perfetto/ext/tracing/core/consumer.h
+++ b/include/perfetto/ext/tracing/core/consumer.h
@@ -22,13 +22,10 @@
 #include "perfetto/base/export.h"
 #include "perfetto/ext/tracing/core/basic_types.h"
 #include "perfetto/ext/tracing/core/observable_events.h"
-
+#include "perfetto/tracing/core/forward_decls.h"
 namespace perfetto {
 
-class TraceConfig;
 class TracePacket;
-class TraceStats;
-class TracingServiceState;
 
 class PERFETTO_EXPORT Consumer {
  public:
diff --git a/include/perfetto/ext/tracing/core/observable_events.h b/include/perfetto/ext/tracing/core/observable_events.h
index abf408d..9459558 100644
--- a/include/perfetto/ext/tracing/core/observable_events.h
+++ b/include/perfetto/ext/tracing/core/observable_events.h
@@ -17,11 +17,12 @@
 #ifndef INCLUDE_PERFETTO_EXT_TRACING_CORE_OBSERVABLE_EVENTS_H_
 #define INCLUDE_PERFETTO_EXT_TRACING_CORE_OBSERVABLE_EVENTS_H_
 
-// This header exists only for legacy code that used to refer to the
-// checked-in auto-generated code, before it was moved to be a build-time gen
-// rule. DO NOT add any new includes to this header, instead directly include
-// the one below.
-// TODO(primiano): cleanup call-sites and remove this header.
+// Creates the aliases in the ::perfetto namespace, doing things like:
+// using ::perfetto::Foo = ::perfetto::protos::gen::Foo.
+// See comments in forward_decls.h for the historical reasons of this
+// indirection layer.
+#include "perfetto/tracing/core/forward_decls.h"
+
 #include "protos/perfetto/common/observable_events.gen.h"
 
 #endif  // INCLUDE_PERFETTO_EXT_TRACING_CORE_OBSERVABLE_EVENTS_H_
diff --git a/include/perfetto/ext/tracing/core/producer.h b/include/perfetto/ext/tracing/core/producer.h
index 30775f7..5c45d8f 100644
--- a/include/perfetto/ext/tracing/core/producer.h
+++ b/include/perfetto/ext/tracing/core/producer.h
@@ -19,10 +19,9 @@
 
 #include "perfetto/base/export.h"
 #include "perfetto/ext/tracing/core/basic_types.h"
-
+#include "perfetto/tracing/core/forward_decls.h"
 namespace perfetto {
 
-class DataSourceConfig;
 class SharedMemory;
 
 // A Producer is an entity that connects to the write-only port of the Service
diff --git a/include/perfetto/ext/tracing/core/trace_stats.h b/include/perfetto/ext/tracing/core/trace_stats.h
index c4f9930..b85cb43 100644
--- a/include/perfetto/ext/tracing/core/trace_stats.h
+++ b/include/perfetto/ext/tracing/core/trace_stats.h
@@ -17,11 +17,12 @@
 #ifndef INCLUDE_PERFETTO_EXT_TRACING_CORE_TRACE_STATS_H_
 #define INCLUDE_PERFETTO_EXT_TRACING_CORE_TRACE_STATS_H_
 
-// This header exists only for legacy code that used to refer to the
-// checked-in auto-generated code, before it was moved to be a build-time gen
-// rule. DO NOT add any new includes to this header, instead directly include
-// the one below.
-// TODO(primiano): cleanup call-sites and remove this header.
+// Creates the aliases in the ::perfetto namespace, doing things like:
+// using ::perfetto::Foo = ::perfetto::protos::gen::Foo.
+// See comments in forward_decls.h for the historical reasons of this
+// indirection layer.
+#include "perfetto/tracing/core/forward_decls.h"
+
 #include "protos/perfetto/common/trace_stats.gen.h"
 
 #endif  // INCLUDE_PERFETTO_EXT_TRACING_CORE_TRACE_STATS_H_
diff --git a/include/perfetto/ext/tracing/core/tracing_service.h b/include/perfetto/ext/tracing/core/tracing_service.h
index c39d2e2..c097a6e 100644
--- a/include/perfetto/ext/tracing/core/tracing_service.h
+++ b/include/perfetto/ext/tracing/core/tracing_service.h
@@ -28,6 +28,7 @@
 #include "perfetto/ext/tracing/core/basic_types.h"
 #include "perfetto/ext/tracing/core/shared_memory.h"
 #include "perfetto/tracing/buffer_exhausted_policy.h"
+#include "perfetto/tracing/core/forward_decls.h"
 
 namespace perfetto {
 
@@ -35,13 +36,9 @@
 class TaskRunner;
 }  // namespace base
 
-class CommitDataRequest;
 class Consumer;
-class DataSourceDescriptor;
 class Producer;
 class SharedMemoryArbiter;
-class TracingServiceState;
-class TraceConfig;
 class TraceWriter;
 
 // TODO: for the moment this assumes that all the calls happen on the same
diff --git a/include/perfetto/protozero/BUILD.gn b/include/perfetto/protozero/BUILD.gn
index 7afe1b9..b528a5b 100644
--- a/include/perfetto/protozero/BUILD.gn
+++ b/include/perfetto/protozero/BUILD.gn
@@ -19,6 +19,7 @@
   sources = [
     "contiguous_memory_range.h",
     "copyable_ptr.h",
+    "cpp_message_obj.h",
     "field.h",
     "message.h",
     "message_handle.h",
diff --git a/include/perfetto/protozero/cpp_message_obj.h b/include/perfetto/protozero/cpp_message_obj.h
new file mode 100644
index 0000000..f52574a
--- /dev/null
+++ b/include/perfetto/protozero/cpp_message_obj.h
@@ -0,0 +1,47 @@
+
+/*
+ * Copyright (C) 2019 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_PROTOZERO_CPP_MESSAGE_OBJ_H_
+#define INCLUDE_PERFETTO_PROTOZERO_CPP_MESSAGE_OBJ_H_
+
+#include <stdint.h>
+
+#include <string>
+#include <vector>
+
+#include "perfetto/base/export.h"
+
+namespace protozero {
+
+// Base class for generated .gen.h classes, which are full C++ objects that
+// support both ser and deserialization (but are not zero-copy).
+// This is only used by the "cpp" targets not the "pbzero" ones.
+class PERFETTO_EXPORT CppMessageObj {
+ public:
+  virtual ~CppMessageObj();
+  virtual std::string SerializeAsString() const = 0;
+  virtual std::vector<uint8_t> SerializeAsArray() const = 0;
+  virtual bool ParseFromArray(const void*, size_t) = 0;
+
+  bool ParseFromString(const std::string& str) {
+    return ParseFromArray(str.data(), str.size());
+  }
+};
+
+}  // namespace protozero
+
+#endif  // INCLUDE_PERFETTO_PROTOZERO_CPP_MESSAGE_OBJ_H_
diff --git a/include/perfetto/tracing/BUILD.gn b/include/perfetto/tracing/BUILD.gn
index 57d8619..2a65756 100644
--- a/include/perfetto/tracing/BUILD.gn
+++ b/include/perfetto/tracing/BUILD.gn
@@ -21,6 +21,7 @@
     "../../../protos/perfetto/trace/track_event:zero",
     "../base",
     "../protozero",
+    "core:forward_decls",
   ]
 
   sources = [
diff --git a/include/perfetto/tracing/core/BUILD.gn b/include/perfetto/tracing/core/BUILD.gn
index 8cc4829..a7f4a4c 100644
--- a/include/perfetto/tracing/core/BUILD.gn
+++ b/include/perfetto/tracing/core/BUILD.gn
@@ -14,6 +14,7 @@
 
 source_set("core") {
   public_deps = [
+    ":forward_decls",
     "../../../../protos/perfetto/common:cpp",
     "../../../../protos/perfetto/config:cpp",
   ]
@@ -25,3 +26,12 @@
     "tracing_service_state.h",
   ]
 }
+
+# This is a separate target so other targets in include/**/BUILD.gn can pull
+# forward_decls.h without polluting their public_deps with the proto-generated
+# {common,config}:cpp, which would slow-down build time.
+source_set("forward_decls") {
+  sources = [
+    "forward_decls.h",
+  ]
+}
diff --git a/include/perfetto/tracing/core/chrome_config.h b/include/perfetto/tracing/core/chrome_config.h
index dff4d87..2334b91 100644
--- a/include/perfetto/tracing/core/chrome_config.h
+++ b/include/perfetto/tracing/core/chrome_config.h
@@ -17,11 +17,12 @@
 #ifndef INCLUDE_PERFETTO_TRACING_CORE_CHROME_CONFIG_H_
 #define INCLUDE_PERFETTO_TRACING_CORE_CHROME_CONFIG_H_
 
-// This header exists only for legacy code that used to refer to the
-// checked-in auto-generated code, before it was moved to be a build-time gen
-// rule. DO NOT add any new includes to this header, instead directly include
-// the one below.
-// TODO(primiano): cleanup call-sites and remove this header.
+// Creates the aliases in the ::perfetto namespace, doing things like:
+// using ::perfetto::Foo = ::perfetto::protos::gen::Foo.
+// See comments in forward_decls.h for the historical reasons of this
+// indirection layer.
+#include "perfetto/tracing/core/forward_decls.h"
+
 #include "protos/perfetto/config/chrome/chrome_config.gen.h"
 
 #endif  // INCLUDE_PERFETTO_TRACING_CORE_CHROME_CONFIG_H_
diff --git a/include/perfetto/tracing/core/data_source_config.h b/include/perfetto/tracing/core/data_source_config.h
index 9b7966c..765a642 100644
--- a/include/perfetto/tracing/core/data_source_config.h
+++ b/include/perfetto/tracing/core/data_source_config.h
@@ -17,11 +17,12 @@
 #ifndef INCLUDE_PERFETTO_TRACING_CORE_DATA_SOURCE_CONFIG_H_
 #define INCLUDE_PERFETTO_TRACING_CORE_DATA_SOURCE_CONFIG_H_
 
-// This header exists only for legacy code that used to refer to the
-// checked-in auto-generated code, before it was moved to be a build-time gen
-// rule. DO NOT add any new includes to this header, instead directly include
-// the one below.
-// TODO(primiano): cleanup call-sites and remove this header.
+// Creates the aliases in the ::perfetto namespace, doing things like:
+// using ::perfetto::Foo = ::perfetto::protos::gen::Foo.
+// See comments in forward_decls.h for the historical reasons of this
+// indirection layer.
+#include "perfetto/tracing/core/forward_decls.h"
+
 #include "protos/perfetto/config/data_source_config.gen.h"
 
 #endif  // INCLUDE_PERFETTO_TRACING_CORE_DATA_SOURCE_CONFIG_H_
diff --git a/include/perfetto/tracing/core/data_source_descriptor.h b/include/perfetto/tracing/core/data_source_descriptor.h
index 75818bf..a9987d6 100644
--- a/include/perfetto/tracing/core/data_source_descriptor.h
+++ b/include/perfetto/tracing/core/data_source_descriptor.h
@@ -17,11 +17,12 @@
 #ifndef INCLUDE_PERFETTO_TRACING_CORE_DATA_SOURCE_DESCRIPTOR_H_
 #define INCLUDE_PERFETTO_TRACING_CORE_DATA_SOURCE_DESCRIPTOR_H_
 
-// This header exists only for legacy code that used to refer to the
-// checked-in auto-generated code, before it was moved to be a build-time gen
-// rule. DO NOT add any new includes to this header, instead directly include
-// the one below.
-// TODO(primiano): cleanup call-sites and remove this header.
+// Creates the aliases in the ::perfetto namespace, doing things like:
+// using ::perfetto::Foo = ::perfetto::protos::gen::Foo.
+// See comments in forward_decls.h for the historical reasons of this
+// indirection layer.
+#include "perfetto/tracing/core/forward_decls.h"
+
 #include "protos/perfetto/common/data_source_descriptor.gen.h"
 
 #endif  // INCLUDE_PERFETTO_TRACING_CORE_DATA_SOURCE_DESCRIPTOR_H_
diff --git a/include/perfetto/tracing/core/forward_decls.h b/include/perfetto/tracing/core/forward_decls.h
new file mode 100644
index 0000000..8d5319c
--- /dev/null
+++ b/include/perfetto/tracing/core/forward_decls.h
@@ -0,0 +1,48 @@
+/*
+ * Copyright (C) 2019 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_FORWARD_DECLS_H_
+#define INCLUDE_PERFETTO_TRACING_CORE_FORWARD_DECLS_H_
+
+// Forward declares classes that are generated at build-time from protos.
+// First of all, why are we forward declaring at all?
+//  1. Chromium diverges from the Google style guide on this, because forward
+//     declarations typically make build times faster, and that's a desirable
+//     property for a large and complex codebase.
+//  2. Adding #include to build-time-generated headers from headers typically
+//     creates subtle build errors that are hard to spot in GN. This is because
+//     once a standard header (say foo.h9 has an #include "protos/foo.gen.h",
+//     the build target that depends on foo.h needs to depend on the genrule
+//     that generates foo.gen.h. This is achievable using public_deps in GN but
+//     is not testable / enforceable, hence too easy to get wrong.
+
+// TODO(primiano): update forward declarations and add the rest of the story in
+// the next CLs.
+
+namespace perfetto {
+
+class ChromeConfig;
+class CommitDataRequest;
+class DataSourceConfig;
+class DataSourceDescriptor;
+class ObservableEvents;
+class TraceConfig;
+class TraceStats;
+class TracingServiceState;
+
+}  // namespace perfetto
+
+#endif  // INCLUDE_PERFETTO_TRACING_CORE_FORWARD_DECLS_H_
diff --git a/include/perfetto/tracing/core/trace_config.h b/include/perfetto/tracing/core/trace_config.h
index d2ec6e1..3e2a830 100644
--- a/include/perfetto/tracing/core/trace_config.h
+++ b/include/perfetto/tracing/core/trace_config.h
@@ -17,11 +17,12 @@
 #ifndef INCLUDE_PERFETTO_TRACING_CORE_TRACE_CONFIG_H_
 #define INCLUDE_PERFETTO_TRACING_CORE_TRACE_CONFIG_H_
 
-// This header exists only for legacy code that used to refer to the
-// checked-in auto-generated code, before it was moved to be a build-time gen
-// rule. DO NOT add any new includes to this header, instead directly include
-// the one below.
-// TODO(primiano): cleanup call-sites and remove this header.
+// Creates the aliases in the ::perfetto namespace, doing things like:
+// using ::perfetto::Foo = ::perfetto::protos::gen::Foo.
+// See comments in forward_decls.h for the historical reasons of this
+// indirection layer.
+#include "perfetto/tracing/core/forward_decls.h"
+
 #include "protos/perfetto/config/trace_config.gen.h"
 
 #endif  // INCLUDE_PERFETTO_TRACING_CORE_TRACE_CONFIG_H_
diff --git a/include/perfetto/tracing/core/tracing_service_state.h b/include/perfetto/tracing/core/tracing_service_state.h
index c9d74cd..192cd81 100644
--- a/include/perfetto/tracing/core/tracing_service_state.h
+++ b/include/perfetto/tracing/core/tracing_service_state.h
@@ -18,11 +18,12 @@
 #ifndef INCLUDE_PERFETTO_TRACING_CORE_TRACING_SERVICE_STATE_H_
 #define INCLUDE_PERFETTO_TRACING_CORE_TRACING_SERVICE_STATE_H_
 
-// This header exists only for legacy code that used to refer to the
-// checked-in auto-generated code, before it was moved to be a build-time gen
-// rule. DO NOT add any new includes to this header, instead directly include
-// the one below.
-// TODO(primiano): cleanup call-sites and remove this header.
+// Creates the aliases in the ::perfetto namespace, doing things like:
+// using ::perfetto::Foo = ::perfetto::protos::gen::Foo.
+// See comments in forward_decls.h for the historical reasons of this
+// indirection layer.
+#include "perfetto/tracing/core/forward_decls.h"
+
 #include "protos/perfetto/common/tracing_service_state.gen.h"
 
 #endif  // INCLUDE_PERFETTO_TRACING_CORE_TRACING_SERVICE_STATE_H_
diff --git a/include/perfetto/tracing/data_source.h b/include/perfetto/tracing/data_source.h
index dfbeaed..923e176 100644
--- a/include/perfetto/tracing/data_source.h
+++ b/include/perfetto/tracing/data_source.h
@@ -36,11 +36,13 @@
 #include "perfetto/protozero/message.h"
 #include "perfetto/protozero/message_handle.h"
 #include "perfetto/tracing/buffer_exhausted_policy.h"
+#include "perfetto/tracing/core/forward_decls.h"
 #include "perfetto/tracing/internal/basic_types.h"
 #include "perfetto/tracing/internal/data_source_internal.h"
 #include "perfetto/tracing/internal/tracing_muxer.h"
 #include "perfetto/tracing/locked_handle.h"
 #include "perfetto/tracing/trace_writer_base.h"
+
 #include "protos/perfetto/trace/trace_packet.pbzero.h"
 
 namespace perfetto {
@@ -51,8 +53,6 @@
 class TrackEventDataSource;
 }  // namespace internal
 
-class DataSourceConfig;
-
 // Base class with the virtual methods to get start/stop notifications.
 // Embedders are supposed to derive the templated version below, not this one.
 class PERFETTO_EXPORT DataSourceBase {
diff --git a/include/perfetto/tracing/internal/tracing_muxer.h b/include/perfetto/tracing/internal/tracing_muxer.h
index 4556ed3..4363ca5 100644
--- a/include/perfetto/tracing/internal/tracing_muxer.h
+++ b/include/perfetto/tracing/internal/tracing_muxer.h
@@ -21,14 +21,13 @@
 #include <memory>
 
 #include "perfetto/base/export.h"
+#include "perfetto/tracing/core/forward_decls.h"
 #include "perfetto/tracing/internal/basic_types.h"
 #include "perfetto/tracing/internal/tracing_tls.h"
 #include "perfetto/tracing/platform.h"
-
 namespace perfetto {
 
 class DataSourceBase;
-class DataSourceDescriptor;
 class TraceWriterBase;
 struct TracingInitArgs;
 class TracingSession;
diff --git a/include/perfetto/tracing/internal/track_event_internal.h b/include/perfetto/tracing/internal/track_event_internal.h
index a1465e5..7329201 100644
--- a/include/perfetto/tracing/internal/track_event_internal.h
+++ b/include/perfetto/tracing/internal/track_event_internal.h
@@ -17,17 +17,16 @@
 #ifndef INCLUDE_PERFETTO_TRACING_INTERNAL_TRACK_EVENT_INTERNAL_H_
 #define INCLUDE_PERFETTO_TRACING_INTERNAL_TRACK_EVENT_INTERNAL_H_
 
+#include <unordered_map>
+
 #include "perfetto/protozero/scattered_heap_buffer.h"
+#include "perfetto/tracing/core/forward_decls.h"
 #include "perfetto/tracing/trace_writer_base.h"
 #include "protos/perfetto/trace/interned_data/interned_data.pbzero.h"
 #include "protos/perfetto/trace/track_event/track_event.pbzero.h"
 
-#include <unordered_map>
-
 namespace perfetto {
 class EventContext;
-class DataSourceConfig;
-class DataSourceDescriptor;
 
 namespace internal {
 class TrackEventCategoryRegistry;
diff --git a/include/perfetto/tracing/tracing.h b/include/perfetto/tracing/tracing.h
index 5aa0028..023e6f0 100644
--- a/include/perfetto/tracing/tracing.h
+++ b/include/perfetto/tracing/tracing.h
@@ -27,12 +27,11 @@
 
 #include "perfetto/base/export.h"
 #include "perfetto/base/logging.h"
-
+#include "perfetto/tracing/core/forward_decls.h"
 namespace perfetto {
 
 class TracingBackend;
 class Platform;
-class TraceConfig;
 class TracingSession;  // Declared below.
 
 enum BackendType : uint32_t {
diff --git a/protos/perfetto/trace/BUILD.gn b/protos/perfetto/trace/BUILD.gn
index bc312e0..850c133 100644
--- a/protos/perfetto/trace/BUILD.gn
+++ b/protos/perfetto/trace/BUILD.gn
@@ -58,14 +58,11 @@
   ]
 }
 
-group("cpp") {
-  public_deps = [
-    ":minimal_cpp",
-    ":non_minimal_cpp",
-  ]
-}
-
 perfetto_proto_library("non_minimal_@TYPE@") {
+  proto_generators = [
+    "lite",
+    "zero",
+  ]
   deps = [
     ":minimal_@TYPE@",
     "../config:@TYPE@",
diff --git a/protos/perfetto/trace/ftrace/BUILD.gn b/protos/perfetto/trace/ftrace/BUILD.gn
index 535a119..bda3817 100644
--- a/protos/perfetto/trace/ftrace/BUILD.gn
+++ b/protos/perfetto/trace/ftrace/BUILD.gn
@@ -17,6 +17,10 @@
 import("all_protos.gni")
 
 perfetto_proto_library("@TYPE@") {
+  proto_generators = [
+    "zero",
+    "lite",
+  ]
   sources = ftrace_proto_names
 }
 
diff --git a/src/perfetto_cmd/trigger_producer.h b/src/perfetto_cmd/trigger_producer.h
index d12c178..0a31bd3 100644
--- a/src/perfetto_cmd/trigger_producer.h
+++ b/src/perfetto_cmd/trigger_producer.h
@@ -24,11 +24,9 @@
 #include "perfetto/ext/base/weak_ptr.h"
 #include "perfetto/ext/tracing/core/producer.h"
 #include "perfetto/ext/tracing/core/tracing_service.h"
-
+#include "perfetto/tracing/core/forward_decls.h"
 namespace perfetto {
 
-class DataSourceConfig;
-
 // This is a producer that only sends the provided |triggers| to the service. It
 // will never register any data sources.
 class TriggerProducer : public Producer {
diff --git a/src/profiling/memory/heapprofd_producer.cc b/src/profiling/memory/heapprofd_producer.cc
index cdfca23..2a02b64 100644
--- a/src/profiling/memory/heapprofd_producer.cc
+++ b/src/profiling/memory/heapprofd_producer.cc
@@ -296,7 +296,7 @@
   }
 
   HeapprofdConfig heapprofd_config;
-  heapprofd_config.ParseRawProto(ds_config.heapprofd_config_raw());
+  heapprofd_config.ParseFromString(ds_config.heapprofd_config_raw());
 
   if (heapprofd_config.all() && !heapprofd_config.pid().empty())
     PERFETTO_ELOG("No point setting all and pid");
diff --git a/src/profiling/memory/java_hprof_producer.cc b/src/profiling/memory/java_hprof_producer.cc
index 82346ec..9d101ff 100644
--- a/src/profiling/memory/java_hprof_producer.cc
+++ b/src/profiling/memory/java_hprof_producer.cc
@@ -77,7 +77,7 @@
     return;
   }
   JavaHprofConfig config;
-  config.ParseRawProto(ds_config.java_hprof_config_raw());
+  config.ParseFromString(ds_config.java_hprof_config_raw());
   DataSource ds;
   ds.id = id;
   for (uint64_t pid : config.pid())
diff --git a/src/profiling/perf/BUILD.gn b/src/profiling/perf/BUILD.gn
index e24d619..dba1ca2 100644
--- a/src/profiling/perf/BUILD.gn
+++ b/src/profiling/perf/BUILD.gn
@@ -51,6 +51,9 @@
     "../../../src/base:unix_socket",
     "../../../src/tracing:ipc",
   ]
+  public_deps = [
+    "../../../include/perfetto/tracing/core",
+  ]
   sources = [
     "event_config.h",
     "event_reader.cc",
diff --git a/src/profiling/perf/event_config.h b/src/profiling/perf/event_config.h
index 3b17ef5..da53a0b 100644
--- a/src/profiling/perf/event_config.h
+++ b/src/profiling/perf/event_config.h
@@ -22,7 +22,8 @@
 #include <sys/types.h>
 
 #include "perfetto/ext/base/optional.h"
-#include "protos/perfetto/config/data_source_config.gen.h"
+#include "perfetto/tracing/core/data_source_config.h"
+
 #include "protos/perfetto/config/profiling/perf_event_config.pbzero.h"
 
 namespace perfetto {
diff --git a/src/profiling/perf/event_config_unittest.cc b/src/profiling/perf/event_config_unittest.cc
index 1e32374..6598eb4 100644
--- a/src/profiling/perf/event_config_unittest.cc
+++ b/src/profiling/perf/event_config_unittest.cc
@@ -22,10 +22,11 @@
 #include "perfetto/base/logging.h"
 #include "perfetto/ext/base/optional.h"
 #include "perfetto/protozero/scattered_heap_buffer.h"
-#include "protos/perfetto/config/data_source_config.gen.h"
+#include "perfetto/tracing/core/data_source_config.h"
+#include "test/gtest_and_gmock.h"
+
 #include "protos/perfetto/config/data_source_config.pbzero.h"
 #include "protos/perfetto/config/profiling/perf_event_config.pbzero.h"
-#include "test/gtest_and_gmock.h"
 
 namespace perfetto {
 namespace profiling {
@@ -37,14 +38,14 @@
   protozero::HeapBuffered<protos::pbzero::DataSourceConfig> ds_config;
   ds_config->set_perf_event_config_raw(pb_config.SerializeAsString());
   DataSourceConfig cfg;
-  PERFETTO_CHECK(cfg.ParseRawProto(ds_config.SerializeAsString()));
+  PERFETTO_CHECK(cfg.ParseFromString(ds_config.SerializeAsString()));
   return cfg;
 }
 
 TEST(EventConfigTest, TidRequired) {
   // Doesn't pass validation without a TID
   DataSourceConfig cfg;
-  ASSERT_TRUE(cfg.ParseRawProto(std::string{}));
+  ASSERT_TRUE(cfg.ParseFromString(""));
 
   base::Optional<EventConfig> event_config = EventConfig::Create(cfg);
   ASSERT_FALSE(event_config.has_value());
diff --git a/src/protozero/BUILD.gn b/src/protozero/BUILD.gn
index 23469d8..3161670 100644
--- a/src/protozero/BUILD.gn
+++ b/src/protozero/BUILD.gn
@@ -37,6 +37,7 @@
     "scattered_stream_null_delegate.cc",
     "scattered_stream_writer.cc",
     "static_buffer.cc",
+    "virtual_destructors.cc",
   ]
 }
 
diff --git a/src/protozero/protoc_plugin/cppgen_plugin.cc b/src/protozero/protoc_plugin/cppgen_plugin.cc
index 78ac16a..cdfaf18 100644
--- a/src/protozero/protoc_plugin/cppgen_plugin.cc
+++ b/src/protozero/protoc_plugin/cppgen_plugin.cc
@@ -137,6 +137,7 @@
   h_printer.Print("#include <vector>\n");
   h_printer.Print("#include <string>\n");
   h_printer.Print("#include <type_traits>\n\n");
+  h_printer.Print("#include \"perfetto/protozero/cpp_message_obj.h\"\n");
   h_printer.Print("#include \"perfetto/protozero/copyable_ptr.h\"\n");
   h_printer.Print("#include \"perfetto/base/export.h\"\n\n");
 
@@ -500,7 +501,9 @@
 
 void CppObjGenerator::GenClassDecl(const Descriptor* msg, Printer* p) const {
   std::string full_name = GetFullName(msg);
-  p->Print("\nclass PERFETTO_EXPORT $n$ {\n", "n", full_name);
+  p->Print(
+      "\nclass PERFETTO_EXPORT $n$ : public ::protozero::CppMessageObj {\n",
+      "n", full_name);
   p->Print(" public:\n");
   p->Indent();
 
@@ -530,7 +533,7 @@
   p->Print("};\n\n");
 
   p->Print("$n$();\n", "n", full_name);
-  p->Print("~$n$();\n", "n", full_name);
+  p->Print("~$n$() override;\n", "n", full_name);
   p->Print("$n$($n$&&) noexcept;\n", "n", full_name);
   p->Print("$n$& operator=($n$&&);\n", "n", full_name);
   p->Print("$n$(const $n$&);\n", "n", full_name);
@@ -542,21 +545,16 @@
   p->Print("\n");
 
   std::string proto_type = GetFullName(msg, true);
-  p->Print("// Raw proto decoding.\n");
-  p->Print("bool ParseFromArray(const void*, size_t);\n");
-  p->Print("bool ParseRawProto(const std::string& str) {\n");
-  p->Print("  return ParseFromArray(str.data(), str.size());\n");
-  p->Print("}\n");
-
-  p->Print("std::string SerializeAsString() const;\n");
-  p->Print("std::vector<uint8_t> SerializeAsArray() const;\n");
+  p->Print("bool ParseFromArray(const void*, size_t) override;\n");
+  p->Print("std::string SerializeAsString() const override;\n");
+  p->Print("std::vector<uint8_t> SerializeAsArray() const override;\n");
   p->Print("void Serialize(::protozero::Message*) const;\n");
 
   p->Print("// (DEPRECATED) Conversion methods from/to libprotobuf types.\n");
   p->Print("// These two will go away soon, see go/perfetto-libprotobuf.\n");
   p->Print(
       "template <typename T /*$p$*/> void FromProto(const T& pb_obj) { "
-      "ParseRawProto(pb_obj.SerializeAsString()); }\n",
+      "ParseFromString(pb_obj.SerializeAsString()); }\n",
       "p", proto_type);
   p->Print(
       "template <typename T /*$p$*/> void ToProto(T* pb_obj) const { "
@@ -680,7 +678,7 @@
 
   std::string proto_type = GetFullName(msg, true);
 
-  // Generate the ParseRawProto() method definition.
+  // Generate the ParseFromArray() method definition.
   p->Print("bool $f$::ParseFromArray(const void* raw, size_t size) {\n", "f",
            full_name);
   p->Indent();
@@ -711,7 +709,7 @@
     } else {
       std::string statement;
       if (field->type() == TYPE_MESSAGE) {
-        statement = "$rval$.ParseRawProto(field.as_std_string());\n";
+        statement = "$rval$.ParseFromString(field.as_std_string());\n";
       } else {
         if (field->type() == TYPE_SINT32 || field->type() == TYPE_SINT64) {
           // sint32/64 fields are special and need to be zig-zag-decoded.
diff --git a/src/protozero/test/cppgen_conformance_unittest.cc b/src/protozero/test/cppgen_conformance_unittest.cc
index 040b507..ed12707 100644
--- a/src/protozero/test/cppgen_conformance_unittest.cc
+++ b/src/protozero/test/cppgen_conformance_unittest.cc
@@ -109,7 +109,7 @@
   std::string serialized = gold_msg.SerializeAsString();
 
   pbtest::EveryField msg;
-  EXPECT_TRUE(msg.ParseRawProto(serialized));
+  EXPECT_TRUE(msg.ParseFromString(serialized));
   CheckTestingFields(msg);
 }
 
@@ -119,7 +119,7 @@
   std::string serialized = msg.SerializeAsString();
 
   pbtest::EveryField dec_msg;
-  dec_msg.ParseRawProto(serialized);
+  dec_msg.ParseFromString(serialized);
   CheckTestingFields(dec_msg);
   EXPECT_EQ(serialized.size(), dec_msg.SerializeAsString().size());
 }
@@ -192,7 +192,7 @@
   // the v1 message.
   {
     pbtest::TestVersioning_V1 msg_v1;
-    EXPECT_TRUE(msg_v1.ParseRawProto(serialized));
+    EXPECT_TRUE(msg_v1.ParseFromString(serialized));
     EXPECT_EQ(msg_v1.root_int(), 10);
     EXPECT_EQ(msg_v1.enumz_size(), 3);
     // These are to workaround "ODR-usage" rules that would require that the
@@ -225,7 +225,7 @@
   // fields have been preserved in the double de/serializataion across versions.
   {
     pbtest::TestVersioning_V2 msg_v2;
-    EXPECT_TRUE(msg_v2.ParseRawProto(serialized));
+    EXPECT_TRUE(msg_v2.ParseFromString(serialized));
     EXPECT_EQ(msg_v2.root_int(), 101);
     EXPECT_EQ(msg_v2.root_int_v2(), 11);
     EXPECT_EQ(msg_v2.enumz_size(), 3);
@@ -253,7 +253,7 @@
     }
     {
       pbtest::TestVersioning_V2::Sub1_V2 lazy;
-      EXPECT_TRUE(lazy.ParseRawProto(msg_v2.sub1_lazy_raw()));
+      EXPECT_TRUE(lazy.ParseFromString(msg_v2.sub1_lazy_raw()));
       EXPECT_EQ(lazy.sub1_int(), 15);
       EXPECT_EQ(lazy.sub1_string(), "sub1-lazy-string");
       EXPECT_EQ(lazy.sub1_int_v2(), 16);
@@ -261,7 +261,7 @@
     }
     {
       pbtest::TestVersioning_V2::Sub2_V2 lazy;
-      EXPECT_TRUE(lazy.ParseRawProto(msg_v2.sub2_lazy_raw()));
+      EXPECT_TRUE(lazy.ParseFromString(msg_v2.sub2_lazy_raw()));
       EXPECT_EQ(lazy.sub2_int(), 17);
       EXPECT_EQ(lazy.sub2_string(), "sub2-v2-lazy-string");
     }
@@ -285,7 +285,7 @@
   EXPECT_TRUE(msg.has_field_string());
 
   pbtest::EveryField dec;
-  dec.ParseRawProto(msg.SerializeAsString());
+  dec.ParseFromString(msg.SerializeAsString());
   std::string reserialized = dec.SerializeAsString();
 
   pbgold::EveryField gold_msg;
@@ -320,7 +320,7 @@
   }
   {
     pbtest::PackedRepeatedFields msg;
-    EXPECT_TRUE(msg.ParseRawProto(serialized));
+    EXPECT_TRUE(msg.ParseFromString(serialized));
 
     std::vector<int> exp_int32;
     for (int i = -100; i < 100; i++)
diff --git a/src/protozero/virtual_destructors.cc b/src/protozero/virtual_destructors.cc
new file mode 100644
index 0000000..1e452a4
--- /dev/null
+++ b/src/protozero/virtual_destructors.cc
@@ -0,0 +1,24 @@
+
+/*
+ * Copyright (C) 2019 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.
+ */
+
+#include "perfetto/protozero/cpp_message_obj.h"
+
+namespace protozero {
+
+CppMessageObj::~CppMessageObj() = default;
+
+}  // namespace protozero
diff --git a/src/traced/probes/android_log/android_log_data_source.h b/src/traced/probes/android_log/android_log_data_source.h
index 171e543..12f1ae8 100644
--- a/src/traced/probes/android_log/android_log_data_source.h
+++ b/src/traced/probes/android_log/android_log_data_source.h
@@ -26,11 +26,11 @@
 #include "perfetto/ext/base/string_view.h"
 #include "perfetto/ext/base/unix_socket.h"
 #include "perfetto/ext/base/weak_ptr.h"
+#include "perfetto/tracing/core/forward_decls.h"
 #include "src/traced/probes/probes_data_source.h"
 
 namespace perfetto {
 
-class DataSourceConfig;
 class TraceWriter;
 namespace base {
 class TaskRunner;
diff --git a/src/traced/probes/ftrace/BUILD.gn b/src/traced/probes/ftrace/BUILD.gn
index 11a84ef..959926b 100644
--- a/src/traced/probes/ftrace/BUILD.gn
+++ b/src/traced/probes/ftrace/BUILD.gn
@@ -100,6 +100,7 @@
 
 source_set("ftrace") {
   public_deps = [
+    "../../../../protos/perfetto/config/ftrace:cpp",
     "../../../../protos/perfetto/trace/ftrace:zero",
     "../../../tracing",
   ]
@@ -108,7 +109,6 @@
     "..:data_source",
     "../../../../gn:default_deps",
     "../../../../include/perfetto/ext/traced",
-    "../../../../protos/perfetto/config/ftrace:cpp",
     "../../../android_internal:lazy_library_loader",
     "../../../base",
     "../../../protozero",
diff --git a/src/traced/probes/ftrace/compact_sched.h b/src/traced/probes/ftrace/compact_sched.h
index 657d651..63b7edb 100644
--- a/src/traced/probes/ftrace/compact_sched.h
+++ b/src/traced/probes/ftrace/compact_sched.h
@@ -23,11 +23,10 @@
 #include "perfetto/protozero/packed_repeated_fields.h"
 #include "protos/perfetto/trace/ftrace/ftrace_event_bundle.pbzero.h"
 #include "src/traced/probes/ftrace/event_info_constants.h"
+#include "src/traced/probes/ftrace/ftrace_config_utils.h"
 
 namespace perfetto {
 
-class FtraceConfig;
-
 // The subset of the sched_switch event's format that is used when parsing and
 // encoding into the compact format.
 struct CompactSchedSwitchFormat {
diff --git a/src/traced/probes/probes_producer.cc b/src/traced/probes/probes_producer.cc
index 0c3a5de..f59c8f8 100644
--- a/src/traced/probes/probes_producer.cc
+++ b/src/traced/probes/probes_producer.cc
@@ -252,7 +252,7 @@
   PERFETTO_LOG("Ftrace setup (target_buf=%" PRIu32 ")", config.target_buffer());
   const BufferID buffer_id = static_cast<BufferID>(config.target_buffer());
   FtraceConfig ftrace_config;
-  ftrace_config.ParseRawProto(config.ftrace_config_raw());
+  ftrace_config.ParseFromString(config.ftrace_config_raw());
   std::unique_ptr<FtraceDataSource> data_source(new FtraceDataSource(
       ftrace_->GetWeakPtr(), session_id, std::move(ftrace_config),
       endpoint_->CreateTraceWriter(buffer_id)));
diff --git a/src/traced/probes/ps/process_stats_data_source.h b/src/traced/probes/ps/process_stats_data_source.h
index f301e5d..a9ea6ac 100644
--- a/src/traced/probes/ps/process_stats_data_source.h
+++ b/src/traced/probes/ps/process_stats_data_source.h
@@ -27,8 +27,8 @@
 #include "perfetto/ext/base/weak_ptr.h"
 #include "perfetto/ext/tracing/core/basic_types.h"
 #include "perfetto/ext/tracing/core/trace_writer.h"
+#include "perfetto/tracing/core/forward_decls.h"
 #include "src/traced/probes/probes_data_source.h"
-
 namespace perfetto {
 
 namespace base {
@@ -43,7 +43,6 @@
 }  // namespace pbzero
 }  // namespace protos
 
-class DataSourceConfig;
 
 class ProcessStatsDataSource : public ProbesDataSource {
  public:
diff --git a/src/tracing/core/shared_memory_arbiter_impl.h b/src/tracing/core/shared_memory_arbiter_impl.h
index be00684..22bf09d 100644
--- a/src/tracing/core/shared_memory_arbiter_impl.h
+++ b/src/tracing/core/shared_memory_arbiter_impl.h
@@ -29,11 +29,10 @@
 #include "perfetto/ext/tracing/core/shared_memory_abi.h"
 #include "perfetto/ext/tracing/core/shared_memory_arbiter.h"
 #include "perfetto/ext/tracing/core/startup_trace_writer_registry.h"
+#include "perfetto/tracing/core/forward_decls.h"
 #include "src/tracing/core/id_allocator.h"
-
 namespace perfetto {
 
-class CommitDataRequest;
 class PatchList;
 class TraceWriter;
 class TraceWriterImpl;
diff --git a/src/tracing/core/tracing_service_impl.h b/src/tracing/core/tracing_service_impl.h
index 76ce0e2..36561be 100644
--- a/src/tracing/core/tracing_service_impl.h
+++ b/src/tracing/core/tracing_service_impl.h
@@ -36,9 +36,9 @@
 #include "perfetto/ext/tracing/core/tracing_service.h"
 #include "perfetto/tracing/core/data_source_config.h"
 #include "perfetto/tracing/core/data_source_descriptor.h"
+#include "perfetto/tracing/core/forward_decls.h"
 #include "perfetto/tracing/core/trace_config.h"
 #include "src/tracing/core/id_allocator.h"
-
 namespace perfetto {
 
 namespace base {
@@ -46,12 +46,10 @@
 }  // namespace base
 
 class Consumer;
-class DataSourceConfig;
 class Producer;
 class SharedMemory;
 class SharedMemoryArbiterImpl;
 class TraceBuffer;
-class TraceConfig;
 class TracePacket;
 
 // The tracing service business logic.
diff --git a/src/tracing/internal/tracing_muxer_impl.h b/src/tracing/internal/tracing_muxer_impl.h
index 1f0f8be..6c19902 100644
--- a/src/tracing/internal/tracing_muxer_impl.h
+++ b/src/tracing/internal/tracing_muxer_impl.h
@@ -33,16 +33,15 @@
 #include "perfetto/ext/tracing/core/consumer.h"
 #include "perfetto/ext/tracing/core/producer.h"
 #include "perfetto/tracing/core/data_source_descriptor.h"
+#include "perfetto/tracing/core/forward_decls.h"
 #include "perfetto/tracing/core/trace_config.h"
 #include "perfetto/tracing/internal/basic_types.h"
 #include "perfetto/tracing/internal/tracing_muxer.h"
 #include "perfetto/tracing/tracing.h"
-
 namespace perfetto {
 
 class ConsumerEndpoint;
 class DataSourceBase;
-class DataSourceConfig;
 class ProducerEndpoint;
 class TraceWriterBase;
 class TracingBackend;