| OLD | NEW |
| (Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef MOJO_SERVICES_HTML_VIEWER_DISCARDABLE_MEMORY_ALLOCATOR_H_ |
| 6 #define MOJO_SERVICES_HTML_VIEWER_DISCARDABLE_MEMORY_ALLOCATOR_H_ |
| 7 |
| 8 #include <list> |
| 9 |
| 10 #include "base/memory/discardable_memory_allocator.h" |
| 11 |
| 12 namespace html_viewer { |
| 13 |
| 14 // A discarable memory allocator which will unallocate chunks on new |
| 15 // allocations. |
| 16 class DiscardableMemoryAllocator |
| 17 : public base::DiscardableMemoryAllocator { |
| 18 public: |
| 19 class OwnedMemoryChunk; |
| 20 |
| 21 explicit DiscardableMemoryAllocator(size_t max_memory); |
| 22 ~DiscardableMemoryAllocator() override; |
| 23 |
| 24 // Overridden from DiscardableMemoryAllocator: |
| 25 scoped_ptr<base::DiscardableMemory> AllocateLockedDiscardableMemory( |
| 26 size_t size) override; |
| 27 |
| 28 private: |
| 29 friend class OwnedMemoryChunk; |
| 30 |
| 31 void MoveToBack(std::list<OwnedMemoryChunk*>::iterator it); |
| 32 |
| 33 // The amount of memory we can allocate before we try to free unlocked chunks. |
| 34 const size_t max_memory_; |
| 35 |
| 36 // A count of the sum of memory. Used to trigger discarding the oldest |
| 37 // memory. |
| 38 size_t total_live_memory_; |
| 39 |
| 40 // A linked list of allocated chunks so that the tail is the newest chunks, |
| 41 // and the head is the oldest chunks. On Lock()ing a chunk, it is sent to the |
| 42 // back of this list. |
| 43 std::list<OwnedMemoryChunk*> live_chunks_; |
| 44 |
| 45 DISALLOW_COPY_AND_ASSIGN(DiscardableMemoryAllocator); |
| 46 }; |
| 47 |
| 48 } // namespace html_viewer |
| 49 |
| 50 #endif // MOJO_SERVICES_HTML_VIEWER_DISCARDABLE_MEMORY_ALLOCATOR_H_ |
| OLD | NEW |