| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 "blimp/client/app/blimp_discardable_memory_allocator.h" | 5 #include "blimp/client/app/blimp_discardable_memory_allocator.h" |
| 6 | 6 |
| 7 #include "base/macros.h" | 7 #include "base/macros.h" |
| 8 #include "base/memory/discardable_memory.h" | 8 #include "base/memory/discardable_memory.h" |
| 9 #include "base/stl_util.h" | 9 #include "base/stl_util.h" |
| 10 #include "base/trace_event/memory_allocator_dump.h" | 10 #include "base/trace_event/memory_allocator_dump.h" |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 110 | 110 |
| 111 BlimpDiscardableMemoryAllocator::BlimpDiscardableMemoryAllocator( | 111 BlimpDiscardableMemoryAllocator::BlimpDiscardableMemoryAllocator( |
| 112 size_t desired_max_memory) | 112 size_t desired_max_memory) |
| 113 : desired_max_memory_(desired_max_memory), | 113 : desired_max_memory_(desired_max_memory), |
| 114 total_live_memory_(0u), | 114 total_live_memory_(0u), |
| 115 locked_chunks_(0) { | 115 locked_chunks_(0) { |
| 116 } | 116 } |
| 117 | 117 |
| 118 BlimpDiscardableMemoryAllocator::~BlimpDiscardableMemoryAllocator() { | 118 BlimpDiscardableMemoryAllocator::~BlimpDiscardableMemoryAllocator() { |
| 119 DCHECK_EQ(0, locked_chunks_); | 119 DCHECK_EQ(0, locked_chunks_); |
| 120 STLDeleteElements(&live_unlocked_chunks_); | 120 base::STLDeleteElements(&live_unlocked_chunks_); |
| 121 } | 121 } |
| 122 | 122 |
| 123 std::unique_ptr<base::DiscardableMemory> | 123 std::unique_ptr<base::DiscardableMemory> |
| 124 BlimpDiscardableMemoryAllocator::AllocateLockedDiscardableMemory(size_t size) { | 124 BlimpDiscardableMemoryAllocator::AllocateLockedDiscardableMemory(size_t size) { |
| 125 base::AutoLock lock(lock_); | 125 base::AutoLock lock(lock_); |
| 126 std::unique_ptr<DiscardableMemoryChunkImpl> chunk( | 126 std::unique_ptr<DiscardableMemoryChunkImpl> chunk( |
| 127 new DiscardableMemoryChunkImpl(size, this)); | 127 new DiscardableMemoryChunkImpl(size, this)); |
| 128 total_live_memory_ += size; | 128 total_live_memory_ += size; |
| 129 locked_chunks_++; | 129 locked_chunks_++; |
| 130 | 130 |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 164 while (total_live_memory_ > desired_max_memory_ && | 164 while (total_live_memory_ > desired_max_memory_ && |
| 165 it != live_unlocked_chunks_.end()) { | 165 it != live_unlocked_chunks_.end()) { |
| 166 total_live_memory_ -= (*it)->size(); | 166 total_live_memory_ -= (*it)->size(); |
| 167 (*it)->Discard(); | 167 (*it)->Discard(); |
| 168 it = live_unlocked_chunks_.erase(it); | 168 it = live_unlocked_chunks_.erase(it); |
| 169 } | 169 } |
| 170 } | 170 } |
| 171 | 171 |
| 172 } // namespace client | 172 } // namespace client |
| 173 } // namespace blimp | 173 } // namespace blimp |
| OLD | NEW |