Chromium Code Reviews| Index: base/memory/memory_pressure_monitor_mac.h |
| diff --git a/base/memory/memory_pressure_monitor_mac.h b/base/memory/memory_pressure_monitor_mac.h |
| index 9118632bd664e4e5289c3e60f7b3c842861ab5d6..8a0bc7a9f47b507ecba4cf5bc71c0a1067d97b20 100644 |
| --- a/base/memory/memory_pressure_monitor_mac.h |
| +++ b/base/memory/memory_pressure_monitor_mac.h |
| @@ -9,10 +9,12 @@ |
| #include <dispatch/dispatch.h> |
| #include "base/base_export.h" |
| +#include "base/mac/scoped_cftyperef.h" |
| #include "base/mac/scoped_dispatch_object.h" |
| #include "base/macros.h" |
| #include "base/memory/memory_pressure_listener.h" |
| #include "base/memory/memory_pressure_monitor.h" |
| +#include "base/message_loop/message_pump_mac.h" |
| namespace base { |
| namespace mac { |
| @@ -34,24 +36,51 @@ class BASE_EXPORT MemoryPressureMonitor : public base::MemoryPressureMonitor { |
| private: |
| friend TestMemoryPressureMonitor; |
| - static MemoryPressureLevel |
| - MemoryPressureLevelForMacMemoryPressure(int mac_memory_pressure); |
| + static MemoryPressureLevel MemoryPressureLevelForMacMemoryPressureLevel( |
| + int mac_memory_pressure_level); |
| + static void OnRunLoopExit(CFRunLoopObserverRef observer, |
| + CFRunLoopActivity activity, |
| + void* info); |
| + // Returns the raw memory pressure level from the macOS. Exposed for |
| + // unit testing. |
| + virtual int GetMacMemoryPressureLevel(); |
| + |
| + // Updates |last_pressure_level_| with the current memory pressure level. |
| + void UpdatePressureLevel(); |
| + |
| + // Updates |last_pressure_level_| at the end of every run loop pass (modulo |
| + // some numebr of seconds). |
|
lgrey
2017/02/22 21:33:40
Nit: number
shrike
2017/02/22 23:56:25
Done.
|
| + void UpdatePressureLevelOnRunLoopExit(); |
| + |
| + // Run |dispatch_callback| on memory pressure notifications from the OS. |
| void OnMemoryPressureChanged(dispatch_source_s* event_source, |
| const DispatchCallback& dispatch_callback); |
| - void SendStatisticsIfNecessary(bool pressure_level_changed); |
| + // Returns the number of seconds per UMA tick (for statistics recording). |
| + // Exposed for testing. |
| + static int GetSecondsPerUMATick(); |
| + |
| + // The dispatch source that generates memory pressure change notifications. |
| ScopedDispatchObject<dispatch_source_t> memory_level_event_source_; |
| + // The callback to call upon receiving a memory pressure change notification. |
| DispatchCallback dispatch_callback_; |
| - CFTimeInterval last_statistic_report_; |
| + // Last UMA report time. |
| + CFTimeInterval last_statistic_report_time_; |
| + // Most-recent memory pressure level. |
| MemoryPressureLevel last_pressure_level_; |
| - // The UMA statistic is recorded in 5 second increments. This |
| - // accumulates the remaining time to be rolled into the next |
| - // call. |
| - CFTimeInterval reporting_error_; |
| + // Observer that tracks exits from the main run loop. |
| + ScopedCFTypeRef<CFRunLoopObserverRef> exit_observer_; |
| + |
| + // Next time to update the memory pressure level when exiting the run loop. |
| + CFTimeInterval next_run_loop_update_time_; |
| + |
| + // Seconds left over from the last UMA tick calculation (to be added to the |
| + // next calculation). |
| + CFTimeInterval subtick_seconds_; |
| DISALLOW_COPY_AND_ASSIGN(MemoryPressureMonitor); |
| }; |