| OLD | NEW |
| 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 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 63 | 63 |
| 64 // Get the current memory pressure level. This can be called from any thread. | 64 // Get the current memory pressure level. This can be called from any thread. |
| 65 MemoryPressureLevel GetCurrentPressureLevel() const override; | 65 MemoryPressureLevel GetCurrentPressureLevel() const override; |
| 66 | 66 |
| 67 // Returns the moderate pressure level free memory threshold, in MB. | 67 // Returns the moderate pressure level free memory threshold, in MB. |
| 68 int moderate_threshold_mb() const { return moderate_threshold_mb_; } | 68 int moderate_threshold_mb() const { return moderate_threshold_mb_; } |
| 69 | 69 |
| 70 // Returns the critical pressure level free memory threshold, in MB. | 70 // Returns the critical pressure level free memory threshold, in MB. |
| 71 int critical_threshold_mb() const { return critical_threshold_mb_; } | 71 int critical_threshold_mb() const { return critical_threshold_mb_; } |
| 72 | 72 |
| 73 void SetObserver(MemoryPressureMonitorObserver* observer) override; |
| 74 |
| 73 protected: | 75 protected: |
| 74 // Internals are exposed for unittests. | 76 // Internals are exposed for unittests. |
| 75 | 77 |
| 76 // Automatically infers threshold values based on system memory. This invokes | 78 // Automatically infers threshold values based on system memory. This invokes |
| 77 // GetMemoryStatus so it can be mocked in unittests. | 79 // GetMemoryStatus so it can be mocked in unittests. |
| 78 void InferThresholds(); | 80 void InferThresholds(); |
| 79 | 81 |
| 80 // Starts observing the memory fill level. Calls to StartObserving should | 82 // Starts observing the memory fill level. Calls to StartObserving should |
| 81 // always be matched with calls to StopObserving. | 83 // always be matched with calls to StopObserving. |
| 82 void StartObserving(); | 84 void StartObserving(); |
| (...skipping 22 matching lines...) Expand all Loading... |
| 105 // use any hysteresis and simply returns the result at the current moment. Can | 107 // use any hysteresis and simply returns the result at the current moment. Can |
| 106 // be called on any thread. | 108 // be called on any thread. |
| 107 MemoryPressureLevel CalculateCurrentPressureLevel(); | 109 MemoryPressureLevel CalculateCurrentPressureLevel(); |
| 108 | 110 |
| 109 // Gets system memory status. This is virtual as a unittesting hook. Returns | 111 // 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 | 112 // true if the system call succeeds, false otherwise. Can be called on any |
| 111 // thread. | 113 // thread. |
| 112 virtual bool GetSystemMemoryStatus(MEMORYSTATUSEX* mem_status); | 114 virtual bool GetSystemMemoryStatus(MEMORYSTATUSEX* mem_status); |
| 113 | 115 |
| 114 private: | 116 private: |
| 117 void Notify(MemoryPressureLevel level); |
| 118 |
| 115 // Threshold amounts of available memory that trigger pressure levels. See | 119 // Threshold amounts of available memory that trigger pressure levels. See |
| 116 // memory_pressure_monitor.cc for a discussion of reasonable values for these. | 120 // memory_pressure_monitor.cc for a discussion of reasonable values for these. |
| 117 int moderate_threshold_mb_; | 121 int moderate_threshold_mb_; |
| 118 int critical_threshold_mb_; | 122 int critical_threshold_mb_; |
| 119 | 123 |
| 120 // A periodic timer to check for memory pressure changes. | 124 // A periodic timer to check for memory pressure changes. |
| 121 base::RepeatingTimer timer_; | 125 base::RepeatingTimer timer_; |
| 122 | 126 |
| 123 // The current memory pressure. | 127 // The current memory pressure. |
| 124 MemoryPressureLevel current_memory_pressure_level_; | 128 MemoryPressureLevel current_memory_pressure_level_; |
| 125 | 129 |
| 126 // To slow down the amount of moderate pressure event calls, this gets used to | 130 // 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 | 131 // count the number of events since the last event occured. This is used by |
| 128 // |CheckMemoryPressure| to apply hysteresis on the raw results of | 132 // |CheckMemoryPressure| to apply hysteresis on the raw results of |
| 129 // |CalculateCurrentPressureLevel|. | 133 // |CalculateCurrentPressureLevel|. |
| 130 int moderate_pressure_repeat_count_; | 134 int moderate_pressure_repeat_count_; |
| 131 | 135 |
| 132 // Ensures that this object is used from a single thread. | 136 // Ensures that this object is used from a single thread. |
| 133 base::ThreadChecker thread_checker_; | 137 base::ThreadChecker thread_checker_; |
| 134 | 138 |
| 139 MemoryPressureMonitorObserver* observer_ = nullptr; |
| 140 |
| 135 // Weak pointer factory to ourself used for scheduling calls to | 141 // Weak pointer factory to ourself used for scheduling calls to |
| 136 // CheckMemoryPressure/CheckMemoryPressureAndRecordStatistics via |timer_|. | 142 // CheckMemoryPressure/CheckMemoryPressureAndRecordStatistics via |timer_|. |
| 137 base::WeakPtrFactory<MemoryPressureMonitor> weak_ptr_factory_; | 143 base::WeakPtrFactory<MemoryPressureMonitor> weak_ptr_factory_; |
| 138 | 144 |
| 139 DISALLOW_COPY_AND_ASSIGN(MemoryPressureMonitor); | 145 DISALLOW_COPY_AND_ASSIGN(MemoryPressureMonitor); |
| 140 }; | 146 }; |
| 141 | 147 |
| 142 } // namespace win | 148 } // namespace win |
| 143 } // namespace base | 149 } // namespace base |
| 144 | 150 |
| 145 #endif // BASE_MEMORY_MEMORY_PRESSURE_MONITOR_WIN_H_ | 151 #endif // BASE_MEMORY_MEMORY_PRESSURE_MONITOR_WIN_H_ |
| OLD | NEW |