Fix crash on app list start page contents not existing.
[chromium-blink-merge.git] / content / child / child_discardable_shared_memory_manager.h
bloba5b8081fe03ce6f9d103619349304934a9a165fe
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/content_export.h"
13 #include "content/common/discardable_shared_memory_heap.h"
15 namespace content {
17 // Implementation of DiscardableMemoryShmemAllocator that allocates
18 // discardable memory segments through the browser process.
19 class CONTENT_EXPORT ChildDiscardableSharedMemoryManager
20 : public base::DiscardableMemoryShmemAllocator {
21 public:
22 explicit ChildDiscardableSharedMemoryManager(ThreadSafeSender* sender);
23 ~ChildDiscardableSharedMemoryManager() override;
25 // Overridden from base::DiscardableMemoryShmemAllocator:
26 scoped_ptr<base::DiscardableMemoryShmemChunk> AllocateLockedDiscardableMemory(
27 size_t size) override;
29 // Release memory and associated resources that have been purged.
30 void ReleaseFreeMemory();
32 bool LockSpan(DiscardableSharedMemoryHeap::Span* span);
33 void UnlockSpan(DiscardableSharedMemoryHeap::Span* span);
34 void ReleaseSpan(scoped_ptr<DiscardableSharedMemoryHeap::Span> span);
36 private:
37 scoped_ptr<base::DiscardableSharedMemory>
38 AllocateLockedDiscardableSharedMemory(size_t size);
40 mutable base::Lock lock_;
41 DiscardableSharedMemoryHeap heap_;
42 scoped_refptr<ThreadSafeSender> sender_;
44 DISALLOW_COPY_AND_ASSIGN(ChildDiscardableSharedMemoryManager);
47 } // namespace content
49 #endif // CONTENT_CHILD_CHILD_DISCARDABLE_SHARED_MEMORY_MANAGER_H_