| 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_H_ | 5 #ifndef BASE_MEMORY_MEMORY_PRESSURE_MONITOR_H_ |
| 6 #define BASE_MEMORY_MEMORY_PRESSURE_MONITOR_H_ | 6 #define BASE_MEMORY_MEMORY_PRESSURE_MONITOR_H_ |
| 7 | 7 |
| 8 #include "base/base_export.h" | 8 #include "base/base_export.h" |
| 9 #include "base/callback.h" |
| 9 #include "base/macros.h" | 10 #include "base/macros.h" |
| 10 #include "base/memory/memory_pressure_listener.h" | 11 #include "base/memory/memory_pressure_listener.h" |
| 11 | 12 |
| 12 namespace base { | 13 namespace base { |
| 13 | 14 |
| 14 // TODO(chrisha): Make this a concrete class with per-OS implementations rather | 15 // TODO(chrisha): Make this a concrete class with per-OS implementations rather |
| 15 // than an abstract base class. | 16 // than an abstract base class. |
| 16 | 17 |
| 17 // Declares the interface for a MemoryPressureMonitor. There are multiple | 18 // Declares the interface for a MemoryPressureMonitor. There are multiple |
| 18 // OS specific implementations of this class. An instance of the memory | 19 // OS specific implementations of this class. An instance of the memory |
| 19 // pressure observer is created at the process level, tracks memory usage, and | 20 // pressure observer is created at the process level, tracks memory usage, and |
| 20 // pushes memory state change notifications to the static function | 21 // pushes memory state change notifications to the static function |
| 21 // base::MemoryPressureListener::NotifyMemoryPressure. This is turn notifies | 22 // base::MemoryPressureListener::NotifyMemoryPressure. This is turn notifies |
| 22 // all MemoryPressureListener instances via a callback. | 23 // all MemoryPressureListener instances via a callback. |
| 23 class BASE_EXPORT MemoryPressureMonitor { | 24 class BASE_EXPORT MemoryPressureMonitor { |
| 24 public: | 25 public: |
| 25 using MemoryPressureLevel = base::MemoryPressureListener::MemoryPressureLevel; | 26 using MemoryPressureLevel = base::MemoryPressureListener::MemoryPressureLevel; |
| 27 using DispatchCallback = base::Callback<void(MemoryPressureLevel level)>; |
| 26 | 28 |
| 27 virtual ~MemoryPressureMonitor(); | 29 virtual ~MemoryPressureMonitor(); |
| 28 | 30 |
| 29 // Return the singleton MemoryPressureMonitor. | 31 // Return the singleton MemoryPressureMonitor. |
| 30 static MemoryPressureMonitor* Get(); | 32 static MemoryPressureMonitor* Get(); |
| 31 | 33 |
| 32 // Returns the currently observed memory pressure. | 34 // Returns the currently observed memory pressure. |
| 33 virtual MemoryPressureLevel GetCurrentPressureLevel() const = 0; | 35 virtual MemoryPressureLevel GetCurrentPressureLevel() const = 0; |
| 34 | 36 |
| 37 // Sets a notification callback. The default callback invokes |
| 38 // base::MemoryPressureListener::NotifyMemoryPressure. |
| 39 virtual void SetDispatchCallback(const DispatchCallback& callback) = 0; |
| 40 |
| 35 protected: | 41 protected: |
| 36 MemoryPressureMonitor(); | 42 MemoryPressureMonitor(); |
| 37 | 43 |
| 38 private: | 44 private: |
| 39 DISALLOW_COPY_AND_ASSIGN(MemoryPressureMonitor); | 45 DISALLOW_COPY_AND_ASSIGN(MemoryPressureMonitor); |
| 40 }; | 46 }; |
| 41 | 47 |
| 42 } // namespace base | 48 } // namespace base |
| 43 | 49 |
| 44 #endif // BASE_MEMORY_MEMORY_PRESSURE_MONITOR_H_ | 50 #endif // BASE_MEMORY_MEMORY_PRESSURE_MONITOR_H_ |
| OLD | NEW |