OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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/memory/discardable_memory.h" | 5 #include "base/memory/discardable_memory.h" |
6 | 6 |
7 #include "base/basictypes.h" | 7 #include "base/basictypes.h" |
8 #include "base/compiler_specific.h" | 8 #include "base/compiler_specific.h" |
9 #include "base/lazy_instance.h" | 9 #include "base/lazy_instance.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
(...skipping 14 matching lines...) Expand all Loading... |
25 | 25 |
26 size_t GetOptimalAshmemRegionSizeForAllocator() { | 26 size_t GetOptimalAshmemRegionSizeForAllocator() { |
27 // Note that this may do some I/O (without hitting the disk though) so it | 27 // Note that this may do some I/O (without hitting the disk though) so it |
28 // should not be called on the critical path. | 28 // should not be called on the critical path. |
29 return base::SysInfo::AmountOfPhysicalMemory() / 8; | 29 return base::SysInfo::AmountOfPhysicalMemory() / 8; |
30 } | 30 } |
31 | 31 |
32 // Holds the shared state used for allocations. | 32 // Holds the shared state used for allocations. |
33 struct SharedState { | 33 struct SharedState { |
34 SharedState() | 34 SharedState() |
35 : manager(kAshmemMemoryLimit, kAshmemMemoryLimit, TimeDelta::Max()), | 35 : manager(kAshmemMemoryLimit, |
| 36 kAshmemMemoryLimit, |
| 37 kAshmemMemoryLimit, |
| 38 TimeDelta::Max()), |
36 allocator(kAshmemAllocatorName, | 39 allocator(kAshmemAllocatorName, |
37 GetOptimalAshmemRegionSizeForAllocator()) {} | 40 GetOptimalAshmemRegionSizeForAllocator()) {} |
38 | 41 |
39 internal::DiscardableMemoryManager manager; | 42 internal::DiscardableMemoryManager manager; |
40 internal::DiscardableMemoryAshmemAllocator allocator; | 43 internal::DiscardableMemoryAshmemAllocator allocator; |
41 }; | 44 }; |
42 LazyInstance<SharedState>::Leaky g_shared_state = LAZY_INSTANCE_INITIALIZER; | 45 LazyInstance<SharedState>::Leaky g_shared_state = LAZY_INSTANCE_INITIALIZER; |
43 | 46 |
44 } // namespace | 47 } // namespace |
45 | 48 |
46 // static | 49 // static |
| 50 void DiscardableMemory::RegisterMemoryPressureListeners() { |
| 51 internal::DiscardableMemoryEmulated::RegisterMemoryPressureListeners(); |
| 52 } |
| 53 |
| 54 // static |
| 55 void DiscardableMemory::UnregisterMemoryPressureListeners() { |
| 56 internal::DiscardableMemoryEmulated::UnregisterMemoryPressureListeners(); |
| 57 } |
| 58 |
| 59 // static |
47 bool DiscardableMemory::ReduceMemoryUsage() { | 60 bool DiscardableMemory::ReduceMemoryUsage() { |
48 return internal::DiscardableMemoryEmulated::ReduceMemoryUsage(); | 61 return internal::DiscardableMemoryEmulated::ReduceMemoryUsage(); |
49 } | 62 } |
50 | 63 |
51 // static | 64 // static |
52 void DiscardableMemory::GetSupportedTypes( | 65 void DiscardableMemory::GetSupportedTypes( |
53 std::vector<DiscardableMemoryType>* types) { | 66 std::vector<DiscardableMemoryType>* types) { |
54 const DiscardableMemoryType supported_types[] = { | 67 const DiscardableMemoryType supported_types[] = { |
55 DISCARDABLE_MEMORY_TYPE_ASHMEM, | 68 DISCARDABLE_MEMORY_TYPE_ASHMEM, |
56 DISCARDABLE_MEMORY_TYPE_EMULATED, | 69 DISCARDABLE_MEMORY_TYPE_EMULATED, |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
98 return scoped_ptr<DiscardableMemory>(); | 111 return scoped_ptr<DiscardableMemory>(); |
99 } | 112 } |
100 | 113 |
101 // static | 114 // static |
102 void DiscardableMemory::PurgeForTesting() { | 115 void DiscardableMemory::PurgeForTesting() { |
103 g_shared_state.Pointer()->manager.PurgeAll(); | 116 g_shared_state.Pointer()->manager.PurgeAll(); |
104 internal::DiscardableMemoryEmulated::PurgeForTesting(); | 117 internal::DiscardableMemoryEmulated::PurgeForTesting(); |
105 } | 118 } |
106 | 119 |
107 } // namespace base | 120 } // namespace base |
OLD | NEW |