OLD | NEW |
---|---|
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 #ifndef BASE_MEMORY_DISCARDABLE_MEMORY_PROVIDER_H_ | 5 #ifndef BASE_MEMORY_DISCARDABLE_MEMORY_PROVIDER_H_ |
6 #define BASE_MEMORY_DISCARDABLE_MEMORY_PROVIDER_H_ | 6 #define BASE_MEMORY_DISCARDABLE_MEMORY_PROVIDER_H_ |
7 | 7 |
8 #include "base/base_export.h" | 8 #include "base/base_export.h" |
9 #include "base/containers/hash_tables.h" | 9 #include "base/containers/hash_tables.h" |
10 #include "base/containers/mru_cache.h" | 10 #include "base/containers/mru_cache.h" |
(...skipping 28 matching lines...) Expand all Loading... | |
39 // memory -- if the pressure is moderate -- or all discardable memory | 39 // memory -- if the pressure is moderate -- or all discardable memory |
40 // if the pressure is critical. | 40 // if the pressure is critical. |
41 // | 41 // |
42 // NB - this class is an implementation detail. It has been exposed for testing | 42 // NB - this class is an implementation detail. It has been exposed for testing |
43 // purposes. You should not need to use this class directly. | 43 // purposes. You should not need to use this class directly. |
44 class BASE_EXPORT_PRIVATE DiscardableMemoryProvider { | 44 class BASE_EXPORT_PRIVATE DiscardableMemoryProvider { |
45 public: | 45 public: |
46 DiscardableMemoryProvider(); | 46 DiscardableMemoryProvider(); |
47 ~DiscardableMemoryProvider(); | 47 ~DiscardableMemoryProvider(); |
48 | 48 |
49 static DiscardableMemoryProvider* GetInstance(); | |
50 | |
51 // Sets the instance of DiscardableMemoryProvider to be returned by | |
52 // GetInstance. This should only be used by tests and must be called | |
53 // prior to GetInstance(). The ownership of the given provider is | |
54 // retained by the caller. | |
55 static void SetInstanceForTest(DiscardableMemoryProvider* provider); | |
56 | |
57 // The maximum number of bytes of discardable memory that may be allocated | 49 // The maximum number of bytes of discardable memory that may be allocated |
58 // before we force a purge. If this amount is zero, it is interpreted as | 50 // before we force a purge. If this amount is zero, it is interpreted as |
59 // having no limit at all. | 51 // having no limit at all. |
60 void SetDiscardableMemoryLimit(size_t bytes); | 52 void SetDiscardableMemoryLimit(size_t bytes); |
61 | 53 |
62 // Sets the amount of memory to reclaim when we're under moderate pressure. | 54 // Sets the amount of memory to reclaim when we're under moderate pressure. |
63 void SetBytesToReclaimUnderModeratePressure(size_t bytes); | 55 void SetBytesToReclaimUnderModeratePressure(size_t bytes); |
64 | 56 |
65 // Adds the given discardable memory to the provider's collection. | 57 // Adds the given discardable memory to the provider's collection. |
66 void Register(const DiscardableMemory* discardable, size_t bytes); | 58 void Register(const DiscardableMemory* discardable, size_t bytes); |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
101 memory(NULL) { | 93 memory(NULL) { |
102 } | 94 } |
103 | 95 |
104 size_t bytes; | 96 size_t bytes; |
105 uint8* memory; | 97 uint8* memory; |
106 }; | 98 }; |
107 typedef HashingMRUCache<const DiscardableMemory*, Allocation> AllocationMap; | 99 typedef HashingMRUCache<const DiscardableMemory*, Allocation> AllocationMap; |
108 | 100 |
109 // This can be called as a hint that the system is under memory pressure. | 101 // This can be called as a hint that the system is under memory pressure. |
110 static void NotifyMemoryPressure( | 102 static void NotifyMemoryPressure( |
103 DiscardableMemoryProvider* provider, | |
willchan no longer on Chromium
2013/12/13 19:45:39
If you're going to add the provider, why isn't thi
reveman
2013/12/13 20:12:59
Good call. Fixed.
| |
111 MemoryPressureListener::MemoryPressureLevel pressure_level); | 104 MemoryPressureListener::MemoryPressureLevel pressure_level); |
112 | 105 |
113 // Purges |bytes_to_reclaim_under_moderate_pressure_| bytes of | 106 // Purges |bytes_to_reclaim_under_moderate_pressure_| bytes of |
114 // discardable memory. | 107 // discardable memory. |
115 void Purge(); | 108 void Purge(); |
116 | 109 |
117 // Purges least recently used memory until usage is less or equal to |limit|. | 110 // Purges least recently used memory until usage is less or equal to |limit|. |
118 // Caller must acquire |lock_| prior to calling this function. | 111 // Caller must acquire |lock_| prior to calling this function. |
119 void PurgeLRUWithLockAcquiredUntilUsageIsWithin(size_t limit); | 112 void PurgeLRUWithLockAcquiredUntilUsageIsWithin(size_t limit); |
120 | 113 |
(...skipping 21 matching lines...) Expand all Loading... | |
142 // pressure. | 135 // pressure. |
143 MemoryPressureListener memory_pressure_listener_; | 136 MemoryPressureListener memory_pressure_listener_; |
144 | 137 |
145 DISALLOW_COPY_AND_ASSIGN(DiscardableMemoryProvider); | 138 DISALLOW_COPY_AND_ASSIGN(DiscardableMemoryProvider); |
146 }; | 139 }; |
147 | 140 |
148 } // namespace internal | 141 } // namespace internal |
149 } // namespace base | 142 } // namespace base |
150 | 143 |
151 #endif // BASE_MEMORY_DISCARDABLE_MEMORY_PROVIDER_H_ | 144 #endif // BASE_MEMORY_DISCARDABLE_MEMORY_PROVIDER_H_ |
OLD | NEW |