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

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

Issue 145643008: base: Add uncached malloc based discardable memory type. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 11 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 | Annotate | Revision Log
« no previous file with comments | « base/memory/discardable_memory_unittest.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 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 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/logging.h" 7 #include "base/logging.h"
8 #include "base/memory/discardable_memory_emulated.h" 8 #include "base/memory/discardable_memory_emulated.h"
9 #include "base/memory/discardable_memory_malloc.h"
9 10
10 namespace base { 11 namespace base {
11 12
12 // static 13 // static
13 void DiscardableMemory::RegisterMemoryPressureListeners() { 14 void DiscardableMemory::RegisterMemoryPressureListeners() {
14 internal::DiscardableMemoryEmulated::RegisterMemoryPressureListeners(); 15 internal::DiscardableMemoryEmulated::RegisterMemoryPressureListeners();
15 } 16 }
16 17
17 // static 18 // static
18 void DiscardableMemory::UnregisterMemoryPressureListeners() { 19 void DiscardableMemory::UnregisterMemoryPressureListeners() {
19 internal::DiscardableMemoryEmulated::UnregisterMemoryPressureListeners(); 20 internal::DiscardableMemoryEmulated::UnregisterMemoryPressureListeners();
20 } 21 }
21 22
22 // static 23 // static
23 void DiscardableMemory::GetSupportedTypes( 24 void DiscardableMemory::GetSupportedTypes(
24 std::vector<DiscardableMemoryType>* types) { 25 std::vector<DiscardableMemoryType>* types) {
25 const DiscardableMemoryType supported_types[] = { 26 const DiscardableMemoryType supported_types[] = {
26 DISCARDABLE_MEMORY_TYPE_EMULATED 27 DISCARDABLE_MEMORY_TYPE_EMULATED,
28 DISCARDABLE_MEMORY_TYPE_MALLOC
27 }; 29 };
28 types->assign(supported_types, supported_types + arraysize(supported_types)); 30 types->assign(supported_types, supported_types + arraysize(supported_types));
29 } 31 }
30 32
31 // static 33 // static
32 scoped_ptr<DiscardableMemory> DiscardableMemory::CreateLockedMemoryWithType( 34 scoped_ptr<DiscardableMemory> DiscardableMemory::CreateLockedMemoryWithType(
33 DiscardableMemoryType type, size_t size) { 35 DiscardableMemoryType type, size_t size) {
34 switch (type) { 36 switch (type) {
35 case DISCARDABLE_MEMORY_TYPE_NONE: 37 case DISCARDABLE_MEMORY_TYPE_NONE:
36 case DISCARDABLE_MEMORY_TYPE_ANDROID: 38 case DISCARDABLE_MEMORY_TYPE_ANDROID:
37 case DISCARDABLE_MEMORY_TYPE_MAC: 39 case DISCARDABLE_MEMORY_TYPE_MAC:
38 return scoped_ptr<DiscardableMemory>(); 40 return scoped_ptr<DiscardableMemory>();
39 case DISCARDABLE_MEMORY_TYPE_EMULATED: { 41 case DISCARDABLE_MEMORY_TYPE_EMULATED: {
40 scoped_ptr<internal::DiscardableMemoryEmulated> memory( 42 scoped_ptr<internal::DiscardableMemoryEmulated> memory(
41 new internal::DiscardableMemoryEmulated(size)); 43 new internal::DiscardableMemoryEmulated(size));
42 if (!memory->Initialize()) 44 if (!memory->Initialize())
43 return scoped_ptr<DiscardableMemory>(); 45 return scoped_ptr<DiscardableMemory>();
44 46
45 return memory.PassAs<DiscardableMemory>(); 47 return memory.PassAs<DiscardableMemory>();
46 } 48 }
49 case DISCARDABLE_MEMORY_TYPE_MALLOC: {
50 scoped_ptr<internal::DiscardableMemoryMalloc> memory(
51 new internal::DiscardableMemoryMalloc(size));
52 if (!memory->Initialize())
53 return scoped_ptr<DiscardableMemory>();
54
55 return memory.PassAs<DiscardableMemory>();
56 }
47 } 57 }
48 58
49 NOTREACHED(); 59 NOTREACHED();
50 return scoped_ptr<DiscardableMemory>(); 60 return scoped_ptr<DiscardableMemory>();
51 } 61 }
52 62
53 // static 63 // static
54 bool DiscardableMemory::PurgeForTestingSupported() { 64 bool DiscardableMemory::PurgeForTestingSupported() {
55 return true; 65 return true;
56 } 66 }
57 67
58 // static 68 // static
59 void DiscardableMemory::PurgeForTesting() { 69 void DiscardableMemory::PurgeForTesting() {
60 internal::DiscardableMemoryEmulated::PurgeForTesting(); 70 internal::DiscardableMemoryEmulated::PurgeForTesting();
61 } 71 }
62 72
63 } // namespace base 73 } // namespace base
OLDNEW
« no previous file with comments | « base/memory/discardable_memory_unittest.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698