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
3 // found in the LICENSE file.
5 #include "base/memory/discardable_memory.h"
7 #include "base/logging.h"
8 #include "base/memory/discardable_memory_emulated.h"
9 #include "base/memory/discardable_memory_mach.h"
10 #include "base/memory/discardable_memory_manager.h"
11 #include "base/memory/discardable_memory_shmem.h"
12 #include "base/memory/scoped_ptr.h"
17 void DiscardableMemory::ReleaseFreeMemory() {
18 internal::DiscardableMemoryShmem::ReleaseFreeMemory();
22 bool DiscardableMemory::ReduceMemoryUsage() {
23 return internal::DiscardableMemoryEmulated::ReduceMemoryUsage();
27 void DiscardableMemory::GetSupportedTypes(
28 std::vector
<DiscardableMemoryType
>* types
) {
29 const DiscardableMemoryType supported_types
[] = {
30 DISCARDABLE_MEMORY_TYPE_MACH
,
31 DISCARDABLE_MEMORY_TYPE_EMULATED
,
32 DISCARDABLE_MEMORY_TYPE_SHMEM
34 types
->assign(supported_types
, supported_types
+ arraysize(supported_types
));
38 scoped_ptr
<DiscardableMemory
> DiscardableMemory::CreateLockedMemoryWithType(
39 DiscardableMemoryType type
, size_t size
) {
41 case DISCARDABLE_MEMORY_TYPE_MACH
: {
42 scoped_ptr
<internal::DiscardableMemoryMach
> memory(
43 new internal::DiscardableMemoryMach(size
));
44 if (!memory
->Initialize())
49 case DISCARDABLE_MEMORY_TYPE_EMULATED
: {
50 scoped_ptr
<internal::DiscardableMemoryEmulated
> memory(
51 new internal::DiscardableMemoryEmulated(size
));
52 if (!memory
->Initialize())
57 case DISCARDABLE_MEMORY_TYPE_SHMEM
: {
58 scoped_ptr
<internal::DiscardableMemoryShmem
> memory(
59 new internal::DiscardableMemoryShmem(size
));
60 if (!memory
->Initialize())
65 case DISCARDABLE_MEMORY_TYPE_NONE
:
66 case DISCARDABLE_MEMORY_TYPE_ASHMEM
:
76 void DiscardableMemory::PurgeForTesting() {
77 internal::DiscardableMemoryMach::PurgeForTesting();
78 internal::DiscardableMemoryEmulated::PurgeForTesting();
79 internal::DiscardableMemoryShmem::PurgeForTesting();