Support multiple permission request creators and return a success value.
[chromium-blink-merge.git] / base / memory / discardable_memory_linux.cc
blob578b2c1c756049559e902300dffe1ddf51a82635
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"
11 namespace base {
13 // static
14 bool DiscardableMemory::ReduceMemoryUsage() {
15 return internal::DiscardableMemoryEmulated::ReduceMemoryUsage();
18 // static
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));
28 // static
29 scoped_ptr<DiscardableMemory> DiscardableMemory::CreateLockedMemoryWithType(
30 DiscardableMemoryType type, size_t size) {
31 switch (type) {
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>();
54 NOTREACHED();
55 return scoped_ptr<DiscardableMemory>();
58 // static
59 void DiscardableMemory::PurgeForTesting() {
60 internal::DiscardableMemoryEmulated::PurgeForTesting();
63 } // namespace base