| 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 COMPONENTS_DISCARDABLE_MEMORY_CLIENT_CLIENT_DISCARDABLE_SHARED_MEMORY_MA
NAGER_H_ |
| 6 #define CONTENT_CHILD_CHILD_DISCARDABLE_SHARED_MEMORY_MANAGER_H_ | 6 #define COMPONENTS_DISCARDABLE_MEMORY_CLIENT_CLIENT_DISCARDABLE_SHARED_MEMORY_MA
NAGER_H_ |
| 7 | 7 |
| 8 #include <stddef.h> | 8 #include <stddef.h> |
| 9 | 9 |
| 10 #include "base/macros.h" | 10 #include "base/macros.h" |
| 11 #include "base/memory/discardable_memory_allocator.h" | 11 #include "base/memory/discardable_memory_allocator.h" |
| 12 #include "base/memory/ref_counted.h" | 12 #include "base/memory/ref_counted.h" |
| 13 #include "base/memory/shared_memory_handle.h" |
| 13 #include "base/synchronization/lock.h" | 14 #include "base/synchronization/lock.h" |
| 14 #include "base/trace_event/memory_dump_provider.h" | 15 #include "base/trace_event/memory_dump_provider.h" |
| 15 #include "content/child/thread_safe_sender.h" | 16 #include "components/discardable_memory/common/discardable_memory_export.h" |
| 16 #include "content/common/content_export.h" | 17 #include "components/discardable_memory/common/discardable_shared_memory_heap.h" |
| 17 #include "content/common/discardable_shared_memory_heap.h" | 18 #include "components/discardable_memory/common/discardable_shared_memory_id.h" |
| 18 #include "content/common/host_discardable_shared_memory_manager.h" | |
| 19 | 19 |
| 20 namespace content { | 20 namespace discardable_memory { |
| 21 | 21 |
| 22 // Implementation of DiscardableMemoryAllocator that allocates | 22 // Implementation of DiscardableMemoryAllocator that allocates |
| 23 // discardable memory segments through the browser process. | 23 // discardable memory segments through the browser process. |
| 24 class CONTENT_EXPORT ChildDiscardableSharedMemoryManager | 24 class DISCARDABLE_MEMORY_EXPORT ClientDiscardableSharedMemoryManager |
| 25 : public base::DiscardableMemoryAllocator, | 25 : public base::DiscardableMemoryAllocator, |
| 26 public base::trace_event::MemoryDumpProvider { | 26 public base::trace_event::MemoryDumpProvider { |
| 27 public: | 27 public: |
| 28 explicit ChildDiscardableSharedMemoryManager(ThreadSafeSender* sender); | 28 class Delegate { |
| 29 ~ChildDiscardableSharedMemoryManager() override; | 29 public: |
| 30 virtual void AllocateLockedDiscardableSharedMemory( |
| 31 size_t size, |
| 32 DiscardableSharedMemoryId id, |
| 33 base::SharedMemoryHandle* handle) = 0; |
| 34 virtual void DeletedDiscardableSharedMemory( |
| 35 DiscardableSharedMemoryId id) = 0; |
| 36 |
| 37 protected: |
| 38 virtual ~Delegate() {} |
| 39 }; |
| 40 |
| 41 explicit ClientDiscardableSharedMemoryManager(Delegate* delegate); |
| 42 ~ClientDiscardableSharedMemoryManager() override; |
| 30 | 43 |
| 31 // Overridden from base::DiscardableMemoryAllocator: | 44 // Overridden from base::DiscardableMemoryAllocator: |
| 32 std::unique_ptr<base::DiscardableMemory> AllocateLockedDiscardableMemory( | 45 std::unique_ptr<base::DiscardableMemory> AllocateLockedDiscardableMemory( |
| 33 size_t size) override; | 46 size_t size) override; |
| 34 | 47 |
| 35 // Overridden from base::trace_event::MemoryDumpProvider: | 48 // Overridden from base::trace_event::MemoryDumpProvider: |
| 36 bool OnMemoryDump(const base::trace_event::MemoryDumpArgs& args, | 49 bool OnMemoryDump(const base::trace_event::MemoryDumpArgs& args, |
| 37 base::trace_event::ProcessMemoryDump* pmd) override; | 50 base::trace_event::ProcessMemoryDump* pmd) override; |
| 38 | 51 |
| 39 // Release memory and associated resources that have been purged. | 52 // Release memory and associated resources that have been purged. |
| (...skipping 17 matching lines...) Expand all Loading... |
| 57 | 70 |
| 58 private: | 71 private: |
| 59 std::unique_ptr<base::DiscardableSharedMemory> | 72 std::unique_ptr<base::DiscardableSharedMemory> |
| 60 AllocateLockedDiscardableSharedMemory(size_t size, | 73 AllocateLockedDiscardableSharedMemory(size_t size, |
| 61 DiscardableSharedMemoryId id); | 74 DiscardableSharedMemoryId id); |
| 62 void MemoryUsageChanged(size_t new_bytes_allocated, | 75 void MemoryUsageChanged(size_t new_bytes_allocated, |
| 63 size_t new_bytes_free) const; | 76 size_t new_bytes_free) const; |
| 64 | 77 |
| 65 mutable base::Lock lock_; | 78 mutable base::Lock lock_; |
| 66 DiscardableSharedMemoryHeap heap_; | 79 DiscardableSharedMemoryHeap heap_; |
| 67 scoped_refptr<ThreadSafeSender> sender_; | 80 Delegate* const delegate_; |
| 68 | 81 |
| 69 DISALLOW_COPY_AND_ASSIGN(ChildDiscardableSharedMemoryManager); | 82 DISALLOW_COPY_AND_ASSIGN(ClientDiscardableSharedMemoryManager); |
| 70 }; | 83 }; |
| 71 | 84 |
| 72 } // namespace content | 85 } // namespace discardable_memory |
| 73 | 86 |
| 74 #endif // CONTENT_CHILD_CHILD_DISCARDABLE_SHARED_MEMORY_MANAGER_H_ | 87 #endif // COMPONENTS_DISCARDABLE_MEMORY_CLIENT_CLIENT_DISCARDABLE_SHARED_MEMORY
_MANAGER_H_ |
| OLD | NEW |