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) { | |
13 thunks::GetAllocatorWasteSizeFunction get_allocator_waste_size_function = | |
14 thunks::GetGetAllocatorWasteSizeFunction(); | |
15 return get_allocator_waste_size_function != NULL && | |
16 get_allocator_waste_size_function(size); | |
17 } | |
18 | |
19 void GetStats(char* buffer, int buffer_length) { | 12 void GetStats(char* buffer, int buffer_length) { |
20 DCHECK_GT(buffer_length, 0); | 13 DCHECK_GT(buffer_length, 0); |
21 thunks::GetStatsFunction get_stats_function = thunks::GetGetStatsFunction(); | 14 thunks::GetStatsFunction get_stats_function = thunks::GetGetStatsFunction(); |
22 if (get_stats_function) | 15 if (get_stats_function) |
23 get_stats_function(buffer, buffer_length); | 16 get_stats_function(buffer, buffer_length); |
24 else | 17 else |
25 buffer[0] = '\0'; | 18 buffer[0] = '\0'; |
26 } | 19 } |
27 | 20 |
28 void ReleaseFreeMemory() { | 21 void ReleaseFreeMemory() { |
29 thunks::ReleaseFreeMemoryFunction release_free_memory_function = | 22 thunks::ReleaseFreeMemoryFunction release_free_memory_function = |
30 thunks::GetReleaseFreeMemoryFunction(); | 23 thunks::GetReleaseFreeMemoryFunction(); |
31 if (release_free_memory_function) | 24 if (release_free_memory_function) |
32 release_free_memory_function(); | 25 release_free_memory_function(); |
33 } | 26 } |
34 | 27 |
35 void SetGetAllocatorWasteSizeFunction( | |
36 thunks::GetAllocatorWasteSizeFunction get_allocator_waste_size_function) { | |
37 DCHECK_EQ(thunks::GetGetAllocatorWasteSizeFunction(), | |
38 reinterpret_cast<thunks::GetAllocatorWasteSizeFunction>(NULL)); | |
39 thunks::SetGetAllocatorWasteSizeFunction(get_allocator_waste_size_function); | |
40 } | |
41 | |
42 void SetGetStatsFunction(thunks::GetStatsFunction get_stats_function) { | 28 void SetGetStatsFunction(thunks::GetStatsFunction get_stats_function) { |
43 DCHECK_EQ(thunks::GetGetStatsFunction(), | 29 DCHECK_EQ(thunks::GetGetStatsFunction(), |
44 reinterpret_cast<thunks::GetStatsFunction>(NULL)); | 30 reinterpret_cast<thunks::GetStatsFunction>(NULL)); |
45 thunks::SetGetStatsFunction(get_stats_function); | 31 thunks::SetGetStatsFunction(get_stats_function); |
46 } | 32 } |
47 | 33 |
48 void SetReleaseFreeMemoryFunction( | 34 void SetReleaseFreeMemoryFunction( |
49 thunks::ReleaseFreeMemoryFunction release_free_memory_function) { | 35 thunks::ReleaseFreeMemoryFunction release_free_memory_function) { |
50 DCHECK_EQ(thunks::GetReleaseFreeMemoryFunction(), | 36 DCHECK_EQ(thunks::GetReleaseFreeMemoryFunction(), |
51 reinterpret_cast<thunks::ReleaseFreeMemoryFunction>(NULL)); | 37 reinterpret_cast<thunks::ReleaseFreeMemoryFunction>(NULL)); |
52 thunks::SetReleaseFreeMemoryFunction(release_free_memory_function); | 38 thunks::SetReleaseFreeMemoryFunction(release_free_memory_function); |
53 } | 39 } |
54 | 40 |
55 void SetGetNumericPropertyFunction( | 41 void SetGetNumericPropertyFunction( |
56 thunks::GetNumericPropertyFunction get_numeric_property_function) { | 42 thunks::GetNumericPropertyFunction get_numeric_property_function) { |
57 DCHECK_EQ(thunks::GetGetNumericPropertyFunction(), | 43 DCHECK_EQ(thunks::GetGetNumericPropertyFunction(), |
58 reinterpret_cast<thunks::GetNumericPropertyFunction>(NULL)); | 44 reinterpret_cast<thunks::GetNumericPropertyFunction>(NULL)); |
59 thunks::SetGetNumericPropertyFunction(get_numeric_property_function); | 45 thunks::SetGetNumericPropertyFunction(get_numeric_property_function); |
60 } | 46 } |
61 | 47 |
62 } // namespace allocator | 48 } // namespace allocator |
63 } // namespace base | 49 } // namespace base |
OLD | NEW |