Chromium Code Reviews| 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/gtest_prod_util.h" | 9 #include "base/gtest_prod_util.h" |
| 10 #include "base/macros.h" | 10 #include "base/macros.h" |
| 11 #include "base/memory/memory_pressure_listener.h" | 11 #include "base/memory/memory_pressure_listener.h" |
| 12 #include "base/memory/weak_ptr.h" | 12 #include "base/memory/weak_ptr.h" |
| 13 #include "base/timer/timer.h" | 13 #include "base/timer/timer.h" |
| 14 | 14 |
| 15 namespace base { | 15 namespace base { |
| 16 | 16 |
| 17 class TestMemoryPressureObserver; | 17 class TestMemoryPressureObserver; |
| 18 | 18 |
| 19 //////////////////////////////////////////////////////////////////////////////// | 19 //////////////////////////////////////////////////////////////////////////////// |
| 20 // MemoryPressureObserverChromeOS | 20 // MemoryPressureObserverChromeOS |
| 21 // | 21 // |
| 22 // A class to handle the observation of our free memory. It notifies the | 22 // A class to handle the observation of our free memory. It notifies the |
| 23 // MemoryPressureListener of memory fill level changes, so that it can take | 23 // MemoryPressureListener of memory fill level changes, so that it can take |
| 24 // action to reduce memory resources accordingly. | 24 // action to reduce memory resources accordingly. |
| 25 // | 25 // |
| 26 class BASE_EXPORT MemoryPressureObserverChromeOS { | 26 class BASE_EXPORT MemoryPressureObserverChromeOS { |
| 27 public: | 27 public: |
| 28 using GetUsedMemoryInPercentCallback = int (*)(); | 28 using GetUsedMemoryInPercentCallback = int (*)(); |
| 29 | 29 |
| 30 MemoryPressureObserverChromeOS(); | 30 enum MemoryPressureThresholds { |
| 31 DEFAULT_THRESHOLDS = 0, // Use the default. | |
|
Charlie Reis
2015/01/21 17:42:05
These names and comments are confusing to me. Nor
Mr4D (OOO till 08-26)
2015/01/21 18:52:14
Done.
| |
| 32 NORMAL_THRESHOLDS = 1, // Use both thresholds as normal. | |
| 33 AGGRESSIVE_MODERATE_THRESHOLD = 2, // Use an aggressive moderate threshold. | |
| 34 AGGRESSIVE_CRITICAL_THRESHOLD = 3, // Use an aggressive critical threshold. | |
| 35 AGGRESSIVE_THRESHOLDS = 4 // Both thresholds are aggressive. | |
| 36 }; | |
| 37 | |
| 38 explicit MemoryPressureObserverChromeOS(MemoryPressureThresholds thresholds); | |
| 31 virtual ~MemoryPressureObserverChromeOS(); | 39 virtual ~MemoryPressureObserverChromeOS(); |
| 32 | 40 |
| 33 // Redo the memory pressure calculation soon and call again if a critical | 41 // Redo the memory pressure calculation soon and call again if a critical |
| 34 // memory pressure prevails. Note that this call will trigger an asynchronous | 42 // memory pressure prevails. Note that this call will trigger an asynchronous |
| 35 // action which gives the system time to release memory back into the pool. | 43 // action which gives the system time to release memory back into the pool. |
| 36 void ScheduleEarlyCheck(); | 44 void ScheduleEarlyCheck(); |
| 37 | 45 |
| 38 // Get the current memory pressure level. | 46 // Get the current memory pressure level. |
| 39 base::MemoryPressureListener::MemoryPressureLevel GetCurrentPressureLevel() { | 47 base::MemoryPressureListener::MemoryPressureLevel GetCurrentPressureLevel() { |
| 40 return current_memory_pressure_level_; | 48 return current_memory_pressure_level_; |
| (...skipping 23 matching lines...) Expand all Loading... | |
| 64 current_memory_pressure_level_; | 72 current_memory_pressure_level_; |
| 65 | 73 |
| 66 // A periodic timer to check for resource pressure changes. This will get | 74 // A periodic timer to check for resource pressure changes. This will get |
| 67 // replaced by a kernel triggered event system (see crbug.com/381196). | 75 // replaced by a kernel triggered event system (see crbug.com/381196). |
| 68 base::RepeatingTimer<MemoryPressureObserverChromeOS> timer_; | 76 base::RepeatingTimer<MemoryPressureObserverChromeOS> timer_; |
| 69 | 77 |
| 70 // To slow down the amount of moderate pressure event calls, this counter | 78 // To slow down the amount of moderate pressure event calls, this counter |
| 71 // gets used to count the number of events since the last event occured. | 79 // gets used to count the number of events since the last event occured. |
| 72 int moderate_pressure_repeat_count_; | 80 int moderate_pressure_repeat_count_; |
| 73 | 81 |
| 82 // The thresholds for moderate and critical pressure. | |
| 83 const int moderate_pressure_threshold_; | |
| 84 const int critical_pressure_threshold_; | |
| 85 | |
| 74 base::WeakPtrFactory<MemoryPressureObserverChromeOS> weak_ptr_factory_; | 86 base::WeakPtrFactory<MemoryPressureObserverChromeOS> weak_ptr_factory_; |
| 75 | 87 |
| 76 DISALLOW_COPY_AND_ASSIGN(MemoryPressureObserverChromeOS); | 88 DISALLOW_COPY_AND_ASSIGN(MemoryPressureObserverChromeOS); |
| 77 }; | 89 }; |
| 78 | 90 |
| 79 } // namespace base | 91 } // namespace base |
| 80 | 92 |
| 81 #endif // BASE_CHROMEOS_MEMORY_PRESSURE_OBSERVER_CHROMEOS_H_ | 93 #endif // BASE_CHROMEOS_MEMORY_PRESSURE_OBSERVER_CHROMEOS_H_ |
| OLD | NEW |