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

Side by Side Diff: base/memory/discardable_memory_provider.h

Issue 129963002: Re-land: base: Fix registering of memory pressure listeners used when emulating discardable memory. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Temporarily disable memory_pressure_listener DCHECK 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
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 #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
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 // Call this to register memory pressure listener. Must be called on a
50 // thread with a MessageLoop current.
51 void RegisterMemoryPressureListener();
52
53 // Call this to unregister memory pressure listener.
54 void UnregisterMemoryPressureListener();
55
49 // The maximum number of bytes of discardable memory that may be allocated 56 // The maximum number of bytes of discardable memory that may be allocated
50 // before we force a purge. If this amount is zero, it is interpreted as 57 // before we force a purge. If this amount is zero, it is interpreted as
51 // having no limit at all. 58 // having no limit at all.
52 void SetDiscardableMemoryLimit(size_t bytes); 59 void SetDiscardableMemoryLimit(size_t bytes);
53 60
54 // Sets the amount of memory to reclaim when we're under moderate pressure. 61 // Sets the amount of memory to reclaim when we're under moderate pressure.
55 void SetBytesToReclaimUnderModeratePressure(size_t bytes); 62 void SetBytesToReclaimUnderModeratePressure(size_t bytes);
56 63
57 // Adds the given discardable memory to the provider's collection. 64 // Adds the given discardable memory to the provider's collection.
58 void Register(const DiscardableMemory* discardable, size_t bytes); 65 void Register(const DiscardableMemory* discardable, size_t bytes);
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
92 : bytes(bytes), 99 : bytes(bytes),
93 memory(NULL) { 100 memory(NULL) {
94 } 101 }
95 102
96 size_t bytes; 103 size_t bytes;
97 uint8* memory; 104 uint8* memory;
98 }; 105 };
99 typedef HashingMRUCache<const DiscardableMemory*, Allocation> AllocationMap; 106 typedef HashingMRUCache<const DiscardableMemory*, Allocation> AllocationMap;
100 107
101 // This can be called as a hint that the system is under memory pressure. 108 // This can be called as a hint that the system is under memory pressure.
102 void NotifyMemoryPressure( 109 void OnMemoryPressure(
103 MemoryPressureListener::MemoryPressureLevel pressure_level); 110 MemoryPressureListener::MemoryPressureLevel pressure_level);
104 111
105 // Purges |bytes_to_reclaim_under_moderate_pressure_| bytes of 112 // Purges |bytes_to_reclaim_under_moderate_pressure_| bytes of
106 // discardable memory. 113 // discardable memory.
107 void Purge(); 114 void Purge();
108 115
109 // Purges least recently used memory until usage is less or equal to |limit|. 116 // Purges least recently used memory until usage is less or equal to |limit|.
110 // Caller must acquire |lock_| prior to calling this function. 117 // Caller must acquire |lock_| prior to calling this function.
111 void PurgeLRUWithLockAcquiredUntilUsageIsWithin(size_t limit); 118 void PurgeLRUWithLockAcquiredUntilUsageIsWithin(size_t limit);
112 119
(...skipping 12 matching lines...) Expand all
125 132
126 // The maximum number of bytes of discardable memory that may be allocated 133 // The maximum number of bytes of discardable memory that may be allocated
127 // before we assume moderate memory pressure. 134 // before we assume moderate memory pressure.
128 size_t discardable_memory_limit_; 135 size_t discardable_memory_limit_;
129 136
130 // Under moderate memory pressure, we will purge this amount of memory. 137 // Under moderate memory pressure, we will purge this amount of memory.
131 size_t bytes_to_reclaim_under_moderate_pressure_; 138 size_t bytes_to_reclaim_under_moderate_pressure_;
132 139
133 // Allows us to be respond when the system reports that it is under memory 140 // Allows us to be respond when the system reports that it is under memory
134 // pressure. 141 // pressure.
135 MemoryPressureListener memory_pressure_listener_; 142 scoped_ptr<MemoryPressureListener> memory_pressure_listener_;
136 143
137 DISALLOW_COPY_AND_ASSIGN(DiscardableMemoryProvider); 144 DISALLOW_COPY_AND_ASSIGN(DiscardableMemoryProvider);
138 }; 145 };
139 146
140 } // namespace internal 147 } // namespace internal
141 } // namespace base 148 } // namespace base
142 149
143 #endif // BASE_MEMORY_DISCARDABLE_MEMORY_PROVIDER_H_ 150 #endif // BASE_MEMORY_DISCARDABLE_MEMORY_PROVIDER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698