1 // Copyright 2012 The Chromium Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #if defined(TYPE_PROFILING) 6 7 #include "base/allocator/type_profiler.h" 8 9 #include <assert.h> 10 11 namespace { 12 13 void* NopIntercept(void* ptr, size_t size, const std::type_info& type) { 14 return ptr; 15 } 16 17 base::type_profiler::InterceptFunction* g_new_intercept = NopIntercept; 18 base::type_profiler::InterceptFunction* g_delete_intercept = NopIntercept; 19 20 } 21 22 void* __op_new_intercept__(void* ptr, 23 size_t size, 24 const std::type_info& type) { 25 return g_new_intercept(ptr, size, type); 26 } 27 28 void* __op_delete_intercept__(void* ptr, 29 size_t size, 30 const std::type_info& type) { 31 return g_delete_intercept(ptr, size, type); 32 } 33 34 namespace base { 35 namespace type_profiler { 36 37 // static 38 void InterceptFunctions::SetFunctions(InterceptFunction* new_intercept, 39 InterceptFunction* delete_intercept) { 40 // Don't use DCHECK, as this file is injected into targets 41 // that do not and should not depend on base/base.gyp:base 42 assert(g_new_intercept == NopIntercept); 43 assert(g_delete_intercept == NopIntercept); 44 45 g_new_intercept = new_intercept; 46 g_delete_intercept = delete_intercept; 47 } 48 49 // static 50 void InterceptFunctions::ResetFunctions() { 51 g_new_intercept = NopIntercept; 52 g_delete_intercept = NopIntercept; 53 } 54 55 // static 56 bool InterceptFunctions::IsAvailable() { 57 return g_new_intercept != NopIntercept || g_delete_intercept != NopIntercept; 58 } 59 60 } // namespace type_profiler 61 } // namespace base 62 63 #endif // defined(TYPE_PROFILING) 64