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.
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_malloc.h"
14 bool DiscardableMemory::ReduceMemoryUsage() {
15 return internal::DiscardableMemoryEmulated::ReduceMemoryUsage();
19 void DiscardableMemory::GetSupportedTypes(
20 std::vector
<DiscardableMemoryType
>* types
) {
21 const DiscardableMemoryType supported_types
[] = {
22 DISCARDABLE_MEMORY_TYPE_EMULATED
,
23 DISCARDABLE_MEMORY_TYPE_MALLOC
25 types
->assign(supported_types
, supported_types
+ arraysize(supported_types
));
29 scoped_ptr
<DiscardableMemory
> DiscardableMemory::CreateLockedMemoryWithType(
30 DiscardableMemoryType type
, size_t size
) {
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
>();
42 return memory
.PassAs
<DiscardableMemory
>();
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
>();
50 return memory
.PassAs
<DiscardableMemory
>();
55 return scoped_ptr
<DiscardableMemory
>();
59 void DiscardableMemory::PurgeForTesting() {
60 internal::DiscardableMemoryEmulated::PurgeForTesting();