From 9ea98b46376c901dbfcb026aa2d03fbfb9b456d3 Mon Sep 17 00:00:00 2001
From: klzgrad <kizdiv@gmail.com>
Date: Sat, 29 Aug 2020 20:22:14 +0800
Subject: [PATCH] base: Disable trace event

This allows builds with enable_base_tracing=false.
---
 src/base/trace_event/base_tracing_forward.h  |  2 +-
 src/base/trace_event/memory_allocator_dump.h |  3 ++
 src/base/trace_event/memory_dump_manager.h   |  3 ++
 src/base/trace_event/memory_dump_provider.h  |  3 ++
 src/base/trace_event/process_memory_dump.h   |  3 ++
 src/base/trace_event/trace_event.h           |  3 ++
 src/base/trace_event/trace_event_stub.cc     |  4 ++
 src/base/trace_event/trace_event_stub.h      | 48 +++++++++++++++++---
 src/base/trace_event/typed_macros.h          |  2 +
 src/net/BUILD.gn                             |  2 -
 10 files changed, 64 insertions(+), 9 deletions(-)

diff --git a/src/base/trace_event/base_tracing_forward.h b/src/base/trace_event/base_tracing_forward.h
index 3aaf36d624..effcb9782f 100644
--- a/src/base/trace_event/base_tracing_forward.h
+++ b/src/base/trace_event/base_tracing_forward.h
@@ -10,7 +10,7 @@
 
 #include "base/tracing_buildflags.h"
 
-#if BUILDFLAG(ENABLE_BASE_TRACING)
+#if 1
 #include "third_party/perfetto/include/perfetto/tracing/traced_value_forward.h"  // nogncheck
 #else
 
diff --git a/src/base/trace_event/memory_allocator_dump.h b/src/base/trace_event/memory_allocator_dump.h
index 0076d233a7..e7bbee4950 100644
--- a/src/base/trace_event/memory_allocator_dump.h
+++ b/src/base/trace_event/memory_allocator_dump.h
@@ -5,6 +5,8 @@
 #ifndef BASE_TRACE_EVENT_MEMORY_ALLOCATOR_DUMP_H_
 #define BASE_TRACE_EVENT_MEMORY_ALLOCATOR_DUMP_H_
 
+#include "base/trace_event/trace_event_stub.h"
+#if 0
 #include <stdint.h>
 
 #include <iosfwd>
@@ -159,4 +161,5 @@ void BASE_EXPORT PrintTo(const MemoryAllocatorDump::Entry&, std::ostream*);
 }  // namespace trace_event
 }  // namespace base
 
+#endif
 #endif  // BASE_TRACE_EVENT_MEMORY_ALLOCATOR_DUMP_H_
diff --git a/src/base/trace_event/memory_dump_manager.h b/src/base/trace_event/memory_dump_manager.h
index ef12d9df76..4cdc51528a 100644
--- a/src/base/trace_event/memory_dump_manager.h
+++ b/src/base/trace_event/memory_dump_manager.h
@@ -5,6 +5,8 @@
 #ifndef BASE_TRACE_EVENT_MEMORY_DUMP_MANAGER_H_
 #define BASE_TRACE_EVENT_MEMORY_DUMP_MANAGER_H_
 
+#include "base/trace_event/trace_event_stub.h"
+#if 0
 #include <stdint.h>
 
 #include <map>
@@ -277,4 +279,5 @@ class BASE_EXPORT MemoryDumpManager {
 }  // namespace trace_event
 }  // namespace base
 
+#endif
 #endif  // BASE_TRACE_EVENT_MEMORY_DUMP_MANAGER_H_
diff --git a/src/base/trace_event/memory_dump_provider.h b/src/base/trace_event/memory_dump_provider.h
index 52b54e6c97..af4f7de897 100644
--- a/src/base/trace_event/memory_dump_provider.h
+++ b/src/base/trace_event/memory_dump_provider.h
@@ -5,6 +5,8 @@
 #ifndef BASE_TRACE_EVENT_MEMORY_DUMP_PROVIDER_H_
 #define BASE_TRACE_EVENT_MEMORY_DUMP_PROVIDER_H_
 
+#include "base/trace_event/trace_event_stub.h"
+#if 0
 #include "base/base_export.h"
 #include "base/process/process_handle.h"
 #include "base/trace_event/memory_dump_request_args.h"
@@ -48,4 +50,5 @@ class BASE_EXPORT MemoryDumpProvider {
 }  // namespace trace_event
 }  // namespace base
 
+#endif
 #endif  // BASE_TRACE_EVENT_MEMORY_DUMP_PROVIDER_H_
diff --git a/src/base/trace_event/process_memory_dump.h b/src/base/trace_event/process_memory_dump.h
index 1fb634139e..5f10e55459 100644
--- a/src/base/trace_event/process_memory_dump.h
+++ b/src/base/trace_event/process_memory_dump.h
@@ -5,6 +5,8 @@
 #ifndef BASE_TRACE_EVENT_PROCESS_MEMORY_DUMP_H_
 #define BASE_TRACE_EVENT_PROCESS_MEMORY_DUMP_H_
 
+#include "base/trace_event/trace_event_stub.h"
+#if 0
 #include <stddef.h>
 
 #include <map>
@@ -295,4 +297,5 @@ class BASE_EXPORT ProcessMemoryDump {
 }  // namespace trace_event
 }  // namespace base
 
+#endif
 #endif  // BASE_TRACE_EVENT_PROCESS_MEMORY_DUMP_H_
diff --git a/src/base/trace_event/trace_event.h b/src/base/trace_event/trace_event.h
index 10dcfea46c..48179991ae 100644
--- a/src/base/trace_event/trace_event.h
+++ b/src/base/trace_event/trace_event.h
@@ -5,6 +5,8 @@
 #ifndef BASE_TRACE_EVENT_TRACE_EVENT_H_
 #define BASE_TRACE_EVENT_TRACE_EVENT_H_
 
+#include "base/trace_event/trace_event_stub.h"
+#if 0
 // This header file defines implementation details of how the trace macros in
 // trace_event_common.h collect and store trace events. Anything not
 // implementation-specific should go in trace_event_common.h instead of here.
@@ -465,4 +467,5 @@ class TraceScopedTrackableObject {
 }  // namespace trace_event
 }  // namespace base
 
+#endif
 #endif  // BASE_TRACE_EVENT_TRACE_EVENT_H_
diff --git a/src/base/trace_event/trace_event_stub.cc b/src/base/trace_event/trace_event_stub.cc
index 8c40ae3463..ecadae09cf 100644
--- a/src/base/trace_event/trace_event_stub.cc
+++ b/src/base/trace_event/trace_event_stub.cc
@@ -6,6 +6,7 @@
 
 #include <string>
 
+#include "base/trace_event/memory_usage_estimator.h"
 #include "base/trace_event/trace_event_stub.h"
 
 namespace base {
@@ -20,6 +21,9 @@ MemoryDumpProvider::~MemoryDumpProvider() = default;
 // static
 constexpr const char* const MemoryDumpManager::kTraceCategory;
 
+template size_t EstimateMemoryUsage(const std::string&);
+template size_t EstimateMemoryUsage(const std::u16string&);
+
 }  // namespace trace_event
 }  // namespace base
 
diff --git a/src/base/trace_event/trace_event_stub.h b/src/base/trace_event/trace_event_stub.h
index 18ee118ca2..5f12b440f1 100644
--- a/src/base/trace_event/trace_event_stub.h
+++ b/src/base/trace_event/trace_event_stub.h
@@ -13,6 +13,7 @@
 #include <string_view>
 
 #include "base/base_export.h"
+#include "base/check.h"
 #include "base/trace_event/common/trace_event_common.h"
 #include "base/trace_event/memory_allocator_dump_guid.h"
 #include "base/values.h"
@@ -372,6 +373,41 @@ class BASE_EXPORT MemoryDumpProvider {
   MemoryDumpProvider() = default;
 };
 
+class BASE_EXPORT MemoryAllocatorDump {
+ public:
+  static constexpr char* kNameSize = nullptr;
+  static constexpr char* kNameObjectCount = nullptr;
+  static constexpr char* kUnitsBytes = nullptr;
+  static constexpr char* kUnitsObjects = nullptr;
+  static constexpr char* kTypeScalar = nullptr;
+  static constexpr char* kTypeString = nullptr;
+  void AddScalar(const char* name, const char* units, uint64_t value) {}
+  void AddString(const char* name,
+                 const char* units,
+                 const std::string& value) {}
+  const std::string& absolute_name() const { return absolute_name_; }
+  const MemoryAllocatorDumpGuid& guid() const { return guid_; }
+
+ private:
+  const std::string absolute_name_;
+  MemoryAllocatorDumpGuid guid_;
+};
+
+class BASE_EXPORT ProcessMemoryDump {
+ public:
+  MemoryAllocatorDump* CreateAllocatorDump(const std::string& absolute_name) {
+    CHECK(false);
+    return nullptr;
+  }
+  MemoryAllocatorDump* GetAllocatorDump(
+      const std::string& absolute_name) const {
+    CHECK(false);
+    return nullptr;
+  }
+  void AddOwnershipEdge(const MemoryAllocatorDumpGuid& source,
+                        const MemoryAllocatorDumpGuid& target) {}
+};
+
 class BASE_EXPORT MemoryDumpManager {
  public:
   static constexpr const char* const kTraceCategory =
@@ -394,19 +430,19 @@ class TracedArray;
 class TracedDictionary;
 class EventContext;
 
-class StaticString {
+class BASE_EXPORT StaticString {
  public:
   template <typename T>
   StaticString(T) {}
 };
 
-class DynamicString {
+class BASE_EXPORT DynamicString {
  public:
   template <typename T>
   explicit DynamicString(T) {}
 };
 
-class TracedValue {
+class BASE_EXPORT TracedValue {
  public:
   void WriteInt64(int64_t) && {}
   void WriteUInt64(uint64_t) && {}
@@ -421,7 +457,7 @@ class TracedValue {
   TracedArray WriteArray() &&;
 };
 
-class TracedDictionary {
+class BASE_EXPORT TracedDictionary {
  public:
   TracedValue AddItem(StaticString) { return TracedValue(); }
   TracedValue AddItem(DynamicString) { return TracedValue(); }
@@ -437,7 +473,7 @@ class TracedDictionary {
   TracedArray AddArray(DynamicString);
 };
 
-class TracedArray {
+class BASE_EXPORT TracedArray {
  public:
   TracedValue AppendItem() { return TracedValue(); }
 
@@ -449,7 +485,7 @@ class TracedArray {
 };
 
 template <class T>
-void WriteIntoTracedValue(TracedValue, T&&) {}
+BASE_EXPORT void WriteIntoTracedValue(TracedValue, T&&) {}
 
 struct Track {
   explicit Track(uint64_t id) {}
diff --git a/src/base/trace_event/typed_macros.h b/src/base/trace_event/typed_macros.h
index b4d38682f3..21843af8bd 100644
--- a/src/base/trace_event/typed_macros.h
+++ b/src/base/trace_event/typed_macros.h
@@ -11,8 +11,10 @@
 
 // Needed not for this file, but for every user of the TRACE_EVENT macros for
 // the lambda definition. So included here for convenience.
+#if 0
 #include "base/tracing/protos/chrome_track_event.pbzero.h"
 #include "third_party/perfetto/include/perfetto/tracing/event_context.h"
 #include "third_party/perfetto/include/perfetto/tracing/string_helpers.h"
+#endif
 
 #endif  // BASE_TRACE_EVENT_TYPED_MACROS_H_
diff --git a/src/net/BUILD.gn b/src/net/BUILD.gn
index 8b60607a58..46a820d930 100644
--- a/src/net/BUILD.gn
+++ b/src/net/BUILD.gn
@@ -683,8 +683,6 @@ component("net") {
     "log/net_log_values.h",
     "log/net_log_with_source.cc",
     "log/net_log_with_source.h",
-    "log/trace_net_log_observer.cc",
-    "log/trace_net_log_observer.h",
     "nqe/cached_network_quality.cc",
     "nqe/cached_network_quality.h",
     "nqe/effective_connection_type.cc",