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_allocator.h" |
11 #include "base/memory/discardable_shared_memory.h" | 11 #include "base/memory/discardable_shared_memory.h" |
12 #include "base/memory/linked_ptr.h" | 12 #include "base/memory/linked_ptr.h" |
13 #include "base/memory/memory_pressure_listener.h" | 13 #include "base/memory/memory_pressure_listener.h" |
14 #include "base/memory/shared_memory.h" | 14 #include "base/memory/shared_memory.h" |
15 #include "base/memory/weak_ptr.h" | 15 #include "base/memory/weak_ptr.h" |
16 #include "base/process/process_handle.h" | 16 #include "base/process/process_handle.h" |
17 #include "base/synchronization/lock.h" | 17 #include "base/synchronization/lock.h" |
18 #include "content/common/content_export.h" | 18 #include "content/common/content_export.h" |
19 | 19 |
20 namespace content { | 20 namespace content { |
21 | 21 |
22 // Implementation of DiscardableMemoryShmemAllocator that allocates and | 22 // Implementation of DiscardableMemoryAllocator that allocates and manages |
23 // manages discardable memory segments for the browser process and child | 23 // discardable memory segments for the browser process and child processes. |
24 // processes. This class is thread-safe and instances can safely be used | 24 // This class is thread-safe and instances can safely be used on any thread. |
25 // on any thread. | |
26 class CONTENT_EXPORT HostDiscardableSharedMemoryManager | 25 class CONTENT_EXPORT HostDiscardableSharedMemoryManager |
27 : public base::DiscardableMemoryShmemAllocator { | 26 : public base::DiscardableMemoryAllocator { |
28 public: | 27 public: |
29 HostDiscardableSharedMemoryManager(); | 28 HostDiscardableSharedMemoryManager(); |
30 ~HostDiscardableSharedMemoryManager() override; | 29 ~HostDiscardableSharedMemoryManager() override; |
31 | 30 |
32 // Returns a singleton instance. | 31 // Returns a singleton instance. |
33 static HostDiscardableSharedMemoryManager* current(); | 32 static HostDiscardableSharedMemoryManager* current(); |
34 | 33 |
35 // Overridden from base::DiscardableMemoryShmemAllocator: | 34 // Overridden from base::DiscardableMemoryAllocator: |
36 scoped_ptr<base::DiscardableMemoryShmemChunk> AllocateLockedDiscardableMemory( | 35 scoped_ptr<base::DiscardableMemory> AllocateLockedDiscardableMemory( |
37 size_t size) override; | 36 size_t size) override; |
38 | 37 |
39 // This allocates a discardable memory segment for |process_handle|. | 38 // This allocates a discardable memory segment for |process_handle|. |
40 // A valid shared memory handle is returned on success. | 39 // A valid shared memory handle is returned on success. |
41 void AllocateLockedDiscardableSharedMemoryForChild( | 40 void AllocateLockedDiscardableSharedMemoryForChild( |
42 base::ProcessHandle process_handle, | 41 base::ProcessHandle process_handle, |
43 size_t size, | 42 size_t size, |
44 base::SharedMemoryHandle* shared_memory_handle); | 43 base::SharedMemoryHandle* shared_memory_handle); |
45 | 44 |
46 // Call this to notify the manager that child process associated with | 45 // Call this to notify the manager that child process associated with |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
95 scoped_ptr<base::MemoryPressureListener> memory_pressure_listener_; | 94 scoped_ptr<base::MemoryPressureListener> memory_pressure_listener_; |
96 bool enforce_memory_policy_pending_; | 95 bool enforce_memory_policy_pending_; |
97 base::WeakPtrFactory<HostDiscardableSharedMemoryManager> weak_ptr_factory_; | 96 base::WeakPtrFactory<HostDiscardableSharedMemoryManager> weak_ptr_factory_; |
98 | 97 |
99 DISALLOW_COPY_AND_ASSIGN(HostDiscardableSharedMemoryManager); | 98 DISALLOW_COPY_AND_ASSIGN(HostDiscardableSharedMemoryManager); |
100 }; | 99 }; |
101 | 100 |
102 } // namespace content | 101 } // namespace content |
103 | 102 |
104 #endif // CONTENT_COMMON_HOST_DISCARDABLE_SHARED_MEMORY_MANAGER_H_ | 103 #endif // CONTENT_COMMON_HOST_DISCARDABLE_SHARED_MEMORY_MANAGER_H_ |
OLD | NEW |