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