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/adapters.h" |
8 #include "base/containers/hash_tables.h" | 9 #include "base/containers/hash_tables.h" |
9 #include "base/containers/mru_cache.h" | 10 #include "base/containers/mru_cache.h" |
10 #include "base/debug/crash_logging.h" | 11 #include "base/debug/crash_logging.h" |
11 #include "base/debug/trace_event.h" | 12 #include "base/debug/trace_event.h" |
12 #include "base/strings/string_number_conversions.h" | 13 #include "base/strings/string_number_conversions.h" |
13 #include "base/synchronization/lock.h" | 14 #include "base/synchronization/lock.h" |
14 | 15 |
15 namespace base { | 16 namespace base { |
16 namespace internal { | 17 namespace internal { |
17 | 18 |
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
170 return bytes_allocated_ <= soft_memory_limit_; | 171 return bytes_allocated_ <= soft_memory_limit_; |
171 } | 172 } |
172 | 173 |
173 void DiscardableMemoryManager:: | 174 void DiscardableMemoryManager:: |
174 PurgeIfNotUsedSinceTimestampUntilUsageIsWithinLimitWithLockAcquired( | 175 PurgeIfNotUsedSinceTimestampUntilUsageIsWithinLimitWithLockAcquired( |
175 TimeTicks timestamp, | 176 TimeTicks timestamp, |
176 size_t limit) { | 177 size_t limit) { |
177 lock_.AssertAcquired(); | 178 lock_.AssertAcquired(); |
178 | 179 |
179 size_t bytes_allocated_before_purging = bytes_allocated_; | 180 size_t bytes_allocated_before_purging = bytes_allocated_; |
180 for (AllocationMap::reverse_iterator it = allocations_.rbegin(); | 181 for (auto& entry : base::Reversed(allocations_)) { |
181 it != allocations_.rend(); | 182 Allocation* allocation = entry.first; |
182 ++it) { | 183 AllocationInfo* info = &entry.second; |
183 Allocation* allocation = it->first; | |
184 AllocationInfo* info = &it->second; | |
185 | 184 |
186 if (bytes_allocated_ <= limit) | 185 if (bytes_allocated_ <= limit) |
187 break; | 186 break; |
188 | 187 |
189 bool purgable = info->purgable && info->last_usage <= timestamp; | 188 bool purgable = info->purgable && info->last_usage <= timestamp; |
190 if (!purgable) | 189 if (!purgable) |
191 continue; | 190 continue; |
192 | 191 |
193 size_t bytes_purgable = info->bytes; | 192 size_t bytes_purgable = info->bytes; |
194 DCHECK_LE(bytes_purgable, bytes_allocated_); | 193 DCHECK_LE(bytes_purgable, bytes_allocated_); |
(...skipping 15 matching lines...) Expand all Loading... |
210 base::debug::SetCrashKeyValue(kDiscardableMemoryUsageKey, | 209 base::debug::SetCrashKeyValue(kDiscardableMemoryUsageKey, |
211 Uint64ToString(new_bytes_allocated)); | 210 Uint64ToString(new_bytes_allocated)); |
212 } | 211 } |
213 | 212 |
214 TimeTicks DiscardableMemoryManager::Now() const { | 213 TimeTicks DiscardableMemoryManager::Now() const { |
215 return TimeTicks::Now(); | 214 return TimeTicks::Now(); |
216 } | 215 } |
217 | 216 |
218 } // namespace internal | 217 } // namespace internal |
219 } // namespace base | 218 } // namespace base |
OLD | NEW |