| Index: base/chromeos/memory_pressure_observer_chromeos.h
|
| diff --git a/base/chromeos/memory_pressure_observer_chromeos.h b/base/chromeos/memory_pressure_observer_chromeos.h
|
| index 445119efb73853c1f712dab8c85ad190ddb86f6b..4dd8f4abfc81cd54f0139e545df1ca245d3e3ce8 100644
|
| --- a/base/chromeos/memory_pressure_observer_chromeos.h
|
| +++ b/base/chromeos/memory_pressure_observer_chromeos.h
|
| @@ -8,10 +8,13 @@
|
| #include "base/base_export.h"
|
| #include "base/macros.h"
|
| #include "base/memory/memory_pressure_listener.h"
|
| +#include "base/memory/ref_counted.h"
|
| #include "base/timer/timer.h"
|
|
|
| namespace base {
|
|
|
| +class MemoryPressureObserverChromeOSTest_CheckMemoryPressure_Test;
|
| +
|
| ////////////////////////////////////////////////////////////////////////////////
|
| // MemoryPressureObserverChromeOS
|
| //
|
| @@ -21,15 +24,27 @@ namespace base {
|
| //
|
| class BASE_EXPORT MemoryPressureObserverChromeOS {
|
| public:
|
| + typedef int (*GetUsedMemoryInPercentCallback)(void);
|
| +
|
| MemoryPressureObserverChromeOS();
|
| ~MemoryPressureObserverChromeOS();
|
|
|
| + // Redo the memory pressure calculation soon and call again if a critical
|
| + // memory pressure prevails. Note that this call will trigger an asynchronous
|
| + // action which gives the system time to release memory back into the pool.
|
| + void ScheduleEarlyCheck();
|
| +
|
| // Get the current memory pressure level.
|
| base::MemoryPressureListener::MemoryPressureLevel GetCurrentPressureLevel() {
|
| return current_memory_pressure_level_;
|
| }
|
|
|
| + // Overrides the function which calculates the used memory size in percent.
|
| + void SetGetUsedMemoryInPercentCallbackForUnittest(
|
| + GetUsedMemoryInPercentCallback callback);
|
| +
|
| private:
|
| + friend MemoryPressureObserverChromeOSTest_CheckMemoryPressure_Test;
|
| // Starts observing the memory fill level.
|
| // Calls to StartObserving should always be matched with calls to
|
| // StopObserving.
|
| @@ -39,18 +54,28 @@ class BASE_EXPORT MemoryPressureObserverChromeOS {
|
| // May be safely called if StartObserving has not been called.
|
| void StopObserving();
|
|
|
| - // The function which gets periodically be called to check any changes in the
|
| - // memory pressure.
|
| + // The function which gets periodically called to check any changes in the
|
| + // memory pressure. It will report pressure changes as well as continuous
|
| + // critical pressure levels.
|
| void CheckMemoryPressure();
|
|
|
| // The current memory pressure.
|
| base::MemoryPressureListener::MemoryPressureLevel
|
| current_memory_pressure_level_;
|
|
|
| + // The function which determines the used memory in percent.
|
| + GetUsedMemoryInPercentCallback used_memory_in_percent_;
|
| +
|
| // A periodic timer to check for resource pressure changes. This will get
|
| // replaced by a kernel triggered event system (see crbug.com/381196).
|
| base::RepeatingTimer<MemoryPressureObserverChromeOS> timer_;
|
|
|
| + // To slow down the amount of moderate pressure event calls, this counter
|
| + // gets used to count the number of events since the last event occured.
|
| + int moderate_pressure_repeat_count_;
|
| +
|
| + base::WeakPtrFactory<MemoryPressureObserverChromeOS> weak_ptr_factory_;
|
| +
|
| DISALLOW_COPY_AND_ASSIGN(MemoryPressureObserverChromeOS);
|
| };
|
|
|
|
|