| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "components/html_viewer/discardable_memory_allocator.h" | 5 #include "components/html_viewer/discardable_memory_allocator.h" |
| 6 | 6 |
| 7 #include "base/memory/discardable_memory.h" | 7 #include "base/memory/discardable_memory.h" |
| 8 #include "base/stl_util.h" | 8 #include "base/stl_util.h" |
| 9 #include "base/trace_event/memory_allocator_dump.h" |
| 10 #include "base/trace_event/memory_dump_manager.h" |
| 11 #include "base/trace_event/process_memory_dump.h" |
| 9 | 12 |
| 10 namespace html_viewer { | 13 namespace html_viewer { |
| 11 | 14 |
| 12 // Interface to the rest of the program. These objects are owned outside of the | 15 // Interface to the rest of the program. These objects are owned outside of the |
| 13 // allocator. | 16 // allocator. |
| 14 class DiscardableMemoryAllocator::DiscardableMemoryChunkImpl | 17 class DiscardableMemoryAllocator::DiscardableMemoryChunkImpl |
| 15 : public base::DiscardableMemory { | 18 : public base::DiscardableMemory { |
| 16 public: | 19 public: |
| 17 DiscardableMemoryChunkImpl(size_t size, DiscardableMemoryAllocator* allocator) | 20 DiscardableMemoryChunkImpl(size_t size, DiscardableMemoryAllocator* allocator) |
| 18 : is_locked_(true), | 21 : is_locked_(true), |
| (...skipping 27 matching lines...) Expand all Loading... |
| 46 } | 49 } |
| 47 | 50 |
| 48 void* data() const override { | 51 void* data() const override { |
| 49 if (data_) { | 52 if (data_) { |
| 50 DCHECK(is_locked_); | 53 DCHECK(is_locked_); |
| 51 return data_.get(); | 54 return data_.get(); |
| 52 } | 55 } |
| 53 return nullptr; | 56 return nullptr; |
| 54 } | 57 } |
| 55 | 58 |
| 59 base::trace_event::MemoryAllocatorDump* CreateMemoryAllocatorDump( |
| 60 const char* name, |
| 61 base::trace_event::ProcessMemoryDump* pmd) const override { |
| 62 base::trace_event::MemoryAllocatorDump* dump = |
| 63 pmd->CreateAllocatorDump(name); |
| 64 dump->AddScalar(base::trace_event::MemoryAllocatorDump::kNameSize, |
| 65 base::trace_event::MemoryAllocatorDump::kUnitsBytes, size_); |
| 66 |
| 67 // Memory is allocated from system allocator (malloc). |
| 68 pmd->AddSuballocation(dump->guid(), |
| 69 base::trace_event::MemoryDumpManager::GetInstance() |
| 70 ->system_allocator_pool_name()); |
| 71 return dump; |
| 72 } |
| 73 |
| 56 size_t size() const { return size_; } | 74 size_t size() const { return size_; } |
| 57 | 75 |
| 58 void Discard() { | 76 void Discard() { |
| 59 DCHECK(!is_locked_); | 77 DCHECK(!is_locked_); |
| 60 data_.reset(); | 78 data_.reset(); |
| 61 } | 79 } |
| 62 | 80 |
| 63 private: | 81 private: |
| 64 bool is_locked_; | 82 bool is_locked_; |
| 65 size_t size_; | 83 size_t size_; |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 119 live_unlocked_chunks_.erase(it); | 137 live_unlocked_chunks_.erase(it); |
| 120 } | 138 } |
| 121 | 139 |
| 122 void DiscardableMemoryAllocator::NotifyDestructed( | 140 void DiscardableMemoryAllocator::NotifyDestructed( |
| 123 std::list<DiscardableMemoryChunkImpl*>::iterator it) { | 141 std::list<DiscardableMemoryChunkImpl*>::iterator it) { |
| 124 base::AutoLock lock(lock_); | 142 base::AutoLock lock(lock_); |
| 125 live_unlocked_chunks_.erase(it); | 143 live_unlocked_chunks_.erase(it); |
| 126 } | 144 } |
| 127 | 145 |
| 128 } // namespace html_viewer | 146 } // namespace html_viewer |
| OLD | NEW |