| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 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_emulated.h" | 5 #include "base/memory/discardable_memory_emulated.h" |
| 6 | 6 |
| 7 #include "base/lazy_instance.h" | 7 #include "base/lazy_instance.h" |
| 8 #include "base/memory/discardable_memory_manager.h" | 8 #include "base/memory/discardable_memory_manager.h" |
| 9 | 9 |
| 10 namespace base { | 10 namespace base { |
| (...skipping 27 matching lines...) Expand all Loading... |
| 38 g_shared_state.Pointer()->manager.Register(this, bytes); | 38 g_shared_state.Pointer()->manager.Register(this, bytes); |
| 39 } | 39 } |
| 40 | 40 |
| 41 DiscardableMemoryEmulated::~DiscardableMemoryEmulated() { | 41 DiscardableMemoryEmulated::~DiscardableMemoryEmulated() { |
| 42 if (is_locked_) | 42 if (is_locked_) |
| 43 Unlock(); | 43 Unlock(); |
| 44 g_shared_state.Pointer()->manager.Unregister(this); | 44 g_shared_state.Pointer()->manager.Unregister(this); |
| 45 } | 45 } |
| 46 | 46 |
| 47 // static | 47 // static |
| 48 void DiscardableMemoryEmulated::RegisterMemoryPressureListeners() { | |
| 49 g_shared_state.Pointer()->manager.RegisterMemoryPressureListener(); | |
| 50 } | |
| 51 | |
| 52 // static | |
| 53 void DiscardableMemoryEmulated::UnregisterMemoryPressureListeners() { | |
| 54 g_shared_state.Pointer()->manager.UnregisterMemoryPressureListener(); | |
| 55 } | |
| 56 | |
| 57 // static | |
| 58 bool DiscardableMemoryEmulated::ReduceMemoryUsage() { | 48 bool DiscardableMemoryEmulated::ReduceMemoryUsage() { |
| 59 return g_shared_state.Pointer()->manager.ReduceMemoryUsage(); | 49 return g_shared_state.Pointer()->manager.ReduceMemoryUsage(); |
| 60 } | 50 } |
| 61 | 51 |
| 62 // static | 52 // static |
| 53 void DiscardableMemoryEmulated::SetModeratePressureLimit(size_t bytes) { |
| 54 g_shared_state.Pointer() |
| 55 ->manager.SetBytesToKeepUnderModeratePressure(bytes); |
| 56 } |
| 57 |
| 58 // static |
| 59 void |
| 60 DiscardableMemoryEmulated::ReduceMemoryUsageUntilWithinModeratePressureLimit() { |
| 61 g_shared_state.Pointer() |
| 62 ->manager.ReduceMemoryUsageUntilWithinModeratePressureLimit(); |
| 63 } |
| 64 |
| 65 // static |
| 63 void DiscardableMemoryEmulated::PurgeForTesting() { | 66 void DiscardableMemoryEmulated::PurgeForTesting() { |
| 64 g_shared_state.Pointer()->manager.PurgeAll(); | 67 g_shared_state.Pointer()->manager.PurgeAll(); |
| 65 } | 68 } |
| 66 | 69 |
| 67 bool DiscardableMemoryEmulated::Initialize() { | 70 bool DiscardableMemoryEmulated::Initialize() { |
| 68 return Lock() != DISCARDABLE_MEMORY_LOCK_STATUS_FAILED; | 71 return Lock() != DISCARDABLE_MEMORY_LOCK_STATUS_FAILED; |
| 69 } | 72 } |
| 70 | 73 |
| 71 DiscardableMemoryLockStatus DiscardableMemoryEmulated::Lock() { | 74 DiscardableMemoryLockStatus DiscardableMemoryEmulated::Lock() { |
| 72 DCHECK(!is_locked_); | 75 DCHECK(!is_locked_); |
| (...skipping 26 matching lines...) Expand all Loading... |
| 99 memory_.reset(new uint8[bytes_]); | 102 memory_.reset(new uint8[bytes_]); |
| 100 return false; | 103 return false; |
| 101 } | 104 } |
| 102 | 105 |
| 103 void DiscardableMemoryEmulated::Purge() { | 106 void DiscardableMemoryEmulated::Purge() { |
| 104 memory_.reset(); | 107 memory_.reset(); |
| 105 } | 108 } |
| 106 | 109 |
| 107 } // namespace internal | 110 } // namespace internal |
| 108 } // namespace base | 111 } // namespace base |
| OLD | NEW |