OLD | NEW |
| (Empty) |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #ifndef CONTENT_CHILD_CHILD_DISCARDABLE_SHARED_MEMORY_MANAGER_H_ | |
6 #define CONTENT_CHILD_CHILD_DISCARDABLE_SHARED_MEMORY_MANAGER_H_ | |
7 | |
8 #include <stddef.h> | |
9 | |
10 #include "base/macros.h" | |
11 #include "base/memory/discardable_memory_allocator.h" | |
12 #include "base/memory/ref_counted.h" | |
13 #include "base/synchronization/lock.h" | |
14 #include "base/trace_event/memory_dump_provider.h" | |
15 #include "content/child/thread_safe_sender.h" | |
16 #include "content/common/content_export.h" | |
17 #include "content/common/discardable_shared_memory_heap.h" | |
18 #include "content/common/host_discardable_shared_memory_manager.h" | |
19 | |
20 namespace content { | |
21 | |
22 // Implementation of DiscardableMemoryAllocator that allocates | |
23 // discardable memory segments through the browser process. | |
24 class CONTENT_EXPORT ChildDiscardableSharedMemoryManager | |
25 : public base::DiscardableMemoryAllocator, | |
26 public base::trace_event::MemoryDumpProvider { | |
27 public: | |
28 explicit ChildDiscardableSharedMemoryManager(ThreadSafeSender* sender); | |
29 ~ChildDiscardableSharedMemoryManager() override; | |
30 | |
31 // Overridden from base::DiscardableMemoryAllocator: | |
32 std::unique_ptr<base::DiscardableMemory> AllocateLockedDiscardableMemory( | |
33 size_t size) override; | |
34 | |
35 // Overridden from base::trace_event::MemoryDumpProvider: | |
36 bool OnMemoryDump(const base::trace_event::MemoryDumpArgs& args, | |
37 base::trace_event::ProcessMemoryDump* pmd) override; | |
38 | |
39 // Release memory and associated resources that have been purged. | |
40 void ReleaseFreeMemory(); | |
41 | |
42 bool LockSpan(DiscardableSharedMemoryHeap::Span* span); | |
43 void UnlockSpan(DiscardableSharedMemoryHeap::Span* span); | |
44 void ReleaseSpan(std::unique_ptr<DiscardableSharedMemoryHeap::Span> span); | |
45 | |
46 base::trace_event::MemoryAllocatorDump* CreateMemoryAllocatorDump( | |
47 DiscardableSharedMemoryHeap::Span* span, | |
48 const char* name, | |
49 base::trace_event::ProcessMemoryDump* pmd) const; | |
50 | |
51 struct Statistics { | |
52 size_t total_size; | |
53 size_t freelist_size; | |
54 }; | |
55 | |
56 Statistics GetStatistics() const; | |
57 | |
58 private: | |
59 std::unique_ptr<base::DiscardableSharedMemory> | |
60 AllocateLockedDiscardableSharedMemory(size_t size, | |
61 DiscardableSharedMemoryId id); | |
62 void MemoryUsageChanged(size_t new_bytes_allocated, | |
63 size_t new_bytes_free) const; | |
64 | |
65 mutable base::Lock lock_; | |
66 DiscardableSharedMemoryHeap heap_; | |
67 scoped_refptr<ThreadSafeSender> sender_; | |
68 | |
69 DISALLOW_COPY_AND_ASSIGN(ChildDiscardableSharedMemoryManager); | |
70 }; | |
71 | |
72 } // namespace content | |
73 | |
74 #endif // CONTENT_CHILD_CHILD_DISCARDABLE_SHARED_MEMORY_MANAGER_H_ | |
OLD | NEW |