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 CONTENT_COMMON_HOST_DISCARDABLE_SHARED_MEMORY_MANAGER_H_ |
6 #define CONTENT_COMMON_HOST_DISCARDABLE_SHARED_MEMORY_MANAGER_H_ | 6 #define CONTENT_COMMON_HOST_DISCARDABLE_SHARED_MEMORY_MANAGER_H_ |
7 | 7 |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/memory/discardable_memory_shmem_allocator.h" | 10 #include "base/memory/discardable_memory_shmem_allocator.h" |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
64 linked_ptr<base::DiscardableSharedMemory> memory; | 64 linked_ptr<base::DiscardableSharedMemory> memory; |
65 base::ProcessHandle process_handle; | 65 base::ProcessHandle process_handle; |
66 }; | 66 }; |
67 | 67 |
68 static bool CompareMemoryUsageTime(const MemorySegment& a, | 68 static bool CompareMemoryUsageTime(const MemorySegment& a, |
69 const MemorySegment& b) { | 69 const MemorySegment& b) { |
70 // In this system, LRU memory segment is evicted first. | 70 // In this system, LRU memory segment is evicted first. |
71 return a.memory->last_known_usage() > b.memory->last_known_usage(); | 71 return a.memory->last_known_usage() > b.memory->last_known_usage(); |
72 } | 72 } |
73 | 73 |
74 void AllocateLockedDiscardableSharedMemory( | |
75 base::ProcessHandle process_handle, | |
76 size_t size, | |
77 base::SharedMemoryHandle* shared_memory_handle); | |
78 void OnMemoryPressure( | 74 void OnMemoryPressure( |
79 base::MemoryPressureListener::MemoryPressureLevel memory_pressure_level); | 75 base::MemoryPressureListener::MemoryPressureLevel memory_pressure_level); |
80 void ReduceMemoryUsageUntilWithinMemoryLimit(); | 76 void ReduceMemoryUsageUntilWithinMemoryLimit(); |
81 void ReduceMemoryUsageUntilWithinLimit(size_t limit); | 77 void ReduceMemoryUsageUntilWithinLimit(size_t limit); |
82 void BytesAllocatedChanged(size_t new_bytes_allocated) const; | 78 void BytesAllocatedChanged(size_t new_bytes_allocated) const; |
83 | 79 |
84 // Virtual for tests. | 80 // Virtual for tests. |
85 virtual base::Time Now() const; | 81 virtual base::Time Now() const; |
86 virtual void ScheduleEnforceMemoryPolicy(); | 82 virtual void ScheduleEnforceMemoryPolicy(); |
87 | 83 |
88 base::Lock lock_; | 84 base::Lock lock_; |
89 // Note: The elements in |segments_| are arranged in such a way that they form | 85 // Note: The elements in |segments_| are arranged in such a way that they form |
90 // a heap. The LRU memory segment always first. | 86 // a heap. The LRU memory segment always first. |
91 typedef std::vector<MemorySegment> MemorySegmentVector; | 87 typedef std::vector<MemorySegment> MemorySegmentVector; |
92 MemorySegmentVector segments_; | 88 MemorySegmentVector segments_; |
93 size_t memory_limit_; | 89 size_t memory_limit_; |
94 size_t bytes_allocated_; | 90 size_t bytes_allocated_; |
95 scoped_ptr<base::MemoryPressureListener> memory_pressure_listener_; | 91 scoped_ptr<base::MemoryPressureListener> memory_pressure_listener_; |
96 bool enforce_memory_policy_pending_; | 92 bool enforce_memory_policy_pending_; |
97 base::WeakPtrFactory<HostDiscardableSharedMemoryManager> weak_ptr_factory_; | 93 base::WeakPtrFactory<HostDiscardableSharedMemoryManager> weak_ptr_factory_; |
98 | 94 |
99 DISALLOW_COPY_AND_ASSIGN(HostDiscardableSharedMemoryManager); | 95 DISALLOW_COPY_AND_ASSIGN(HostDiscardableSharedMemoryManager); |
100 }; | 96 }; |
101 | 97 |
102 } // namespace content | 98 } // namespace content |
103 | 99 |
104 #endif // CONTENT_COMMON_HOST_DISCARDABLE_SHARED_MEMORY_MANAGER_H_ | 100 #endif // CONTENT_COMMON_HOST_DISCARDABLE_SHARED_MEMORY_MANAGER_H_ |
OLD | NEW |