[Android WebView] Fix webview perf bot switchover to use org.chromium.webview_shell...
[chromium-blink-merge.git] / content / child / child_discardable_shared_memory_manager.h
blob27f5f5e3034b3ae15f1ef0eadabdd30414e631c0
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(base::trace_event::ProcessMemoryDump* pmd) override;
35 // Release memory and associated resources that have been purged.
36 void ReleaseFreeMemory();
38 bool LockSpan(DiscardableSharedMemoryHeap::Span* span);
39 void UnlockSpan(DiscardableSharedMemoryHeap::Span* span);
40 void ReleaseSpan(scoped_ptr<DiscardableSharedMemoryHeap::Span> span);
42 private:
43 scoped_ptr<base::DiscardableSharedMemory>
44 AllocateLockedDiscardableSharedMemory(size_t size,
45 DiscardableSharedMemoryId id);
46 void MemoryUsageChanged(size_t new_bytes_allocated,
47 size_t new_bytes_free) const;
49 mutable base::Lock lock_;
50 DiscardableSharedMemoryHeap heap_;
51 scoped_refptr<ThreadSafeSender> sender_;
53 DISALLOW_COPY_AND_ASSIGN(ChildDiscardableSharedMemoryManager);
56 } // namespace content
58 #endif // CONTENT_CHILD_CHILD_DISCARDABLE_SHARED_MEMORY_MANAGER_H_