Commit 3b10e258 authored by noamsml@chromium.org's avatar noamsml@chromium.org

Revert of https://codereview.chromium.org/129193002/

Reason for revert: Did not fix chromeos failures

TBR=bartfab@chromium.org,benwells@chromium.org,derat@chromium.org
NOTREECHECKS=true
NOTRY=true
BUG=329930

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

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@243671 0039d316-1c4b-4281-b951-d872f2087c98
parent 9d86384c
...@@ -1260,8 +1260,8 @@ class RestartDeviceTest : public PlatformAppBrowserTest { ...@@ -1260,8 +1260,8 @@ class RestartDeviceTest : public PlatformAppBrowserTest {
PlatformAppBrowserTest::TearDownInProcessBrowserTestFixture(); PlatformAppBrowserTest::TearDownInProcessBrowserTestFixture();
} }
int request_restart_call_count() const { int num_request_restart_calls() const {
return power_manager_client_->request_restart_call_count(); return power_manager_client_->num_request_restart_calls();
} }
private: private:
...@@ -1275,7 +1275,7 @@ class RestartDeviceTest : public PlatformAppBrowserTest { ...@@ -1275,7 +1275,7 @@ class RestartDeviceTest : public PlatformAppBrowserTest {
// Tests that chrome.runtime.restart would request device restart in // Tests that chrome.runtime.restart would request device restart in
// ChromeOS kiosk mode. // ChromeOS kiosk mode.
IN_PROC_BROWSER_TEST_F(RestartDeviceTest, Restart) { IN_PROC_BROWSER_TEST_F(RestartDeviceTest, Restart) {
ASSERT_EQ(0, request_restart_call_count()); ASSERT_EQ(0, num_request_restart_calls());
ExtensionTestMessageListener launched_listener("Launched", true); ExtensionTestMessageListener launched_listener("Launched", true);
const Extension* extension = LoadAndLaunchPlatformApp("restart_device"); const Extension* extension = LoadAndLaunchPlatformApp("restart_device");
...@@ -1287,7 +1287,7 @@ IN_PROC_BROWSER_TEST_F(RestartDeviceTest, Restart) { ...@@ -1287,7 +1287,7 @@ IN_PROC_BROWSER_TEST_F(RestartDeviceTest, Restart) {
false); false);
ASSERT_TRUE(restart_requested_listener.WaitUntilSatisfied()); ASSERT_TRUE(restart_requested_listener.WaitUntilSatisfied());
EXPECT_EQ(1, request_restart_call_count()); EXPECT_EQ(1, num_request_restart_calls());
} }
#endif // defined(OS_CHROMEOS) #endif // defined(OS_CHROMEOS)
......
...@@ -290,7 +290,7 @@ void PowerPolicyInSessionBrowserTest::SetUpOnMainThread() { ...@@ -290,7 +290,7 @@ void PowerPolicyInSessionBrowserTest::SetUpOnMainThread() {
// Verifies that device policy is applied on the login screen. // Verifies that device policy is applied on the login screen.
IN_PROC_BROWSER_TEST_F(PowerPolicyLoginScreenBrowserTest, SetDevicePolicy) { IN_PROC_BROWSER_TEST_F(PowerPolicyLoginScreenBrowserTest, SetDevicePolicy) {
pm::PowerManagementPolicy power_management_policy = pm::PowerManagementPolicy power_management_policy =
power_manager_client_->get_policy(); power_manager_client_->policy();
power_management_policy.mutable_ac_delays()->set_screen_dim_ms(5000); power_management_policy.mutable_ac_delays()->set_screen_dim_ms(5000);
power_management_policy.mutable_ac_delays()->set_screen_off_ms(7000); power_management_policy.mutable_ac_delays()->set_screen_off_ms(7000);
power_management_policy.mutable_ac_delays()->set_idle_ms(9000); power_management_policy.mutable_ac_delays()->set_idle_ms(9000);
...@@ -310,26 +310,26 @@ IN_PROC_BROWSER_TEST_F(PowerPolicyLoginScreenBrowserTest, SetDevicePolicy) { ...@@ -310,26 +310,26 @@ IN_PROC_BROWSER_TEST_F(PowerPolicyLoginScreenBrowserTest, SetDevicePolicy) {
set_login_screen_power_management(kLoginScreenPowerManagementPolicy); set_login_screen_power_management(kLoginScreenPowerManagementPolicy);
StoreAndReloadDevicePolicyAndWaitForLoginProfileChange(); StoreAndReloadDevicePolicyAndWaitForLoginProfileChange();
EXPECT_EQ(GetDebugString(power_management_policy), EXPECT_EQ(GetDebugString(power_management_policy),
GetDebugString(power_manager_client_->get_policy())); GetDebugString(power_manager_client_->policy()));
} }
// Verifies that device policy is ignored during a session. // Verifies that device policy is ignored during a session.
IN_PROC_BROWSER_TEST_F(PowerPolicyInSessionBrowserTest, SetDevicePolicy) { IN_PROC_BROWSER_TEST_F(PowerPolicyInSessionBrowserTest, SetDevicePolicy) {
pm::PowerManagementPolicy power_management_policy = pm::PowerManagementPolicy power_management_policy =
power_manager_client_->get_policy(); power_manager_client_->policy();
em::ChromeDeviceSettingsProto& proto(device_policy()->payload()); em::ChromeDeviceSettingsProto& proto(device_policy()->payload());
proto.mutable_login_screen_power_management()-> proto.mutable_login_screen_power_management()->
set_login_screen_power_management(kLoginScreenPowerManagementPolicy); set_login_screen_power_management(kLoginScreenPowerManagementPolicy);
StoreAndReloadDevicePolicyAndWaitForLoginProfileChange(); StoreAndReloadDevicePolicyAndWaitForLoginProfileChange();
EXPECT_EQ(GetDebugString(power_management_policy), EXPECT_EQ(GetDebugString(power_management_policy),
GetDebugString(power_manager_client_->get_policy())); GetDebugString(power_manager_client_->policy()));
} }
// Verifies that user policy is applied during a session. // Verifies that user policy is applied during a session.
IN_PROC_BROWSER_TEST_F(PowerPolicyInSessionBrowserTest, SetUserPolicy) { IN_PROC_BROWSER_TEST_F(PowerPolicyInSessionBrowserTest, SetUserPolicy) {
pm::PowerManagementPolicy power_management_policy = pm::PowerManagementPolicy power_management_policy =
power_manager_client_->get_policy(); power_manager_client_->policy();
power_management_policy.mutable_ac_delays()->set_screen_dim_ms(5000); power_management_policy.mutable_ac_delays()->set_screen_dim_ms(5000);
power_management_policy.mutable_ac_delays()->set_screen_lock_ms(6000); power_management_policy.mutable_ac_delays()->set_screen_lock_ms(6000);
power_management_policy.mutable_ac_delays()->set_screen_off_ms(7000); power_management_policy.mutable_ac_delays()->set_screen_off_ms(7000);
...@@ -379,14 +379,14 @@ IN_PROC_BROWSER_TEST_F(PowerPolicyInSessionBrowserTest, SetUserPolicy) { ...@@ -379,14 +379,14 @@ IN_PROC_BROWSER_TEST_F(PowerPolicyInSessionBrowserTest, SetUserPolicy) {
user_policy_.payload().mutable_waitforinitialuseractivity()->set_value(true); user_policy_.payload().mutable_waitforinitialuseractivity()->set_value(true);
StoreAndReloadUserPolicy(); StoreAndReloadUserPolicy();
EXPECT_EQ(GetDebugString(power_management_policy), EXPECT_EQ(GetDebugString(power_management_policy),
GetDebugString(power_manager_client_->get_policy())); GetDebugString(power_manager_client_->policy()));
} }
// Verifies that screen wake locks can be enabled and disabled by extensions and // Verifies that screen wake locks can be enabled and disabled by extensions and
// user policy during a session. // user policy during a session.
IN_PROC_BROWSER_TEST_F(PowerPolicyInSessionBrowserTest, AllowScreenWakeLocks) { IN_PROC_BROWSER_TEST_F(PowerPolicyInSessionBrowserTest, AllowScreenWakeLocks) {
pm::PowerManagementPolicy baseline_policy = pm::PowerManagementPolicy baseline_policy =
power_manager_client_->get_policy(); power_manager_client_->policy();
// Default settings should have delays. // Default settings should have delays.
pm::PowerManagementPolicy power_management_policy = baseline_policy; pm::PowerManagementPolicy power_management_policy = baseline_policy;
...@@ -409,24 +409,23 @@ IN_PROC_BROWSER_TEST_F(PowerPolicyInSessionBrowserTest, AllowScreenWakeLocks) { ...@@ -409,24 +409,23 @@ IN_PROC_BROWSER_TEST_F(PowerPolicyInSessionBrowserTest, AllowScreenWakeLocks) {
policy.mutable_battery_delays()->set_screen_dim_ms(0); policy.mutable_battery_delays()->set_screen_dim_ms(0);
policy.mutable_battery_delays()->set_screen_off_ms(0); policy.mutable_battery_delays()->set_screen_off_ms(0);
policy.set_ac_idle_action( policy.set_ac_idle_action(
power_manager_client_->get_policy().ac_idle_action()); power_manager_client_->policy().ac_idle_action());
policy.set_battery_idle_action( policy.set_battery_idle_action(
power_manager_client_->get_policy().battery_idle_action()); power_manager_client_->policy().battery_idle_action());
policy.set_reason(power_manager_client_->get_policy().reason()); policy.set_reason(power_manager_client_->policy().reason());
EXPECT_EQ(GetDebugString(policy), EXPECT_EQ(GetDebugString(policy),
GetDebugString(power_manager_client_->get_policy())); GetDebugString(power_manager_client_->policy()));
// Engage the user policy and verify that the defaults take effect again. // Engage the user policy and verify that the defaults take effect again.
user_policy_.payload().mutable_allowscreenwakelocks()->set_value(false); user_policy_.payload().mutable_allowscreenwakelocks()->set_value(false);
StoreAndReloadUserPolicy(); StoreAndReloadUserPolicy();
policy = baseline_policy; policy = baseline_policy;
policy.set_ac_idle_action( policy.set_ac_idle_action(power_manager_client_->policy().ac_idle_action());
power_manager_client_->get_policy().ac_idle_action());
policy.set_battery_idle_action( policy.set_battery_idle_action(
power_manager_client_->get_policy().battery_idle_action()); power_manager_client_->policy().battery_idle_action());
policy.set_reason(power_manager_client_->get_policy().reason()); policy.set_reason(power_manager_client_->policy().reason());
EXPECT_EQ(GetDebugString(policy), EXPECT_EQ(GetDebugString(policy),
GetDebugString(power_manager_client_->get_policy())); GetDebugString(power_manager_client_->policy()));
} }
} // namespace policy } // namespace policy
...@@ -237,10 +237,8 @@ void PowerPrefs::SetProfile(Profile* profile) { ...@@ -237,10 +237,8 @@ void PowerPrefs::SetProfile(Profile* profile) {
profile_ = profile; profile_ = profile;
pref_change_registrar_.reset(); pref_change_registrar_.reset();
if (!profile) { if (!profile)
power_policy_controller_->ClearPrefs();
return; return;
}
base::Closure update_callback(base::Bind( base::Closure update_callback(base::Bind(
&PowerPrefs::UpdatePowerPolicyFromPrefs, &PowerPrefs::UpdatePowerPolicyFromPrefs,
......
...@@ -140,7 +140,7 @@ std::string PowerPrefsTest::GetExpectedPowerPolicyForProfile( ...@@ -140,7 +140,7 @@ std::string PowerPrefsTest::GetExpectedPowerPolicyForProfile(
std::string PowerPrefsTest::GetCurrentPowerPolicy() const { std::string PowerPrefsTest::GetCurrentPowerPolicy() const {
return PowerPolicyController::GetPolicyDebugString( return PowerPolicyController::GetPolicyDebugString(
fake_power_manager_client_->get_policy()); fake_power_manager_client_->policy());
} }
bool PowerPrefsTest::GetCurrentAllowScreenWakeLocks() const { bool PowerPrefsTest::GetCurrentAllowScreenWakeLocks() const {
...@@ -202,9 +202,9 @@ TEST_F(PowerPrefsTest, LoginScreen) { ...@@ -202,9 +202,9 @@ TEST_F(PowerPrefsTest, LoginScreen) {
content::Source<Profile>(login_profile), content::Source<Profile>(login_profile),
content::NotificationService::NoDetails()); content::NotificationService::NoDetails());
// The login profile's prefs should still be used.
EXPECT_FALSE(GetProfile()); EXPECT_FALSE(GetProfile());
EXPECT_EQ(PowerPolicyController::GetPolicyDebugString( EXPECT_EQ(GetExpectedPowerPolicyForProfile(login_profile),
power_manager::PowerManagementPolicy()),
GetCurrentPowerPolicy()); GetCurrentPowerPolicy());
} }
...@@ -259,9 +259,9 @@ TEST_F(PowerPrefsTest, UserSession) { ...@@ -259,9 +259,9 @@ TEST_F(PowerPrefsTest, UserSession) {
content::Source<Profile>(user_profile), content::Source<Profile>(user_profile),
content::NotificationService::NoDetails()); content::NotificationService::NoDetails());
// The user profile's prefs should still be used.
EXPECT_FALSE(GetProfile()); EXPECT_FALSE(GetProfile());
EXPECT_EQ(PowerPolicyController::GetPolicyDebugString( EXPECT_EQ(GetExpectedPowerPolicyForProfile(user_profile),
power_manager::PowerManagementPolicy()),
GetCurrentPowerPolicy()); GetCurrentPowerPolicy());
} }
......
...@@ -400,7 +400,7 @@ void AutomaticRebootManagerBasicTest::SetRebootAfterUpdate( ...@@ -400,7 +400,7 @@ void AutomaticRebootManagerBasicTest::SetRebootAfterUpdate(
base::Value::CreateBooleanValue(reboot_after_update)); base::Value::CreateBooleanValue(reboot_after_update));
task_runner_->RunUntilIdle(); task_runner_->RunUntilIdle();
EXPECT_EQ(expect_reboot ? 1 : 0, EXPECT_EQ(expect_reboot ? 1 : 0,
power_manager_client_->request_restart_call_count()); power_manager_client_->num_request_restart_calls());
} }
void AutomaticRebootManagerBasicTest::SetUptimeLimit( void AutomaticRebootManagerBasicTest::SetUptimeLimit(
...@@ -416,7 +416,7 @@ void AutomaticRebootManagerBasicTest::SetUptimeLimit( ...@@ -416,7 +416,7 @@ void AutomaticRebootManagerBasicTest::SetUptimeLimit(
} }
task_runner_->RunUntilIdle(); task_runner_->RunUntilIdle();
EXPECT_EQ(expect_reboot ? 1 : 0, EXPECT_EQ(expect_reboot ? 1 : 0,
power_manager_client_->request_restart_call_count()); power_manager_client_->num_request_restart_calls());
} }
void AutomaticRebootManagerBasicTest::NotifyUpdateRebootNeeded() { void AutomaticRebootManagerBasicTest::NotifyUpdateRebootNeeded() {
...@@ -424,14 +424,14 @@ void AutomaticRebootManagerBasicTest::NotifyUpdateRebootNeeded() { ...@@ -424,14 +424,14 @@ void AutomaticRebootManagerBasicTest::NotifyUpdateRebootNeeded() {
automatic_reboot_manager_->UpdateStatusChanged( automatic_reboot_manager_->UpdateStatusChanged(
update_engine_client_->GetLastStatus()); update_engine_client_->GetLastStatus());
task_runner_->RunUntilIdle(); task_runner_->RunUntilIdle();
EXPECT_EQ(0, power_manager_client_->request_restart_call_count()); EXPECT_EQ(0, power_manager_client_->num_request_restart_calls());
} }
void AutomaticRebootManagerBasicTest::NotifyResumed(bool expect_reboot) { void AutomaticRebootManagerBasicTest::NotifyResumed(bool expect_reboot) {
automatic_reboot_manager_->SystemResumed(base::TimeDelta::FromHours(1)); automatic_reboot_manager_->SystemResumed(base::TimeDelta::FromHours(1));
task_runner_->RunUntilIdle(); task_runner_->RunUntilIdle();
EXPECT_EQ(expect_reboot ? 1 : 0, EXPECT_EQ(expect_reboot ? 1 : 0,
power_manager_client_->request_restart_call_count()); power_manager_client_->num_request_restart_calls());
} }
void AutomaticRebootManagerBasicTest::NotifyTerminating(bool expect_reboot) { void AutomaticRebootManagerBasicTest::NotifyTerminating(bool expect_reboot) {
...@@ -441,7 +441,7 @@ void AutomaticRebootManagerBasicTest::NotifyTerminating(bool expect_reboot) { ...@@ -441,7 +441,7 @@ void AutomaticRebootManagerBasicTest::NotifyTerminating(bool expect_reboot) {
content::NotificationService::NoDetails()); content::NotificationService::NoDetails());
task_runner_->RunUntilIdle(); task_runner_->RunUntilIdle();
EXPECT_EQ(expect_reboot ? 1 : 0, EXPECT_EQ(expect_reboot ? 1 : 0,
power_manager_client_->request_restart_call_count()); power_manager_client_->num_request_restart_calls());
} }
void AutomaticRebootManagerBasicTest::FastForwardBy( void AutomaticRebootManagerBasicTest::FastForwardBy(
...@@ -449,14 +449,14 @@ void AutomaticRebootManagerBasicTest::FastForwardBy( ...@@ -449,14 +449,14 @@ void AutomaticRebootManagerBasicTest::FastForwardBy(
bool expect_reboot) { bool expect_reboot) {
task_runner_->FastForwardBy(delta); task_runner_->FastForwardBy(delta);
EXPECT_EQ(expect_reboot ? 1 : 0, EXPECT_EQ(expect_reboot ? 1 : 0,
power_manager_client_->request_restart_call_count()); power_manager_client_->num_request_restart_calls());
} }
void AutomaticRebootManagerBasicTest::FastForwardUntilNoTasksRemain( void AutomaticRebootManagerBasicTest::FastForwardUntilNoTasksRemain(
bool expect_reboot) { bool expect_reboot) {
task_runner_->FastForwardUntilNoTasksRemain(); task_runner_->FastForwardUntilNoTasksRemain();
EXPECT_EQ(expect_reboot ? 1 : 0, EXPECT_EQ(expect_reboot ? 1 : 0,
power_manager_client_->request_restart_call_count()); power_manager_client_->num_request_restart_calls());
} }
void AutomaticRebootManagerBasicTest::CreateAutomaticRebootManager( void AutomaticRebootManagerBasicTest::CreateAutomaticRebootManager(
...@@ -465,7 +465,7 @@ void AutomaticRebootManagerBasicTest::CreateAutomaticRebootManager( ...@@ -465,7 +465,7 @@ void AutomaticRebootManagerBasicTest::CreateAutomaticRebootManager(
scoped_ptr<base::TickClock>(new MockTimeTickClock(task_runner_)))); scoped_ptr<base::TickClock>(new MockTimeTickClock(task_runner_))));
task_runner_->RunUntilIdle(); task_runner_->RunUntilIdle();
EXPECT_EQ(expect_reboot ? 1 : 0, EXPECT_EQ(expect_reboot ? 1 : 0,
power_manager_client_->request_restart_call_count()); power_manager_client_->num_request_restart_calls());
uptime_processing_delay_ = uptime_processing_delay_ =
base::TimeTicks() - automatic_reboot_manager_->boot_time_ - base::TimeTicks() - automatic_reboot_manager_->boot_time_ -
......
...@@ -8,7 +8,8 @@ ...@@ -8,7 +8,8 @@
namespace chromeos { namespace chromeos {
FakePowerManagerClient::FakePowerManagerClient() FakePowerManagerClient::FakePowerManagerClient()
: request_restart_call_count_(0) { : num_request_restart_calls_(0),
num_set_policy_calls_(0) {
} }
FakePowerManagerClient::~FakePowerManagerClient() { FakePowerManagerClient::~FakePowerManagerClient() {
...@@ -31,6 +32,7 @@ void FakePowerManagerClient::RequestStatusUpdate() { ...@@ -31,6 +32,7 @@ void FakePowerManagerClient::RequestStatusUpdate() {
void FakePowerManagerClient::SetPolicy( void FakePowerManagerClient::SetPolicy(
const power_manager::PowerManagementPolicy& policy) { const power_manager::PowerManagementPolicy& policy) {
policy_ = policy; policy_ = policy;
++num_set_policy_calls_;
} }
void FakePowerManagerClient::RequestShutdown() { void FakePowerManagerClient::RequestShutdown() {
...@@ -60,7 +62,7 @@ bool FakePowerManagerClient::HasObserver(Observer* observer) { ...@@ -60,7 +62,7 @@ bool FakePowerManagerClient::HasObserver(Observer* observer) {
} }
void FakePowerManagerClient::RequestRestart() { void FakePowerManagerClient::RequestRestart() {
++request_restart_call_count_; ++num_request_restart_calls_;
} }
void FakePowerManagerClient::IncreaseKeyboardBrightness() { void FakePowerManagerClient::IncreaseKeyboardBrightness() {
......
...@@ -24,6 +24,14 @@ class FakePowerManagerClient : public PowerManagerClient { ...@@ -24,6 +24,14 @@ class FakePowerManagerClient : public PowerManagerClient {
FakePowerManagerClient(); FakePowerManagerClient();
virtual ~FakePowerManagerClient(); virtual ~FakePowerManagerClient();
power_manager::PowerManagementPolicy& policy() { return policy_; }
int num_request_restart_calls() const {
return num_request_restart_calls_;
}
int num_set_policy_calls() const {
return num_set_policy_calls_;
}
// PowerManagerClient overrides // PowerManagerClient overrides
virtual void Init(dbus::Bus* bus) OVERRIDE; virtual void Init(dbus::Bus* bus) OVERRIDE;
virtual void AddObserver(Observer* observer) OVERRIDE; virtual void AddObserver(Observer* observer) OVERRIDE;
...@@ -49,13 +57,6 @@ class FakePowerManagerClient : public PowerManagerClient { ...@@ -49,13 +57,6 @@ class FakePowerManagerClient : public PowerManagerClient {
virtual base::Closure GetSuspendReadinessCallback() OVERRIDE; virtual base::Closure GetSuspendReadinessCallback() OVERRIDE;
virtual int GetNumPendingSuspendReadinessCallbacks() OVERRIDE; virtual int GetNumPendingSuspendReadinessCallbacks() OVERRIDE;
power_manager::PowerManagementPolicy& get_policy() { return policy_; }
// Returns how many times RequestRestart() was called.
int request_restart_call_count() const {
return request_restart_call_count_;
}
// Emulates that the dbus server sends a message "SuspendImminent" to the // Emulates that the dbus server sends a message "SuspendImminent" to the
// client. // client.
void SendSuspendImminent(); void SendSuspendImminent();
...@@ -66,10 +67,19 @@ class FakePowerManagerClient : public PowerManagerClient { ...@@ -66,10 +67,19 @@ class FakePowerManagerClient : public PowerManagerClient {
const power_manager::SuspendState& suspend_state); const power_manager::SuspendState& suspend_state);
private: private:
ObserverList<Observer> observers_;
// Last policy passed to SetPolicy().
power_manager::PowerManagementPolicy policy_; power_manager::PowerManagementPolicy policy_;
// Last time passed to a SUSPEND_TO_MEMORY call to SendSuspendStateChanged().
base::Time last_suspend_wall_time_; base::Time last_suspend_wall_time_;
ObserverList<Observer> observers_;
int request_restart_call_count_; // Number of times that RequestRestart() has been called.
int num_request_restart_calls_;
// Number of times that SetPolicy() has been called.
int num_set_policy_calls_;
DISALLOW_COPY_AND_ASSIGN(FakePowerManagerClient); DISALLOW_COPY_AND_ASSIGN(FakePowerManagerClient);
}; };
......
...@@ -134,31 +134,22 @@ std::string PowerPolicyController::GetPolicyDebugString( ...@@ -134,31 +134,22 @@ std::string PowerPolicyController::GetPolicyDebugString(
} }
PowerPolicyController::PowerPolicyController() PowerPolicyController::PowerPolicyController()
: manager_(NULL), : client_(NULL),
client_(NULL),
prefs_were_set_(false), prefs_were_set_(false),
honor_screen_wake_locks_(true), honor_screen_wake_locks_(true),
next_wake_lock_id_(1) { next_wake_lock_id_(1) {
} }
PowerPolicyController::~PowerPolicyController() { PowerPolicyController::~PowerPolicyController() {
DCHECK(manager_); if (client_) {
// The power manager's policy is reset before this point, in client_->RemoveObserver(this);
// OnDBusThreadManagerDestroying(). At the time that client_ = NULL;
// PowerPolicyController is destroyed, PowerManagerClient's D-Bus proxy }
// to the power manager is already gone.
client_->RemoveObserver(this);
client_ = NULL;
manager_->RemoveObserver(this);
manager_ = NULL;
} }
void PowerPolicyController::Init(DBusThreadManager* manager) { void PowerPolicyController::Init(DBusThreadManager* manager) {
manager_ = manager; client_ = manager->GetPowerManagerClient();
manager_->AddObserver(this);
client_ = manager_->GetPowerManagerClient();
client_->AddObserver(this); client_->AddObserver(this);
SendCurrentPolicy();
} }
void PowerPolicyController::ApplyPrefs(const PrefValues& values) { void PowerPolicyController::ApplyPrefs(const PrefValues& values) {
...@@ -220,13 +211,6 @@ void PowerPolicyController::ApplyPrefs(const PrefValues& values) { ...@@ -220,13 +211,6 @@ void PowerPolicyController::ApplyPrefs(const PrefValues& values) {
SendCurrentPolicy(); SendCurrentPolicy();
} }
void PowerPolicyController::ClearPrefs() {
prefs_policy_.Clear();
honor_screen_wake_locks_ = true;
prefs_were_set_ = false;
SendCurrentPolicy();
}
int PowerPolicyController::AddScreenWakeLock(const std::string& reason) { int PowerPolicyController::AddScreenWakeLock(const std::string& reason) {
int id = next_wake_lock_id_++; int id = next_wake_lock_id_++;
screen_wake_locks_[id] = reason; screen_wake_locks_[id] = reason;
...@@ -248,12 +232,6 @@ void PowerPolicyController::RemoveWakeLock(int id) { ...@@ -248,12 +232,6 @@ void PowerPolicyController::RemoveWakeLock(int id) {
SendCurrentPolicy(); SendCurrentPolicy();
} }
void PowerPolicyController::OnDBusThreadManagerDestroying(
DBusThreadManager* manager) {
DCHECK_EQ(manager, manager_);
SendEmptyPolicy();
}
void PowerPolicyController::PowerManagerRestarted() { void PowerPolicyController::PowerManagerRestarted() {
SendCurrentPolicy(); SendCurrentPolicy();
} }
...@@ -301,8 +279,4 @@ void PowerPolicyController::SendCurrentPolicy() { ...@@ -301,8 +279,4 @@ void PowerPolicyController::SendCurrentPolicy() {
client_->SetPolicy(policy); client_->SetPolicy(policy);
} }
void PowerPolicyController::SendEmptyPolicy() {
client_->SetPolicy(power_manager::PowerManagementPolicy());
}
} // namespace chromeos } // namespace chromeos
...@@ -11,7 +11,6 @@ ...@@ -11,7 +11,6 @@
#include "base/basictypes.h" #include "base/basictypes.h"
#include "base/compiler_specific.h" #include "base/compiler_specific.h"
#include "chromeos/chromeos_export.h" #include "chromeos/chromeos_export.h"
#include "chromeos/dbus/dbus_thread_manager_observer.h"
#include "chromeos/dbus/power_manager/policy.pb.h" #include "chromeos/dbus/power_manager/policy.pb.h"
#include "chromeos/dbus/power_manager_client.h" #include "chromeos/dbus/power_manager_client.h"
...@@ -22,8 +21,7 @@ class DBusThreadManager; ...@@ -22,8 +21,7 @@ class DBusThreadManager;
// PowerPolicyController is responsible for sending Chrome's assorted power // PowerPolicyController is responsible for sending Chrome's assorted power
// management preferences to the Chrome OS power manager. // management preferences to the Chrome OS power manager.
class CHROMEOS_EXPORT PowerPolicyController class CHROMEOS_EXPORT PowerPolicyController
: public DBusThreadManagerObserver, : public PowerManagerClient::Observer {
public PowerManagerClient::Observer {
public: public:
// Note: Do not change these values; they are used by preferences. // Note: Do not change these values; they are used by preferences.
enum Action { enum Action {
...@@ -79,9 +77,6 @@ class CHROMEOS_EXPORT PowerPolicyController ...@@ -79,9 +77,6 @@ class CHROMEOS_EXPORT PowerPolicyController
// Updates |prefs_policy_| with |values| and sends an updated policy. // Updates |prefs_policy_| with |values| and sends an updated policy.
void ApplyPrefs(const PrefValues& values); void ApplyPrefs(const PrefValues& values);
// Resets |prefs_policy_| to its defaults and sends an updated policy.
void ClearPrefs();
// Registers a request to temporarily prevent the screen from getting // Registers a request to temporarily prevent the screen from getting
// dimmed or turned off or the system from suspending in response to user // dimmed or turned off or the system from suspending in response to user
// inactivity and sends an updated policy. |reason| is a human-readable // inactivity and sends an updated policy. |reason| is a human-readable
...@@ -94,10 +89,6 @@ class CHROMEOS_EXPORT PowerPolicyController ...@@ -94,10 +89,6 @@ class CHROMEOS_EXPORT PowerPolicyController
// AddSystemWakeLock() and sends an updated policy. // AddSystemWakeLock() and sends an updated policy.
void RemoveWakeLock(int id); void RemoveWakeLock(int id);
// DBusThreadManagerObserver implementation:
virtual void OnDBusThreadManagerDestroying(DBusThreadManager* manager)
OVERRIDE;
// PowerManagerClient::Observer implementation: // PowerManagerClient::Observer implementation:
virtual void PowerManagerRestarted() OVERRIDE; virtual void PowerManagerRestarted() OVERRIDE;
...@@ -109,11 +100,7 @@ class CHROMEOS_EXPORT PowerPolicyController ...@@ -109,11 +100,7 @@ class CHROMEOS_EXPORT PowerPolicyController
// Sends a policy based on |prefs_policy_| to the power manager. // Sends a policy based on |prefs_policy_| to the power manager.
void SendCurrentPolicy(); void SendCurrentPolicy();
// Sends an empty policy to the power manager to reset its configuration. PowerManagerClient* client_; // weak
void SendEmptyPolicy();
DBusThreadManager* manager_; // not owned
PowerManagerClient* client_; // not owned
// Policy derived from values passed to ApplyPrefs(). // Policy derived from values passed to ApplyPrefs().
power_manager::PowerManagementPolicy prefs_policy_; power_manager::PowerManagementPolicy prefs_policy_;
......
...@@ -91,7 +91,7 @@ TEST_F(PowerPolicyControllerTest, Prefs) { ...@@ -91,7 +91,7 @@ TEST_F(PowerPolicyControllerTest, Prefs) {
expected_policy.set_reason("Prefs"); expected_policy.set_reason("Prefs");
EXPECT_EQ(PowerPolicyController::GetPolicyDebugString(expected_policy), EXPECT_EQ(PowerPolicyController::GetPolicyDebugString(expected_policy),
PowerPolicyController::GetPolicyDebugString( PowerPolicyController::GetPolicyDebugString(
fake_power_client_->get_policy())); fake_power_client_->policy()));
// Change some prefs and check that an updated policy is sent. // Change some prefs and check that an updated policy is sent.
prefs.ac_idle_warning_delay_ms = 700000; prefs.ac_idle_warning_delay_ms = 700000;
...@@ -106,7 +106,7 @@ TEST_F(PowerPolicyControllerTest, Prefs) { ...@@ -106,7 +106,7 @@ TEST_F(PowerPolicyControllerTest, Prefs) {
expected_policy.clear_ac_brightness_percent(); expected_policy.clear_ac_brightness_percent();
EXPECT_EQ(PowerPolicyController::GetPolicyDebugString(expected_policy), EXPECT_EQ(PowerPolicyController::GetPolicyDebugString(expected_policy),
PowerPolicyController::GetPolicyDebugString( PowerPolicyController::GetPolicyDebugString(
fake_power_client_->get_policy())); fake_power_client_->policy()));
// The enable-screen-lock pref should force the screen-lock delays to // The enable-screen-lock pref should force the screen-lock delays to
// match the screen-off delays plus a constant value. // match the screen-off delays plus a constant value.
...@@ -118,7 +118,7 @@ TEST_F(PowerPolicyControllerTest, Prefs) { ...@@ -118,7 +118,7 @@ TEST_F(PowerPolicyControllerTest, Prefs) {
360000 + PowerPolicyController::kScreenLockAfterOffDelayMs); 360000 + PowerPolicyController::kScreenLockAfterOffDelayMs);
EXPECT_EQ(PowerPolicyController::GetPolicyDebugString(expected_policy), EXPECT_EQ(PowerPolicyController::GetPolicyDebugString(expected_policy),
PowerPolicyController::GetPolicyDebugString( PowerPolicyController::GetPolicyDebugString(
fake_power_client_->get_policy())); fake_power_client_->policy()));
// If the screen-lock-delay prefs are set to lower values than the // If the screen-lock-delay prefs are set to lower values than the
// screen-off delays plus the constant, the lock prefs should take // screen-off delays plus the constant, the lock prefs should take
...@@ -130,7 +130,7 @@ TEST_F(PowerPolicyControllerTest, Prefs) { ...@@ -130,7 +130,7 @@ TEST_F(PowerPolicyControllerTest, Prefs) {
expected_policy.mutable_battery_delays()->set_screen_lock_ms(60000); expected_policy.mutable_battery_delays()->set_screen_lock_ms(60000);
EXPECT_EQ(PowerPolicyController::GetPolicyDebugString(expected_policy), EXPECT_EQ(PowerPolicyController::GetPolicyDebugString(expected_policy),
PowerPolicyController::GetPolicyDebugString( PowerPolicyController::GetPolicyDebugString(
fake_power_client_->get_policy())); fake_power_client_->policy()));
// If the artificial screen-lock delays would exceed the idle delay, they // If the artificial screen-lock delays would exceed the idle delay, they
// shouldn't be set -- the power manager would ignore them since the // shouldn't be set -- the power manager would ignore them since the
...@@ -148,7 +148,7 @@ TEST_F(PowerPolicyControllerTest, Prefs) { ...@@ -148,7 +148,7 @@ TEST_F(PowerPolicyControllerTest, Prefs) {
expected_policy.mutable_battery_delays()->set_screen_lock_ms(-1); expected_policy.mutable_battery_delays()->set_screen_lock_ms(-1);
EXPECT_EQ(PowerPolicyController::GetPolicyDebugString(expected_policy), EXPECT_EQ(PowerPolicyController::GetPolicyDebugString(expected_policy),
PowerPolicyController::GetPolicyDebugString( PowerPolicyController::GetPolicyDebugString(
fake_power_client_->get_policy())); fake_power_client_->policy()));
// Set the "allow screen wake locks" pref to false. The system should be // Set the "allow screen wake locks" pref to false. The system should be
// prevented from suspending due to user inactivity on AC power but the // prevented from suspending due to user inactivity on AC power but the
...@@ -161,7 +161,7 @@ TEST_F(PowerPolicyControllerTest, Prefs) { ...@@ -161,7 +161,7 @@ TEST_F(PowerPolicyControllerTest, Prefs) {
expected_policy.set_reason("Prefs, Screen"); expected_policy.set_reason("Prefs, Screen");
EXPECT_EQ(PowerPolicyController::GetPolicyDebugString(expected_policy), EXPECT_EQ(PowerPolicyController::GetPolicyDebugString(expected_policy),
PowerPolicyController::GetPolicyDebugString( PowerPolicyController::GetPolicyDebugString(
fake_power_client_->get_policy())); fake_power_client_->policy()));
} }
TEST_F(PowerPolicyControllerTest, WakeLocks) { TEST_F(PowerPolicyControllerTest, WakeLocks) {
...@@ -176,7 +176,7 @@ TEST_F(PowerPolicyControllerTest, WakeLocks) { ...@@ -176,7 +176,7 @@ TEST_F(PowerPolicyControllerTest, WakeLocks) {
expected_policy.set_reason(kSystemWakeLockReason); expected_policy.set_reason(kSystemWakeLockReason);
EXPECT_EQ(PowerPolicyController::GetPolicyDebugString(expected_policy), EXPECT_EQ(PowerPolicyController::GetPolicyDebugString(expected_policy),
PowerPolicyController::GetPolicyDebugString( PowerPolicyController::GetPolicyDebugString(
fake_power_client_->get_policy())); fake_power_client_->policy()));
const char kScreenWakeLockReason[] = "screen"; const char kScreenWakeLockReason[] = "screen";
const int screen_id = policy_controller_->AddScreenWakeLock( const int screen_id = policy_controller_->AddScreenWakeLock(
...@@ -191,19 +191,27 @@ TEST_F(PowerPolicyControllerTest, WakeLocks) { ...@@ -191,19 +191,27 @@ TEST_F(PowerPolicyControllerTest, WakeLocks) {
std::string(kScreenWakeLockReason) + ", " + kSystemWakeLockReason); std::string(kScreenWakeLockReason) + ", " + kSystemWakeLockReason);
EXPECT_EQ(PowerPolicyController::GetPolicyDebugString(expected_policy), EXPECT_EQ(PowerPolicyController::GetPolicyDebugString(expected_policy),
PowerPolicyController::GetPolicyDebugString( PowerPolicyController::GetPolicyDebugString(
fake_power_client_->get_policy())); fake_power_client_->policy()));
policy_controller_->RemoveWakeLock(system_id); policy_controller_->RemoveWakeLock(system_id);
expected_policy.set_reason(kScreenWakeLockReason); expected_policy.set_reason(kScreenWakeLockReason);
EXPECT_EQ(PowerPolicyController::GetPolicyDebugString(expected_policy), EXPECT_EQ(PowerPolicyController::GetPolicyDebugString(expected_policy),
PowerPolicyController::GetPolicyDebugString( PowerPolicyController::GetPolicyDebugString(
fake_power_client_->get_policy())); fake_power_client_->policy()));
policy_controller_->RemoveWakeLock(screen_id); policy_controller_->RemoveWakeLock(screen_id);
expected_policy.Clear(); expected_policy.Clear();
EXPECT_EQ(PowerPolicyController::GetPolicyDebugString(expected_policy), EXPECT_EQ(PowerPolicyController::GetPolicyDebugString(expected_policy),
PowerPolicyController::GetPolicyDebugString( PowerPolicyController::GetPolicyDebugString(
fake_power_client_->get_policy())); fake_power_client_->policy()));
}
TEST_F(PowerPolicyControllerTest, AvoidSendingEmptyPolicies) {
// Check that empty policies aren't sent when PowerPolicyController is created
// or destroyed.
EXPECT_EQ(0, fake_power_client_->num_set_policy_calls());
policy_controller_.reset();
EXPECT_EQ(0, fake_power_client_->num_set_policy_calls());
} }
} // namespace chromeos } // namespace chromeos
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