Index: chrome/common/memory_pressure_monitor_chromeos.cc |
diff --git a/base/chromeos/memory_pressure_observer_chromeos.cc b/chrome/common/memory_pressure_monitor_chromeos.cc |
similarity index 83% |
rename from base/chromeos/memory_pressure_observer_chromeos.cc |
rename to chrome/common/memory_pressure_monitor_chromeos.cc |
index 5691eb8b4ed1dbd626e85ef1ea617886396eeafd..46f3367168731fc602bd3bf281115bfca44e3503 100644 |
--- a/base/chromeos/memory_pressure_observer_chromeos.cc |
+++ b/chrome/common/memory_pressure_monitor_chromeos.cc |
@@ -2,14 +2,15 @@ |
// Use of this source code is governed by a BSD-style license that can be |
// found in the LICENSE file. |
-#include "base/chromeos/memory_pressure_observer_chromeos.h" |
+#include "chrome/common/memory_pressure_monitor_chromeos.h" |
#include "base/message_loop/message_loop.h" |
#include "base/metrics/histogram_macros.h" |
#include "base/process/process_metrics.h" |
#include "base/time/time.h" |
-namespace base { |
+using base::MemoryPressureListener; |
+using chromeos::switches::MemoryPressureThresholds; |
namespace { |
@@ -42,22 +43,18 @@ enum MemoryPressureLevelUMA { |
// Converts a |MemoryPressureThreshold| value into a used memory percentage for |
// the moderate pressure event. |
-int GetModerateMemoryThresholdInPercent( |
- MemoryPressureObserverChromeOS::MemoryPressureThresholds thresholds) { |
- return thresholds == MemoryPressureObserverChromeOS:: |
- THRESHOLD_AGGRESSIVE_CACHE_DISCARD || |
- thresholds == MemoryPressureObserverChromeOS::THRESHOLD_AGGRESSIVE |
+int GetModerateMemoryThresholdInPercent(MemoryPressureThresholds thresholds) { |
+ return thresholds == chromeos::switches::THRESHOLD_AGGRESSIVE_CACHE_DISCARD || |
+ thresholds == chromeos::switches::THRESHOLD_AGGRESSIVE |
? kAggressiveMemoryPressureModerateThresholdPercent |
: kNormalMemoryPressureModerateThresholdPercent; |
} |
// Converts a |MemoryPressureThreshold| value into a used memory percentage for |
// the critical pressure event. |
-int GetCriticalMemoryThresholdInPercent( |
- MemoryPressureObserverChromeOS::MemoryPressureThresholds thresholds) { |
- return thresholds == MemoryPressureObserverChromeOS:: |
- THRESHOLD_AGGRESSIVE_TAB_DISCARD || |
- thresholds == MemoryPressureObserverChromeOS::THRESHOLD_AGGRESSIVE |
+int GetCriticalMemoryThresholdInPercent(MemoryPressureThresholds thresholds) { |
+ return thresholds == chromeos::switches::THRESHOLD_AGGRESSIVE_TAB_DISCARD || |
+ thresholds == chromeos::switches::THRESHOLD_AGGRESSIVE |
? kAggressiveMemoryPressureCriticalThresholdPercent |
: kNormalMemoryPressureCriticalThresholdPercent; |
} |
@@ -76,7 +73,7 @@ MemoryPressureListener::MemoryPressureLevel GetMemoryPressureLevelFromFillLevel( |
} // namespace |
-MemoryPressureObserverChromeOS::MemoryPressureObserverChromeOS( |
+MemoryPressureMonitorChromeOS::MemoryPressureMonitorChromeOS( |
MemoryPressureThresholds thresholds) |
: current_memory_pressure_level_( |
MemoryPressureListener::MEMORY_PRESSURE_LEVEL_NONE), |
@@ -89,31 +86,36 @@ MemoryPressureObserverChromeOS::MemoryPressureObserverChromeOS( |
StartObserving(); |
} |
-MemoryPressureObserverChromeOS::~MemoryPressureObserverChromeOS() { |
+MemoryPressureMonitorChromeOS::~MemoryPressureMonitorChromeOS() { |
StopObserving(); |
} |
-void MemoryPressureObserverChromeOS::ScheduleEarlyCheck() { |
- MessageLoop::current()->PostTask( |
+MemoryPressureListener::MemoryPressureLevel |
+MemoryPressureMonitorChromeOS::GetCurrentPressureLevel() const { |
+ return current_memory_pressure_level_; |
+} |
+ |
+void MemoryPressureMonitorChromeOS::ScheduleEarlyCheck() { |
+ base::MessageLoop::current()->PostTask( |
FROM_HERE, |
- Bind(&MemoryPressureObserverChromeOS::CheckMemoryPressure, |
+ Bind(&MemoryPressureMonitorChromeOS::CheckMemoryPressure, |
weak_ptr_factory_.GetWeakPtr())); |
} |
-void MemoryPressureObserverChromeOS::StartObserving() { |
+void MemoryPressureMonitorChromeOS::StartObserving() { |
timer_.Start(FROM_HERE, |
- TimeDelta::FromMilliseconds(kMemoryPressureIntervalMs), |
- Bind(&MemoryPressureObserverChromeOS:: |
+ base::TimeDelta::FromMilliseconds(kMemoryPressureIntervalMs), |
+ Bind(&MemoryPressureMonitorChromeOS:: |
CheckMemoryPressureAndRecordStatistics, |
weak_ptr_factory_.GetWeakPtr())); |
} |
-void MemoryPressureObserverChromeOS::StopObserving() { |
+void MemoryPressureMonitorChromeOS::StopObserving() { |
// If StartObserving failed, StopObserving will still get called. |
timer_.Stop(); |
} |
-void MemoryPressureObserverChromeOS::CheckMemoryPressureAndRecordStatistics() { |
+void MemoryPressureMonitorChromeOS::CheckMemoryPressureAndRecordStatistics() { |
CheckMemoryPressure(); |
// Record UMA histogram statistics for the current memory pressure level. |
@@ -135,7 +137,7 @@ void MemoryPressureObserverChromeOS::CheckMemoryPressureAndRecordStatistics() { |
NUM_MEMORY_PRESSURE_LEVELS); |
} |
-void MemoryPressureObserverChromeOS::CheckMemoryPressure() { |
+void MemoryPressureMonitorChromeOS::CheckMemoryPressure() { |
MemoryPressureListener::MemoryPressureLevel old_pressure = |
current_memory_pressure_level_; |
current_memory_pressure_level_ = |
@@ -171,7 +173,7 @@ void MemoryPressureObserverChromeOS::CheckMemoryPressure() { |
} |
// Gets the used ChromeOS memory in percent. |
-int MemoryPressureObserverChromeOS::GetUsedMemoryInPercent() { |
+int MemoryPressureMonitorChromeOS::GetUsedMemoryInPercent() { |
base::SystemMemoryInfoKB info; |
if (!base::GetSystemMemoryInfo(&info)) { |
VLOG(1) << "Cannot determine the free memory of the system."; |
@@ -208,4 +210,3 @@ int MemoryPressureObserverChromeOS::GetUsedMemoryInPercent() { |
return percentage; |
} |
-} // namespace base |