| 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 #include <sys/mman.h> | 8 #include <sys/mman.h> |
| 9 | 9 |
| 10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 108 DISCARDABLE_MEMORY_TYPE_MALLOC | 108 DISCARDABLE_MEMORY_TYPE_MALLOC |
| 109 }; | 109 }; |
| 110 types->assign(supported_types, supported_types + arraysize(supported_types)); | 110 types->assign(supported_types, supported_types + arraysize(supported_types)); |
| 111 } | 111 } |
| 112 | 112 |
| 113 // static | 113 // static |
| 114 scoped_ptr<DiscardableMemory> DiscardableMemory::CreateLockedMemoryWithType( | 114 scoped_ptr<DiscardableMemory> DiscardableMemory::CreateLockedMemoryWithType( |
| 115 DiscardableMemoryType type, size_t size) { | 115 DiscardableMemoryType type, size_t size) { |
| 116 switch (type) { | 116 switch (type) { |
| 117 case DISCARDABLE_MEMORY_TYPE_NONE: | 117 case DISCARDABLE_MEMORY_TYPE_NONE: |
| 118 case DISCARDABLE_MEMORY_TYPE_ASHMEM: | 118 case DISCARDABLE_MEMORY_TYPE_ANDROID: |
| 119 return scoped_ptr<DiscardableMemory>(); | 119 return scoped_ptr<DiscardableMemory>(); |
| 120 case DISCARDABLE_MEMORY_TYPE_MAC: { | 120 case DISCARDABLE_MEMORY_TYPE_MAC: { |
| 121 scoped_ptr<DiscardableMemoryMac> memory(new DiscardableMemoryMac(size)); | 121 scoped_ptr<DiscardableMemoryMac> memory(new DiscardableMemoryMac(size)); |
| 122 if (!memory->Initialize()) | 122 if (!memory->Initialize()) |
| 123 return scoped_ptr<DiscardableMemory>(); | 123 return scoped_ptr<DiscardableMemory>(); |
| 124 | 124 |
| 125 return memory.PassAs<DiscardableMemory>(); | 125 return memory.PassAs<DiscardableMemory>(); |
| 126 } | 126 } |
| 127 case DISCARDABLE_MEMORY_TYPE_EMULATED: { | 127 case DISCARDABLE_MEMORY_TYPE_EMULATED: { |
| 128 scoped_ptr<internal::DiscardableMemoryEmulated> memory( | 128 scoped_ptr<internal::DiscardableMemoryEmulated> memory( |
| (...skipping 11 matching lines...) Expand all Loading... |
| 140 | 140 |
| 141 return memory.PassAs<DiscardableMemory>(); | 141 return memory.PassAs<DiscardableMemory>(); |
| 142 } | 142 } |
| 143 } | 143 } |
| 144 | 144 |
| 145 NOTREACHED(); | 145 NOTREACHED(); |
| 146 return scoped_ptr<DiscardableMemory>(); | 146 return scoped_ptr<DiscardableMemory>(); |
| 147 } | 147 } |
| 148 | 148 |
| 149 // static | 149 // static |
| 150 bool DiscardableMemory::PurgeForTestingSupported() { |
| 151 return true; |
| 152 } |
| 153 |
| 154 // static |
| 150 void DiscardableMemory::PurgeForTesting() { | 155 void DiscardableMemory::PurgeForTesting() { |
| 151 int state = 0; | 156 int state = 0; |
| 152 vm_purgable_control(mach_task_self(), 0, VM_PURGABLE_PURGE_ALL, &state); | 157 vm_purgable_control(mach_task_self(), 0, VM_PURGABLE_PURGE_ALL, &state); |
| 153 internal::DiscardableMemoryEmulated::PurgeForTesting(); | 158 internal::DiscardableMemoryEmulated::PurgeForTesting(); |
| 154 } | 159 } |
| 155 | 160 |
| 156 } // namespace base | 161 } // namespace base |
| OLD | NEW |