OLD | NEW |
---|---|
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_OBSERVER_CHROMEOS_H_ | 5 #ifndef BASE_CHROMEOS_MEMORY_PRESSURE_OBSERVER_CHROMEOS_H_ |
6 #define BASE_CHROMEOS_MEMORY_PRESSURE_OBSERVER_CHROMEOS_H_ | 6 #define BASE_CHROMEOS_MEMORY_PRESSURE_OBSERVER_CHROMEOS_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 #include "base/timer/timer.h" | 11 #include "base/timer/timer.h" |
12 | 12 |
13 namespace base { | 13 namespace base { |
14 | 14 |
15 //////////////////////////////////////////////////////////////////////////////// | 15 //////////////////////////////////////////////////////////////////////////////// |
16 // MemoryPressureObserverChromeOS | 16 // MemoryPressureObserverChromeOS |
17 // | 17 // |
18 // A class to handle the observation of our free memory. It notifies the | 18 // A class to handle the observation of our free memory. It notifies the |
19 // MemoryPressureListener of memory fill level changes, so that it can take | 19 // MemoryPressureListener of memory fill level changes, so that it can take |
20 // action to reduce memory resources accordingly. | 20 // action to reduce memory resources accordingly. |
21 // | 21 // |
22 class BASE_EXPORT MemoryPressureObserverChromeOS { | 22 class BASE_EXPORT MemoryPressureObserverChromeOS { |
23 public: | 23 public: |
24 MemoryPressureObserverChromeOS(); | 24 MemoryPressureObserverChromeOS(); |
25 ~MemoryPressureObserverChromeOS(); | 25 ~MemoryPressureObserverChromeOS(); |
26 | 26 |
27 // Redo the memory pressure calculation soon and call again if a critical | |
28 // memory pressure prevails. Note that this call will trigger an asynchronous | |
29 // action which gives the system time to release memory back into the pool. | |
30 void ScheduleEarlyCheck(); | |
31 | |
27 // Get the current memory pressure level. | 32 // Get the current memory pressure level. |
28 base::MemoryPressureListener::MemoryPressureLevel GetCurrentPressureLevel() { | 33 base::MemoryPressureListener::MemoryPressureLevel GetCurrentPressureLevel() { |
29 return current_memory_pressure_level_; | 34 return current_memory_pressure_level_; |
30 } | 35 } |
31 | 36 |
32 private: | 37 private: |
33 // Starts observing the memory fill level. | 38 // Starts observing the memory fill level. |
34 // Calls to StartObserving should always be matched with calls to | 39 // Calls to StartObserving should always be matched with calls to |
35 // StopObserving. | 40 // StopObserving. |
36 void StartObserving(); | 41 void StartObserving(); |
37 | 42 |
38 // Stop observing the memory fill level. | 43 // Stop observing the memory fill level. |
39 // May be safely called if StartObserving has not been called. | 44 // May be safely called if StartObserving has not been called. |
40 void StopObserving(); | 45 void StopObserving(); |
41 | 46 |
42 // The function which gets periodically be called to check any changes in the | 47 // The function which gets periodically called to check any changes in the |
43 // memory pressure. | 48 // memory pressure. It will report pressure changes as well as continuous |
49 // critical pressure levels. | |
44 void CheckMemoryPressure(); | 50 void CheckMemoryPressure(); |
45 | 51 |
46 // The current memory pressure. | 52 // The current memory pressure. |
47 base::MemoryPressureListener::MemoryPressureLevel | 53 base::MemoryPressureListener::MemoryPressureLevel |
48 current_memory_pressure_level_; | 54 current_memory_pressure_level_; |
49 | 55 |
50 // A periodic timer to check for resource pressure changes. This will get | 56 // A periodic timer to check for resource pressure changes. This will get |
51 // replaced by a kernel triggered event system (see crbug.com/381196). | 57 // replaced by a kernel triggered event system (see crbug.com/381196). |
52 base::RepeatingTimer<MemoryPressureObserverChromeOS> timer_; | 58 base::RepeatingTimer<MemoryPressureObserverChromeOS> timer_; |
53 | 59 |
60 // To slow down the amount of moderate pressure event calls, this counter | |
61 // gets used to count the number of events since the last event occured. | |
62 int moderate_pressure_repeat_counter_; | |
James Cook
2014/12/19 19:38:07
nit: maybe "moderate_pressure_repeat_count_"?
Mr4D (OOO till 08-26)
2014/12/19 23:34:41
Done.
| |
63 | |
54 DISALLOW_COPY_AND_ASSIGN(MemoryPressureObserverChromeOS); | 64 DISALLOW_COPY_AND_ASSIGN(MemoryPressureObserverChromeOS); |
55 }; | 65 }; |
56 | 66 |
57 } // namespace base | 67 } // namespace base |
58 | 68 |
59 #endif // BASE_CHROMEOS_MEMORY_PRESSURE_OBSERVER_CHROMEOS_H_ | 69 #endif // BASE_CHROMEOS_MEMORY_PRESSURE_OBSERVER_CHROMEOS_H_ |
OLD | NEW |