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

Side by Side Diff: base/memory/memory_pressure_monitor_chromeos.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
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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_CHROMEOS_H_ 5 #ifndef BASE_MEMORY_MEMORY_PRESSURE_MONITOR_CHROMEOS_H_
6 #define BASE_MEMORY_MEMORY_PRESSURE_MONITOR_CHROMEOS_H_ 6 #define BASE_MEMORY_MEMORY_PRESSURE_MONITOR_CHROMEOS_H_
7 7
8 #include "base/base_export.h" 8 #include "base/base_export.h"
9 #include "base/files/scoped_file.h" 9 #include "base/files/scoped_file.h"
10 #include "base/macros.h" 10 #include "base/macros.h"
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
58 void ScheduleEarlyCheck(); 58 void ScheduleEarlyCheck();
59 59
60 // Get the current memory pressure level. 60 // Get the current memory pressure level.
61 MemoryPressureListener::MemoryPressureLevel GetCurrentPressureLevel() const 61 MemoryPressureListener::MemoryPressureLevel GetCurrentPressureLevel() const
62 override; 62 override;
63 63
64 // Returns a type-casted version of the current memory pressure monitor. A 64 // Returns a type-casted version of the current memory pressure monitor. A
65 // simple wrapper to base::MemoryPressureMonitor::Get. 65 // simple wrapper to base::MemoryPressureMonitor::Get.
66 static MemoryPressureMonitor* Get(); 66 static MemoryPressureMonitor* Get();
67 67
68 private: 68 void SetObserver(MemoryPressureMonitorObserver* observer) override;
69
70 private:
69 friend TestMemoryPressureMonitor; 71 friend TestMemoryPressureMonitor;
70 // Starts observing the memory fill level. 72 // Starts observing the memory fill level.
71 // Calls to StartObserving should always be matched with calls to 73 // Calls to StartObserving should always be matched with calls to
72 // StopObserving. 74 // StopObserving.
73 void StartObserving(); 75 void StartObserving();
74 76
75 // Stop observing the memory fill level. 77 // Stop observing the memory fill level.
76 // May be safely called if StartObserving has not been called. 78 // May be safely called if StartObserving has not been called.
77 void StopObserving(); 79 void StopObserving();
78 80
79 // The function which gets periodically called to check any changes in the 81 // The function which gets periodically called to check any changes in the
80 // memory pressure. It will report pressure changes as well as continuous 82 // memory pressure. It will report pressure changes as well as continuous
81 // critical pressure levels. 83 // critical pressure levels.
82 void CheckMemoryPressure(); 84 void CheckMemoryPressure();
83 85
84 // The function periodically checks the memory pressure changes and records 86 // The function periodically checks the memory pressure changes and records
85 // the UMA histogram statistics for the current memory pressure level. 87 // the UMA histogram statistics for the current memory pressure level.
86 void CheckMemoryPressureAndRecordStatistics(); 88 void CheckMemoryPressureAndRecordStatistics();
87 89
88 // Get the memory pressure in percent (virtual for testing). 90 // Get the memory pressure in percent (virtual for testing).
89 virtual int GetUsedMemoryInPercent(); 91 virtual int GetUsedMemoryInPercent();
90 92
93 // Notify memory pressure level.
94 void Notify(MemoryPressureLevel level);
95
91 // The current memory pressure. 96 // The current memory pressure.
92 base::MemoryPressureListener::MemoryPressureLevel 97 base::MemoryPressureListener::MemoryPressureLevel
93 current_memory_pressure_level_; 98 current_memory_pressure_level_;
94 99
95 // A periodic timer to check for resource pressure changes. This will get 100 // A periodic timer to check for resource pressure changes. This will get
96 // replaced by a kernel triggered event system (see crbug.com/381196). 101 // replaced by a kernel triggered event system (see crbug.com/381196).
97 base::RepeatingTimer timer_; 102 base::RepeatingTimer timer_;
98 103
99 // To slow down the amount of moderate pressure event calls, this counter 104 // To slow down the amount of moderate pressure event calls, this counter
100 // gets used to count the number of events since the last event occured. 105 // gets used to count the number of events since the last event occured.
101 int moderate_pressure_repeat_count_; 106 int moderate_pressure_repeat_count_;
102 107
103 // The thresholds for moderate and critical pressure. 108 // The thresholds for moderate and critical pressure.
104 const int moderate_pressure_threshold_percent_; 109 const int moderate_pressure_threshold_percent_;
105 const int critical_pressure_threshold_percent_; 110 const int critical_pressure_threshold_percent_;
106 111
107 // File descriptor used to detect low memory condition. 112 // File descriptor used to detect low memory condition.
108 ScopedFD low_mem_file_; 113 ScopedFD low_mem_file_;
109 114
115 MemoryPressureMonitorObserver* observer_ = nullptr;
116
110 base::WeakPtrFactory<MemoryPressureMonitor> weak_ptr_factory_; 117 base::WeakPtrFactory<MemoryPressureMonitor> weak_ptr_factory_;
111 118
112 DISALLOW_COPY_AND_ASSIGN(MemoryPressureMonitor); 119 DISALLOW_COPY_AND_ASSIGN(MemoryPressureMonitor);
113 }; 120 };
114 121
115 } // namespace chromeos 122 } // namespace chromeos
116 } // namespace base 123 } // namespace base
117 124
118 #endif // BASE_MEMORY_MEMORY_PRESSURE_MONITOR_CHROMEOS_H_ 125 #endif // BASE_MEMORY_MEMORY_PRESSURE_MONITOR_CHROMEOS_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698