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

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

Issue 651913003: base: Remove non-caching discardable memory implementation. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase Created 6 years, 2 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
« no previous file with comments | « base/memory/discardable_memory_linux.cc ('k') | base/memory/discardable_memory_malloc.h » ('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.h" 5 #include "base/memory/discardable_memory.h"
6 6
7 #include <mach/mach.h> 7 #include <mach/mach.h>
8 8
9 #include "base/basictypes.h" 9 #include "base/basictypes.h"
10 #include "base/compiler_specific.h" 10 #include "base/compiler_specific.h"
11 #include "base/lazy_instance.h" 11 #include "base/lazy_instance.h"
12 #include "base/logging.h" 12 #include "base/logging.h"
13 #include "base/mac/mach_logging.h" 13 #include "base/mac/mach_logging.h"
14 #include "base/mac/scoped_mach_vm.h" 14 #include "base/mac/scoped_mach_vm.h"
15 #include "base/memory/discardable_memory_emulated.h" 15 #include "base/memory/discardable_memory_emulated.h"
16 #include "base/memory/discardable_memory_malloc.h"
17 #include "base/memory/discardable_memory_manager.h" 16 #include "base/memory/discardable_memory_manager.h"
18 #include "base/memory/scoped_ptr.h" 17 #include "base/memory/scoped_ptr.h"
19 18
20 namespace base { 19 namespace base {
21 namespace { 20 namespace {
22 21
23 // For Mac, have the DiscardableMemoryManager trigger userspace eviction when 22 // For Mac, have the DiscardableMemoryManager trigger userspace eviction when
24 // address space usage gets too high (e.g. 512 MBytes). 23 // address space usage gets too high (e.g. 512 MBytes).
25 const size_t kMacMemoryLimit = 512 * 1024 * 1024; 24 const size_t kMacMemoryLimit = 512 * 1024 * 1024;
26 25
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after
158 // static 157 // static
159 bool DiscardableMemory::ReduceMemoryUsage() { 158 bool DiscardableMemory::ReduceMemoryUsage() {
160 return internal::DiscardableMemoryEmulated::ReduceMemoryUsage(); 159 return internal::DiscardableMemoryEmulated::ReduceMemoryUsage();
161 } 160 }
162 161
163 // static 162 // static
164 void DiscardableMemory::GetSupportedTypes( 163 void DiscardableMemory::GetSupportedTypes(
165 std::vector<DiscardableMemoryType>* types) { 164 std::vector<DiscardableMemoryType>* types) {
166 const DiscardableMemoryType supported_types[] = { 165 const DiscardableMemoryType supported_types[] = {
167 DISCARDABLE_MEMORY_TYPE_MAC, 166 DISCARDABLE_MEMORY_TYPE_MAC,
168 DISCARDABLE_MEMORY_TYPE_EMULATED, 167 DISCARDABLE_MEMORY_TYPE_EMULATED
169 DISCARDABLE_MEMORY_TYPE_MALLOC
170 }; 168 };
171 types->assign(supported_types, supported_types + arraysize(supported_types)); 169 types->assign(supported_types, supported_types + arraysize(supported_types));
172 } 170 }
173 171
174 // static 172 // static
175 scoped_ptr<DiscardableMemory> DiscardableMemory::CreateLockedMemoryWithType( 173 scoped_ptr<DiscardableMemory> DiscardableMemory::CreateLockedMemoryWithType(
176 DiscardableMemoryType type, size_t size) { 174 DiscardableMemoryType type, size_t size) {
177 switch (type) { 175 switch (type) {
178 case DISCARDABLE_MEMORY_TYPE_MAC: { 176 case DISCARDABLE_MEMORY_TYPE_MAC: {
179 scoped_ptr<DiscardableMemoryMac> memory(new DiscardableMemoryMac(size)); 177 scoped_ptr<DiscardableMemoryMac> memory(new DiscardableMemoryMac(size));
180 if (!memory->Initialize()) 178 if (!memory->Initialize())
181 return scoped_ptr<DiscardableMemory>(); 179 return scoped_ptr<DiscardableMemory>();
182 180
183 return memory.PassAs<DiscardableMemory>(); 181 return memory.PassAs<DiscardableMemory>();
184 } 182 }
185 case DISCARDABLE_MEMORY_TYPE_EMULATED: { 183 case DISCARDABLE_MEMORY_TYPE_EMULATED: {
186 scoped_ptr<internal::DiscardableMemoryEmulated> memory( 184 scoped_ptr<internal::DiscardableMemoryEmulated> memory(
187 new internal::DiscardableMemoryEmulated(size)); 185 new internal::DiscardableMemoryEmulated(size));
188 if (!memory->Initialize()) 186 if (!memory->Initialize())
189 return scoped_ptr<DiscardableMemory>(); 187 return scoped_ptr<DiscardableMemory>();
190 188
191 return memory.PassAs<DiscardableMemory>(); 189 return memory.PassAs<DiscardableMemory>();
192 } 190 }
193 case DISCARDABLE_MEMORY_TYPE_MALLOC: {
194 scoped_ptr<internal::DiscardableMemoryMalloc> memory(
195 new internal::DiscardableMemoryMalloc(size));
196 if (!memory->Initialize())
197 return scoped_ptr<DiscardableMemory>();
198
199 return memory.PassAs<DiscardableMemory>();
200 }
201 case DISCARDABLE_MEMORY_TYPE_NONE: 191 case DISCARDABLE_MEMORY_TYPE_NONE:
202 case DISCARDABLE_MEMORY_TYPE_ASHMEM: 192 case DISCARDABLE_MEMORY_TYPE_ASHMEM:
203 NOTREACHED(); 193 NOTREACHED();
204 return scoped_ptr<DiscardableMemory>(); 194 return scoped_ptr<DiscardableMemory>();
205 } 195 }
206 196
207 NOTREACHED(); 197 NOTREACHED();
208 return scoped_ptr<DiscardableMemory>(); 198 return scoped_ptr<DiscardableMemory>();
209 } 199 }
210 200
211 // static 201 // static
212 void DiscardableMemory::PurgeForTesting() { 202 void DiscardableMemory::PurgeForTesting() {
213 int state = 0; 203 int state = 0;
214 vm_purgable_control(mach_task_self(), 0, VM_PURGABLE_PURGE_ALL, &state); 204 vm_purgable_control(mach_task_self(), 0, VM_PURGABLE_PURGE_ALL, &state);
215 internal::DiscardableMemoryEmulated::PurgeForTesting(); 205 internal::DiscardableMemoryEmulated::PurgeForTesting();
216 } 206 }
217 207
218 } // namespace base 208 } // namespace base
OLDNEW
« no previous file with comments | « base/memory/discardable_memory_linux.cc ('k') | base/memory/discardable_memory_malloc.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698