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/containers/hash_tables.h" | 10 #include "base/containers/hash_tables.h" |
11 #include "base/memory/discardable_memory_shmem_allocator.h" | 11 #include "base/memory/discardable_memory_allocator.h" |
12 #include "base/memory/discardable_shared_memory.h" | 12 #include "base/memory/discardable_shared_memory.h" |
13 #include "base/memory/memory_pressure_listener.h" | 13 #include "base/memory/memory_pressure_listener.h" |
14 #include "base/memory/ref_counted.h" | 14 #include "base/memory/ref_counted.h" |
15 #include "base/memory/shared_memory.h" | 15 #include "base/memory/shared_memory.h" |
16 #include "base/memory/weak_ptr.h" | 16 #include "base/memory/weak_ptr.h" |
17 #include "base/process/process_handle.h" | 17 #include "base/process/process_handle.h" |
18 #include "base/synchronization/lock.h" | 18 #include "base/synchronization/lock.h" |
19 #include "content/common/content_export.h" | 19 #include "content/common/content_export.h" |
20 | 20 |
21 namespace content { | 21 namespace content { |
22 typedef int32_t DiscardableSharedMemoryId; | 22 typedef int32_t DiscardableSharedMemoryId; |
23 | 23 |
24 // Implementation of DiscardableMemoryShmemAllocator that allocates and | 24 // Implementation of DiscardableMemoryAllocator that allocates and manages |
25 // manages discardable memory segments for the browser process and child | 25 // discardable memory segments for the browser process and child processes. |
26 // processes. This class is thread-safe and instances can safely be used | 26 // This class is thread-safe and instances can safely be used on any thread. |
27 // on any thread. | |
28 class CONTENT_EXPORT HostDiscardableSharedMemoryManager | 27 class CONTENT_EXPORT HostDiscardableSharedMemoryManager |
29 : public base::DiscardableMemoryShmemAllocator { | 28 : public base::DiscardableMemoryAllocator { |
30 public: | 29 public: |
31 HostDiscardableSharedMemoryManager(); | 30 HostDiscardableSharedMemoryManager(); |
32 ~HostDiscardableSharedMemoryManager() override; | 31 ~HostDiscardableSharedMemoryManager() override; |
33 | 32 |
34 // Returns a singleton instance. | 33 // Returns a singleton instance. |
35 static HostDiscardableSharedMemoryManager* current(); | 34 static HostDiscardableSharedMemoryManager* current(); |
36 | 35 |
37 // Overridden from base::DiscardableMemoryShmemAllocator: | 36 // Overridden from base::DiscardableMemoryAllocator: |
38 scoped_ptr<base::DiscardableMemoryShmemChunk> AllocateLockedDiscardableMemory( | 37 scoped_ptr<base::DiscardableMemory> AllocateLockedDiscardableMemory( |
39 size_t size) override; | 38 size_t size) override; |
40 | 39 |
41 // This allocates a discardable memory segment for |process_handle|. | 40 // This allocates a discardable memory segment for |process_handle|. |
42 // A valid shared memory handle is returned on success. | 41 // A valid shared memory handle is returned on success. |
43 void AllocateLockedDiscardableSharedMemoryForChild( | 42 void AllocateLockedDiscardableSharedMemoryForChild( |
44 base::ProcessHandle process_handle, | 43 base::ProcessHandle process_handle, |
45 size_t size, | 44 size_t size, |
46 DiscardableSharedMemoryId id, | 45 DiscardableSharedMemoryId id, |
47 base::SharedMemoryHandle* shared_memory_handle); | 46 base::SharedMemoryHandle* shared_memory_handle); |
48 | 47 |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
121 scoped_ptr<base::MemoryPressureListener> memory_pressure_listener_; | 120 scoped_ptr<base::MemoryPressureListener> memory_pressure_listener_; |
122 bool enforce_memory_policy_pending_; | 121 bool enforce_memory_policy_pending_; |
123 base::WeakPtrFactory<HostDiscardableSharedMemoryManager> weak_ptr_factory_; | 122 base::WeakPtrFactory<HostDiscardableSharedMemoryManager> weak_ptr_factory_; |
124 | 123 |
125 DISALLOW_COPY_AND_ASSIGN(HostDiscardableSharedMemoryManager); | 124 DISALLOW_COPY_AND_ASSIGN(HostDiscardableSharedMemoryManager); |
126 }; | 125 }; |
127 | 126 |
128 } // namespace content | 127 } // namespace content |
129 | 128 |
130 #endif // CONTENT_COMMON_HOST_DISCARDABLE_SHARED_MEMORY_MANAGER_H_ | 129 #endif // CONTENT_COMMON_HOST_DISCARDABLE_SHARED_MEMORY_MANAGER_H_ |
OLD | NEW |