| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 // Declares the MemoryPressureMonitor class. This is responsible for monitoring | 5 // Declares the MemoryPressureMonitor class. This is responsible for monitoring |
| 6 // system-wide memory pressure and dispatching memory pressure signals to | 6 // system-wide memory pressure and dispatching memory pressure signals to |
| 7 // MemoryPressureListener. It is also responsible for rate limiting calls to the | 7 // MemoryPressureListener. It is also responsible for rate limiting calls to the |
| 8 // memory pressure subsytem and gathering statistics for UMA. | 8 // memory pressure subsytem and gathering statistics for UMA. |
| 9 // | 9 // |
| 10 // The class has a few compile time differences depending on if | 10 // The class has a few compile time differences depending on if |
| (...skipping 11 matching lines...) Expand all Loading... |
| 22 // The memory pressure system periodically repeats memory pressure signals while | 22 // The memory pressure system periodically repeats memory pressure signals while |
| 23 // under memory pressure (the interval varying depending on the pressure level). | 23 // under memory pressure (the interval varying depending on the pressure level). |
| 24 // As such, even non-polling platforms require a scheduling mechanism for | 24 // As such, even non-polling platforms require a scheduling mechanism for |
| 25 // repeating notifications. Both implementations share this basic scheduling | 25 // repeating notifications. Both implementations share this basic scheduling |
| 26 // subsystem, and also leverage it to make timely UMA reports. | 26 // subsystem, and also leverage it to make timely UMA reports. |
| 27 | 27 |
| 28 #ifndef COMPONENTS_MEMORY_PRESSURE_MEMORY_PRESSURE_MONITOR_H_ | 28 #ifndef COMPONENTS_MEMORY_PRESSURE_MEMORY_PRESSURE_MONITOR_H_ |
| 29 #define COMPONENTS_MEMORY_PRESSURE_MEMORY_PRESSURE_MONITOR_H_ | 29 #define COMPONENTS_MEMORY_PRESSURE_MEMORY_PRESSURE_MONITOR_H_ |
| 30 | 30 |
| 31 #include <map> | 31 #include <map> |
| 32 #include <memory> |
| 32 | 33 |
| 33 #include "base/callback.h" | 34 #include "base/callback.h" |
| 34 #include "base/memory/scoped_ptr.h" | |
| 35 #include "base/memory/weak_ptr.h" | 35 #include "base/memory/weak_ptr.h" |
| 36 #include "base/synchronization/lock.h" | 36 #include "base/synchronization/lock.h" |
| 37 #include "base/time/time.h" | 37 #include "base/time/time.h" |
| 38 #include "components/memory_pressure/memory_pressure_listener.h" | 38 #include "components/memory_pressure/memory_pressure_listener.h" |
| 39 | 39 |
| 40 namespace base { | 40 namespace base { |
| 41 class TaskRunner; | 41 class TaskRunner; |
| 42 class TickClock; | 42 class TickClock; |
| 43 } // namespace | 43 } // namespace |
| 44 | 44 |
| (...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 169 // The memory pressure calculator in use. Used under |lock_|. | 169 // The memory pressure calculator in use. Used under |lock_|. |
| 170 MemoryPressureCalculator* calculator_; | 170 MemoryPressureCalculator* calculator_; |
| 171 // The dispatch callback to use. | 171 // The dispatch callback to use. |
| 172 DispatchCallback dispatch_callback_; | 172 DispatchCallback dispatch_callback_; |
| 173 | 173 |
| 174 #if !defined(MEMORY_PRESSURE_IS_POLLING) | 174 #if !defined(MEMORY_PRESSURE_IS_POLLING) |
| 175 // On non-polling platforms this object is responsible for routing OS | 175 // On non-polling platforms this object is responsible for routing OS |
| 176 // notifications to OnMemoryPressureChanged, and setting the initial pressure | 176 // notifications to OnMemoryPressureChanged, and setting the initial pressure |
| 177 // value. The OS specific implementation is responsible for allocating this | 177 // value. The OS specific implementation is responsible for allocating this |
| 178 // object. | 178 // object. |
| 179 scoped_ptr<MemoryPressureMonitorImpl> monitor_impl_; | 179 std::unique_ptr<MemoryPressureMonitorImpl> monitor_impl_; |
| 180 #endif | 180 #endif |
| 181 | 181 |
| 182 // Object state. | 182 // Object state. |
| 183 // The pressure level as of the most recent poll or notification. Under | 183 // The pressure level as of the most recent poll or notification. Under |
| 184 // |lock_|. | 184 // |lock_|. |
| 185 MemoryPressureLevel current_memory_pressure_level_; | 185 MemoryPressureLevel current_memory_pressure_level_; |
| 186 #if defined(MEMORY_PRESSURE_IS_POLLING) | 186 #if defined(MEMORY_PRESSURE_IS_POLLING) |
| 187 // Time of the last pressure check. Under |lock_|. Only needed for polling | 187 // Time of the last pressure check. Under |lock_|. Only needed for polling |
| 188 // implementations. | 188 // implementations. |
| 189 base::TimeTicks last_check_; | 189 base::TimeTicks last_check_; |
| (...skipping 11 matching lines...) Expand all Loading... |
| 201 // Weak pointer factory to ourself used for posting delayed tasks to | 201 // Weak pointer factory to ourself used for posting delayed tasks to |
| 202 // task_runner_. | 202 // task_runner_. |
| 203 base::WeakPtrFactory<MemoryPressureMonitor> weak_ptr_factory_; | 203 base::WeakPtrFactory<MemoryPressureMonitor> weak_ptr_factory_; |
| 204 | 204 |
| 205 DISALLOW_COPY_AND_ASSIGN(MemoryPressureMonitor); | 205 DISALLOW_COPY_AND_ASSIGN(MemoryPressureMonitor); |
| 206 }; | 206 }; |
| 207 | 207 |
| 208 } // namespace memory_pressure | 208 } // namespace memory_pressure |
| 209 | 209 |
| 210 #endif // COMPONENTS_MEMORY_PRESSURE_MEMORY_PRESSURE_MONITOR_H_ | 210 #endif // COMPONENTS_MEMORY_PRESSURE_MEMORY_PRESSURE_MONITOR_H_ |
| OLD | NEW |