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 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
61 bool DiscardableMemoryEmulated::ReduceMemoryUsage() { | 61 bool DiscardableMemoryEmulated::ReduceMemoryUsage() { |
62 return g_manager.Pointer()->ReduceMemoryUsage(); | 62 return g_manager.Pointer()->ReduceMemoryUsage(); |
63 } | 63 } |
64 | 64 |
65 // static | 65 // static |
66 void DiscardableMemoryEmulated::ReduceMemoryUsageUntilWithinLimit( | 66 void DiscardableMemoryEmulated::ReduceMemoryUsageUntilWithinLimit( |
67 size_t bytes) { | 67 size_t bytes) { |
68 g_manager.Pointer()->ReduceMemoryUsageUntilWithinLimit(bytes); | 68 g_manager.Pointer()->ReduceMemoryUsageUntilWithinLimit(bytes); |
69 } | 69 } |
70 | 70 |
71 // static | |
72 void DiscardableMemoryEmulated::PurgeForTesting() { | |
73 g_manager.Pointer()->PurgeAll(); | |
74 } | |
75 | |
76 bool DiscardableMemoryEmulated::Initialize() { | 71 bool DiscardableMemoryEmulated::Initialize() { |
77 return Lock() != DISCARDABLE_MEMORY_LOCK_STATUS_FAILED; | 72 return Lock() != DISCARDABLE_MEMORY_LOCK_STATUS_FAILED; |
78 } | 73 } |
79 | 74 |
80 DiscardableMemoryLockStatus DiscardableMemoryEmulated::Lock() { | 75 DiscardableMemoryLockStatus DiscardableMemoryEmulated::Lock() { |
81 DCHECK(!is_locked_); | 76 DCHECK(!is_locked_); |
82 | 77 |
83 bool purged = false; | 78 bool purged = false; |
84 if (!g_manager.Pointer()->AcquireLock(this, &purged)) | 79 if (!g_manager.Pointer()->AcquireLock(this, &purged)) |
85 return DISCARDABLE_MEMORY_LOCK_STATUS_FAILED; | 80 return DISCARDABLE_MEMORY_LOCK_STATUS_FAILED; |
(...skipping 20 matching lines...) Expand all Loading... |
106 return true; | 101 return true; |
107 | 102 |
108 memory_.reset(new uint8[bytes_]); | 103 memory_.reset(new uint8[bytes_]); |
109 return false; | 104 return false; |
110 } | 105 } |
111 | 106 |
112 void DiscardableMemoryEmulated::Purge() { | 107 void DiscardableMemoryEmulated::Purge() { |
113 memory_.reset(); | 108 memory_.reset(); |
114 } | 109 } |
115 | 110 |
116 bool DiscardableMemoryEmulated::IsMemoryResident() const { | |
117 return true; | |
118 } | |
119 | |
120 } // namespace internal | 111 } // namespace internal |
121 } // namespace base | 112 } // namespace base |
OLD | NEW |