Chromium Code Reviews| 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 |
|
danakj
2016/06/30 18:48:05
Is this something that will be done as part of thi
bashi
2016/06/30 23:33:10
I don't plan to do that. I'm not sure this still a
danakj
2016/07/01 20:49:28
I think this comment is saying GetCurrentPressureL
danakj
2016/07/01 20:50:09
An alternate could be to make the setter abstract
bashi
2016/07/03 23:54:47
Could you elaborate what's the benefit of doing th
danakj
2016/07/06 18:57:23
Half abstraction looks fine in the first CL, but a
danakj
2016/07/06 19:00:20
The Notify() method could just be a concrete metho
bashi
2016/07/07 01:42:39
I'm not fully convinced but updated the CL as you
chrisha
2016/07/07 03:09:19
That's exactly what the comment is saying. MemoryP
| |
| 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; |
| 26 | 27 |
| 27 virtual ~MemoryPressureMonitor(); | 28 virtual ~MemoryPressureMonitor(); |
| 28 | 29 |
| 29 // Return the singleton MemoryPressureMonitor. | 30 // Return the singleton MemoryPressureMonitor. |
| 30 static MemoryPressureMonitor* Get(); | 31 static MemoryPressureMonitor* Get(); |
| 31 | 32 |
| 32 // Returns the currently observed memory pressure. | 33 // Returns the currently observed memory pressure. |
| 33 virtual MemoryPressureLevel GetCurrentPressureLevel() const = 0; | 34 virtual MemoryPressureLevel GetCurrentPressureLevel() const = 0; |
| 34 | 35 |
| 36 // Sets a notification callback. Once a callback is set, | |
|
danakj
2016/06/30 18:48:05
I tried to get this from the doc, but I think mayb
bashi
2016/06/30 23:33:10
We are implementing MemoryCoordinator which will r
danakj
2016/07/01 20:49:28
A virtual interface would do the same, where Memor
bashi
2016/07/03 23:54:47
That makes sense. Done.
| |
| 37 // MemoryPressureMonitor pushes memory pressure notifications to the callback | |
| 38 // instead of base::MemoryPressureListener::NotifyMemoryPressure. | |
| 39 using Notifier = base::Callback<void(MemoryPressureLevel level)>; | |
|
danakj
2016/06/30 18:48:05
"Notifier" is the wrong direction here. The notifi
bashi
2016/06/30 23:33:10
The callback replaces MemoryPressureListener::Noti
danakj
2016/07/01 20:49:28
Yes, and the monitor notifies it by that, so it *i
| |
| 40 void SetNotifier(const Notifier& notifier) { notifier_ = notifier; } | |
|
danakj
2016/07/01 20:49:28
Can we DCHECK that this is only set once? Or only
bashi
2016/07/03 23:54:47
Added DCHECK.
| |
| 41 | |
| 42 void Notify(MemoryPressureLevel level); | |
|
bashi
2016/06/27 03:47:54
public because this is called by a static method (
| |
| 43 | |
| 35 protected: | 44 protected: |
| 36 MemoryPressureMonitor(); | 45 MemoryPressureMonitor(); |
| 37 | 46 |
| 38 private: | 47 private: |
| 48 Notifier notifier_; | |
| 49 | |
| 39 DISALLOW_COPY_AND_ASSIGN(MemoryPressureMonitor); | 50 DISALLOW_COPY_AND_ASSIGN(MemoryPressureMonitor); |
| 40 }; | 51 }; |
| 41 | 52 |
| 42 } // namespace base | 53 } // namespace base |
| 43 | 54 |
| 44 #endif // BASE_MEMORY_MEMORY_PRESSURE_MONITOR_H_ | 55 #endif // BASE_MEMORY_MEMORY_PRESSURE_MONITOR_H_ |
| OLD | NEW |