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_CHILD_CHILD_DISCARDABLE_SHARED_MEMORY_MANAGER_H_ | 5 #ifndef CONTENT_CHILD_CHILD_DISCARDABLE_SHARED_MEMORY_MANAGER_H_ |
6 #define CONTENT_CHILD_CHILD_DISCARDABLE_SHARED_MEMORY_MANAGER_H_ | 6 #define CONTENT_CHILD_CHILD_DISCARDABLE_SHARED_MEMORY_MANAGER_H_ |
7 | 7 |
8 #include "base/memory/discardable_memory_shmem_allocator.h" | 8 #include "base/memory/discardable_memory_allocator.h" |
9 #include "base/memory/ref_counted.h" | 9 #include "base/memory/ref_counted.h" |
10 #include "base/synchronization/lock.h" | 10 #include "base/synchronization/lock.h" |
11 #include "content/child/thread_safe_sender.h" | 11 #include "content/child/thread_safe_sender.h" |
12 #include "content/common/content_export.h" | 12 #include "content/common/content_export.h" |
13 #include "content/common/discardable_shared_memory_heap.h" | 13 #include "content/common/discardable_shared_memory_heap.h" |
14 | 14 |
15 namespace content { | 15 namespace content { |
16 | 16 |
17 // Implementation of DiscardableMemoryShmemAllocator that allocates | 17 // Implementation of DiscardableMemoryAllocator that allocates |
18 // discardable memory segments through the browser process. | 18 // discardable memory segments through the browser process. |
19 class CONTENT_EXPORT ChildDiscardableSharedMemoryManager | 19 class CONTENT_EXPORT ChildDiscardableSharedMemoryManager |
20 : public base::DiscardableMemoryShmemAllocator { | 20 : public base::DiscardableMemoryAllocator { |
21 public: | 21 public: |
22 explicit ChildDiscardableSharedMemoryManager(ThreadSafeSender* sender); | 22 explicit ChildDiscardableSharedMemoryManager(ThreadSafeSender* sender); |
23 ~ChildDiscardableSharedMemoryManager() override; | 23 ~ChildDiscardableSharedMemoryManager() override; |
24 | 24 |
25 // Overridden from base::DiscardableMemoryShmemAllocator: | 25 // Overridden from base::DiscardableMemoryAllocator: |
26 scoped_ptr<base::DiscardableMemoryShmemChunk> AllocateLockedDiscardableMemory( | 26 scoped_ptr<base::DiscardableMemory> AllocateLockedDiscardableMemory( |
27 size_t size) override; | 27 size_t size) override; |
28 | 28 |
29 // Release memory and associated resources that have been purged. | 29 // Release memory and associated resources that have been purged. |
30 void ReleaseFreeMemory(); | 30 void ReleaseFreeMemory(); |
31 | 31 |
32 bool LockSpan(DiscardableSharedMemoryHeap::Span* span); | 32 bool LockSpan(DiscardableSharedMemoryHeap::Span* span); |
33 void UnlockSpan(DiscardableSharedMemoryHeap::Span* span); | 33 void UnlockSpan(DiscardableSharedMemoryHeap::Span* span); |
34 void ReleaseSpan(scoped_ptr<DiscardableSharedMemoryHeap::Span> span); | 34 void ReleaseSpan(scoped_ptr<DiscardableSharedMemoryHeap::Span> span); |
35 | 35 |
36 private: | 36 private: |
37 scoped_ptr<base::DiscardableSharedMemory> | 37 scoped_ptr<base::DiscardableSharedMemory> |
38 AllocateLockedDiscardableSharedMemory(size_t size); | 38 AllocateLockedDiscardableSharedMemory(size_t size); |
39 void MemoryUsageChanged(size_t new_bytes_allocated, | 39 void MemoryUsageChanged(size_t new_bytes_allocated, |
40 size_t new_bytes_free) const; | 40 size_t new_bytes_free) const; |
41 | 41 |
42 mutable base::Lock lock_; | 42 mutable base::Lock lock_; |
43 DiscardableSharedMemoryHeap heap_; | 43 DiscardableSharedMemoryHeap heap_; |
44 scoped_refptr<ThreadSafeSender> sender_; | 44 scoped_refptr<ThreadSafeSender> sender_; |
45 | 45 |
46 DISALLOW_COPY_AND_ASSIGN(ChildDiscardableSharedMemoryManager); | 46 DISALLOW_COPY_AND_ASSIGN(ChildDiscardableSharedMemoryManager); |
47 }; | 47 }; |
48 | 48 |
49 } // namespace content | 49 } // namespace content |
50 | 50 |
51 #endif // CONTENT_CHILD_CHILD_DISCARDABLE_SHARED_MEMORY_MANAGER_H_ | 51 #endif // CONTENT_CHILD_CHILD_DISCARDABLE_SHARED_MEMORY_MANAGER_H_ |
OLD | NEW |