Added llvm into exceptions as we can't add README.chromium into 3rd party repository
[chromium-blink-merge.git] / base / memory / discardable_memory_linux.cc
blob977b029bee59c4a9155dc524a88274bc1d7319c4
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_shmem.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_SHMEM
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_EMULATED: {
33 scoped_ptr<internal::DiscardableMemoryEmulated> memory(
34 new internal::DiscardableMemoryEmulated(size));
35 if (!memory->Initialize())
36 return nullptr;
38 return memory.Pass();
40 case DISCARDABLE_MEMORY_TYPE_SHMEM: {
41 scoped_ptr<internal::DiscardableMemoryShmem> memory(
42 new internal::DiscardableMemoryShmem(size));
43 if (!memory->Initialize())
44 return nullptr;
46 return memory.Pass();
48 case DISCARDABLE_MEMORY_TYPE_NONE:
49 case DISCARDABLE_MEMORY_TYPE_ASHMEM:
50 case DISCARDABLE_MEMORY_TYPE_MACH:
51 NOTREACHED();
52 return nullptr;
55 NOTREACHED();
56 return nullptr;
59 } // namespace base