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

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: Fix nits 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_malloc.cc b/base/memory/discardable_memory_ashmem.cc
similarity index 37%
copy from base/memory/discardable_memory_malloc.cc
copy to base/memory/discardable_memory_ashmem.cc
index be9d1576783f72d2a4ec22d88a20cb9bcb8334cb..63719cdbf5435f410e49786d2dd480278af55541 100644
--- a/base/memory/discardable_memory_malloc.cc
+++ b/base/memory/discardable_memory_ashmem.cc
@@ -2,41 +2,50 @@
// 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_malloc.h"
+#include "base/memory/discardable_memory_ashmem.h"
#include "base/logging.h"
namespace base {
namespace internal {
-DiscardableMemoryMalloc::DiscardableMemoryMalloc(size_t size) : size_(size) {
+DiscardableMemoryAshmem::DiscardableMemoryAshmem(
+ DiscardableMemoryManager* manager,
+ size_t size)
+ : manager_(manager),
+ allocation_id_(manager->Register(size)),
+ memory_(NULL) {
}
-DiscardableMemoryMalloc::~DiscardableMemoryMalloc() {
+DiscardableMemoryAshmem::~DiscardableMemoryAshmem() {
+ manager_->Unregister(allocation_id_);
}
-bool DiscardableMemoryMalloc::Initialize() {
+bool DiscardableMemoryAshmem::Initialize() {
return Lock() == DISCARDABLE_MEMORY_LOCK_STATUS_PURGED;
}
-DiscardableMemoryLockStatus DiscardableMemoryMalloc::Lock() {
+DiscardableMemoryLockStatus DiscardableMemoryAshmem::Lock() {
DCHECK(!memory_);
- memory_.reset(static_cast<uint8*>(malloc(size_)));
+ bool purged = false;
+ memory_ = manager_->Lock(allocation_id_, &purged);
if (!memory_)
return DISCARDABLE_MEMORY_LOCK_STATUS_FAILED;
- return DISCARDABLE_MEMORY_LOCK_STATUS_PURGED;
+ return purged ? DISCARDABLE_MEMORY_LOCK_STATUS_PURGED
+ : DISCARDABLE_MEMORY_LOCK_STATUS_SUCCESS;
}
-void DiscardableMemoryMalloc::Unlock() {
+void DiscardableMemoryAshmem::Unlock() {
DCHECK(memory_);
- memory_.reset();
+ manager_->Unlock(allocation_id_);
+ memory_ = NULL;
}
-void* DiscardableMemoryMalloc::Memory() const {
+void* DiscardableMemoryAshmem::Memory() const {
DCHECK(memory_);
- return memory_.get();
+ return memory_;
}
} // namespace internal

Powered by Google App Engine
This is Rietveld 408576698