summaryrefslogtreecommitdiffstats
path: root/chromeos/dbus/power_policy_controller.cc
diff options
context:
space:
mode:
authornoamsml@chromium.org <noamsml@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-01-08 20:17:32 +0000
committernoamsml@chromium.org <noamsml@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-01-08 20:17:32 +0000
commit10d04d455e223f608af021ac2faaed9e5a04fd37 (patch)
tree42cfc9d294bdc8a89202517eab9984400de3c001 /chromeos/dbus/power_policy_controller.cc
parent0fda73aa4bdeeb0cc13aeea0f4adca3ee0a374cd (diff)
downloadchromium_src-10d04d455e223f608af021ac2faaed9e5a04fd37.zip
chromium_src-10d04d455e223f608af021ac2faaed9e5a04fd37.tar.gz
chromium_src-10d04d455e223f608af021ac2faaed9e5a04fd37.tar.bz2
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
Diffstat (limited to 'chromeos/dbus/power_policy_controller.cc')
-rw-r--r--chromeos/dbus/power_policy_controller.cc38
1 files changed, 32 insertions, 6 deletions
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