Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(7)

Side by Side Diff: base/memory/discardable_memory_android.cc

Issue 654593002: base: Add NOTREACHED() for when using a non-supported discardable memory type. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | base/memory/discardable_memory_linux.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "base/memory/discardable_memory.h" 5 #include "base/memory/discardable_memory.h"
6 6
7 #include "base/basictypes.h" 7 #include "base/basictypes.h"
8 #include "base/compiler_specific.h" 8 #include "base/compiler_specific.h"
9 #include "base/lazy_instance.h" 9 #include "base/lazy_instance.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
56 DISCARDABLE_MEMORY_TYPE_EMULATED, 56 DISCARDABLE_MEMORY_TYPE_EMULATED,
57 DISCARDABLE_MEMORY_TYPE_MALLOC 57 DISCARDABLE_MEMORY_TYPE_MALLOC
58 }; 58 };
59 types->assign(supported_types, supported_types + arraysize(supported_types)); 59 types->assign(supported_types, supported_types + arraysize(supported_types));
60 } 60 }
61 61
62 // static 62 // static
63 scoped_ptr<DiscardableMemory> DiscardableMemory::CreateLockedMemoryWithType( 63 scoped_ptr<DiscardableMemory> DiscardableMemory::CreateLockedMemoryWithType(
64 DiscardableMemoryType type, size_t size) { 64 DiscardableMemoryType type, size_t size) {
65 switch (type) { 65 switch (type) {
66 case DISCARDABLE_MEMORY_TYPE_NONE:
67 case DISCARDABLE_MEMORY_TYPE_MAC:
68 return scoped_ptr<DiscardableMemory>();
69 case DISCARDABLE_MEMORY_TYPE_ASHMEM: { 66 case DISCARDABLE_MEMORY_TYPE_ASHMEM: {
70 SharedState* const shared_state = g_shared_state.Pointer(); 67 SharedState* const shared_state = g_shared_state.Pointer();
71 scoped_ptr<internal::DiscardableMemoryAshmem> memory( 68 scoped_ptr<internal::DiscardableMemoryAshmem> memory(
72 new internal::DiscardableMemoryAshmem( 69 new internal::DiscardableMemoryAshmem(
73 size, &shared_state->allocator, &shared_state->manager)); 70 size, &shared_state->allocator, &shared_state->manager));
74 if (!memory->Initialize()) 71 if (!memory->Initialize())
75 return scoped_ptr<DiscardableMemory>(); 72 return scoped_ptr<DiscardableMemory>();
76 73
77 return memory.PassAs<DiscardableMemory>(); 74 return memory.PassAs<DiscardableMemory>();
78 } 75 }
79 case DISCARDABLE_MEMORY_TYPE_EMULATED: { 76 case DISCARDABLE_MEMORY_TYPE_EMULATED: {
80 scoped_ptr<internal::DiscardableMemoryEmulated> memory( 77 scoped_ptr<internal::DiscardableMemoryEmulated> memory(
81 new internal::DiscardableMemoryEmulated(size)); 78 new internal::DiscardableMemoryEmulated(size));
82 if (!memory->Initialize()) 79 if (!memory->Initialize())
83 return scoped_ptr<DiscardableMemory>(); 80 return scoped_ptr<DiscardableMemory>();
84 81
85 return memory.PassAs<DiscardableMemory>(); 82 return memory.PassAs<DiscardableMemory>();
86 } 83 }
87 case DISCARDABLE_MEMORY_TYPE_MALLOC: { 84 case DISCARDABLE_MEMORY_TYPE_MALLOC: {
88 scoped_ptr<internal::DiscardableMemoryMalloc> memory( 85 scoped_ptr<internal::DiscardableMemoryMalloc> memory(
89 new internal::DiscardableMemoryMalloc(size)); 86 new internal::DiscardableMemoryMalloc(size));
90 if (!memory->Initialize()) 87 if (!memory->Initialize())
91 return scoped_ptr<DiscardableMemory>(); 88 return scoped_ptr<DiscardableMemory>();
92 89
93 return memory.PassAs<DiscardableMemory>(); 90 return memory.PassAs<DiscardableMemory>();
94 } 91 }
92 case DISCARDABLE_MEMORY_TYPE_NONE:
93 case DISCARDABLE_MEMORY_TYPE_MAC:
94 NOTREACHED();
95 return scoped_ptr<DiscardableMemory>();
95 } 96 }
96 97
97 NOTREACHED(); 98 NOTREACHED();
98 return scoped_ptr<DiscardableMemory>(); 99 return scoped_ptr<DiscardableMemory>();
99 } 100 }
100 101
101 // static 102 // static
102 void DiscardableMemory::PurgeForTesting() { 103 void DiscardableMemory::PurgeForTesting() {
103 g_shared_state.Pointer()->manager.PurgeAll(); 104 g_shared_state.Pointer()->manager.PurgeAll();
104 internal::DiscardableMemoryEmulated::PurgeForTesting(); 105 internal::DiscardableMemoryEmulated::PurgeForTesting();
105 } 106 }
106 107
107 } // namespace base 108 } // namespace base
OLDNEW
« no previous file with comments | « no previous file | base/memory/discardable_memory_linux.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698