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

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

Issue 2097753002: Make memory pressure notifier configurable (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: comment Created 4 years, 5 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
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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_MEMORY_PRESSURE_MONITOR_WIN_H_ 5 #ifndef BASE_MEMORY_MEMORY_PRESSURE_MONITOR_WIN_H_
6 #define BASE_MEMORY_MEMORY_PRESSURE_MONITOR_WIN_H_ 6 #define BASE_MEMORY_MEMORY_PRESSURE_MONITOR_WIN_H_
7 7
8 #include "base/base_export.h" 8 #include "base/base_export.h"
9 #include "base/macros.h" 9 #include "base/macros.h"
10 #include "base/memory/memory_pressure_listener.h" 10 #include "base/memory/memory_pressure_listener.h"
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
104 // Calculates the current instantaneous memory pressure level. This does not 104 // Calculates the current instantaneous memory pressure level. This does not
105 // use any hysteresis and simply returns the result at the current moment. Can 105 // use any hysteresis and simply returns the result at the current moment. Can
106 // be called on any thread. 106 // be called on any thread.
107 MemoryPressureLevel CalculateCurrentPressureLevel(); 107 MemoryPressureLevel CalculateCurrentPressureLevel();
108 108
109 // Gets system memory status. This is virtual as a unittesting hook. Returns 109 // Gets system memory status. This is virtual as a unittesting hook. Returns
110 // true if the system call succeeds, false otherwise. Can be called on any 110 // true if the system call succeeds, false otherwise. Can be called on any
111 // thread. 111 // thread.
112 virtual bool GetSystemMemoryStatus(MEMORYSTATUSEX* mem_status); 112 virtual bool GetSystemMemoryStatus(MEMORYSTATUSEX* mem_status);
113 113
114 private: 114 void SetDispatchCallback(DispatchCallback callback) override;
115
116 private:
115 // Threshold amounts of available memory that trigger pressure levels. See 117 // Threshold amounts of available memory that trigger pressure levels. See
116 // memory_pressure_monitor.cc for a discussion of reasonable values for these. 118 // memory_pressure_monitor.cc for a discussion of reasonable values for these.
117 int moderate_threshold_mb_; 119 int moderate_threshold_mb_;
118 int critical_threshold_mb_; 120 int critical_threshold_mb_;
119 121
120 // A periodic timer to check for memory pressure changes. 122 // A periodic timer to check for memory pressure changes.
121 base::RepeatingTimer timer_; 123 base::RepeatingTimer timer_;
122 124
123 // The current memory pressure. 125 // The current memory pressure.
124 MemoryPressureLevel current_memory_pressure_level_; 126 MemoryPressureLevel current_memory_pressure_level_;
125 127
126 // To slow down the amount of moderate pressure event calls, this gets used to 128 // To slow down the amount of moderate pressure event calls, this gets used to
127 // count the number of events since the last event occured. This is used by 129 // count the number of events since the last event occured. This is used by
128 // |CheckMemoryPressure| to apply hysteresis on the raw results of 130 // |CheckMemoryPressure| to apply hysteresis on the raw results of
129 // |CalculateCurrentPressureLevel|. 131 // |CalculateCurrentPressureLevel|.
130 int moderate_pressure_repeat_count_; 132 int moderate_pressure_repeat_count_;
131 133
132 // Ensures that this object is used from a single thread. 134 // Ensures that this object is used from a single thread.
133 base::ThreadChecker thread_checker_; 135 base::ThreadChecker thread_checker_;
134 136
137 DispatchCallback dispatch_callback_ =
138 &MemoryPressureListener::NotifyMemoryPressure;
139
135 // Weak pointer factory to ourself used for scheduling calls to 140 // Weak pointer factory to ourself used for scheduling calls to
136 // CheckMemoryPressure/CheckMemoryPressureAndRecordStatistics via |timer_|. 141 // CheckMemoryPressure/CheckMemoryPressureAndRecordStatistics via |timer_|.
137 base::WeakPtrFactory<MemoryPressureMonitor> weak_ptr_factory_; 142 base::WeakPtrFactory<MemoryPressureMonitor> weak_ptr_factory_;
138 143
139 DISALLOW_COPY_AND_ASSIGN(MemoryPressureMonitor); 144 DISALLOW_COPY_AND_ASSIGN(MemoryPressureMonitor);
140 }; 145 };
141 146
142 } // namespace win 147 } // namespace win
143 } // namespace base 148 } // namespace base
144 149
145 #endif // BASE_MEMORY_MEMORY_PRESSURE_MONITOR_WIN_H_ 150 #endif // BASE_MEMORY_MEMORY_PRESSURE_MONITOR_WIN_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698