Infobar material design refresh: bg color
[chromium-blink-merge.git] / content / child / child_discardable_shared_memory_manager.h
blob4eb327d41c1d1d8e8b4a0bf5a9155c9a844aadc4
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.
5 #ifndef CONTENT_CHILD_CHILD_DISCARDABLE_SHARED_MEMORY_MANAGER_H_
6 #define CONTENT_CHILD_CHILD_DISCARDABLE_SHARED_MEMORY_MANAGER_H_
8 #include "base/memory/discardable_memory_allocator.h"
9 #include "base/memory/ref_counted.h"
10 #include "base/synchronization/lock.h"
11 #include "base/trace_event/memory_dump_provider.h"
12 #include "content/child/thread_safe_sender.h"
13 #include "content/common/content_export.h"
14 #include "content/common/discardable_shared_memory_heap.h"
15 #include "content/common/host_discardable_shared_memory_manager.h"
17 namespace content {
19 // Implementation of DiscardableMemoryAllocator that allocates
20 // discardable memory segments through the browser process.
21 class CONTENT_EXPORT ChildDiscardableSharedMemoryManager
22 : public base::DiscardableMemoryAllocator,
23 public base::trace_event::MemoryDumpProvider {
24 public:
25 explicit ChildDiscardableSharedMemoryManager(ThreadSafeSender* sender);
26 ~ChildDiscardableSharedMemoryManager() override;
28 // Overridden from base::DiscardableMemoryAllocator:
29 scoped_ptr<base::DiscardableMemory> AllocateLockedDiscardableMemory(
30 size_t size) override;
32 // Overridden from base::trace_event::MemoryDumpProvider:
33 bool OnMemoryDump(const base::trace_event::MemoryDumpArgs& args,
34 base::trace_event::ProcessMemoryDump* pmd) override;
36 // Release memory and associated resources that have been purged.
37 void ReleaseFreeMemory();
39 bool LockSpan(DiscardableSharedMemoryHeap::Span* span);
40 void UnlockSpan(DiscardableSharedMemoryHeap::Span* span);
41 void ReleaseSpan(scoped_ptr<DiscardableSharedMemoryHeap::Span> span);
43 base::trace_event::MemoryAllocatorDump* CreateMemoryAllocatorDump(
44 DiscardableSharedMemoryHeap::Span* span,
45 const char* name,
46 base::trace_event::ProcessMemoryDump* pmd) const;
48 private:
49 scoped_ptr<base::DiscardableSharedMemory>
50 AllocateLockedDiscardableSharedMemory(size_t size,
51 DiscardableSharedMemoryId id);
52 void MemoryUsageChanged(size_t new_bytes_allocated,
53 size_t new_bytes_free) const;
55 mutable base::Lock lock_;
56 DiscardableSharedMemoryHeap heap_;
57 scoped_refptr<ThreadSafeSender> sender_;
59 DISALLOW_COPY_AND_ASSIGN(ChildDiscardableSharedMemoryManager);
62 } // namespace content
64 #endif // CONTENT_CHILD_CHILD_DISCARDABLE_SHARED_MEMORY_MANAGER_H_