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

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

Issue 1124163003: Rename OS-specific MemoryPressureMonitor implementations. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix compile error on ChromeOS. Created 5 years, 7 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_CHROMEOS_MEMORY_PRESSURE_MONITOR_CHROMEOS_H_ 5 #ifndef BASE_CHROMEOS_MEMORY_PRESSURE_MONITOR_H_
6 #define BASE_CHROMEOS_MEMORY_PRESSURE_MONITOR_CHROMEOS_H_ 6 #define BASE_CHROMEOS_MEMORY_PRESSURE_MONITOR_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/gtest_prod_util.h" 10 #include "base/gtest_prod_util.h"
11 #include "base/macros.h" 11 #include "base/macros.h"
12 #include "base/memory/memory_pressure_listener.h" 12 #include "base/memory/memory_pressure_listener.h"
13 #include "base/memory/memory_pressure_monitor.h" 13 #include "base/memory/memory_pressure_monitor.h"
14 #include "base/memory/weak_ptr.h" 14 #include "base/memory/weak_ptr.h"
15 #include "base/timer/timer.h" 15 #include "base/timer/timer.h"
16 16
17 namespace base { 17 namespace base {
18 namespace chromeos {
18 19
19 class TestMemoryPressureMonitor; 20 class TestMemoryPressureMonitor;
20 21
21 //////////////////////////////////////////////////////////////////////////////// 22 ////////////////////////////////////////////////////////////////////////////////
22 // MemoryPressureMonitorChromeOS 23 // MemoryPressureMonitor
23 // 24 //
24 // A class to handle the observation of our free memory. It notifies the 25 // A class to handle the observation of our free memory. It notifies the
25 // MemoryPressureListener of memory fill level changes, so that it can take 26 // MemoryPressureListener of memory fill level changes, so that it can take
26 // action to reduce memory resources accordingly. 27 // action to reduce memory resources accordingly.
27 // 28 //
28 class BASE_EXPORT MemoryPressureMonitorChromeOS : public MemoryPressureMonitor { 29 class BASE_EXPORT MemoryPressureMonitor : public base::MemoryPressureMonitor {
Nico 2015/05/14 20:03:37 Having the same class name in slightly different n
29 public: 30 public:
30 using GetUsedMemoryInPercentCallback = int (*)(); 31 using GetUsedMemoryInPercentCallback = int (*)();
31 32
32 // There are two memory pressure events: 33 // There are two memory pressure events:
33 // MODERATE - which will mainly release caches. 34 // MODERATE - which will mainly release caches.
34 // CRITICAL - which will discard tabs. 35 // CRITICAL - which will discard tabs.
35 // The |MemoryPressureThresholds| enum selects the strategy of firing these 36 // The |MemoryPressureThresholds| enum selects the strategy of firing these
36 // events: A conservative strategy will keep as much content in memory as 37 // events: A conservative strategy will keep as much content in memory as
37 // possible (causing the system to swap to zram) and an aggressive strategy 38 // possible (causing the system to swap to zram) and an aggressive strategy
38 // will release memory earlier to avoid swapping. 39 // will release memory earlier to avoid swapping.
39 enum MemoryPressureThresholds { 40 enum MemoryPressureThresholds {
40 // Use the system default. 41 // Use the system default.
41 THRESHOLD_DEFAULT = 0, 42 THRESHOLD_DEFAULT = 0,
42 // Try to keep as much content in memory as possible. 43 // Try to keep as much content in memory as possible.
43 THRESHOLD_CONSERVATIVE = 1, 44 THRESHOLD_CONSERVATIVE = 1,
44 // Discard caches earlier, allowing to keep more tabs in memory. 45 // Discard caches earlier, allowing to keep more tabs in memory.
45 THRESHOLD_AGGRESSIVE_CACHE_DISCARD = 2, 46 THRESHOLD_AGGRESSIVE_CACHE_DISCARD = 2,
46 // Discard tabs earlier, allowing the system to get faster. 47 // Discard tabs earlier, allowing the system to get faster.
47 THRESHOLD_AGGRESSIVE_TAB_DISCARD = 3, 48 THRESHOLD_AGGRESSIVE_TAB_DISCARD = 3,
48 // Discard caches and tabs earlier to allow the system to be faster. 49 // Discard caches and tabs earlier to allow the system to be faster.
49 THRESHOLD_AGGRESSIVE = 4 50 THRESHOLD_AGGRESSIVE = 4
50 }; 51 };
51 52
52 explicit MemoryPressureMonitorChromeOS(MemoryPressureThresholds thresholds); 53 explicit MemoryPressureMonitor(MemoryPressureThresholds thresholds);
53 ~MemoryPressureMonitorChromeOS() override; 54 ~MemoryPressureMonitor() override;
54 55
55 // Redo the memory pressure calculation soon and call again if a critical 56 // Redo the memory pressure calculation soon and call again if a critical
56 // memory pressure prevails. Note that this call will trigger an asynchronous 57 // memory pressure prevails. Note that this call will trigger an asynchronous
57 // action which gives the system time to release memory back into the pool. 58 // action which gives the system time to release memory back into the pool.
58 void ScheduleEarlyCheck(); 59 void ScheduleEarlyCheck();
59 60
60 // Get the current memory pressure level. 61 // Get the current memory pressure level.
61 MemoryPressureListener::MemoryPressureLevel GetCurrentPressureLevel() const 62 MemoryPressureListener::MemoryPressureLevel GetCurrentPressureLevel() const
62 override; 63 override;
63 64
65 // Returns a type-casted version of the current memory pressure monitor. A
66 // simple wrapper to base::MemoryPressureMonitor::Get.
67 static MemoryPressureMonitor* Get();
68
64 private: 69 private:
65 friend TestMemoryPressureMonitor; 70 friend TestMemoryPressureMonitor;
66 // Starts observing the memory fill level. 71 // Starts observing the memory fill level.
67 // Calls to StartObserving should always be matched with calls to 72 // Calls to StartObserving should always be matched with calls to
68 // StopObserving. 73 // StopObserving.
69 void StartObserving(); 74 void StartObserving();
70 75
71 // Stop observing the memory fill level. 76 // Stop observing the memory fill level.
72 // May be safely called if StartObserving has not been called. 77 // May be safely called if StartObserving has not been called.
73 void StopObserving(); 78 void StopObserving();
74 79
75 // The function which gets periodically called to check any changes in the 80 // The function which gets periodically called to check any changes in the
76 // memory pressure. It will report pressure changes as well as continuous 81 // memory pressure. It will report pressure changes as well as continuous
77 // critical pressure levels. 82 // critical pressure levels.
78 void CheckMemoryPressure(); 83 void CheckMemoryPressure();
79 84
80 // The function periodically checks the memory pressure changes and records 85 // The function periodically checks the memory pressure changes and records
81 // the UMA histogram statistics for the current memory pressure level. 86 // the UMA histogram statistics for the current memory pressure level.
82 void CheckMemoryPressureAndRecordStatistics(); 87 void CheckMemoryPressureAndRecordStatistics();
83 88
84 // Get the memory pressure in percent (virtual for testing). 89 // Get the memory pressure in percent (virtual for testing).
85 virtual int GetUsedMemoryInPercent(); 90 virtual int GetUsedMemoryInPercent();
86 91
87 // The current memory pressure. 92 // The current memory pressure.
88 base::MemoryPressureListener::MemoryPressureLevel 93 base::MemoryPressureListener::MemoryPressureLevel
89 current_memory_pressure_level_; 94 current_memory_pressure_level_;
90 95
91 // A periodic timer to check for resource pressure changes. This will get 96 // A periodic timer to check for resource pressure changes. This will get
92 // replaced by a kernel triggered event system (see crbug.com/381196). 97 // replaced by a kernel triggered event system (see crbug.com/381196).
93 base::RepeatingTimer<MemoryPressureMonitorChromeOS> timer_; 98 base::RepeatingTimer<MemoryPressureMonitor> timer_;
94 99
95 // To slow down the amount of moderate pressure event calls, this counter 100 // To slow down the amount of moderate pressure event calls, this counter
96 // gets used to count the number of events since the last event occured. 101 // gets used to count the number of events since the last event occured.
97 int moderate_pressure_repeat_count_; 102 int moderate_pressure_repeat_count_;
98 103
99 // The thresholds for moderate and critical pressure. 104 // The thresholds for moderate and critical pressure.
100 const int moderate_pressure_threshold_percent_; 105 const int moderate_pressure_threshold_percent_;
101 const int critical_pressure_threshold_percent_; 106 const int critical_pressure_threshold_percent_;
102 107
103 // File descriptor used to detect low memory condition. 108 // File descriptor used to detect low memory condition.
104 ScopedFD low_mem_file_; 109 ScopedFD low_mem_file_;
105 110
106 base::WeakPtrFactory<MemoryPressureMonitorChromeOS> weak_ptr_factory_; 111 base::WeakPtrFactory<MemoryPressureMonitor> weak_ptr_factory_;
107 112
108 DISALLOW_COPY_AND_ASSIGN(MemoryPressureMonitorChromeOS); 113 DISALLOW_COPY_AND_ASSIGN(MemoryPressureMonitor);
109 }; 114 };
110 115
116 } // namespace chromeos
111 } // namespace base 117 } // namespace base
112 118
113 #endif // BASE_CHROMEOS_MEMORY_PRESSURE_MONITOR_CHROMEOS_H_ 119 #endif // BASE_CHROMEOS_MEMORY_PRESSURE_MONITOR_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698