Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(678)

Unified Diff: base/memory/discardable_memory_ashmem.cc

Issue 195863005: Use DiscardableMemoryManager on Android. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Use DiscardableMemoryController on Android Created 6 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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

Powered by Google App Engine
This is Rietveld 408576698