From 10d04d455e223f608af021ac2faaed9e5a04fd37 Mon Sep 17 00:00:00 2001 From: "noamsml@chromium.org" Date: Wed, 8 Jan 2014 20:17:32 +0000 Subject: Revert of https://codereview.chromium.org/116983008/ Reason for revert: ChromeOS bot failures on x86/amd64 TBR=bartfab@chromium.org,benwells@chromium.org,derat@chromium.org NOTREECHECKS=true NOTRY=true BUG=329930 Review URL: https://codereview.chromium.org/129193002 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@243634 0039d316-1c4b-4281-b951-d872f2087c98 --- chromeos/dbus/power_policy_controller.cc | 38 +++++++++++++++++++++++++++----- 1 file changed, 32 insertions(+), 6 deletions(-) (limited to 'chromeos/dbus/power_policy_controller.cc') diff --git a/chromeos/dbus/power_policy_controller.cc b/chromeos/dbus/power_policy_controller.cc index 6cd696f..e7888ee 100644 --- a/chromeos/dbus/power_policy_controller.cc +++ b/chromeos/dbus/power_policy_controller.cc @@ -134,22 +134,31 @@ std::string PowerPolicyController::GetPolicyDebugString( } PowerPolicyController::PowerPolicyController() - : client_(NULL), + : manager_(NULL), + client_(NULL), prefs_were_set_(false), honor_screen_wake_locks_(true), next_wake_lock_id_(1) { } PowerPolicyController::~PowerPolicyController() { - if (client_) { - client_->RemoveObserver(this); - client_ = NULL; - } + DCHECK(manager_); + // The power manager's policy is reset before this point, in + // OnDBusThreadManagerDestroying(). At the time that + // 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) { - client_ = manager->GetPowerManagerClient(); + manager_ = manager; + manager_->AddObserver(this); + client_ = manager_->GetPowerManagerClient(); client_->AddObserver(this); + SendCurrentPolicy(); } void PowerPolicyController::ApplyPrefs(const PrefValues& values) { @@ -211,6 +220,13 @@ void PowerPolicyController::ApplyPrefs(const PrefValues& values) { 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 id = next_wake_lock_id_++; screen_wake_locks_[id] = reason; @@ -232,6 +248,12 @@ void PowerPolicyController::RemoveWakeLock(int id) { SendCurrentPolicy(); } +void PowerPolicyController::OnDBusThreadManagerDestroying( + DBusThreadManager* manager) { + DCHECK_EQ(manager, manager_); + SendEmptyPolicy(); +} + void PowerPolicyController::PowerManagerRestarted() { SendCurrentPolicy(); } @@ -279,4 +301,8 @@ void PowerPolicyController::SendCurrentPolicy() { client_->SetPolicy(policy); } +void PowerPolicyController::SendEmptyPolicy() { + client_->SetPolicy(power_manager::PowerManagementPolicy()); +} + } // namespace chromeos -- cgit v1.1