| Index: chrome/common/memory_pressure_monitor_chromeos.h
|
| diff --git a/base/chromeos/memory_pressure_observer_chromeos.h b/chrome/common/memory_pressure_monitor_chromeos.h
|
| similarity index 54%
|
| rename from base/chromeos/memory_pressure_observer_chromeos.h
|
| rename to chrome/common/memory_pressure_monitor_chromeos.h
|
| index 9af07d41d4789fd40a886123e4fdb3ae89cf39f5..893734779b615ed30239773483a20ff226e81556 100644
|
| --- a/base/chromeos/memory_pressure_observer_chromeos.h
|
| +++ b/chrome/common/memory_pressure_monitor_chromeos.h
|
| @@ -2,8 +2,8 @@
|
| // Use of this source code is governed by a BSD-style license that can be
|
| // found in the LICENSE file.
|
|
|
| -#ifndef BASE_CHROMEOS_MEMORY_PRESSURE_OBSERVER_CHROMEOS_H_
|
| -#define BASE_CHROMEOS_MEMORY_PRESSURE_OBSERVER_CHROMEOS_H_
|
| +#ifndef CHROME_COMMON_MEMORY_PRESSURE_MONITOR_CHROMEOS_H_
|
| +#define CHROME_COMMON_MEMORY_PRESSURE_MONITOR_CHROMEOS_H_
|
|
|
| #include "base/base_export.h"
|
| #include "base/gtest_prod_util.h"
|
| @@ -11,57 +11,36 @@
|
| #include "base/memory/memory_pressure_listener.h"
|
| #include "base/memory/weak_ptr.h"
|
| #include "base/timer/timer.h"
|
| +#include "chromeos/chromeos_switches.h"
|
| +#include "content/public/common/memory_pressure_monitor.h"
|
|
|
| -namespace base {
|
| -
|
| -class TestMemoryPressureObserver;
|
| +class TestMemoryPressureMonitor;
|
|
|
| ////////////////////////////////////////////////////////////////////////////////
|
| -// MemoryPressureObserverChromeOS
|
| +// MemoryPressureMonitorChromeOS
|
| //
|
| // A class to handle the observation of our free memory. It notifies the
|
| // MemoryPressureListener of memory fill level changes, so that it can take
|
| // action to reduce memory resources accordingly.
|
| //
|
| -class BASE_EXPORT MemoryPressureObserverChromeOS {
|
| +class MemoryPressureMonitorChromeOS : public content::MemoryPressureMonitor {
|
| public:
|
| using GetUsedMemoryInPercentCallback = int (*)();
|
|
|
| - // There are two memory pressure events:
|
| - // MODERATE - which will mainly release caches.
|
| - // CRITICAL - which will discard tabs.
|
| - // The |MemoryPressureThresholds| enum selects the strategy of firing these
|
| - // events: A conservative strategy will keep as much content in memory as
|
| - // possible (causing the system to swap to zram) and an aggressive strategy
|
| - // will release memory earlier to avoid swapping.
|
| - enum MemoryPressureThresholds {
|
| - // Use the system default.
|
| - THRESHOLD_DEFAULT = 0,
|
| - // Try to keep as much content in memory as possible.
|
| - THRESHOLD_CONSERVATIVE = 1,
|
| - // Discard caches earlier, allowing to keep more tabs in memory.
|
| - THRESHOLD_AGGRESSIVE_CACHE_DISCARD = 2,
|
| - // Discard tabs earlier, allowing the system to get faster.
|
| - THRESHOLD_AGGRESSIVE_TAB_DISCARD = 3,
|
| - // Discard caches and tabs earlier to allow the system to be faster.
|
| - THRESHOLD_AGGRESSIVE = 4
|
| - };
|
| -
|
| - explicit MemoryPressureObserverChromeOS(MemoryPressureThresholds thresholds);
|
| - virtual ~MemoryPressureObserverChromeOS();
|
| + explicit MemoryPressureMonitorChromeOS(
|
| + chromeos::switches::MemoryPressureThresholds thresholds);
|
| + ~MemoryPressureMonitorChromeOS() override;
|
|
|
| + // MemoryPressureMonitor implementation.
|
| + MemoryPressureMonitor::MemoryPressureLevel GetCurrentPressureLevel() const
|
| + override;
|
| // 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_;
|
| - }
|
| + void ScheduleEarlyCheck() override;
|
|
|
| private:
|
| - friend TestMemoryPressureObserver;
|
| + friend TestMemoryPressureMonitor;
|
| // Starts observing the memory fill level.
|
| // Calls to StartObserving should always be matched with calls to
|
| // StopObserving.
|
| @@ -84,12 +63,11 @@ class BASE_EXPORT MemoryPressureObserverChromeOS {
|
| virtual int GetUsedMemoryInPercent();
|
|
|
| // The current memory pressure.
|
| - base::MemoryPressureListener::MemoryPressureLevel
|
| - current_memory_pressure_level_;
|
| + MemoryPressureLevel current_memory_pressure_level_;
|
|
|
| // 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_;
|
| + base::RepeatingTimer<MemoryPressureMonitorChromeOS> 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.
|
| @@ -99,11 +77,9 @@ class BASE_EXPORT MemoryPressureObserverChromeOS {
|
| const int moderate_pressure_threshold_percent_;
|
| const int critical_pressure_threshold_percent_;
|
|
|
| - base::WeakPtrFactory<MemoryPressureObserverChromeOS> weak_ptr_factory_;
|
| + base::WeakPtrFactory<MemoryPressureMonitorChromeOS> weak_ptr_factory_;
|
|
|
| - DISALLOW_COPY_AND_ASSIGN(MemoryPressureObserverChromeOS);
|
| + DISALLOW_COPY_AND_ASSIGN(MemoryPressureMonitorChromeOS);
|
| };
|
|
|
| -} // namespace base
|
| -
|
| -#endif // BASE_CHROMEOS_MEMORY_PRESSURE_OBSERVER_CHROMEOS_H_
|
| +#endif // CHROME_COMMON_MEMORY_PRESSURE_MONITOR_CHROMEOS_H_
|
|
|