| 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, | 35 : manager(kAshmemMemoryLimit, kAshmemMemoryLimit, TimeDelta::Max()), |
| 36 kAshmemMemoryLimit, | |
| 37 kAshmemMemoryLimit, | |
| 38 TimeDelta::Max()), | |
| 39 allocator(kAshmemAllocatorName, | 36 allocator(kAshmemAllocatorName, |
| 40 GetOptimalAshmemRegionSizeForAllocator()) {} | 37 GetOptimalAshmemRegionSizeForAllocator()) {} |
| 41 | 38 |
| 42 internal::DiscardableMemoryManager manager; | 39 internal::DiscardableMemoryManager manager; |
| 43 internal::DiscardableMemoryAshmemAllocator allocator; | 40 internal::DiscardableMemoryAshmemAllocator allocator; |
| 44 }; | 41 }; |
| 45 LazyInstance<SharedState>::Leaky g_shared_state = LAZY_INSTANCE_INITIALIZER; | 42 LazyInstance<SharedState>::Leaky g_shared_state = LAZY_INSTANCE_INITIALIZER; |
| 46 | 43 |
| 47 } // namespace | 44 } // namespace |
| 48 | 45 |
| 49 // static | 46 // 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 | |
| 60 bool DiscardableMemory::ReduceMemoryUsage() { | 47 bool DiscardableMemory::ReduceMemoryUsage() { |
| 61 return internal::DiscardableMemoryEmulated::ReduceMemoryUsage(); | 48 return internal::DiscardableMemoryEmulated::ReduceMemoryUsage(); |
| 62 } | 49 } |
| 63 | 50 |
| 64 // static | 51 // static |
| 65 void DiscardableMemory::GetSupportedTypes( | 52 void DiscardableMemory::GetSupportedTypes( |
| 66 std::vector<DiscardableMemoryType>* types) { | 53 std::vector<DiscardableMemoryType>* types) { |
| 67 const DiscardableMemoryType supported_types[] = { | 54 const DiscardableMemoryType supported_types[] = { |
| 68 DISCARDABLE_MEMORY_TYPE_ASHMEM, | 55 DISCARDABLE_MEMORY_TYPE_ASHMEM, |
| 69 DISCARDABLE_MEMORY_TYPE_EMULATED, | 56 DISCARDABLE_MEMORY_TYPE_EMULATED, |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 111 return scoped_ptr<DiscardableMemory>(); | 98 return scoped_ptr<DiscardableMemory>(); |
| 112 } | 99 } |
| 113 | 100 |
| 114 // static | 101 // static |
| 115 void DiscardableMemory::PurgeForTesting() { | 102 void DiscardableMemory::PurgeForTesting() { |
| 116 g_shared_state.Pointer()->manager.PurgeAll(); | 103 g_shared_state.Pointer()->manager.PurgeAll(); |
| 117 internal::DiscardableMemoryEmulated::PurgeForTesting(); | 104 internal::DiscardableMemoryEmulated::PurgeForTesting(); |
| 118 } | 105 } |
| 119 | 106 |
| 120 } // namespace base | 107 } // namespace base |
| OLD | NEW |