| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "base/memory/discardable_memory_shmem_allocator.h" | 5 #include "base/memory/discardable_memory_shmem_allocator.h" |
| 6 | 6 |
| 7 #include "base/lazy_instance.h" | 7 #include "base/lazy_instance.h" |
| 8 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "base/memory/discardable_shared_memory.h" | 9 #include "base/memory/discardable_shared_memory.h" |
| 10 | 10 |
| 11 namespace base { | 11 namespace base { |
| 12 namespace { | 12 namespace { |
| 13 | 13 |
| 14 class DiscardableMemoryShmemChunkImpl : public DiscardableMemoryShmemChunk { | 14 class DiscardableMemoryShmemChunkImpl : public DiscardableMemoryShmemChunk { |
| 15 public: | 15 public: |
| 16 explicit DiscardableMemoryShmemChunkImpl( | 16 explicit DiscardableMemoryShmemChunkImpl( |
| 17 scoped_ptr<DiscardableSharedMemory> shared_memory) | 17 scoped_ptr<DiscardableSharedMemory> shared_memory) |
| 18 : shared_memory_(shared_memory.Pass()) {} | 18 : shared_memory_(shared_memory.Pass()) {} |
| 19 | 19 |
| 20 // Overridden from DiscardableMemoryShmemChunk: | 20 // Overridden from DiscardableMemoryShmemChunk: |
| 21 bool Lock() override { | 21 bool Lock() override { return false; } |
| 22 auto result = shared_memory_->Lock(0, 0); | 22 void Unlock() override { |
| 23 DCHECK_NE(result, DiscardableSharedMemory::PURGED); | 23 shared_memory_->Unlock(0, 0); |
| 24 return result == DiscardableSharedMemory::SUCCESS; | 24 shared_memory_.reset(); |
| 25 } | 25 } |
| 26 void Unlock() override { shared_memory_->Unlock(0, 0); } | |
| 27 void* Memory() const override { return shared_memory_->memory(); } | 26 void* Memory() const override { return shared_memory_->memory(); } |
| 28 bool IsMemoryResident() const override { | |
| 29 return shared_memory_->IsMemoryResident(); | |
| 30 } | |
| 31 | 27 |
| 32 private: | 28 private: |
| 33 scoped_ptr<DiscardableSharedMemory> shared_memory_; | 29 scoped_ptr<DiscardableSharedMemory> shared_memory_; |
| 34 | 30 |
| 35 DISALLOW_COPY_AND_ASSIGN(DiscardableMemoryShmemChunkImpl); | 31 DISALLOW_COPY_AND_ASSIGN(DiscardableMemoryShmemChunkImpl); |
| 36 }; | 32 }; |
| 37 | 33 |
| 38 // Default allocator implementation that allocates in-process | 34 // Default allocator implementation that allocates in-process |
| 39 // DiscardableSharedMemory instances. | 35 // DiscardableSharedMemory instances. |
| 40 class DiscardableMemoryShmemAllocatorImpl | 36 class DiscardableMemoryShmemAllocatorImpl |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 73 // static | 69 // static |
| 74 DiscardableMemoryShmemAllocator* | 70 DiscardableMemoryShmemAllocator* |
| 75 DiscardableMemoryShmemAllocator::GetInstance() { | 71 DiscardableMemoryShmemAllocator::GetInstance() { |
| 76 if (!g_allocator) | 72 if (!g_allocator) |
| 77 g_allocator = g_default_allocator.Pointer(); | 73 g_allocator = g_default_allocator.Pointer(); |
| 78 | 74 |
| 79 return g_allocator; | 75 return g_allocator; |
| 80 } | 76 } |
| 81 | 77 |
| 82 } // namespace base | 78 } // namespace base |
| OLD | NEW |