Chromium Code Reviews| Index: content/common/host_discardable_shared_memory_manager.h |
| diff --git a/content/common/host_discardable_shared_memory_manager.h b/content/common/host_discardable_shared_memory_manager.h |
| index 624dd2fdf164895db32e4427645d28a7b9e3f209..093667a430db597d940bead73dbc8cacf78f3d0c 100644 |
| --- a/content/common/host_discardable_shared_memory_manager.h |
| +++ b/content/common/host_discardable_shared_memory_manager.h |
| @@ -7,10 +7,11 @@ |
| #include <vector> |
| +#include "base/containers/hash_tables.h" |
| #include "base/memory/discardable_memory_shmem_allocator.h" |
| #include "base/memory/discardable_shared_memory.h" |
| -#include "base/memory/linked_ptr.h" |
| #include "base/memory/memory_pressure_listener.h" |
| +#include "base/memory/ref_counted.h" |
| #include "base/memory/shared_memory.h" |
| #include "base/memory/weak_ptr.h" |
| #include "base/process/process_handle.h" |
| @@ -18,6 +19,7 @@ |
| #include "content/common/content_export.h" |
| namespace content { |
| +typedef int32 DiscardableSharedMemoryId; |
|
Avi (use Gerrit)
2015/03/16 16:58:21
First, int32_t, per the deprecation notice in base
reveman
2015/03/16 18:30:55
int32 -> int32_t, Done.
The reason I didn't make
|
| // Implementation of DiscardableMemoryShmemAllocator that allocates and |
| // manages discardable memory segments for the browser process and child |
| @@ -41,9 +43,15 @@ class CONTENT_EXPORT HostDiscardableSharedMemoryManager |
| void AllocateLockedDiscardableSharedMemoryForChild( |
| base::ProcessHandle process_handle, |
| size_t size, |
| + DiscardableSharedMemoryId id, |
| base::SharedMemoryHandle* shared_memory_handle); |
| // Call this to notify the manager that child process associated with |
| + // |process_handle| has deleted discardable memory segment with |id|. |
| + void ChildDeletedDiscardableSharedMemory(DiscardableSharedMemoryId id, |
| + base::ProcessHandle process_handle); |
| + |
| + // Call this to notify the manager that child process associated with |
| // |process_handle| has been removed. The manager will use this to release |
| // memory segments allocated for child process to the OS. |
| void ProcessRemoved(base::ProcessHandle process_handle); |
| @@ -55,26 +63,37 @@ class CONTENT_EXPORT HostDiscardableSharedMemoryManager |
| // Reduce memory usage if above current memory limit. |
| void EnforceMemoryPolicy(); |
| + // Returns bytes of allocated discardable memory. |
| + size_t GetBytesAllocated(); |
| + |
| private: |
| - struct MemorySegment { |
| - MemorySegment(linked_ptr<base::DiscardableSharedMemory> memory, |
| - base::ProcessHandle process_handle); |
| + class MemorySegment : public base::RefCountedThreadSafe<MemorySegment> { |
| + public: |
| + MemorySegment(scoped_ptr<base::DiscardableSharedMemory> memory); |
| + |
| + base::DiscardableSharedMemory* memory() const { return memory_.get(); } |
| + |
| + private: |
| + friend class base::RefCountedThreadSafe<MemorySegment>; |
| + |
| ~MemorySegment(); |
| - linked_ptr<base::DiscardableSharedMemory> memory; |
| - base::ProcessHandle process_handle; |
| + scoped_ptr<base::DiscardableSharedMemory> memory_; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(MemorySegment); |
| }; |
| - static bool CompareMemoryUsageTime(const MemorySegment& a, |
| - const MemorySegment& b) { |
| + static bool CompareMemoryUsageTime(const scoped_refptr<MemorySegment>& a, |
| + const scoped_refptr<MemorySegment>& b) { |
| // In this system, LRU memory segment is evicted first. |
| - return a.memory->last_known_usage() > b.memory->last_known_usage(); |
| + return a->memory()->last_known_usage() > b->memory()->last_known_usage(); |
| } |
| void OnMemoryPressure( |
| base::MemoryPressureListener::MemoryPressureLevel memory_pressure_level); |
| void ReduceMemoryUsageUntilWithinMemoryLimit(); |
| void ReduceMemoryUsageUntilWithinLimit(size_t limit); |
| + void ReleaseMemory(base::DiscardableSharedMemory* memory); |
| void BytesAllocatedChanged(size_t new_bytes_allocated) const; |
| // Virtual for tests. |
| @@ -82,9 +101,13 @@ class CONTENT_EXPORT HostDiscardableSharedMemoryManager |
| virtual void ScheduleEnforceMemoryPolicy(); |
| base::Lock lock_; |
| + typedef base::hash_map<DiscardableSharedMemoryId, |
| + scoped_refptr<MemorySegment>> MemorySegmentMap; |
| + typedef base::hash_map<base::ProcessHandle, MemorySegmentMap> ProcessMap; |
| + ProcessMap processes_; |
| // Note: The elements in |segments_| are arranged in such a way that they form |
| // a heap. The LRU memory segment always first. |
| - typedef std::vector<MemorySegment> MemorySegmentVector; |
| + typedef std::vector<scoped_refptr<MemorySegment>> MemorySegmentVector; |
| MemorySegmentVector segments_; |
| size_t memory_limit_; |
| size_t bytes_allocated_; |