OLD | NEW |
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 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
169 types->assign(supported_types, supported_types + arraysize(supported_types)); | 169 types->assign(supported_types, supported_types + arraysize(supported_types)); |
170 } | 170 } |
171 | 171 |
172 // static | 172 // static |
173 scoped_ptr<DiscardableMemory> DiscardableMemory::CreateLockedMemoryWithType( | 173 scoped_ptr<DiscardableMemory> DiscardableMemory::CreateLockedMemoryWithType( |
174 DiscardableMemoryType type, size_t size) { | 174 DiscardableMemoryType type, size_t size) { |
175 switch (type) { | 175 switch (type) { |
176 case DISCARDABLE_MEMORY_TYPE_MAC: { | 176 case DISCARDABLE_MEMORY_TYPE_MAC: { |
177 scoped_ptr<DiscardableMemoryMac> memory(new DiscardableMemoryMac(size)); | 177 scoped_ptr<DiscardableMemoryMac> memory(new DiscardableMemoryMac(size)); |
178 if (!memory->Initialize()) | 178 if (!memory->Initialize()) |
179 return scoped_ptr<DiscardableMemory>(); | 179 return nullptr; |
180 | 180 |
181 return memory.PassAs<DiscardableMemory>(); | 181 return memory.Pass(); |
182 } | 182 } |
183 case DISCARDABLE_MEMORY_TYPE_EMULATED: { | 183 case DISCARDABLE_MEMORY_TYPE_EMULATED: { |
184 scoped_ptr<internal::DiscardableMemoryEmulated> memory( | 184 scoped_ptr<internal::DiscardableMemoryEmulated> memory( |
185 new internal::DiscardableMemoryEmulated(size)); | 185 new internal::DiscardableMemoryEmulated(size)); |
186 if (!memory->Initialize()) | 186 if (!memory->Initialize()) |
187 return scoped_ptr<DiscardableMemory>(); | 187 return nullptr; |
188 | 188 |
189 return memory.PassAs<DiscardableMemory>(); | 189 return memory.Pass(); |
190 } | 190 } |
191 case DISCARDABLE_MEMORY_TYPE_NONE: | 191 case DISCARDABLE_MEMORY_TYPE_NONE: |
192 case DISCARDABLE_MEMORY_TYPE_ASHMEM: | 192 case DISCARDABLE_MEMORY_TYPE_ASHMEM: |
193 NOTREACHED(); | 193 NOTREACHED(); |
194 return scoped_ptr<DiscardableMemory>(); | 194 return nullptr; |
195 } | 195 } |
196 | 196 |
197 NOTREACHED(); | 197 NOTREACHED(); |
198 return scoped_ptr<DiscardableMemory>(); | 198 return nullptr; |
199 } | 199 } |
200 | 200 |
201 // static | 201 // static |
202 void DiscardableMemory::PurgeForTesting() { | 202 void DiscardableMemory::PurgeForTesting() { |
203 int state = 0; | 203 int state = 0; |
204 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); |
205 internal::DiscardableMemoryEmulated::PurgeForTesting(); | 205 internal::DiscardableMemoryEmulated::PurgeForTesting(); |
206 } | 206 } |
207 | 207 |
208 } // namespace base | 208 } // namespace base |
OLD | NEW |