| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "base/allocator/allocator_extension.h" | 5 #include "base/allocator/allocator_extension.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 | 8 |
| 9 namespace base { | 9 namespace base { |
| 10 namespace allocator { | 10 namespace allocator { |
| 11 | 11 |
| 12 bool GetAllocatorWasteSize(size_t* size) { | 12 bool GetAllocatorWasteSize(size_t* size) { |
| 13 thunks::GetAllocatorWasteSizeFunction get_allocator_waste_size_function = | 13 thunks::GetAllocatorWasteSizeFunction get_allocator_waste_size_function = |
| 14 thunks::GetGetAllocatorWasteSizeFunction(); | 14 thunks::GetGetAllocatorWasteSizeFunction(); |
| 15 return get_allocator_waste_size_function != NULL && | 15 return get_allocator_waste_size_function != NULL && |
| 16 get_allocator_waste_size_function(size); | 16 get_allocator_waste_size_function(size); |
| 17 } | 17 } |
| 18 | 18 |
| 19 void GetStats(char* buffer, int buffer_length) { | |
| 20 DCHECK_GT(buffer_length, 0); | |
| 21 thunks::GetStatsFunction get_stats_function = thunks::GetGetStatsFunction(); | |
| 22 if (get_stats_function) | |
| 23 get_stats_function(buffer, buffer_length); | |
| 24 else | |
| 25 buffer[0] = '\0'; | |
| 26 } | |
| 27 | |
| 28 void ReleaseFreeMemory() { | 19 void ReleaseFreeMemory() { |
| 29 thunks::ReleaseFreeMemoryFunction release_free_memory_function = | 20 thunks::ReleaseFreeMemoryFunction release_free_memory_function = |
| 30 thunks::GetReleaseFreeMemoryFunction(); | 21 thunks::GetReleaseFreeMemoryFunction(); |
| 31 if (release_free_memory_function) | 22 if (release_free_memory_function) |
| 32 release_free_memory_function(); | 23 release_free_memory_function(); |
| 33 } | 24 } |
| 34 | 25 |
| 35 void SetGetAllocatorWasteSizeFunction( | 26 void SetGetAllocatorWasteSizeFunction( |
| 36 thunks::GetAllocatorWasteSizeFunction get_allocator_waste_size_function) { | 27 thunks::GetAllocatorWasteSizeFunction get_allocator_waste_size_function) { |
| 37 DCHECK_EQ(thunks::GetGetAllocatorWasteSizeFunction(), | 28 DCHECK_EQ(thunks::GetGetAllocatorWasteSizeFunction(), |
| 38 reinterpret_cast<thunks::GetAllocatorWasteSizeFunction>(NULL)); | 29 reinterpret_cast<thunks::GetAllocatorWasteSizeFunction>(NULL)); |
| 39 thunks::SetGetAllocatorWasteSizeFunction(get_allocator_waste_size_function); | 30 thunks::SetGetAllocatorWasteSizeFunction(get_allocator_waste_size_function); |
| 40 } | 31 } |
| 41 | 32 |
| 42 void SetGetStatsFunction(thunks::GetStatsFunction get_stats_function) { | |
| 43 DCHECK_EQ(thunks::GetGetStatsFunction(), | |
| 44 reinterpret_cast<thunks::GetStatsFunction>(NULL)); | |
| 45 thunks::SetGetStatsFunction(get_stats_function); | |
| 46 } | |
| 47 | |
| 48 void SetReleaseFreeMemoryFunction( | 33 void SetReleaseFreeMemoryFunction( |
| 49 thunks::ReleaseFreeMemoryFunction release_free_memory_function) { | 34 thunks::ReleaseFreeMemoryFunction release_free_memory_function) { |
| 50 DCHECK_EQ(thunks::GetReleaseFreeMemoryFunction(), | 35 DCHECK_EQ(thunks::GetReleaseFreeMemoryFunction(), |
| 51 reinterpret_cast<thunks::ReleaseFreeMemoryFunction>(NULL)); | 36 reinterpret_cast<thunks::ReleaseFreeMemoryFunction>(NULL)); |
| 52 thunks::SetReleaseFreeMemoryFunction(release_free_memory_function); | 37 thunks::SetReleaseFreeMemoryFunction(release_free_memory_function); |
| 53 } | 38 } |
| 54 | 39 |
| 55 void SetGetNumericPropertyFunction( | 40 void SetGetNumericPropertyFunction( |
| 56 thunks::GetNumericPropertyFunction get_numeric_property_function) { | 41 thunks::GetNumericPropertyFunction get_numeric_property_function) { |
| 57 DCHECK_EQ(thunks::GetGetNumericPropertyFunction(), | 42 DCHECK_EQ(thunks::GetGetNumericPropertyFunction(), |
| 58 reinterpret_cast<thunks::GetNumericPropertyFunction>(NULL)); | 43 reinterpret_cast<thunks::GetNumericPropertyFunction>(NULL)); |
| 59 thunks::SetGetNumericPropertyFunction(get_numeric_property_function); | 44 thunks::SetGetNumericPropertyFunction(get_numeric_property_function); |
| 60 } | 45 } |
| 61 | 46 |
| 62 } // namespace allocator | 47 } // namespace allocator |
| 63 } // namespace base | 48 } // namespace base |
| OLD | NEW |