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 "content/child/thread_safe_sender.h"
12 #include "content/common/content_export.h"
13 #include "content/common/discardable_shared_memory_heap.h"
14 #include "content/common/host_discardable_shared_memory_manager.h"
18 // Implementation of DiscardableMemoryAllocator that allocates
19 // discardable memory segments through the browser process.
20 class CONTENT_EXPORT ChildDiscardableSharedMemoryManager
21 : public base::DiscardableMemoryAllocator
{
23 explicit ChildDiscardableSharedMemoryManager(ThreadSafeSender
* sender
);
24 ~ChildDiscardableSharedMemoryManager() override
;
26 // Overridden from base::DiscardableMemoryAllocator:
27 scoped_ptr
<base::DiscardableMemory
> AllocateLockedDiscardableMemory(
28 size_t size
) override
;
30 // Release memory and associated resources that have been purged.
31 void ReleaseFreeMemory();
33 bool LockSpan(DiscardableSharedMemoryHeap::Span
* span
);
34 void UnlockSpan(DiscardableSharedMemoryHeap::Span
* span
);
35 void ReleaseSpan(scoped_ptr
<DiscardableSharedMemoryHeap::Span
> span
);
38 scoped_ptr
<base::DiscardableSharedMemory
>
39 AllocateLockedDiscardableSharedMemory(size_t size
,
40 DiscardableSharedMemoryId id
);
41 void MemoryUsageChanged(size_t new_bytes_allocated
,
42 size_t new_bytes_free
) const;
44 mutable base::Lock lock_
;
45 DiscardableSharedMemoryHeap heap_
;
46 scoped_refptr
<ThreadSafeSender
> sender_
;
48 DISALLOW_COPY_AND_ASSIGN(ChildDiscardableSharedMemoryManager
);
51 } // namespace content
53 #endif // CONTENT_CHILD_CHILD_DISCARDABLE_SHARED_MEMORY_MANAGER_H_