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/scoped_ptr.h"
16 bool DiscardableMemory::ReduceMemoryUsage() {
17 return internal::DiscardableMemoryEmulated::ReduceMemoryUsage();
21 void DiscardableMemory::GetSupportedTypes(
22 std::vector
<DiscardableMemoryType
>* types
) {
23 const DiscardableMemoryType supported_types
[] = {
24 DISCARDABLE_MEMORY_TYPE_MACH
,
25 DISCARDABLE_MEMORY_TYPE_EMULATED
27 types
->assign(supported_types
, supported_types
+ arraysize(supported_types
));
31 scoped_ptr
<DiscardableMemory
> DiscardableMemory::CreateLockedMemoryWithType(
32 DiscardableMemoryType type
, size_t size
) {
34 case DISCARDABLE_MEMORY_TYPE_MACH
: {
35 scoped_ptr
<internal::DiscardableMemoryMach
> memory(
36 new internal::DiscardableMemoryMach(size
));
37 if (!memory
->Initialize())
42 case DISCARDABLE_MEMORY_TYPE_EMULATED
: {
43 scoped_ptr
<internal::DiscardableMemoryEmulated
> memory(
44 new internal::DiscardableMemoryEmulated(size
));
45 if (!memory
->Initialize())
50 case DISCARDABLE_MEMORY_TYPE_NONE
:
51 case DISCARDABLE_MEMORY_TYPE_ASHMEM
:
61 void DiscardableMemory::PurgeForTesting() {
62 internal::DiscardableMemoryMach::PurgeForTesting();
63 internal::DiscardableMemoryEmulated::PurgeForTesting();