 Chromium Code Reviews
 Chromium Code Reviews Issue 1016493002:
  Add a DiscardableMemoryShmemeAllocator.  (Closed) 
  Base URL: https://chromium.googlesource.com/chromium/src.git@master
    
  
    Issue 1016493002:
  Add a DiscardableMemoryShmemeAllocator.  (Closed) 
  Base URL: https://chromium.googlesource.com/chromium/src.git@master| 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_shmem_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::DiscardableMemoryShmemAllocator { | |
| 18 public: | |
| 19 class OwnedMemoryChunk; | |
| 
jamesr
2015/03/17 23:26:19
does this forward declaration need to be public?
 
Elliot Glaysher
2015/03/18 20:36:22
It does if I want to hide the implementation of Di
 | |
| 20 | |
| 21 DiscardableMemoryAllocator(size_t max_memory); | |
| 
jamesr
2015/03/17 23:26:19
explicit
 | |
| 22 ~DiscardableMemoryAllocator() override; | |
| 23 | |
| 24 // Overridden from DiscardableMemoryShmemAllocator: | |
| 25 scoped_ptr<base::DiscardableMemoryShmemChunk> 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 |