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

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

Issue 654593002: base: Add NOTREACHED() for when using a non-supported discardable memory type. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: 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_win.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.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"
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after
168 DISCARDABLE_MEMORY_TYPE_EMULATED, 168 DISCARDABLE_MEMORY_TYPE_EMULATED,
169 DISCARDABLE_MEMORY_TYPE_MALLOC 169 DISCARDABLE_MEMORY_TYPE_MALLOC
170 }; 170 };
171 types->assign(supported_types, supported_types + arraysize(supported_types)); 171 types->assign(supported_types, supported_types + arraysize(supported_types));
172 } 172 }
173 173
174 // static 174 // static
175 scoped_ptr<DiscardableMemory> DiscardableMemory::CreateLockedMemoryWithType( 175 scoped_ptr<DiscardableMemory> DiscardableMemory::CreateLockedMemoryWithType(
176 DiscardableMemoryType type, size_t size) { 176 DiscardableMemoryType type, size_t size) {
177 switch (type) { 177 switch (type) {
178 case DISCARDABLE_MEMORY_TYPE_NONE:
179 case DISCARDABLE_MEMORY_TYPE_ASHMEM:
180 return scoped_ptr<DiscardableMemory>();
181 case DISCARDABLE_MEMORY_TYPE_MAC: { 178 case DISCARDABLE_MEMORY_TYPE_MAC: {
182 scoped_ptr<DiscardableMemoryMac> memory(new DiscardableMemoryMac(size)); 179 scoped_ptr<DiscardableMemoryMac> memory(new DiscardableMemoryMac(size));
183 if (!memory->Initialize()) 180 if (!memory->Initialize())
184 return scoped_ptr<DiscardableMemory>(); 181 return scoped_ptr<DiscardableMemory>();
185 182
186 return memory.PassAs<DiscardableMemory>(); 183 return memory.PassAs<DiscardableMemory>();
187 } 184 }
188 case DISCARDABLE_MEMORY_TYPE_EMULATED: { 185 case DISCARDABLE_MEMORY_TYPE_EMULATED: {
189 scoped_ptr<internal::DiscardableMemoryEmulated> memory( 186 scoped_ptr<internal::DiscardableMemoryEmulated> memory(
190 new internal::DiscardableMemoryEmulated(size)); 187 new internal::DiscardableMemoryEmulated(size));
191 if (!memory->Initialize()) 188 if (!memory->Initialize())
192 return scoped_ptr<DiscardableMemory>(); 189 return scoped_ptr<DiscardableMemory>();
193 190
194 return memory.PassAs<DiscardableMemory>(); 191 return memory.PassAs<DiscardableMemory>();
195 } 192 }
196 case DISCARDABLE_MEMORY_TYPE_MALLOC: { 193 case DISCARDABLE_MEMORY_TYPE_MALLOC: {
197 scoped_ptr<internal::DiscardableMemoryMalloc> memory( 194 scoped_ptr<internal::DiscardableMemoryMalloc> memory(
198 new internal::DiscardableMemoryMalloc(size)); 195 new internal::DiscardableMemoryMalloc(size));
199 if (!memory->Initialize()) 196 if (!memory->Initialize())
200 return scoped_ptr<DiscardableMemory>(); 197 return scoped_ptr<DiscardableMemory>();
201 198
202 return memory.PassAs<DiscardableMemory>(); 199 return memory.PassAs<DiscardableMemory>();
203 } 200 }
201 case DISCARDABLE_MEMORY_TYPE_NONE:
202 case DISCARDABLE_MEMORY_TYPE_ASHMEM:
203 NOTREACHED();
204 return scoped_ptr<DiscardableMemory>();
204 } 205 }
205 206
206 NOTREACHED(); 207 NOTREACHED();
207 return scoped_ptr<DiscardableMemory>(); 208 return scoped_ptr<DiscardableMemory>();
208 } 209 }
209 210
210 // static 211 // static
211 void DiscardableMemory::PurgeForTesting() { 212 void DiscardableMemory::PurgeForTesting() {
212 int state = 0; 213 int state = 0;
213 vm_purgable_control(mach_task_self(), 0, VM_PURGABLE_PURGE_ALL, &state); 214 vm_purgable_control(mach_task_self(), 0, VM_PURGABLE_PURGE_ALL, &state);
214 internal::DiscardableMemoryEmulated::PurgeForTesting(); 215 internal::DiscardableMemoryEmulated::PurgeForTesting();
215 } 216 }
216 217
217 } // namespace base 218 } // namespace base
OLDNEW
« no previous file with comments | « base/memory/discardable_memory_linux.cc ('k') | base/memory/discardable_memory_win.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698