Commit dc837f50 authored by chrisha's avatar chrisha Committed by Commit bot

Rename OS-specific MemoryPressureMonitor implementations.

This is cleanup from https://codereview.chromium.org/1122863005/

BUG=472772

Review URL: https://codereview.chromium.org/1124163003

Cr-Commit-Position: refs/heads/master@{#330032}
parent 04f883bb
......@@ -167,8 +167,8 @@ component("base") {
"callback_internal.cc",
"callback_internal.h",
"cancelable_callback.h",
"chromeos/memory_pressure_monitor_chromeos.cc",
"chromeos/memory_pressure_monitor_chromeos.h",
"chromeos/memory_pressure_monitor.cc",
"chromeos/memory_pressure_monitor.h",
"command_line.cc",
"command_line.h",
"compiler_specific.h",
......@@ -287,8 +287,8 @@ component("base") {
"mac/mac_util.mm",
"mac/mach_logging.cc",
"mac/mach_logging.h",
"mac/memory_pressure_monitor_mac.cc",
"mac/memory_pressure_monitor_mac.h",
"mac/memory_pressure_monitor.cc",
"mac/memory_pressure_monitor.h",
"mac/objc_property_releaser.h",
"mac/objc_property_releaser.mm",
"mac/os_crash_dumps.cc",
......@@ -1098,7 +1098,7 @@ test("base_unittests") {
"callback_unittest.cc",
"callback_unittest.nc",
"cancelable_callback_unittest.cc",
"chromeos/memory_pressure_monitor_chromeos_unittest.cc",
"chromeos/memory_pressure_monitor_unittest.cc",
"command_line_unittest.cc",
"containers/adapters_unittest.cc",
"containers/hash_tables_unittest.cc",
......
......@@ -458,7 +458,7 @@
'callback_unittest.cc',
'callback_unittest.nc',
'cancelable_callback_unittest.cc',
'chromeos/memory_pressure_monitor_chromeos_unittest.cc',
'chromeos/memory_pressure_monitor_unittest.cc',
'command_line_unittest.cc',
'containers/adapters_unittest.cc',
'containers/hash_tables_unittest.cc',
......@@ -518,7 +518,7 @@
'mac/foundation_util_unittest.mm',
'mac/libdispatch_task_runner_unittest.cc',
'mac/mac_util_unittest.mm',
'mac/memory_pressure_monitor_mac_unittest.cc',
'mac/memory_pressure_monitor_unittest.cc',
'mac/objc_property_releaser_unittest.mm',
'mac/scoped_nsobject_unittest.mm',
'mac/scoped_objc_class_swizzler_unittest.mm',
......
......@@ -128,8 +128,8 @@
'callback_internal.h',
'callback_list.h',
'cancelable_callback.h',
'chromeos/memory_pressure_monitor_chromeos.cc',
'chromeos/memory_pressure_monitor_chromeos.h',
'chromeos/memory_pressure_monitor.cc',
'chromeos/memory_pressure_monitor.h',
'command_line.cc',
'command_line.h',
'compiler_specific.h',
......@@ -296,8 +296,8 @@
'mac/mac_util.mm',
'mac/mach_logging.cc',
'mac/mach_logging.h',
'mac/memory_pressure_monitor_mac.cc',
'mac/memory_pressure_monitor_mac.h',
'mac/memory_pressure_monitor.cc',
'mac/memory_pressure_monitor.h',
'mac/objc_property_releaser.h',
'mac/objc_property_releaser.mm',
'mac/os_crash_dumps.cc',
......
......@@ -2,7 +2,7 @@
// 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_monitor_chromeos.h"
#include "base/chromeos/memory_pressure_monitor.h"
#include <fcntl.h>
#include <sys/select.h>
......@@ -15,6 +15,7 @@
#include "base/time/time.h"
namespace base {
namespace chromeos {
namespace {
......@@ -53,10 +54,10 @@ const char kLowMemFile[] = "/dev/chromeos-low-mem";
// Converts a |MemoryPressureThreshold| value into a used memory percentage for
// the moderate pressure event.
int GetModerateMemoryThresholdInPercent(
MemoryPressureMonitorChromeOS::MemoryPressureThresholds thresholds) {
return thresholds == MemoryPressureMonitorChromeOS::
MemoryPressureMonitor::MemoryPressureThresholds thresholds) {
return thresholds == MemoryPressureMonitor::
THRESHOLD_AGGRESSIVE_CACHE_DISCARD ||
thresholds == MemoryPressureMonitorChromeOS::THRESHOLD_AGGRESSIVE
thresholds == MemoryPressureMonitor::THRESHOLD_AGGRESSIVE
? kAggressiveMemoryPressureModerateThresholdPercent
: kNormalMemoryPressureModerateThresholdPercent;
}
......@@ -64,10 +65,10 @@ int GetModerateMemoryThresholdInPercent(
// Converts a |MemoryPressureThreshold| value into a used memory percentage for
// the critical pressure event.
int GetCriticalMemoryThresholdInPercent(
MemoryPressureMonitorChromeOS::MemoryPressureThresholds thresholds) {
return thresholds == MemoryPressureMonitorChromeOS::
MemoryPressureMonitor::MemoryPressureThresholds thresholds) {
return thresholds == MemoryPressureMonitor::
THRESHOLD_AGGRESSIVE_TAB_DISCARD ||
thresholds == MemoryPressureMonitorChromeOS::THRESHOLD_AGGRESSIVE
thresholds == MemoryPressureMonitor::THRESHOLD_AGGRESSIVE
? kAggressiveMemoryPressureCriticalThresholdPercent
: kNormalMemoryPressureCriticalThresholdPercent;
}
......@@ -101,7 +102,7 @@ bool IsLowMemoryCondition(int file_descriptor) {
} // namespace
MemoryPressureMonitorChromeOS::MemoryPressureMonitorChromeOS(
MemoryPressureMonitor::MemoryPressureMonitor(
MemoryPressureThresholds thresholds)
: current_memory_pressure_level_(
MemoryPressureListener::MEMORY_PRESSURE_LEVEL_NONE),
......@@ -116,35 +117,41 @@ MemoryPressureMonitorChromeOS::MemoryPressureMonitorChromeOS(
LOG_IF(ERROR, !low_mem_file_.is_valid()) << "Cannot open kernel listener";
}
MemoryPressureMonitorChromeOS::~MemoryPressureMonitorChromeOS() {
MemoryPressureMonitor::~MemoryPressureMonitor() {
StopObserving();
}
void MemoryPressureMonitorChromeOS::ScheduleEarlyCheck() {
void MemoryPressureMonitor::ScheduleEarlyCheck() {
ThreadTaskRunnerHandle::Get()->PostTask(
FROM_HERE, Bind(&MemoryPressureMonitorChromeOS::CheckMemoryPressure,
FROM_HERE, Bind(&MemoryPressureMonitor::CheckMemoryPressure,
weak_ptr_factory_.GetWeakPtr()));
}
MemoryPressureListener::MemoryPressureLevel
MemoryPressureMonitorChromeOS::GetCurrentPressureLevel() const {
MemoryPressureMonitor::GetCurrentPressureLevel() const {
return current_memory_pressure_level_;
}
void MemoryPressureMonitorChromeOS::StartObserving() {
// static
MemoryPressureMonitor* MemoryPressureMonitor::Get() {
return static_cast<MemoryPressureMonitor*>(
base::MemoryPressureMonitor::Get());
}
void MemoryPressureMonitor::StartObserving() {
timer_.Start(FROM_HERE,
TimeDelta::FromMilliseconds(kMemoryPressureIntervalMs),
Bind(&MemoryPressureMonitorChromeOS::
Bind(&MemoryPressureMonitor::
CheckMemoryPressureAndRecordStatistics,
weak_ptr_factory_.GetWeakPtr()));
}
void MemoryPressureMonitorChromeOS::StopObserving() {
void MemoryPressureMonitor::StopObserving() {
// If StartObserving failed, StopObserving will still get called.
timer_.Stop();
}
void MemoryPressureMonitorChromeOS::CheckMemoryPressureAndRecordStatistics() {
void MemoryPressureMonitor::CheckMemoryPressureAndRecordStatistics() {
CheckMemoryPressure();
// Record UMA histogram statistics for the current memory pressure level.
......@@ -166,7 +173,7 @@ void MemoryPressureMonitorChromeOS::CheckMemoryPressureAndRecordStatistics() {
NUM_MEMORY_PRESSURE_LEVELS);
}
void MemoryPressureMonitorChromeOS::CheckMemoryPressure() {
void MemoryPressureMonitor::CheckMemoryPressure() {
MemoryPressureListener::MemoryPressureLevel old_pressure =
current_memory_pressure_level_;
......@@ -224,7 +231,7 @@ void MemoryPressureMonitorChromeOS::CheckMemoryPressure() {
}
// Gets the used ChromeOS memory in percent.
int MemoryPressureMonitorChromeOS::GetUsedMemoryInPercent() {
int MemoryPressureMonitor::GetUsedMemoryInPercent() {
base::SystemMemoryInfoKB info;
if (!base::GetSystemMemoryInfo(&info)) {
VLOG(1) << "Cannot determine the free memory of the system.";
......@@ -261,4 +268,5 @@ int MemoryPressureMonitorChromeOS::GetUsedMemoryInPercent() {
return percentage;
}
} // namespace chromeos
} // namespace base
......@@ -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_MONITOR_CHROMEOS_H_
#define BASE_CHROMEOS_MEMORY_PRESSURE_MONITOR_CHROMEOS_H_
#ifndef BASE_CHROMEOS_MEMORY_PRESSURE_MONITOR_H_
#define BASE_CHROMEOS_MEMORY_PRESSURE_MONITOR_H_
#include "base/base_export.h"
#include "base/files/scoped_file.h"
......@@ -15,17 +15,18 @@
#include "base/timer/timer.h"
namespace base {
namespace chromeos {
class TestMemoryPressureMonitor;
////////////////////////////////////////////////////////////////////////////////
// MemoryPressureMonitorChromeOS
// MemoryPressureMonitor
//
// 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 MemoryPressureMonitorChromeOS : public MemoryPressureMonitor {
class BASE_EXPORT MemoryPressureMonitor : public base::MemoryPressureMonitor {
public:
using GetUsedMemoryInPercentCallback = int (*)();
......@@ -49,8 +50,8 @@ class BASE_EXPORT MemoryPressureMonitorChromeOS : public MemoryPressureMonitor {
THRESHOLD_AGGRESSIVE = 4
};
explicit MemoryPressureMonitorChromeOS(MemoryPressureThresholds thresholds);
~MemoryPressureMonitorChromeOS() override;
explicit MemoryPressureMonitor(MemoryPressureThresholds thresholds);
~MemoryPressureMonitor() override;
// Redo the memory pressure calculation soon and call again if a critical
// memory pressure prevails. Note that this call will trigger an asynchronous
......@@ -61,6 +62,10 @@ class BASE_EXPORT MemoryPressureMonitorChromeOS : public MemoryPressureMonitor {
MemoryPressureListener::MemoryPressureLevel GetCurrentPressureLevel() const
override;
// Returns a type-casted version of the current memory pressure monitor. A
// simple wrapper to base::MemoryPressureMonitor::Get.
static MemoryPressureMonitor* Get();
private:
friend TestMemoryPressureMonitor;
// Starts observing the memory fill level.
......@@ -90,7 +95,7 @@ class BASE_EXPORT MemoryPressureMonitorChromeOS : public MemoryPressureMonitor {
// 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<MemoryPressureMonitorChromeOS> timer_;
base::RepeatingTimer<MemoryPressureMonitor> 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.
......@@ -103,11 +108,12 @@ class BASE_EXPORT MemoryPressureMonitorChromeOS : public MemoryPressureMonitor {
// File descriptor used to detect low memory condition.
ScopedFD low_mem_file_;
base::WeakPtrFactory<MemoryPressureMonitorChromeOS> weak_ptr_factory_;
base::WeakPtrFactory<MemoryPressureMonitor> weak_ptr_factory_;
DISALLOW_COPY_AND_ASSIGN(MemoryPressureMonitorChromeOS);
DISALLOW_COPY_AND_ASSIGN(MemoryPressureMonitor);
};
} // namespace chromeos
} // namespace base
#endif // BASE_CHROMEOS_MEMORY_PRESSURE_MONITOR_CHROMEOS_H_
#endif // BASE_CHROMEOS_MEMORY_PRESSURE_MONITOR_H_
......@@ -3,12 +3,13 @@
// found in the LICENSE file.
#include "base/basictypes.h"
#include "base/chromeos/memory_pressure_monitor_chromeos.h"
#include "base/chromeos/memory_pressure_monitor.h"
#include "base/memory/memory_pressure_listener.h"
#include "base/message_loop/message_loop.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace base {
namespace chromeos {
namespace {
......@@ -40,12 +41,11 @@ bool WasOnMemoryPressureCalled() {
} // namespace
class TestMemoryPressureMonitor : public MemoryPressureMonitorChromeOS {
class TestMemoryPressureMonitor : public MemoryPressureMonitor {
public:
TestMemoryPressureMonitor() :
MemoryPressureMonitorChromeOS(
MemoryPressureMonitorChromeOS::THRESHOLD_DEFAULT),
memory_in_percent_override_(0) {
TestMemoryPressureMonitor()
: MemoryPressureMonitor(THRESHOLD_DEFAULT),
memory_in_percent_override_(0) {
// Disable any timers which are going on and set a special memory reporting
// function.
StopObserving();
......@@ -71,7 +71,7 @@ class TestMemoryPressureMonitor : public MemoryPressureMonitorChromeOS {
// This test tests the various transition states from memory pressure, looking
// for the correct behavior on event reposting as well as state updates.
TEST(MemoryPressureMonitorChromeOSTest, CheckMemoryPressure) {
TEST(ChromeOSMemoryPressureMonitorTest, CheckMemoryPressure) {
base::MessageLoopForUI message_loop;
scoped_ptr<TestMemoryPressureMonitor> monitor(
new TestMemoryPressureMonitor);
......@@ -161,4 +161,5 @@ TEST(MemoryPressureMonitorChromeOSTest, CheckMemoryPressure) {
EXPECT_EQ(j, i);
}
} // namespace chromeos
} // namespace base
......@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "base/mac/memory_pressure_monitor_mac.h"
#include "base/mac/memory_pressure_monitor.h"
#include <dlfcn.h>
#include <sys/sysctl.h>
......@@ -10,9 +10,10 @@
#include "base/mac/mac_util.h"
namespace base {
namespace mac {
MemoryPressureListener::MemoryPressureLevel
MemoryPressureMonitorMac::MemoryPressureLevelForMacMemoryPressure(
MemoryPressureMonitor::MemoryPressureLevelForMacMemoryPressure(
int mac_memory_pressure) {
switch (mac_memory_pressure) {
case DISPATCH_MEMORYPRESSURE_NORMAL:
......@@ -25,7 +26,7 @@ MemoryPressureMonitorMac::MemoryPressureLevelForMacMemoryPressure(
return MemoryPressureListener::MEMORY_PRESSURE_LEVEL_NONE;
}
void MemoryPressureMonitorMac::NotifyMemoryPressureChanged(
void MemoryPressureMonitor::NotifyMemoryPressureChanged(
dispatch_source_s* event_source) {
int mac_memory_pressure = dispatch_source_get_data(event_source);
MemoryPressureListener::MemoryPressureLevel memory_pressure_level =
......@@ -33,7 +34,7 @@ void MemoryPressureMonitorMac::NotifyMemoryPressureChanged(
MemoryPressureListener::NotifyMemoryPressure(memory_pressure_level);
}
MemoryPressureMonitorMac::MemoryPressureMonitorMac()
MemoryPressureMonitor::MemoryPressureMonitor()
: memory_level_event_source_(nullptr) {
// _dispatch_source_type_memorypressure is not available prior to 10.9.
dispatch_source_type_t dispatch_source_memorypressure =
......@@ -58,11 +59,11 @@ MemoryPressureMonitorMac::MemoryPressureMonitorMac()
}
}
MemoryPressureMonitorMac::~MemoryPressureMonitorMac() {
MemoryPressureMonitor::~MemoryPressureMonitor() {
}
MemoryPressureListener::MemoryPressureLevel
MemoryPressureMonitorMac::GetCurrentPressureLevel() const {
MemoryPressureMonitor::GetCurrentPressureLevel() const {
if (base::mac::IsOSMountainLionOrEarlier()) {
return MemoryPressureListener::MEMORY_PRESSURE_LEVEL_NONE;
}
......@@ -73,4 +74,5 @@ MemoryPressureMonitorMac::GetCurrentPressureLevel() const {
return MemoryPressureLevelForMacMemoryPressure(mac_memory_pressure);
}
} // namespace mac
} // namespace base
......@@ -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_MAC_MEMORY_PRESSURE_MONITOR_MAC_H_
#define BASE_MAC_MEMORY_PRESSURE_MONITOR_MAC_H_
#ifndef BASE_MAC_MEMORY_PRESSURE_MONITOR_H_
#define BASE_MAC_MEMORY_PRESSURE_MONITOR_H_
#include <dispatch/dispatch.h>
......@@ -23,8 +23,9 @@
#endif // DISPATCH_MEMORYPRESSURE_NORMAL
namespace base {
namespace mac {
class TestMemoryPressureMonitorMac;
class TestMemoryPressureMonitor;
struct DispatchSourceSDeleter {
void operator()(dispatch_source_s* ptr) {
......@@ -35,17 +36,16 @@ struct DispatchSourceSDeleter {
// Declares the interface for the Mac MemoryPressureMonitor, which reports
// memory pressure events and status.
class BASE_EXPORT MemoryPressureMonitorMac : public MemoryPressureMonitor {
class BASE_EXPORT MemoryPressureMonitor : public base::MemoryPressureMonitor {
public:
using MemoryPressureLevel = base::MemoryPressureListener::MemoryPressureLevel;
MemoryPressureMonitorMac();
~MemoryPressureMonitorMac() override;
MemoryPressureMonitor();
~MemoryPressureMonitor() override;
// Returns the currently-observed memory pressure.
MemoryPressureLevel GetCurrentPressureLevel() const override;
private:
friend TestMemoryPressureMonitorMac;
friend TestMemoryPressureMonitor;
static MemoryPressureLevel
MemoryPressureLevelForMacMemoryPressure(int mac_memory_pressure);
......@@ -54,9 +54,10 @@ class BASE_EXPORT MemoryPressureMonitorMac : public MemoryPressureMonitor {
scoped_ptr<dispatch_source_s, DispatchSourceSDeleter>
memory_level_event_source_;
DISALLOW_COPY_AND_ASSIGN(MemoryPressureMonitorMac);
DISALLOW_COPY_AND_ASSIGN(MemoryPressureMonitor);
};
} // namespace mac
} // namespace base
#endif // BASE_MAC_MEMORY_PRESSURE_MONITOR_MAC_H_
#endif // BASE_MAC_MEMORY_PRESSURE_MONITOR_H_
......@@ -2,50 +2,51 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "base/mac/memory_pressure_monitor_mac.h"
#include "base/mac/memory_pressure_monitor.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace base {
namespace mac {
class TestMemoryPressureMonitorMac : public MemoryPressureMonitorMac {
class TestMemoryPressureMonitor : public MemoryPressureMonitor {
public:
using MemoryPressureMonitorMac::MemoryPressureLevelForMacMemoryPressure;
using MemoryPressureMonitor::MemoryPressureLevelForMacMemoryPressure;
TestMemoryPressureMonitorMac() { }
TestMemoryPressureMonitor() { }
private:
DISALLOW_COPY_AND_ASSIGN(TestMemoryPressureMonitorMac);
DISALLOW_COPY_AND_ASSIGN(TestMemoryPressureMonitor);
};
TEST(TestMemoryPressureMonitorMac, MemoryPressureFromMacMemoryPressure) {
TEST(MacMemoryPressureMonitorTest, MemoryPressureFromMacMemoryPressure) {
EXPECT_EQ(MemoryPressureListener::MEMORY_PRESSURE_LEVEL_NONE,
TestMemoryPressureMonitorMac::
TestMemoryPressureMonitor::
MemoryPressureLevelForMacMemoryPressure(
DISPATCH_MEMORYPRESSURE_NORMAL));
EXPECT_EQ(MemoryPressureListener::MEMORY_PRESSURE_LEVEL_MODERATE,
TestMemoryPressureMonitorMac::
TestMemoryPressureMonitor::
MemoryPressureLevelForMacMemoryPressure(
DISPATCH_MEMORYPRESSURE_WARN));
EXPECT_EQ(MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL,
TestMemoryPressureMonitorMac::
TestMemoryPressureMonitor::
MemoryPressureLevelForMacMemoryPressure(
DISPATCH_MEMORYPRESSURE_CRITICAL));
EXPECT_EQ(MemoryPressureListener::MEMORY_PRESSURE_LEVEL_NONE,
TestMemoryPressureMonitorMac::
TestMemoryPressureMonitor::
MemoryPressureLevelForMacMemoryPressure(0));
EXPECT_EQ(MemoryPressureListener::MEMORY_PRESSURE_LEVEL_NONE,
TestMemoryPressureMonitorMac::
TestMemoryPressureMonitor::
MemoryPressureLevelForMacMemoryPressure(3));
EXPECT_EQ(MemoryPressureListener::MEMORY_PRESSURE_LEVEL_NONE,
TestMemoryPressureMonitorMac::
TestMemoryPressureMonitor::
MemoryPressureLevelForMacMemoryPressure(5));
EXPECT_EQ(MemoryPressureListener::MEMORY_PRESSURE_LEVEL_NONE,
TestMemoryPressureMonitorMac::
TestMemoryPressureMonitor::
MemoryPressureLevelForMacMemoryPressure(-1));
}
TEST(TestMemoryPressureMonitorMac, CurrentMemoryPressure) {
TestMemoryPressureMonitorMac monitor;
TEST(MacMemoryPressureMonitorTest, CurrentMemoryPressure) {
TestMemoryPressureMonitor monitor;
MemoryPressureListener::MemoryPressureLevel memory_pressure =
monitor.GetCurrentPressureLevel();
EXPECT_TRUE(memory_pressure ==
......@@ -56,4 +57,5 @@ TEST(TestMemoryPressureMonitorMac, CurrentMemoryPressure) {
MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL);
}
} // namespace mac
} // namespace base
......@@ -10,6 +10,9 @@
namespace base {
// TODO(chrisha): Make this a concrete class with per-OS implementations rather
// than an abstract base class.
// Declares the interface for a MemoryPressureMonitor. There are multiple
// OS specific implementations of this class. An instance of the memory
// pressure observer is created at the process level, tracks memory usage, and
......
......@@ -512,9 +512,8 @@ void OomPriorityManager::Observe(int type,
// driven MemoryPressureMonitor will continue to produce timed events
// on top. So the longer the cleanup phase takes, the more tabs will
// get discarded in parallel.
base::MemoryPressureMonitorChromeOS* monitor =
static_cast<base::MemoryPressureMonitorChromeOS*>(
base::MemoryPressureMonitor::Get());
base::chromeos::MemoryPressureMonitor* monitor =
base::chromeos::MemoryPressureMonitor::Get();
if (monitor)
monitor->ScheduleEarlyCheck();
}
......
......@@ -348,40 +348,38 @@ bool MemoryPressureHandlingEnabled() {
return true;
}
base::MemoryPressureMonitorChromeOS::MemoryPressureThresholds
base::chromeos::MemoryPressureMonitor::MemoryPressureThresholds
GetMemoryPressureThresholds() {
using MemoryPressureMonitor = base::chromeos::MemoryPressureMonitor;
if (!base::CommandLine::ForCurrentProcess()->HasSwitch(
kMemoryPressureThresholds)) {
const std::string group_name =
base::FieldTrialList::FindFullName(kMemoryPressureExperimentName);
if (group_name == kConservativeThreshold)
return base::MemoryPressureMonitorChromeOS::THRESHOLD_CONSERVATIVE;
return MemoryPressureMonitor::THRESHOLD_CONSERVATIVE;
if (group_name == kAggressiveCacheDiscardThreshold)
return base::MemoryPressureMonitorChromeOS::
THRESHOLD_AGGRESSIVE_CACHE_DISCARD;
return MemoryPressureMonitor::THRESHOLD_AGGRESSIVE_CACHE_DISCARD;
if (group_name == kAggressiveTabDiscardThreshold)
return base::MemoryPressureMonitorChromeOS::
THRESHOLD_AGGRESSIVE_TAB_DISCARD;
return MemoryPressureMonitor::THRESHOLD_AGGRESSIVE_TAB_DISCARD;
if (group_name == kAggressiveThreshold)
return base::MemoryPressureMonitorChromeOS::THRESHOLD_AGGRESSIVE;
return base::MemoryPressureMonitorChromeOS::THRESHOLD_DEFAULT;
return MemoryPressureMonitor::THRESHOLD_AGGRESSIVE;
return MemoryPressureMonitor::THRESHOLD_DEFAULT;
}
const std::string option =
base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII(
kMemoryPressureThresholds);
if (option == kConservativeThreshold)
return base::MemoryPressureMonitorChromeOS::THRESHOLD_CONSERVATIVE;
return MemoryPressureMonitor::THRESHOLD_CONSERVATIVE;
if (option == kAggressiveCacheDiscardThreshold)
return base::MemoryPressureMonitorChromeOS::
THRESHOLD_AGGRESSIVE_CACHE_DISCARD;
return MemoryPressureMonitor::THRESHOLD_AGGRESSIVE_CACHE_DISCARD;
if (option == kAggressiveTabDiscardThreshold)
return base::MemoryPressureMonitorChromeOS::
THRESHOLD_AGGRESSIVE_TAB_DISCARD;
return MemoryPressureMonitor::THRESHOLD_AGGRESSIVE_TAB_DISCARD;
if (option == kAggressiveThreshold)
return base::MemoryPressureMonitorChromeOS::THRESHOLD_AGGRESSIVE;
return MemoryPressureMonitor::THRESHOLD_AGGRESSIVE;
return base::MemoryPressureMonitorChromeOS::THRESHOLD_DEFAULT;
return MemoryPressureMonitor::THRESHOLD_DEFAULT;
}
} // namespace switches
......
......@@ -5,7 +5,7 @@
#ifndef CHROMEOS_CHROMEOS_SWITCHES_H_
#define CHROMEOS_CHROMEOS_SWITCHES_H_
#include "base/chromeos/memory_pressure_monitor_chromeos.h"
#include "base/chromeos/memory_pressure_monitor.h"
#include "chromeos/chromeos_export.h"
namespace chromeos {
......@@ -114,7 +114,7 @@ CHROMEOS_EXPORT extern const char kDataSaverPromptDemoMode[];
CHROMEOS_EXPORT bool WakeOnWifiEnabled();
CHROMEOS_EXPORT bool MemoryPressureHandlingEnabled();
CHROMEOS_EXPORT base::MemoryPressureMonitorChromeOS::MemoryPressureThresholds
CHROMEOS_EXPORT base::chromeos::MemoryPressureMonitor::MemoryPressureThresholds
GetMemoryPressureThresholds();
} // namespace switches
......
......@@ -7,6 +7,7 @@
#include "base/bind.h"
#include "base/command_line.h"
#include "base/logging.h"
#include "base/memory/memory_pressure_monitor.h"
#include "base/message_loop/message_loop.h"
#include "base/metrics/field_trial.h"
#include "base/metrics/histogram.h"
......@@ -91,7 +92,7 @@
#endif
#if defined(OS_MACOSX) && !defined(OS_IOS)
#include "base/mac/memory_pressure_monitor_mac.h"
#include "base/mac/memory_pressure_monitor.h"
#include "content/browser/bootstrap_sandbox_mac.h"
#include "content/browser/cocoa/system_hotkey_helper_mac.h"
#include "content/browser/compositor/browser_compositor_view_mac.h"
......@@ -111,7 +112,7 @@
#endif
#if defined(OS_CHROMEOS)
#include "base/chromeos/memory_pressure_monitor_chromeos.h"
#include "base/chromeos/memory_pressure_monitor.h"
#include "chromeos/chromeos_switches.h"
#endif
......@@ -644,13 +645,15 @@ int BrowserMainLoop::PreCreateThreads() {
result_code_ = parts_->PreCreateThreads();
}
// TODO(chrisha): Abstract away this construction mess to a helper function,
// once MemoryPressureMonitor is made a concrete class.
#if defined(OS_CHROMEOS)
if (chromeos::switches::MemoryPressureHandlingEnabled()) {
memory_pressure_monitor_.reset(new base::MemoryPressureMonitorChromeOS(
memory_pressure_monitor_.reset(new base::chromeos::MemoryPressureMonitor(
chromeos::switches::GetMemoryPressureThresholds()));
}
#elif defined(OS_MACOSX) && !defined(OS_IOS)
memory_pressure_monitor_.reset(new base::MemoryPressureMonitorMac());
memory_pressure_monitor_.reset(new base::mac::MemoryPressureMonitor());
#elif defined(OS_WIN)
memory_pressure_monitor_.reset(CreateWinMemoryPressureMonitor(
parsed_command_line_));
......@@ -917,9 +920,7 @@ void BrowserMainLoop::ShutdownThreadsAndCleanUp() {
resource_dispatcher_host_.get()->Shutdown();
}
#if defined(OS_CHROMEOS) || defined(OS_MACOSX)
memory_pressure_monitor_.reset();
#endif
#if defined(OS_MACOSX)
BrowserCompositorMac::DisableRecyclingForShutdown();
......
......@@ -20,11 +20,7 @@ class HighResolutionTimerManager;
class MessageLoop;
class PowerMonitor;
class SystemMonitor;
#if defined(OS_CHROMEOS)
class MemoryPressureMonitorChromeOS;
#elif (defined(OS_MACOSX) && !defined(OS_IOS)) || defined(OS_WIN)
class MemoryPressureMonitor;
#endif
namespace trace_event {
class TraceMemoryController;
class TraceEventSystemStatsMonitor;
......@@ -182,11 +178,11 @@ class CONTENT_EXPORT BrowserMainLoop {
// Android implementation of ScreenOrientationDelegate
scoped_ptr<ScreenOrientationDelegate> screen_orientation_delegate_;
#endif
#if defined(OS_CHROMEOS)
scoped_ptr<base::MemoryPressureMonitorChromeOS> memory_pressure_monitor_;
#elif (defined(OS_MACOSX) && !defined(OS_IOS)) || defined(OS_WIN)
// Memory pressure monitor. Created in PreCreateThreads and torn down in
// ShutdownThreadsAndCleanUp.
scoped_ptr<base::MemoryPressureMonitor> memory_pressure_monitor_;
#endif
// The startup task runner is created by CreateStartupTasks()
scoped_ptr<StartupTaskRunner> startup_task_runner_;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment