Index: base/memory/discardable_memory_ashmem.cc |
diff --git a/base/memory/discardable_memory_ashmem.cc b/base/memory/discardable_memory_ashmem.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..43f07b618cabdcee625c9d6475f67b1b56949c35 |
--- /dev/null |
+++ b/base/memory/discardable_memory_ashmem.cc |
@@ -0,0 +1,54 @@ |
+// Copyright 2014 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#include "base/memory/discardable_memory_ashmem.h" |
+ |
+#include "base/lazy_instance.h" |
+#include "base/memory/discardable_memory_allocation_ashmem_factory.h" |
+#include "base/memory/discardable_memory_manager.h" |
+ |
+namespace base { |
+namespace internal { |
+ |
+DiscardableMemoryAshmem::DiscardableMemoryAshmem( |
+ DiscardableMemoryManager* manager, |
+ size_t size) |
+ : manager_(manager), |
+ allocation_id_(manager->Register(size)), |
+ memory_(NULL) { |
+} |
+ |
+DiscardableMemoryAshmem::~DiscardableMemoryAshmem() { |
+ manager_->Unregister(allocation_id_); |
+} |
+ |
+bool DiscardableMemoryAshmem::Initialize() { |
+ return Lock() == DISCARDABLE_MEMORY_LOCK_STATUS_PURGED; |
+} |
+ |
+DiscardableMemoryLockStatus DiscardableMemoryAshmem::Lock() { |
+ DCHECK(!memory_); |
+ |
+ bool purged = false; |
+ memory_ = manager_->Lock(allocation_id_, &purged); |
+ if (!memory_) |
+ return DISCARDABLE_MEMORY_LOCK_STATUS_FAILED; |
+ |
+ return purged ? DISCARDABLE_MEMORY_LOCK_STATUS_PURGED |
+ : DISCARDABLE_MEMORY_LOCK_STATUS_SUCCESS; |
+} |
+ |
+void DiscardableMemoryAshmem::Unlock() { |
+ DCHECK(memory_); |
+ manager_->Unlock(allocation_id_); |
+ memory_ = NULL; |
+} |
+ |
+void* DiscardableMemoryAshmem::Memory() const { |
+ DCHECK(memory_); |
+ return memory_; |
+} |
+ |
+} // namespace internal |
+} // namespace base |