 Chromium Code Reviews
 Chromium Code Reviews Issue 2459733002:
  Move discardable memory  to //components from //content  (Closed)
    
  
    Issue 2459733002:
  Move discardable memory  to //components from //content  (Closed) 
  | OLD | NEW | 
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be | 
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. | 
| 4 | 4 | 
| 5 #ifndef CONTENT_COMMON_HOST_DISCARDABLE_SHARED_MEMORY_MANAGER_H_ | 5 #ifndef COMPONENTS_DISCARDABLE_MEMORY_COMMON_HOST_DISCARDABLE_SHARED_MEMORY_MANA GER_H_ | 
| 6 #define CONTENT_COMMON_HOST_DISCARDABLE_SHARED_MEMORY_MANAGER_H_ | 6 #define COMPONENTS_DISCARDABLE_MEMORY_COMMON_HOST_DISCARDABLE_SHARED_MEMORY_MANA GER_H_ | 
| 7 | 7 | 
| 8 #include <stddef.h> | 8 #include <stddef.h> | 
| 9 #include <stdint.h> | 9 #include <stdint.h> | 
| 10 | 10 | 
| 11 #include <memory> | 11 #include <memory> | 
| 12 #include <vector> | 12 #include <vector> | 
| 13 | 13 | 
| 14 #include "base/callback.h" | 14 #include "base/callback.h" | 
| 15 #include "base/containers/hash_tables.h" | 15 #include "base/containers/hash_tables.h" | 
| 16 #include "base/format_macros.h" | 16 #include "base/format_macros.h" | 
| 17 #include "base/macros.h" | 17 #include "base/macros.h" | 
| 18 #include "base/memory/discardable_memory_allocator.h" | 18 #include "base/memory/discardable_memory_allocator.h" | 
| 19 #include "base/memory/discardable_shared_memory.h" | 19 #include "base/memory/discardable_shared_memory.h" | 
| 20 #include "base/memory/memory_coordinator_client.h" | 20 #include "base/memory/memory_coordinator_client.h" | 
| 21 #include "base/memory/memory_pressure_listener.h" | 21 #include "base/memory/memory_pressure_listener.h" | 
| 22 #include "base/memory/ref_counted.h" | 22 #include "base/memory/ref_counted.h" | 
| 23 #include "base/memory/shared_memory.h" | 23 #include "base/memory/shared_memory.h" | 
| 24 #include "base/memory/weak_ptr.h" | 24 #include "base/memory/weak_ptr.h" | 
| 25 #include "base/process/process_handle.h" | 25 #include "base/process/process_handle.h" | 
| 26 #include "base/synchronization/lock.h" | 26 #include "base/synchronization/lock.h" | 
| 27 #include "base/threading/thread_task_runner_handle.h" | 27 #include "base/threading/thread_task_runner_handle.h" | 
| 28 #include "base/trace_event/memory_dump_provider.h" | 28 #include "base/trace_event/memory_dump_provider.h" | 
| 29 #include "content/common/content_export.h" | 29 #include "components/discardable_memory/common/discardable_memory_export.h" | 
| 30 | 30 | 
| 31 namespace content { | 31 namespace discardable_memory { | 
| 32 typedef int32_t DiscardableSharedMemoryId; | 32 typedef int32_t DiscardableSharedMemoryId; | 
| 33 | 33 | 
| 34 // Implementation of DiscardableMemoryAllocator that allocates and manages | 34 // Implementation of DiscardableMemoryAllocator that allocates and manages | 
| 35 // discardable memory segments for the browser process and child processes. | 35 // discardable memory segments for the browser process and child processes. | 
| 
reveman
2016/10/31 22:46:02
Can you update this comment to make sense in more
 
Peng
2016/11/01 14:26:18
Done.
 | |
| 36 // This class is thread-safe and instances can safely be used on any thread. | 36 // This class is thread-safe and instances can safely be used on any thread. | 
| 37 class CONTENT_EXPORT HostDiscardableSharedMemoryManager | 37 class DISCARDABLE_MEMORY_EXPORT DiscardableSharedMemoryManager | 
| 
reveman
2016/10/31 22:46:02
what's the reason 'Host' was removed from the name
 
Peng
2016/11/01 14:26:18
I just think the term Host is more like old chromi
 
reveman
2016/11/01 14:48:45
Sgtm. Should we change the name of child manager t
 
Peng
2016/11/01 16:00:23
Done.
 | |
| 38 : public base::DiscardableMemoryAllocator, | 38 : public base::DiscardableMemoryAllocator, | 
| 39 public base::trace_event::MemoryDumpProvider, | 39 public base::trace_event::MemoryDumpProvider, | 
| 40 public base::MemoryCoordinatorClient { | 40 public base::MemoryCoordinatorClient { | 
| 41 public: | 41 public: | 
| 42 HostDiscardableSharedMemoryManager(); | 42 DiscardableSharedMemoryManager(); | 
| 43 ~HostDiscardableSharedMemoryManager() override; | 43 ~DiscardableSharedMemoryManager() override; | 
| 44 | 44 | 
| 45 // Returns a singleton instance. | 45 // Returns a singleton instance. | 
| 46 static HostDiscardableSharedMemoryManager* current(); | 46 static DiscardableSharedMemoryManager* current(); | 
| 47 | 47 | 
| 48 // Overridden from base::DiscardableMemoryAllocator: | 48 // Overridden from base::DiscardableMemoryAllocator: | 
| 49 std::unique_ptr<base::DiscardableMemory> AllocateLockedDiscardableMemory( | 49 std::unique_ptr<base::DiscardableMemory> AllocateLockedDiscardableMemory( | 
| 50 size_t size) override; | 50 size_t size) override; | 
| 51 | 51 | 
| 52 // Overridden from base::trace_event::MemoryDumpProvider: | 52 // Overridden from base::trace_event::MemoryDumpProvider: | 
| 53 bool OnMemoryDump(const base::trace_event::MemoryDumpArgs& args, | 53 bool OnMemoryDump(const base::trace_event::MemoryDumpArgs& args, | 
| 54 base::trace_event::ProcessMemoryDump* pmd) override; | 54 base::trace_event::ProcessMemoryDump* pmd) override; | 
| 55 | 55 | 
| 56 // This allocates a discardable memory segment for |process_handle|. | 56 // This allocates a discardable memory segment for |process_handle|. | 
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 122 void ReduceMemoryUsageUntilWithinLimit(size_t limit); | 122 void ReduceMemoryUsageUntilWithinLimit(size_t limit); | 
| 123 void ReleaseMemory(base::DiscardableSharedMemory* memory); | 123 void ReleaseMemory(base::DiscardableSharedMemory* memory); | 
| 124 void BytesAllocatedChanged(size_t new_bytes_allocated) const; | 124 void BytesAllocatedChanged(size_t new_bytes_allocated) const; | 
| 125 | 125 | 
| 126 // Virtual for tests. | 126 // Virtual for tests. | 
| 127 virtual base::Time Now() const; | 127 virtual base::Time Now() const; | 
| 128 virtual void ScheduleEnforceMemoryPolicy(); | 128 virtual void ScheduleEnforceMemoryPolicy(); | 
| 129 | 129 | 
| 130 base::Lock lock_; | 130 base::Lock lock_; | 
| 131 typedef base::hash_map<DiscardableSharedMemoryId, | 131 typedef base::hash_map<DiscardableSharedMemoryId, | 
| 132 scoped_refptr<MemorySegment>> MemorySegmentMap; | 132 scoped_refptr<MemorySegment>> | 
| 133 MemorySegmentMap; | |
| 133 typedef base::hash_map<int, MemorySegmentMap> ProcessMap; | 134 typedef base::hash_map<int, MemorySegmentMap> ProcessMap; | 
| 134 ProcessMap processes_; | 135 ProcessMap processes_; | 
| 135 // Note: The elements in |segments_| are arranged in such a way that they form | 136 // Note: The elements in |segments_| are arranged in such a way that they form | 
| 136 // a heap. The LRU memory segment always first. | 137 // a heap. The LRU memory segment always first. | 
| 137 typedef std::vector<scoped_refptr<MemorySegment>> MemorySegmentVector; | 138 typedef std::vector<scoped_refptr<MemorySegment>> MemorySegmentVector; | 
| 138 MemorySegmentVector segments_; | 139 MemorySegmentVector segments_; | 
| 139 size_t default_memory_limit_; | 140 size_t default_memory_limit_; | 
| 140 size_t memory_limit_; | 141 size_t memory_limit_; | 
| 141 size_t bytes_allocated_; | 142 size_t bytes_allocated_; | 
| 142 std::unique_ptr<base::MemoryPressureListener> memory_pressure_listener_; | 143 std::unique_ptr<base::MemoryPressureListener> memory_pressure_listener_; | 
| 143 scoped_refptr<base::SingleThreadTaskRunner> | 144 scoped_refptr<base::SingleThreadTaskRunner> | 
| 144 enforce_memory_policy_task_runner_; | 145 enforce_memory_policy_task_runner_; | 
| 145 base::Closure enforce_memory_policy_callback_; | 146 base::Closure enforce_memory_policy_callback_; | 
| 146 bool enforce_memory_policy_pending_; | 147 bool enforce_memory_policy_pending_; | 
| 147 base::WeakPtrFactory<HostDiscardableSharedMemoryManager> weak_ptr_factory_; | 148 base::WeakPtrFactory<DiscardableSharedMemoryManager> weak_ptr_factory_; | 
| 148 | 149 | 
| 149 DISALLOW_COPY_AND_ASSIGN(HostDiscardableSharedMemoryManager); | 150 DISALLOW_COPY_AND_ASSIGN(DiscardableSharedMemoryManager); | 
| 150 }; | 151 }; | 
| 151 | 152 | 
| 152 } // namespace content | 153 } // namespace discardable_memory | 
| 153 | 154 | 
| 154 #endif // CONTENT_COMMON_HOST_DISCARDABLE_SHARED_MEMORY_MANAGER_H_ | 155 #endif // COMPONENTS_DISCARDABLE_MEMORY_COMMON_HOST_DISCARDABLE_SHARED_MEMORY_M ANAGER_H_ | 
| OLD | NEW |