Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(107)

Side by Side Diff: base/memory/memory_pressure_monitor.h

Issue 2097753002: Make memory pressure notifier configurable (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: comment Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | base/memory/memory_pressure_monitor_chromeos.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/macros.h" 9 #include "base/macros.h"
10 #include "base/memory/memory_pressure_listener.h" 10 #include "base/memory/memory_pressure_listener.h"
11 11
12 namespace base { 12 namespace base {
13 13
14 class MemoryPressureMonitorObserver;
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;
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 observer. Does not take the ownership. Once a observer
37 // is set, MemoryPressureMonitor pushes memory pressure notifications to the
38 // observer instead of base::MemoryPressureListener::NotifyMemoryPressure.
39 virtual void SetObserver(MemoryPressureMonitorObserver* observer) = 0;
chrisha 2016/07/07 03:09:19 This is more than just an observer. It actually ta
bashi 2016/07/07 03:32:32 Makes sense. Will do that if danakj@ is fine.
danakj 2016/07/07 23:12:06 Ya that sounds good to me, and is a good reason fo
bashi 2016/07/07 23:57:19 Done.
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
48 // An interface to observe memory pressure level.
49 class BASE_EXPORT MemoryPressureMonitorObserver {
50 public:
51 virtual ~MemoryPressureMonitorObserver() {}
52
53 // Called when MemoryPressureMonitor detects changes in memory pressure
54 // level.
55 virtual void OnMemoryPressure(
56 MemoryPressureMonitor::MemoryPressureLevel level) = 0;
57 };
58
42 } // namespace base 59 } // namespace base
43 60
44 #endif // BASE_MEMORY_MEMORY_PRESSURE_MONITOR_H_ 61 #endif // BASE_MEMORY_MEMORY_PRESSURE_MONITOR_H_
OLDNEW
« no previous file with comments | « no previous file | base/memory/memory_pressure_monitor_chromeos.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698