1 // Copyright 2015 The Chromium Authors 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #ifndef BASE_MEMORY_MEMORY_PRESSURE_MONITOR_H_ 6 #define BASE_MEMORY_MEMORY_PRESSURE_MONITOR_H_ 7 8 #include "base/base_export.h" 9 #include "base/functional/callback.h" 10 #include "base/memory/memory_pressure_listener.h" 11 #include "base/time/time.h" 12 13 namespace base { 14 15 // TODO(chrisha): Make this a concrete class with per-OS implementations rather 16 // than an abstract base class. 17 18 // Declares the interface for a MemoryPressureMonitor. There are multiple 19 // OS specific implementations of this class. An instance of the memory 20 // pressure observer is created at the process level, tracks memory usage, and 21 // pushes memory state change notifications to the static function 22 // base::MemoryPressureListener::NotifyMemoryPressure. This is turn notifies 23 // all MemoryPressureListener instances via a callback. 24 class BASE_EXPORT MemoryPressureMonitor { 25 public: 26 using MemoryPressureLevel = base::MemoryPressureListener::MemoryPressureLevel; 27 using DispatchCallback = 28 base::RepeatingCallback<void(MemoryPressureLevel level)>; 29 30 MemoryPressureMonitor(const MemoryPressureMonitor&) = delete; 31 MemoryPressureMonitor& operator=(const MemoryPressureMonitor&) = delete; 32 33 virtual ~MemoryPressureMonitor(); 34 35 // Return the singleton MemoryPressureMonitor. 36 static MemoryPressureMonitor* Get(); 37 38 // Returns the currently observed memory pressure. 39 virtual MemoryPressureLevel GetCurrentPressureLevel() const = 0; 40 41 protected: 42 MemoryPressureMonitor(); 43 }; 44 45 } // namespace base 46 47 #endif // BASE_MEMORY_MEMORY_PRESSURE_MONITOR_H_ 48