OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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_manager.h" | 5 #include "base/memory/discardable_memory_manager.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/containers/hash_tables.h" | 8 #include "base/containers/hash_tables.h" |
9 #include "base/containers/mru_cache.h" | 9 #include "base/containers/mru_cache.h" |
10 #include "base/debug/trace_event.h" | 10 #include "base/debug/trace_event.h" |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
107 if (bytes_required < memory_limit_) | 107 if (bytes_required < memory_limit_) |
108 limit = memory_limit_ - bytes_required; | 108 limit = memory_limit_ - bytes_required; |
109 | 109 |
110 PurgeLRUWithLockAcquiredUntilUsageIsWithin(limit); | 110 PurgeLRUWithLockAcquiredUntilUsageIsWithin(limit); |
111 } | 111 } |
112 | 112 |
113 // Check for overflow. | 113 // Check for overflow. |
114 if (std::numeric_limits<size_t>::max() - bytes_required < bytes_allocated_) | 114 if (std::numeric_limits<size_t>::max() - bytes_required < bytes_allocated_) |
115 return false; | 115 return false; |
116 | 116 |
117 *purged = !allocation->AllocateAndAcquireLock(info->bytes); | 117 *purged = !allocation->AllocateAndAcquireLock(); |
118 info->purgable = false; | 118 info->purgable = false; |
119 if (bytes_required) { | 119 if (bytes_required) { |
120 bytes_allocated_ += bytes_required; | 120 bytes_allocated_ += bytes_required; |
121 BytesAllocatedChanged(); | 121 BytesAllocatedChanged(); |
122 } | 122 } |
123 return true; | 123 return true; |
124 } | 124 } |
125 | 125 |
126 void DiscardableMemoryManager::ReleaseLock(Allocation* allocation) { | 126 void DiscardableMemoryManager::ReleaseLock(Allocation* allocation) { |
127 AutoLock lock(lock_); | 127 AutoLock lock(lock_); |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
217 void DiscardableMemoryManager::EnforcePolicyWithLockAcquired() { | 217 void DiscardableMemoryManager::EnforcePolicyWithLockAcquired() { |
218 PurgeLRUWithLockAcquiredUntilUsageIsWithin(memory_limit_); | 218 PurgeLRUWithLockAcquiredUntilUsageIsWithin(memory_limit_); |
219 } | 219 } |
220 | 220 |
221 void DiscardableMemoryManager::BytesAllocatedChanged() const { | 221 void DiscardableMemoryManager::BytesAllocatedChanged() const { |
222 TRACE_COUNTER_ID1("base", "DiscardableMemoryUsage", this, bytes_allocated_); | 222 TRACE_COUNTER_ID1("base", "DiscardableMemoryUsage", this, bytes_allocated_); |
223 } | 223 } |
224 | 224 |
225 } // namespace internal | 225 } // namespace internal |
226 } // namespace base | 226 } // namespace base |
OLD | NEW |