OLD | NEW |
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 #ifndef BASE_MEMORY_DISCARDABLE_MEMORY_H_ | 5 #ifndef BASE_MEMORY_DISCARDABLE_MEMORY_H_ |
6 #define BASE_MEMORY_DISCARDABLE_MEMORY_H_ | 6 #define BASE_MEMORY_DISCARDABLE_MEMORY_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
11 #include "base/base_export.h" | 11 #include "base/base_export.h" |
12 #include "base/basictypes.h" | 12 #include "base/basictypes.h" |
13 #include "base/compiler_specific.h" | 13 #include "base/compiler_specific.h" |
14 #include "base/memory/scoped_ptr.h" | 14 #include "base/memory/scoped_ptr.h" |
15 | 15 |
16 namespace base { | 16 namespace base { |
17 | 17 |
18 enum DiscardableMemoryType { | 18 enum DiscardableMemoryType { |
19 DISCARDABLE_MEMORY_TYPE_NONE, | 19 DISCARDABLE_MEMORY_TYPE_NONE, |
20 DISCARDABLE_MEMORY_TYPE_ASHMEM, | 20 DISCARDABLE_MEMORY_TYPE_ASHMEM, |
21 DISCARDABLE_MEMORY_TYPE_MACH, | 21 DISCARDABLE_MEMORY_TYPE_MACH, |
22 DISCARDABLE_MEMORY_TYPE_EMULATED | 22 DISCARDABLE_MEMORY_TYPE_EMULATED, |
| 23 DISCARDABLE_MEMORY_TYPE_SHMEM |
23 }; | 24 }; |
24 | 25 |
25 enum DiscardableMemoryLockStatus { | 26 enum DiscardableMemoryLockStatus { |
26 DISCARDABLE_MEMORY_LOCK_STATUS_FAILED, | 27 DISCARDABLE_MEMORY_LOCK_STATUS_FAILED, |
27 DISCARDABLE_MEMORY_LOCK_STATUS_PURGED, | 28 DISCARDABLE_MEMORY_LOCK_STATUS_PURGED, |
28 DISCARDABLE_MEMORY_LOCK_STATUS_SUCCESS | 29 DISCARDABLE_MEMORY_LOCK_STATUS_SUCCESS |
29 }; | 30 }; |
30 | 31 |
31 // Platform abstraction for discardable memory. DiscardableMemory is used to | 32 // Platform abstraction for discardable memory. DiscardableMemory is used to |
32 // cache large objects without worrying about blowing out memory, both on mobile | 33 // cache large objects without worrying about blowing out memory, both on mobile |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
81 // Gets the preferred discardable memory type. | 82 // Gets the preferred discardable memory type. |
82 static DiscardableMemoryType GetPreferredType(); | 83 static DiscardableMemoryType GetPreferredType(); |
83 | 84 |
84 // Create a DiscardableMemory instance with specified |type| and |size|. | 85 // Create a DiscardableMemory instance with specified |type| and |size|. |
85 static scoped_ptr<DiscardableMemory> CreateLockedMemoryWithType( | 86 static scoped_ptr<DiscardableMemory> CreateLockedMemoryWithType( |
86 DiscardableMemoryType type, size_t size); | 87 DiscardableMemoryType type, size_t size); |
87 | 88 |
88 // Create a DiscardableMemory instance with preferred type and |size|. | 89 // Create a DiscardableMemory instance with preferred type and |size|. |
89 static scoped_ptr<DiscardableMemory> CreateLockedMemory(size_t size); | 90 static scoped_ptr<DiscardableMemory> CreateLockedMemory(size_t size); |
90 | 91 |
| 92 // Discardable memory implementations might use this to release memory |
| 93 // or resources assigned to instances that have been purged. |
| 94 static void ReleaseFreeMemory(); |
| 95 |
91 // Discardable memory implementations might allow an elevated usage level | 96 // Discardable memory implementations might allow an elevated usage level |
92 // while in frequent use. Call this to have the usage reduced to the base | 97 // while in frequent use. Call this to have the usage reduced to the base |
93 // level. Returns true if there's no need to call this again until | 98 // level. Returns true if there's no need to call this again until |
94 // memory instances have been used. This indicates that all discardable | 99 // memory instances have been used. This indicates that all discardable |
95 // memory implementations have reduced usage to the base level or below. | 100 // memory implementations have reduced usage to the base level or below. |
96 // Note: calling this too often or while discardable memory is in frequent | 101 // Note: calling this too often or while discardable memory is in frequent |
97 // use can hurt performance, whereas calling it too infrequently can result | 102 // use can hurt performance, whereas calling it too infrequently can result |
98 // in memory bloat. | 103 // in memory bloat. |
99 static bool ReduceMemoryUsage(); | 104 static bool ReduceMemoryUsage(); |
100 | 105 |
(...skipping 16 matching lines...) Expand all Loading... |
117 // Testing utility calls. | 122 // Testing utility calls. |
118 | 123 |
119 // Purge all discardable memory in the system. This call has global effects | 124 // Purge all discardable memory in the system. This call has global effects |
120 // across all running processes, so it should only be used for testing! | 125 // across all running processes, so it should only be used for testing! |
121 static void PurgeForTesting(); | 126 static void PurgeForTesting(); |
122 }; | 127 }; |
123 | 128 |
124 } // namespace base | 129 } // namespace base |
125 | 130 |
126 #endif // BASE_MEMORY_DISCARDABLE_MEMORY_H_ | 131 #endif // BASE_MEMORY_DISCARDABLE_MEMORY_H_ |
OLD | NEW |