| 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(
|
|
|