OLD | NEW |
(Empty) | |
| 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 #include "base/allocator/type_profiler.h" |
| 6 |
| 7 #include <assert.h> |
| 8 |
| 9 #if defined(TYPE_PROFILING) |
| 10 |
| 11 namespace { |
| 12 void* NopIntercept(void* ptr, size_t size, const std::type_info& type) { |
| 13 return ptr; |
| 14 } |
| 15 } |
| 16 |
| 17 void* __op_new_intercept__(void* ptr, |
| 18 size_t size, |
| 19 const std::type_info& type) { |
| 20 return base::type_profiler::InterceptFunctions::new_intercept_( |
| 21 ptr, size, type); |
| 22 } |
| 23 |
| 24 void* __op_delete_intercept__(void* ptr, |
| 25 size_t size, |
| 26 const std::type_info& type) { |
| 27 return base::type_profiler::InterceptFunctions::delete_intercept_( |
| 28 ptr, size, type); |
| 29 } |
| 30 |
| 31 namespace base { |
| 32 namespace type_profiler { |
| 33 |
| 34 InterceptFunction* InterceptFunctions::new_intercept_ = NopIntercept; |
| 35 InterceptFunction* InterceptFunctions::delete_intercept_ = NopIntercept; |
| 36 |
| 37 // static |
| 38 void InterceptFunctions::SetFunctions(InterceptFunction* new_intercept, |
| 39 InterceptFunction* delete_intercept) { |
| 40 // Don't use DCHECKs as this file is injected also to non-Chromium binaries. |
| 41 // They don't link base/ files. |
| 42 assert(new_intercept_ == NopIntercept); |
| 43 assert(delete_intercept_ == NopIntercept); |
| 44 |
| 45 new_intercept_ = new_intercept; |
| 46 delete_intercept_ = delete_intercept; |
| 47 } |
| 48 |
| 49 // static |
| 50 void InterceptFunctions::ResetFunctions() { |
| 51 new_intercept_ = NopIntercept; |
| 52 delete_intercept_ = NopIntercept; |
| 53 } |
| 54 |
| 55 // static |
| 56 bool InterceptFunctions::IsAvailable() { |
| 57 return new_intercept_ != NopIntercept || delete_intercept_ != NopIntercept; |
| 58 } |
| 59 |
| 60 } // namespace type_profiler |
| 61 } // namespace base |
| 62 |
| 63 #endif // defined(TYPE_PROFILING) |
OLD | NEW |