| 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" | |
| 10 #include "base/trace_event/memory_allocator_dump.h" | 9 #include "base/trace_event/memory_allocator_dump.h" |
| 11 #include "base/trace_event/memory_dump_manager.h" | 10 #include "base/trace_event/memory_dump_manager.h" |
| 12 #include "base/trace_event/process_memory_dump.h" | 11 #include "base/trace_event/process_memory_dump.h" |
| 13 | 12 |
| 14 namespace blimp { | 13 namespace blimp { |
| 15 namespace client { | 14 namespace client { |
| 16 | 15 |
| 17 namespace { | 16 namespace { |
| 18 | 17 |
| 19 size_t kDesiredMaxMemory = 20 * 1024 * 1024; /* 20 MB */ | 18 size_t kDesiredMaxMemory = 20 * 1024 * 1024; /* 20 MB */ |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 110 | 109 |
| 111 BlimpDiscardableMemoryAllocator::BlimpDiscardableMemoryAllocator( | 110 BlimpDiscardableMemoryAllocator::BlimpDiscardableMemoryAllocator( |
| 112 size_t desired_max_memory) | 111 size_t desired_max_memory) |
| 113 : desired_max_memory_(desired_max_memory), | 112 : desired_max_memory_(desired_max_memory), |
| 114 total_live_memory_(0u), | 113 total_live_memory_(0u), |
| 115 locked_chunks_(0) { | 114 locked_chunks_(0) { |
| 116 } | 115 } |
| 117 | 116 |
| 118 BlimpDiscardableMemoryAllocator::~BlimpDiscardableMemoryAllocator() { | 117 BlimpDiscardableMemoryAllocator::~BlimpDiscardableMemoryAllocator() { |
| 119 DCHECK_EQ(0, locked_chunks_); | 118 DCHECK_EQ(0, locked_chunks_); |
| 120 base::STLDeleteElements(&live_unlocked_chunks_); | 119 DCHECK_EQ(0u, live_unlocked_chunks_.size()); |
| 121 } | 120 } |
| 122 | 121 |
| 123 std::unique_ptr<base::DiscardableMemory> | 122 std::unique_ptr<base::DiscardableMemory> |
| 124 BlimpDiscardableMemoryAllocator::AllocateLockedDiscardableMemory(size_t size) { | 123 BlimpDiscardableMemoryAllocator::AllocateLockedDiscardableMemory(size_t size) { |
| 125 base::AutoLock lock(lock_); | 124 base::AutoLock lock(lock_); |
| 126 std::unique_ptr<DiscardableMemoryChunkImpl> chunk( | 125 std::unique_ptr<DiscardableMemoryChunkImpl> chunk( |
| 127 new DiscardableMemoryChunkImpl(size, this)); | 126 new DiscardableMemoryChunkImpl(size, this)); |
| 128 total_live_memory_ += size; | 127 total_live_memory_ += size; |
| 129 locked_chunks_++; | 128 locked_chunks_++; |
| 130 | 129 |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 164 while (total_live_memory_ > desired_max_memory_ && | 163 while (total_live_memory_ > desired_max_memory_ && |
| 165 it != live_unlocked_chunks_.end()) { | 164 it != live_unlocked_chunks_.end()) { |
| 166 total_live_memory_ -= (*it)->size(); | 165 total_live_memory_ -= (*it)->size(); |
| 167 (*it)->Discard(); | 166 (*it)->Discard(); |
| 168 it = live_unlocked_chunks_.erase(it); | 167 it = live_unlocked_chunks_.erase(it); |
| 169 } | 168 } |
| 170 } | 169 } |
| 171 | 170 |
| 172 } // namespace client | 171 } // namespace client |
| 173 } // namespace blimp | 172 } // namespace blimp |
| OLD | NEW |