| Index: base/memory/discardable_memory_shmem_allocator.cc
|
| diff --git a/base/memory/discardable_memory_shmem_allocator.cc b/base/memory/discardable_memory_shmem_allocator.cc
|
| index a87c58d415d480d2cac8b7dc30389222d78e557f..761204f31220d043e526f6cb35e3548e6eca237f 100644
|
| --- a/base/memory/discardable_memory_shmem_allocator.cc
|
| +++ b/base/memory/discardable_memory_shmem_allocator.cc
|
| @@ -11,6 +11,45 @@
|
| namespace base {
|
| namespace {
|
|
|
| +class DiscardableMemoryShmemChunkImpl : public DiscardableMemoryShmemChunk {
|
| + public:
|
| + explicit DiscardableMemoryShmemChunkImpl(
|
| + scoped_ptr<DiscardableSharedMemory> shared_memory)
|
| + : shared_memory_(shared_memory.Pass()) {}
|
| +
|
| + // Overridden from DiscardableMemoryShmemChunk:
|
| + bool Lock() override { return false; }
|
| + void Unlock() override {
|
| + shared_memory_->Unlock(0, 0);
|
| + shared_memory_.reset();
|
| + }
|
| + void* Memory() const override { return shared_memory_->memory(); }
|
| +
|
| + private:
|
| + scoped_ptr<DiscardableSharedMemory> shared_memory_;
|
| +
|
| + DISALLOW_COPY_AND_ASSIGN(DiscardableMemoryShmemChunkImpl);
|
| +};
|
| +
|
| +// Default allocator implementation that allocates in-process
|
| +// DiscardableSharedMemory instances.
|
| +class DiscardableMemoryShmemAllocatorImpl
|
| + : public DiscardableMemoryShmemAllocator {
|
| + public:
|
| + // Overridden from DiscardableMemoryShmemAllocator:
|
| + scoped_ptr<DiscardableMemoryShmemChunk>
|
| + AllocateLockedDiscardableMemory(size_t size) override {
|
| + scoped_ptr<DiscardableSharedMemory> memory(new DiscardableSharedMemory);
|
| + if (!memory->CreateAndMap(size))
|
| + return nullptr;
|
| +
|
| + return make_scoped_ptr(new DiscardableMemoryShmemChunkImpl(memory.Pass()));
|
| + }
|
| +};
|
| +
|
| +LazyInstance<DiscardableMemoryShmemAllocatorImpl>::Leaky g_default_allocator =
|
| + LAZY_INSTANCE_INITIALIZER;
|
| +
|
| DiscardableMemoryShmemAllocator* g_allocator = nullptr;
|
|
|
| } // namespace
|
| @@ -30,7 +69,9 @@ void DiscardableMemoryShmemAllocator::SetInstance(
|
| // static
|
| DiscardableMemoryShmemAllocator*
|
| DiscardableMemoryShmemAllocator::GetInstance() {
|
| - DCHECK(g_allocator);
|
| + if (!g_allocator)
|
| + g_allocator = g_default_allocator.Pointer();
|
| +
|
| return g_allocator;
|
| }
|
|
|
|
|