| 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 : public base::DiscardableMemoryAllocator { | 
|  | 17  public: | 
|  | 18   class OwnedMemoryChunk; | 
|  | 19 | 
|  | 20   explicit DiscardableMemoryAllocator(size_t desired_max_memory); | 
|  | 21   ~DiscardableMemoryAllocator() override; | 
|  | 22 | 
|  | 23   // Overridden from DiscardableMemoryAllocator: | 
|  | 24   scoped_ptr<base::DiscardableMemory> AllocateLockedDiscardableMemory( | 
|  | 25       size_t size) override; | 
|  | 26 | 
|  | 27  private: | 
|  | 28   friend class OwnedMemoryChunk; | 
|  | 29 | 
|  | 30   // Called by OwnedMemoryChunks when they are unlocked. This puts them at the | 
|  | 31   // end of the live_unlocked_chunks_ list and passes an iterator to their | 
|  | 32   // position in the unlocked chunk list. | 
|  | 33   std::list<OwnedMemoryChunk*>::iterator NotifyUnlocked( | 
|  | 34       OwnedMemoryChunk* chunk); | 
|  | 35 | 
|  | 36   // Called by OwnedMemoryChunks when they are locked. This removes the passed | 
|  | 37   // in unlocked chunk list. | 
|  | 38   void NotifyLocked(std::list<OwnedMemoryChunk*>::iterator it); | 
|  | 39 | 
|  | 40   // The amount of memory we can allocate before we try to free unlocked | 
|  | 41   // chunks. We can go over this amount if all callers keep their discardable | 
|  | 42   // chunks locked. | 
|  | 43   const size_t desired_max_memory_; | 
|  | 44 | 
|  | 45   // A count of the sum of memory. Used to trigger discarding the oldest | 
|  | 46   // memory. | 
|  | 47   size_t total_live_memory_; | 
|  | 48 | 
|  | 49   // The number of locked chunks. | 
|  | 50   int locked_chunks_; | 
|  | 51 | 
|  | 52   // A linked list of unlocked allocated chunks so that the tail is most | 
|  | 53   // recently accessed chunks. | 
|  | 54   std::list<OwnedMemoryChunk*> live_unlocked_chunks_; | 
|  | 55 | 
|  | 56   DISALLOW_COPY_AND_ASSIGN(DiscardableMemoryAllocator); | 
|  | 57 }; | 
|  | 58 | 
|  | 59 }  // namespace html_viewer | 
|  | 60 | 
|  | 61 #endif  // MOJO_SERVICES_HTML_VIEWER_DISCARDABLE_MEMORY_ALLOCATOR_H_ | 
| OLD | NEW | 
|---|