OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chromeos/dbus/power_policy_controller.h" | 5 #include "chromeos/dbus/power_policy_controller.h" |
6 | 6 |
7 #include "base/format_macros.h" | 7 #include "base/format_macros.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "base/strings/string_util.h" | 9 #include "base/strings/string_util.h" |
10 #include "base/strings/stringprintf.h" | 10 #include "base/strings/stringprintf.h" |
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
116 if (policy.has_wait_for_initial_user_activity()) { | 116 if (policy.has_wait_for_initial_user_activity()) { |
117 str += base::StringPrintf("wait_for_initial_user_activity=%d ", | 117 str += base::StringPrintf("wait_for_initial_user_activity=%d ", |
118 policy.wait_for_initial_user_activity()); | 118 policy.wait_for_initial_user_activity()); |
119 } | 119 } |
120 if (policy.has_reason()) | 120 if (policy.has_reason()) |
121 str += base::StringPrintf("reason=\"%s\" ", policy.reason().c_str()); | 121 str += base::StringPrintf("reason=\"%s\" ", policy.reason().c_str()); |
122 TrimWhitespace(str, TRIM_TRAILING, &str); | 122 TrimWhitespace(str, TRIM_TRAILING, &str); |
123 return str; | 123 return str; |
124 } | 124 } |
125 | 125 |
126 PowerPolicyController::PowerPolicyController(DBusThreadManager* manager, | 126 PowerPolicyController::PowerPolicyController() |
127 PowerManagerClient* client) | 127 : manager_(NULL), |
128 : manager_(manager), | 128 client_(NULL), |
129 client_(client), | |
130 prefs_were_set_(false), | 129 prefs_were_set_(false), |
131 honor_screen_wake_locks_(true), | 130 honor_screen_wake_locks_(true), |
132 next_wake_lock_id_(1) { | 131 next_wake_lock_id_(1) { |
133 manager_->AddObserver(this); | |
134 client_->AddObserver(this); | |
135 SendCurrentPolicy(); | |
136 } | 132 } |
137 | 133 |
138 PowerPolicyController::~PowerPolicyController() { | 134 PowerPolicyController::~PowerPolicyController() { |
| 135 DCHECK(manager_); |
139 // The power manager's policy is reset before this point, in | 136 // The power manager's policy is reset before this point, in |
140 // OnDBusThreadManagerDestroying(). At the time that | 137 // OnDBusThreadManagerDestroying(). At the time that |
141 // PowerPolicyController is destroyed, PowerManagerClient's D-Bus proxy | 138 // PowerPolicyController is destroyed, PowerManagerClient's D-Bus proxy |
142 // to the power manager is already gone. | 139 // to the power manager is already gone. |
143 client_->RemoveObserver(this); | 140 client_->RemoveObserver(this); |
144 client_ = NULL; | 141 client_ = NULL; |
145 manager_->RemoveObserver(this); | 142 manager_->RemoveObserver(this); |
146 manager_ = NULL; | 143 manager_ = NULL; |
147 } | 144 } |
148 | 145 |
| 146 void PowerPolicyController::Init(DBusThreadManager* manager) { |
| 147 manager_ = manager; |
| 148 manager_->AddObserver(this); |
| 149 client_ = manager_->GetPowerManagerClient(); |
| 150 client_->AddObserver(this); |
| 151 SendCurrentPolicy(); |
| 152 } |
| 153 |
149 void PowerPolicyController::ApplyPrefs(const PrefValues& values) { | 154 void PowerPolicyController::ApplyPrefs(const PrefValues& values) { |
150 prefs_policy_.Clear(); | 155 prefs_policy_.Clear(); |
151 | 156 |
152 power_manager::PowerManagementPolicy::Delays* delays = | 157 power_manager::PowerManagementPolicy::Delays* delays = |
153 prefs_policy_.mutable_ac_delays(); | 158 prefs_policy_.mutable_ac_delays(); |
154 delays->set_screen_dim_ms(values.ac_screen_dim_delay_ms); | 159 delays->set_screen_dim_ms(values.ac_screen_dim_delay_ms); |
155 delays->set_screen_off_ms(values.ac_screen_off_delay_ms); | 160 delays->set_screen_off_ms(values.ac_screen_off_delay_ms); |
156 delays->set_screen_lock_ms(values.ac_screen_lock_delay_ms); | 161 delays->set_screen_lock_ms(values.ac_screen_lock_delay_ms); |
157 delays->set_idle_warning_ms(values.ac_idle_warning_delay_ms); | 162 delays->set_idle_warning_ms(values.ac_idle_warning_delay_ms); |
158 delays->set_idle_ms(values.ac_idle_delay_ms); | 163 delays->set_idle_ms(values.ac_idle_delay_ms); |
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
278 if (!reason.empty()) | 283 if (!reason.empty()) |
279 policy.set_reason(reason); | 284 policy.set_reason(reason); |
280 client_->SetPolicy(policy); | 285 client_->SetPolicy(policy); |
281 } | 286 } |
282 | 287 |
283 void PowerPolicyController::SendEmptyPolicy() { | 288 void PowerPolicyController::SendEmptyPolicy() { |
284 client_->SetPolicy(power_manager::PowerManagementPolicy()); | 289 client_->SetPolicy(power_manager::PowerManagementPolicy()); |
285 } | 290 } |
286 | 291 |
287 } // namespace chromeos | 292 } // namespace chromeos |
OLD | NEW |