MacViews: Get c/b/ui/views/tabs to build on Mac
[chromium-blink-merge.git] / base / memory / discardable_memory_mac.cc
blob6896e5a7c167a311560a79c35a0e7ca7b7793823
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"
13 namespace base {
15 // static
16 bool DiscardableMemory::ReduceMemoryUsage() {
17 return internal::DiscardableMemoryEmulated::ReduceMemoryUsage();
20 // static
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));
30 // static
31 scoped_ptr<DiscardableMemory> DiscardableMemory::CreateLockedMemoryWithType(
32 DiscardableMemoryType type, size_t size) {
33 switch (type) {
34 case DISCARDABLE_MEMORY_TYPE_MACH: {
35 scoped_ptr<internal::DiscardableMemoryMach> memory(
36 new internal::DiscardableMemoryMach(size));
37 if (!memory->Initialize())
38 return nullptr;
40 return memory.Pass();
42 case DISCARDABLE_MEMORY_TYPE_EMULATED: {
43 scoped_ptr<internal::DiscardableMemoryEmulated> memory(
44 new internal::DiscardableMemoryEmulated(size));
45 if (!memory->Initialize())
46 return nullptr;
48 return memory.Pass();
50 case DISCARDABLE_MEMORY_TYPE_NONE:
51 case DISCARDABLE_MEMORY_TYPE_ASHMEM:
52 NOTREACHED();
53 return nullptr;
56 NOTREACHED();
57 return nullptr;
60 // static
61 void DiscardableMemory::PurgeForTesting() {
62 internal::DiscardableMemoryMach::PurgeForTesting();
63 internal::DiscardableMemoryEmulated::PurgeForTesting();
66 } // namespace base