Allocator cleanup: remove CHROME_PROFILER_TIME and rotten tcmalloc deps

This CL removes the support for the CHROME_PROFILER_TIME env var,
originally introduced by crrev.com/9212025 more than 3 years ago, which
allows to change the time source for the profiler via the environment.
Reason for deleting it: could not find any active user of that.
See also discussion in project-trim@chromium.org @ goo.gl/p3GEUy .

After this CL (almost*) nothing outside of base depends on tcmalloc.
This is the place where we want to be, as base should be the only thing
knowing about allocator internals.

* There is only one dep left in content_child_helpers.cc, which is
relied on by old-style telemetry memory benchmarks. But that code is
literally a dead man walking and there is no point refactoring it.

BUG=564618, 581365

Review URL: https://codereview.chromium.org/1632253002

Cr-Commit-Position: refs/heads/master@{#371770}
diff --git a/base/profiler/alternate_timer.cc b/base/profiler/alternate_timer.cc
index b2d2c70..14b4c348 100644
--- a/base/profiler/alternate_timer.cc
+++ b/base/profiler/alternate_timer.cc
@@ -14,8 +14,6 @@
 
 namespace tracked_objects {
 
-const char kAlternateProfilerTime[] = "CHROME_PROFILER_TIME";
-
 // Set an alternate timer function to replace the OS time function when
 // profiling.
 void SetAlternateTimeSource(NowFunction* now_function, TimeSourceType type) {
diff --git a/base/profiler/alternate_timer.h b/base/profiler/alternate_timer.h
index fdc75dc6..608a474 100644
--- a/base/profiler/alternate_timer.h
+++ b/base/profiler/alternate_timer.h
@@ -12,19 +12,11 @@
 
 namespace tracked_objects {
 
-enum TimeSourceType {
-  TIME_SOURCE_TYPE_WALL_TIME,
-  TIME_SOURCE_TYPE_TCMALLOC
-};
+enum TimeSourceType { TIME_SOURCE_TYPE_WALL_TIME };
 
 // Provide type for an alternate timer function.
 typedef unsigned int NowFunction();
 
-// Environment variable name that is used to activate alternate timer profiling
-// (such as using TCMalloc allocations to provide a pseudo-timer) for tasks
-// instead of wall clock profiling.
-BASE_EXPORT extern const char kAlternateProfilerTime[];
-
 // Set an alternate timer function to replace the OS time function when
 // profiling.  Typically this is called by an allocator that is providing a
 // function that indicates how much memory has been allocated on any given
diff --git a/content/DEPS b/content/DEPS
index e62959c7..d954f6e3 100644
--- a/content/DEPS
+++ b/content/DEPS
@@ -71,7 +71,6 @@
   "+third_party/re2",
   "+third_party/skia",
   "+third_party/sqlite",
-  "+third_party/tcmalloc",
   "+third_party/khronos",
   "+third_party/webrtc",
   "+third_party/zlib/google",
diff --git a/content/app/content_main_runner.cc b/content/app/content_main_runner.cc
index c04782f..a8235c3 100644
--- a/content/app/content_main_runner.cc
+++ b/content/app/content_main_runner.cc
@@ -28,7 +28,6 @@
 #include "base/process/launch.h"
 #include "base/process/memory.h"
 #include "base/process/process_handle.h"
-#include "base/profiler/alternate_timer.h"
 #include "base/profiler/scoped_tracker.h"
 #include "base/strings/string_number_conversions.h"
 #include "base/strings/string_util.h"
@@ -64,10 +63,6 @@
 #include "gin/v8_initializer.h"
 #endif
 
-#if defined(USE_TCMALLOC)
-#include "third_party/tcmalloc/chromium/src/gperftools/malloc_extension.h"
-#endif
-
 #if !defined(OS_IOS)
 #include "content/app/mojo/mojo_init.h"
 #include "content/browser/gpu/gpu_process_host.h"
@@ -425,19 +420,6 @@
     TRACE_EVENT0("startup,benchmark", "ContentMainRunnerImpl::Initialize");
 #endif  // OS_ANDROID
 
-#if !defined(OS_MACOSX) && defined(USE_TCMALLOC)
-    // Provide optional hook for monitoring allocation quantities on a
-    // per-thread basis.  Only set the hook if the environment indicates this
-    // needs to be enabled.
-    const char* profiling = getenv(tracked_objects::kAlternateProfilerTime);
-    if (profiling &&
-        (atoi(profiling) == tracked_objects::TIME_SOURCE_TYPE_TCMALLOC)) {
-      tracked_objects::SetAlternateTimeSource(
-          MallocExtension::GetBytesAllocatedOnCurrentThread,
-          tracked_objects::TIME_SOURCE_TYPE_TCMALLOC);
-    }
-#endif  // !OS_MACOSX && USE_TCMALLOC
-
 #if !defined(OS_IOS)
     base::GlobalDescriptors* g_fds = base::GlobalDescriptors::GetInstance();
 #endif
diff --git a/content/browser/browser_main_loop.cc b/content/browser/browser_main_loop.cc
index 141eab8..d4425cc 100644
--- a/content/browser/browser_main_loop.cc
+++ b/content/browser/browser_main_loop.cc
@@ -164,10 +164,6 @@
 #include "content/browser/plugin_service_impl.h"
 #endif
 
-#if defined(TCMALLOC_TRACE_MEMORY_SUPPORTED)
-#include "third_party/tcmalloc/chromium/src/gperftools/heap-profiler.h"
-#endif
-
 #if defined(USE_X11)
 #include "ui/base/x/x11_util_internal.h"
 #include "ui/gfx/x/x11_connection.h"
diff --git a/content/child/child_thread_impl.cc b/content/child/child_thread_impl.cc
index 53838039..4eb0972d 100644
--- a/content/child/child_thread_impl.cc
+++ b/content/child/child_thread_impl.cc
@@ -64,10 +64,6 @@
 #include "ipc/mojo/ipc_channel_mojo.h"
 #include "third_party/mojo/src/mojo/edk/embedder/embedder.h"
 
-#if defined(TCMALLOC_TRACE_MEMORY_SUPPORTED)
-#include "third_party/tcmalloc/chromium/src/gperftools/heap-profiler.h"
-#endif
-
 #if defined(USE_OZONE)
 #include "ui/ozone/public/client_native_pixmap_factory.h"
 #endif
diff --git a/content/child/content_child_helpers.cc b/content/child/content_child_helpers.cc
index 4398bc06..66775a2 100644
--- a/content/child/content_child_helpers.cc
+++ b/content/child/content_child_helpers.cc
@@ -18,6 +18,12 @@
 
 namespace content {
 
+// TODO(primiano): get rid of this file together with --memory-metrics.
+// This function is both misplaced and misnamed. If useful, this should
+// be moved to base/process/process_metrics.h. Regardless the name,
+// though, this provides only a partial and misleading value.
+// Unfortunately some telemetry benchmark rely on it and these need to
+// be refactored before getting rid of this. See crbug.com/581365 .
 #if defined(OS_LINUX) || defined(OS_ANDROID)
 size_t GetMemoryUsageKB() {
   struct mallinfo minfo = mallinfo();
diff --git a/content/renderer/DEPS b/content/renderer/DEPS
index 3a49854..5c5ff3a 100644
--- a/content/renderer/DEPS
+++ b/content/renderer/DEPS
@@ -20,7 +20,6 @@
   "-storage/browser",
   "+third_party/hyphen/hyphen.h",
   "+third_party/libjingle",
-  "+third_party/tcmalloc",
   "+v8/include",
   "+v8/src/third_party/vtune",
 ]
diff --git a/content/renderer/devtools/devtools_agent.cc b/content/renderer/devtools/devtools_agent.cc
index 6de2625..11f9219 100644
--- a/content/renderer/devtools/devtools_agent.cc
+++ b/content/renderer/devtools/devtools_agent.cc
@@ -25,10 +25,6 @@
 #include "third_party/WebKit/public/web/WebDevToolsAgent.h"
 #include "third_party/WebKit/public/web/WebLocalFrame.h"
 
-#if defined(USE_TCMALLOC)
-#include "third_party/tcmalloc/chromium/src/gperftools/heap-profiler.h"
-#endif
-
 using blink::WebConsoleMessage;
 using blink::WebDevToolsAgent;
 using blink::WebDevToolsAgentClient;
diff --git a/third_party/cld/README.chromium b/third_party/cld/README.chromium
index 865ba588..4799d100 100644
--- a/third_party/cld/README.chromium
+++ b/third_party/cld/README.chromium
@@ -13,3 +13,4 @@
 
 Local Modifications:
   * Add support for arm64 architecture
+  * Remove dead USE_TCMALLOC #define.
diff --git a/third_party/cld/base/build_config.h b/third_party/cld/base/build_config.h
index ef6d40b..6fbf5c1 100644
--- a/third_party/cld/base/build_config.h
+++ b/third_party/cld/base/build_config.h
@@ -58,11 +58,6 @@
 #define USE_BASE_DATA_PACK 1
 #endif
 
-// Use tcmalloc
-#if defined(OS_WIN) && ! defined(NO_TCMALLOC)
-#define USE_TCMALLOC 1
-#endif
-
 // Compiler detection.
 #if defined(__GNUC__)
 #define COMPILER_GCC 1