Remove allocator_extension_thunks since this layer is not required

Original patch author: [email protected]

Original CL description:
crrev.com/10239012 added thunks target. There allocator_shim.cc wanted
to set function pointers when heap_init_() was called. To do this,
allocator_shim.cc (part of allocator target) used thunks to store the
functions without actually depending on thunks (relying on the fact
that base would finally link thunks). Since allocator_shim.cc included
thunks.h and allocator_unittests included allocator, but not base,
thunks target was introduced to avoid depending on base. Current
situation is that thunks is no longer used by the shim layer and not
used by allocator_unittests either (after shim was removed). Thunks was
left around for no reason. See design doc in the bug.

This CL removes the target and stores the functions in base.

BUG=564618
[email protected],[email protected]
TBR Reason=the original patch was reviewed in crrev.com/1487403002.
           Just rebasing and landing it as ssid is OOO for one week.

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

Cr-Commit-Position: refs/heads/master@{#363497}
diff --git a/base/allocator/BUILD.gn b/base/allocator/BUILD.gn
index c1402265..470f363 100644
--- a/base/allocator/BUILD.gn
+++ b/base/allocator/BUILD.gn
@@ -272,15 +272,3 @@
     deps += [ "//base/third_party/dynamic_annotations" ]
   }
 }  # !is_android
-
-source_set("extension_thunks") {
-  visibility = [ "//base/*" ]
-  sources = [
-    "allocator_extension_thunks.cc",
-    "allocator_extension_thunks.h",
-  ]
-  if (is_android && !is_debug) {
-    configs -= [ "//build/config/compiler:default_optimization" ]
-    configs += [ "//build/config/compiler:optimize_max" ]
-  }
-}
diff --git a/base/allocator/allocator.gyp b/base/allocator/allocator.gyp
index aed1620..d5ec2b6 100644
--- a/base/allocator/allocator.gyp
+++ b/base/allocator/allocator.gyp
@@ -358,19 +358,7 @@
         }],
       ],  # conditions of 'allocator' target.
     },  # 'allocator' target.
-    {
-      'target_name': 'allocator_extension_thunks',
-      'type': 'static_library',
-      'sources': [
-        'allocator_extension_thunks.cc',
-        'allocator_extension_thunks.h',
-      ],
-      'toolsets': ['host', 'target'],
-      'include_dirs': [
-        '../../'
-      ],
-    },
-   ],
+  ],  # targets.
   'conditions': [
     ['OS=="win" and component!="shared_library"', {
       'targets': [
@@ -398,26 +386,5 @@
         },
       ],
     }],
-    ['OS=="win" and target_arch=="ia32"', {
-      'targets': [
-        {
-          'target_name': 'allocator_extension_thunks_win64',
-          'type': 'static_library',
-          'sources': [
-            'allocator_extension_thunks.cc',
-            'allocator_extension_thunks.h',
-          ],
-          'toolsets': ['host', 'target'],
-          'include_dirs': [
-            '../../'
-          ],
-          'configurations': {
-            'Common_Base': {
-              'msvs_target_platform': 'x64',
-            },
-          },
-        },
-      ],
-    }],
   ],
 }
diff --git a/base/allocator/allocator_extension.cc b/base/allocator/allocator_extension.cc
index 75918d1c..4f0b3a90 100644
--- a/base/allocator/allocator_extension.cc
+++ b/base/allocator/allocator_extension.cc
@@ -9,25 +9,31 @@
 namespace base {
 namespace allocator {
 
+namespace {
+ReleaseFreeMemoryFunction g_release_free_memory_function = nullptr;
+GetNumericPropertyFunction g_get_numeric_property_function = nullptr;
+}
+
 void ReleaseFreeMemory() {
-  thunks::ReleaseFreeMemoryFunction release_free_memory_function =
-      thunks::GetReleaseFreeMemoryFunction();
-  if (release_free_memory_function)
-    release_free_memory_function();
+  if (g_release_free_memory_function)
+    g_release_free_memory_function();
+}
+
+bool GetNumericProperty(const char* name, size_t* value) {
+  return g_get_numeric_property_function &&
+         g_get_numeric_property_function(name, value);
 }
 
 void SetReleaseFreeMemoryFunction(
-    thunks::ReleaseFreeMemoryFunction release_free_memory_function) {
-  DCHECK_EQ(thunks::GetReleaseFreeMemoryFunction(),
-            reinterpret_cast<thunks::ReleaseFreeMemoryFunction>(NULL));
-  thunks::SetReleaseFreeMemoryFunction(release_free_memory_function);
+    ReleaseFreeMemoryFunction release_free_memory_function) {
+  DCHECK(!g_release_free_memory_function);
+  g_release_free_memory_function = release_free_memory_function;
 }
 
 void SetGetNumericPropertyFunction(
-    thunks::GetNumericPropertyFunction get_numeric_property_function) {
-  DCHECK_EQ(thunks::GetGetNumericPropertyFunction(),
-            reinterpret_cast<thunks::GetNumericPropertyFunction>(NULL));
-  thunks::SetGetNumericPropertyFunction(get_numeric_property_function);
+    GetNumericPropertyFunction get_numeric_property_function) {
+  DCHECK(!g_get_numeric_property_function);
+  g_get_numeric_property_function = get_numeric_property_function;
 }
 
 }  // namespace allocator
diff --git a/base/allocator/allocator_extension.h b/base/allocator/allocator_extension.h
index e2f1e70..3be2cea0 100644
--- a/base/allocator/allocator_extension.h
+++ b/base/allocator/allocator_extension.h
@@ -7,17 +7,25 @@
 
 #include <stddef.h> // for size_t
 
-#include "base/allocator/allocator_extension_thunks.h"
 #include "base/base_export.h"
 #include "build/build_config.h"
 
 namespace base {
 namespace allocator {
 
+typedef void (*ReleaseFreeMemoryFunction)();
+typedef bool (*GetNumericPropertyFunction)(const char* name, size_t* value);
+
 // Request that the allocator release any free memory it knows about to the
 // system.
 BASE_EXPORT void ReleaseFreeMemory();
 
+// Get the named property's |value|. Returns true if the property is known.
+// Returns false if the property is not a valid property name for the current
+// allocator implementation.
+// |name| or |value| cannot be NULL
+BASE_EXPORT bool GetNumericProperty(const char* name, size_t* value);
+
 // These settings allow specifying a callback used to implement the allocator
 // extension functions.  These are optional, but if set they must only be set
 // once.  These will typically called in an allocator-specific initialization
@@ -28,10 +36,10 @@
 // functions.
 
 BASE_EXPORT void SetReleaseFreeMemoryFunction(
-    thunks::ReleaseFreeMemoryFunction release_free_memory_function);
+    ReleaseFreeMemoryFunction release_free_memory_function);
 
 BASE_EXPORT void SetGetNumericPropertyFunction(
-    thunks::GetNumericPropertyFunction get_numeric_property_function);
+    GetNumericPropertyFunction get_numeric_property_function);
 
 }  // namespace allocator
 }  // namespace base
diff --git a/base/allocator/allocator_extension_thunks.cc b/base/allocator/allocator_extension_thunks.cc
deleted file mode 100644
index 8dedb986c..0000000
--- a/base/allocator/allocator_extension_thunks.cc
+++ /dev/null
@@ -1,43 +0,0 @@
-// Copyright (c) 2012 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include "base/allocator/allocator_extension_thunks.h"
-
-#include <cstddef> // for NULL
-
-namespace base {
-namespace allocator {
-namespace thunks {
-
-// This slightly odd translation unit exists because of the peculularity of how
-// allocator_unittests work on windows.  That target has to perform
-// tcmalloc-specific initialization on windows, but it cannot depend on base
-// otherwise. This target sits in the middle - base and allocator_unittests
-// can depend on it. This file can't depend on anything else in base, including
-// logging.
-
-static ReleaseFreeMemoryFunction g_release_free_memory_function = NULL;
-static GetNumericPropertyFunction g_get_numeric_property_function = NULL;
-
-void SetReleaseFreeMemoryFunction(
-    ReleaseFreeMemoryFunction release_free_memory_function) {
-  g_release_free_memory_function = release_free_memory_function;
-}
-
-ReleaseFreeMemoryFunction GetReleaseFreeMemoryFunction() {
-  return g_release_free_memory_function;
-}
-
-void SetGetNumericPropertyFunction(
-    GetNumericPropertyFunction get_numeric_property_function) {
-  g_get_numeric_property_function = get_numeric_property_function;
-}
-
-GetNumericPropertyFunction GetGetNumericPropertyFunction() {
-  return g_get_numeric_property_function;
-}
-
-}  // namespace thunks
-}  // namespace allocator
-}  // namespace base
diff --git a/base/allocator/allocator_extension_thunks.h b/base/allocator/allocator_extension_thunks.h
deleted file mode 100644
index c316767..0000000
--- a/base/allocator/allocator_extension_thunks.h
+++ /dev/null
@@ -1,32 +0,0 @@
-// Copyright (c) 2012 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#ifndef BASE_ALLOCATOR_ALLOCATOR_EXTENSION_THUNKS_H_
-#define BASE_ALLOCATOR_ALLOCATOR_EXTENSION_THUNKS_H_
-
-#include <stddef.h> // for size_t
-
-namespace base {
-namespace allocator {
-namespace thunks {
-
-// WARNING: You probably don't want to use this file unless you are routing a
-// new allocator extension from a specific allocator implementation to base.
-// See allocator_extension.h to see the interface that base exports.
-
-typedef void (*ReleaseFreeMemoryFunction)();
-void SetReleaseFreeMemoryFunction(
-    ReleaseFreeMemoryFunction release_free_memory_function);
-ReleaseFreeMemoryFunction GetReleaseFreeMemoryFunction();
-
-typedef bool (*GetNumericPropertyFunction)(const char* name, size_t* value);
-void SetGetNumericPropertyFunction(
-    GetNumericPropertyFunction get_numeric_property_function);
-GetNumericPropertyFunction GetGetNumericPropertyFunction();
-
-}  // namespace thunks
-}  // namespace allocator
-}  // namespace base
-
-#endif  // BASE_ALLOCATOR_ALLOCATOR_EXTENSION_THUNKS_H_