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_shmem_allocator.h"
9 #include "base/memory/ref_counted.h"
10 #include "base/synchronization/lock.h"
11 #include "content/child/thread_safe_sender.h"
12 #include "content/common/discardable_shared_memory_heap.h"
16 // Implementation of DiscardableMemoryShmemAllocator that allocates
17 // discardable memory segments through the browser process.
18 class ChildDiscardableSharedMemoryManager
19 : public base::DiscardableMemoryShmemAllocator
{
21 explicit ChildDiscardableSharedMemoryManager(ThreadSafeSender
* sender
);
22 ~ChildDiscardableSharedMemoryManager() override
;
24 // Overridden from base::DiscardableMemoryShmemAllocator:
25 scoped_ptr
<base::DiscardableMemoryShmemChunk
> AllocateLockedDiscardableMemory(
26 size_t size
) override
;
28 bool LockSpan(DiscardableSharedMemoryHeap::Span
* span
);
29 void UnlockSpan(DiscardableSharedMemoryHeap::Span
* span
);
30 bool IsSpanResident(DiscardableSharedMemoryHeap::Span
* span
) const;
31 void ReleaseSpan(scoped_ptr
<DiscardableSharedMemoryHeap::Span
> span
);
34 scoped_ptr
<base::DiscardableSharedMemory
>
35 AllocateLockedDiscardableSharedMemory(size_t size
);
37 mutable base::Lock lock_
;
38 DiscardableSharedMemoryHeap heap_
;
39 scoped_refptr
<ThreadSafeSender
> sender_
;
41 DISALLOW_COPY_AND_ASSIGN(ChildDiscardableSharedMemoryManager
);
44 } // namespace content
46 #endif // CONTENT_CHILD_CHILD_DISCARDABLE_SHARED_MEMORY_MANAGER_H_