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

Side by Side Diff: base/memory/discardable_memory_android.cc

Issue 145643008: base: Add uncached malloc based discardable memory type. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 11 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « base/memory/discardable_memory.cc ('k') | base/memory/discardable_memory_linux.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "base/memory/discardable_memory_android.h" 5 #include "base/memory/discardable_memory_android.h"
6 6
7 #include <sys/mman.h> 7 #include <sys/mman.h>
8 #include <unistd.h> 8 #include <unistd.h>
9 9
10 #include <limits> 10 #include <limits>
11 11
12 #include "base/android/sys_utils.h" 12 #include "base/android/sys_utils.h"
13 #include "base/basictypes.h" 13 #include "base/basictypes.h"
14 #include "base/compiler_specific.h" 14 #include "base/compiler_specific.h"
15 #include "base/file_util.h" 15 #include "base/file_util.h"
16 #include "base/lazy_instance.h" 16 #include "base/lazy_instance.h"
17 #include "base/logging.h" 17 #include "base/logging.h"
18 #include "base/memory/discardable_memory_allocator_android.h" 18 #include "base/memory/discardable_memory_allocator_android.h"
19 #include "base/memory/discardable_memory_emulated.h" 19 #include "base/memory/discardable_memory_emulated.h"
20 #include "base/memory/discardable_memory_malloc.h"
20 #include "third_party/ashmem/ashmem.h" 21 #include "third_party/ashmem/ashmem.h"
21 22
22 namespace base { 23 namespace base {
23 namespace { 24 namespace {
24 25
25 const char kAshmemAllocatorName[] = "DiscardableMemoryAllocator"; 26 const char kAshmemAllocatorName[] = "DiscardableMemoryAllocator";
26 27
27 struct DiscardableMemoryAllocatorWrapper { 28 struct DiscardableMemoryAllocatorWrapper {
28 DiscardableMemoryAllocatorWrapper() 29 DiscardableMemoryAllocatorWrapper()
29 : allocator(kAshmemAllocatorName, 30 : allocator(kAshmemAllocatorName,
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
119 // static 120 // static
120 void DiscardableMemory::UnregisterMemoryPressureListeners() { 121 void DiscardableMemory::UnregisterMemoryPressureListeners() {
121 internal::DiscardableMemoryEmulated::UnregisterMemoryPressureListeners(); 122 internal::DiscardableMemoryEmulated::UnregisterMemoryPressureListeners();
122 } 123 }
123 124
124 // static 125 // static
125 void DiscardableMemory::GetSupportedTypes( 126 void DiscardableMemory::GetSupportedTypes(
126 std::vector<DiscardableMemoryType>* types) { 127 std::vector<DiscardableMemoryType>* types) {
127 const DiscardableMemoryType supported_types[] = { 128 const DiscardableMemoryType supported_types[] = {
128 DISCARDABLE_MEMORY_TYPE_ANDROID, 129 DISCARDABLE_MEMORY_TYPE_ANDROID,
129 DISCARDABLE_MEMORY_TYPE_EMULATED 130 DISCARDABLE_MEMORY_TYPE_EMULATED,
131 DISCARDABLE_MEMORY_TYPE_MALLOC
130 }; 132 };
131 types->assign(supported_types, supported_types + arraysize(supported_types)); 133 types->assign(supported_types, supported_types + arraysize(supported_types));
132 } 134 }
133 135
134 // static 136 // static
135 scoped_ptr<DiscardableMemory> DiscardableMemory::CreateLockedMemoryWithType( 137 scoped_ptr<DiscardableMemory> DiscardableMemory::CreateLockedMemoryWithType(
136 DiscardableMemoryType type, size_t size) { 138 DiscardableMemoryType type, size_t size) {
137 switch (type) { 139 switch (type) {
138 case DISCARDABLE_MEMORY_TYPE_NONE: 140 case DISCARDABLE_MEMORY_TYPE_NONE:
139 case DISCARDABLE_MEMORY_TYPE_MAC: 141 case DISCARDABLE_MEMORY_TYPE_MAC:
140 return scoped_ptr<DiscardableMemory>(); 142 return scoped_ptr<DiscardableMemory>();
141 case DISCARDABLE_MEMORY_TYPE_ANDROID: { 143 case DISCARDABLE_MEMORY_TYPE_ANDROID: {
142 return g_context.Pointer()->allocator.Allocate(size); 144 return g_context.Pointer()->allocator.Allocate(size);
143 } 145 }
144 case DISCARDABLE_MEMORY_TYPE_EMULATED: { 146 case DISCARDABLE_MEMORY_TYPE_EMULATED: {
145 scoped_ptr<internal::DiscardableMemoryEmulated> memory( 147 scoped_ptr<internal::DiscardableMemoryEmulated> memory(
146 new internal::DiscardableMemoryEmulated(size)); 148 new internal::DiscardableMemoryEmulated(size));
147 if (!memory->Initialize()) 149 if (!memory->Initialize())
148 return scoped_ptr<DiscardableMemory>(); 150 return scoped_ptr<DiscardableMemory>();
149 151
150 return memory.PassAs<DiscardableMemory>(); 152 return memory.PassAs<DiscardableMemory>();
151 } 153 }
154 case DISCARDABLE_MEMORY_TYPE_MALLOC: {
155 scoped_ptr<internal::DiscardableMemoryMalloc> memory(
156 new internal::DiscardableMemoryMalloc(size));
157 if (!memory->Initialize())
158 return scoped_ptr<DiscardableMemory>();
159
160 return memory.PassAs<DiscardableMemory>();
161 }
152 } 162 }
153 163
154 NOTREACHED(); 164 NOTREACHED();
155 return scoped_ptr<DiscardableMemory>(); 165 return scoped_ptr<DiscardableMemory>();
156 } 166 }
157 167
158 // static 168 // static
159 bool DiscardableMemory::PurgeForTestingSupported() { 169 bool DiscardableMemory::PurgeForTestingSupported() {
160 return false; 170 return false;
161 } 171 }
162 172
163 // static 173 // static
164 void DiscardableMemory::PurgeForTesting() { 174 void DiscardableMemory::PurgeForTesting() {
165 NOTIMPLEMENTED(); 175 NOTIMPLEMENTED();
166 } 176 }
167 177
168 } // namespace base 178 } // namespace base
OLDNEW
« no previous file with comments | « base/memory/discardable_memory.cc ('k') | base/memory/discardable_memory_linux.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698