Chromium Code Reviews| Index: components/html_viewer/discardable_memory_allocator.h |
| diff --git a/components/html_viewer/discardable_memory_allocator.h b/components/html_viewer/discardable_memory_allocator.h |
| index be7f063ef9064fb9e3dcaa2fc87057bfd7b3570a..d756d8f488e16c86196395f11b43a725e63ecf66 100644 |
| --- a/components/html_viewer/discardable_memory_allocator.h |
| +++ b/components/html_viewer/discardable_memory_allocator.h |
| @@ -7,7 +7,8 @@ |
| #include <list> |
| -#include "base/memory/discardable_memory_allocator.h" |
| +#include "base/memory/discardable_memory_allocator.h" |
| +#include "base/synchronization/lock.h" |
| namespace html_viewer { |
| @@ -15,8 +16,6 @@ namespace html_viewer { |
| // allocations. |
| class DiscardableMemoryAllocator : public base::DiscardableMemoryAllocator { |
| public: |
| - class OwnedMemoryChunk; |
| - |
| explicit DiscardableMemoryAllocator(size_t desired_max_memory); |
| ~DiscardableMemoryAllocator() override; |
| @@ -25,23 +24,30 @@ class DiscardableMemoryAllocator : public base::DiscardableMemoryAllocator { |
| size_t size) override; |
| private: |
| - friend class OwnedMemoryChunk; |
| + class DiscardableMemoryChunkImpl; |
| + friend class DiscardableMemoryChunkImpl; |
| + |
| + // Called by DiscardableMemoryChunkImpl when they are unlocked. This puts them |
| + // at the end of the live_unlocked_chunks_ list and passes an iterator to |
| + // their position in the unlocked chunk list. |
| + std::list<DiscardableMemoryChunkImpl*>::iterator NotifyUnlocked( |
| + DiscardableMemoryChunkImpl* chunk); |
| - // Called by OwnedMemoryChunks when they are unlocked. This puts them at the |
| - // end of the live_unlocked_chunks_ list and passes an iterator to their |
| - // position in the unlocked chunk list. |
| - std::list<OwnedMemoryChunk*>::iterator NotifyUnlocked( |
| - OwnedMemoryChunk* chunk); |
| + // Called by DiscardableMemoryChunkImpl when they are locked. This removes the |
| + // passed in unlocked chunk list. |
| + void NotifyLocked(std::list<DiscardableMemoryChunkImpl*>::iterator it); |
| - // Called by OwnedMemoryChunks when they are locked. This removes the passed |
| - // in unlocked chunk list. |
| - void NotifyLocked(std::list<OwnedMemoryChunk*>::iterator it); |
| + // Called by DiscardableMemoryChunkImpl when it's destructed. It must be |
| + // unlocked, by definition. |
| + void NotifyDestructed(std::list<DiscardableMemoryChunkImpl*>::iterator it); |
| // The amount of memory we can allocate before we try to free unlocked |
| // chunks. We can go over this amount if all callers keep their discardable |
| // chunks locked. |
| const size_t desired_max_memory_; |
| + base::Lock lock_; |
|
danakj
2015/06/15 17:47:34
Could you comment or otherwise make it clear which
sky
2015/06/15 21:47:46
Also document what threads are in use here. That i
jam
2015/06/15 22:06:01
Done.
jam
2015/06/15 22:44:55
Done.
|
| + |
| // A count of the sum of memory. Used to trigger discarding the oldest |
| // memory. |
| size_t total_live_memory_; |
| @@ -51,7 +57,7 @@ class DiscardableMemoryAllocator : public base::DiscardableMemoryAllocator { |
| // A linked list of unlocked allocated chunks so that the tail is most |
| // recently accessed chunks. |
| - std::list<OwnedMemoryChunk*> live_unlocked_chunks_; |
| + std::list<DiscardableMemoryChunkImpl*> live_unlocked_chunks_; |
| DISALLOW_COPY_AND_ASSIGN(DiscardableMemoryAllocator); |
| }; |