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

Unified Diff: base/memory/discardable_memory_android.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_android.cc
diff --git a/base/memory/discardable_memory_android.cc b/base/memory/discardable_memory_android.cc
index fa89c189db7be5170ecf30ea3a2a882c24fc87db..77bfd1f6a4795b9fb1f2cbc8f969cc4d6397c3e8 100644
--- a/base/memory/discardable_memory_android.cc
+++ b/base/memory/discardable_memory_android.cc
@@ -9,22 +9,32 @@
#include "base/compiler_specific.h"
#include "base/lazy_instance.h"
#include "base/logging.h"
-#include "base/memory/discardable_memory_allocator_android.h"
+#include "base/memory/discardable_memory_allocation_ashmem_factory.h"
+#include "base/memory/discardable_memory_ashmem.h"
#include "base/memory/discardable_memory_emulated.h"
#include "base/memory/discardable_memory_malloc.h"
+#include "base/memory/discardable_memory_manager.h"
namespace base {
namespace {
const char kAshmemAllocatorName[] = "DiscardableMemoryAllocator";
-struct DiscardableMemoryAllocatorWrapper {
- DiscardableMemoryAllocatorWrapper()
- : allocator(kAshmemAllocatorName,
- GetOptimalAshmemRegionSizeForAllocator()) {
+// High limit used only to avoid running out of address space. The kernel takes
+// care of ensuring that we don't run out of physical memory.
+const size_t kDefaultDiscardableMemoryLimit = 512 * 1024 * 1024;
+
+class DiscardableMemoryManagerImpl {
+ public:
+ DiscardableMemoryManagerImpl()
+ : factory_(
+ kAshmemAllocatorName, GetOptimalAshmemRegionSizeForAllocator()),
+ manager_(&factory_, kDefaultDiscardableMemoryLimit) {
}
- internal::DiscardableMemoryAllocator allocator;
+ internal::DiscardableMemoryManager* instance() {
+ return &manager_;
+ }
private:
// Returns 64 MBytes for a 512 MBytes device, 128 MBytes for 1024 MBytes...
@@ -33,9 +43,12 @@ struct DiscardableMemoryAllocatorWrapper {
// should not be called on the critical path.
return base::android::SysUtils::AmountOfPhysicalMemoryKB() * 1024 / 8;
}
+
+ internal::DiscardableMemoryAllocationAshmemFactory factory_;
+ internal::DiscardableMemoryManager manager_;
};
-LazyInstance<DiscardableMemoryAllocatorWrapper>::Leaky g_context =
+base::LazyInstance<DiscardableMemoryManagerImpl>::Leaky g_manager =
LAZY_INSTANCE_INITIALIZER;
} // namespace
@@ -69,7 +82,13 @@ scoped_ptr<DiscardableMemory> DiscardableMemory::CreateLockedMemoryWithType(
case DISCARDABLE_MEMORY_TYPE_MAC:
return scoped_ptr<DiscardableMemory>();
case DISCARDABLE_MEMORY_TYPE_ANDROID: {
- return g_context.Pointer()->allocator.Allocate(size);
+ scoped_ptr<internal::DiscardableMemoryAshmem> memory(
+ new internal::DiscardableMemoryAshmem(
+ g_manager.Get().instance(), size));
+ if (!memory->Initialize())
+ return scoped_ptr<DiscardableMemory>();
+
+ return memory.PassAs<DiscardableMemory>();
}
case DISCARDABLE_MEMORY_TYPE_EMULATED: {
scoped_ptr<internal::DiscardableMemoryEmulated> memory(

Powered by Google App Engine
This is Rietveld 408576698