Add test_runner support for new accessibility event
[chromium-blink-merge.git] / content / child / child_discardable_shared_memory_manager.h
blob3dee17397ffdebd08cf1bae055a2b93f58ca2b19
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/memory/weak_ptr.h"
11 #include "base/synchronization/lock.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:
24 explicit ChildDiscardableSharedMemoryManager(ThreadSafeSender* sender);
25 ~ChildDiscardableSharedMemoryManager() override;
27 // Overridden from base::DiscardableMemoryAllocator:
28 scoped_ptr<base::DiscardableMemory> AllocateLockedDiscardableMemory(
29 size_t size) override;
31 // Release memory and associated resources that have been purged.
32 void ReleaseFreeMemory();
34 bool LockSpan(DiscardableSharedMemoryHeap::Span* span);
35 void UnlockSpan(DiscardableSharedMemoryHeap::Span* span);
36 void ReleaseSpan(scoped_ptr<DiscardableSharedMemoryHeap::Span> span);
38 private:
39 scoped_ptr<base::DiscardableSharedMemory>
40 AllocateLockedDiscardableSharedMemory(size_t size,
41 DiscardableSharedMemoryId id);
42 void DeletedDiscardableSharedMemory(DiscardableSharedMemoryId id);
43 void MemoryUsageChanged(size_t new_bytes_allocated,
44 size_t new_bytes_free) const;
46 mutable base::Lock lock_;
47 DiscardableSharedMemoryHeap heap_;
48 scoped_refptr<ThreadSafeSender> sender_;
49 base::WeakPtrFactory<ChildDiscardableSharedMemoryManager> weak_ptr_factory_;
51 DISALLOW_COPY_AND_ASSIGN(ChildDiscardableSharedMemoryManager);
54 } // namespace content
56 #endif // CONTENT_CHILD_CHILD_DISCARDABLE_SHARED_MEMORY_MANAGER_H_