1 // Copyright 2013 The Chromium Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #include "base/memory/discardable_memory.h" 6 7 #include "base/logging.h" 8 #include "base/memory/discardable_memory_emulated.h" 9 #include "base/memory/discardable_memory_malloc.h" 10 11 namespace base { 12 13 // static 14 bool DiscardableMemory::ReduceMemoryUsage() { 15 return internal::DiscardableMemoryEmulated::ReduceMemoryUsage(); 16 } 17 18 // static 19 void DiscardableMemory::GetSupportedTypes( 20 std::vector<DiscardableMemoryType>* types) { 21 const DiscardableMemoryType supported_types[] = { 22 DISCARDABLE_MEMORY_TYPE_EMULATED, 23 DISCARDABLE_MEMORY_TYPE_MALLOC 24 }; 25 types->assign(supported_types, supported_types + arraysize(supported_types)); 26 } 27 28 // static 29 scoped_ptr<DiscardableMemory> DiscardableMemory::CreateLockedMemoryWithType( 30 DiscardableMemoryType type, size_t size) { 31 switch (type) { 32 case DISCARDABLE_MEMORY_TYPE_NONE: 33 case DISCARDABLE_MEMORY_TYPE_ASHMEM: 34 case DISCARDABLE_MEMORY_TYPE_MAC: 35 return scoped_ptr<DiscardableMemory>(); 36 case DISCARDABLE_MEMORY_TYPE_EMULATED: { 37 scoped_ptr<internal::DiscardableMemoryEmulated> memory( 38 new internal::DiscardableMemoryEmulated(size)); 39 if (!memory->Initialize()) 40 return scoped_ptr<DiscardableMemory>(); 41 42 return memory.PassAs<DiscardableMemory>(); 43 } 44 case DISCARDABLE_MEMORY_TYPE_MALLOC: { 45 scoped_ptr<internal::DiscardableMemoryMalloc> memory( 46 new internal::DiscardableMemoryMalloc(size)); 47 if (!memory->Initialize()) 48 return scoped_ptr<DiscardableMemory>(); 49 50 return memory.PassAs<DiscardableMemory>(); 51 } 52 } 53 54 NOTREACHED(); 55 return scoped_ptr<DiscardableMemory>(); 56 } 57 58 // static 59 void DiscardableMemory::PurgeForTesting() { 60 internal::DiscardableMemoryEmulated::PurgeForTesting(); 61 } 62 63 } // namespace base 64