Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(7)

Side by Side Diff: chromeos/dbus/power_policy_controller.cc

Issue 129303003: Revert of Revert of chromeos: Don't send empty power management policies. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
127 str += base::StringPrintf("wait_for_initial_user_activity=%d ", 127 str += base::StringPrintf("wait_for_initial_user_activity=%d ",
128 policy.wait_for_initial_user_activity()); 128 policy.wait_for_initial_user_activity());
129 } 129 }
130 if (policy.has_reason()) 130 if (policy.has_reason())
131 str += base::StringPrintf("reason=\"%s\" ", policy.reason().c_str()); 131 str += base::StringPrintf("reason=\"%s\" ", policy.reason().c_str());
132 TrimWhitespace(str, TRIM_TRAILING, &str); 132 TrimWhitespace(str, TRIM_TRAILING, &str);
133 return str; 133 return str;
134 } 134 }
135 135
136 PowerPolicyController::PowerPolicyController() 136 PowerPolicyController::PowerPolicyController()
137 : manager_(NULL), 137 : client_(NULL),
138 client_(NULL),
139 prefs_were_set_(false), 138 prefs_were_set_(false),
140 honor_screen_wake_locks_(true), 139 honor_screen_wake_locks_(true),
141 next_wake_lock_id_(1) { 140 next_wake_lock_id_(1) {
142 } 141 }
143 142
144 PowerPolicyController::~PowerPolicyController() { 143 PowerPolicyController::~PowerPolicyController() {
145 DCHECK(manager_); 144 if (client_) {
146 // The power manager's policy is reset before this point, in 145 client_->RemoveObserver(this);
147 // OnDBusThreadManagerDestroying(). At the time that 146 client_ = NULL;
148 // PowerPolicyController is destroyed, PowerManagerClient's D-Bus proxy 147 }
149 // to the power manager is already gone.
150 client_->RemoveObserver(this);
151 client_ = NULL;
152 manager_->RemoveObserver(this);
153 manager_ = NULL;
154 } 148 }
155 149
156 void PowerPolicyController::Init(DBusThreadManager* manager) { 150 void PowerPolicyController::Init(DBusThreadManager* manager) {
157 manager_ = manager; 151 client_ = manager->GetPowerManagerClient();
158 manager_->AddObserver(this);
159 client_ = manager_->GetPowerManagerClient();
160 client_->AddObserver(this); 152 client_->AddObserver(this);
161 SendCurrentPolicy();
162 } 153 }
163 154
164 void PowerPolicyController::ApplyPrefs(const PrefValues& values) { 155 void PowerPolicyController::ApplyPrefs(const PrefValues& values) {
165 prefs_policy_.Clear(); 156 prefs_policy_.Clear();
166 157
167 power_manager::PowerManagementPolicy::Delays* delays = 158 power_manager::PowerManagementPolicy::Delays* delays =
168 prefs_policy_.mutable_ac_delays(); 159 prefs_policy_.mutable_ac_delays();
169 delays->set_screen_dim_ms(values.ac_screen_dim_delay_ms); 160 delays->set_screen_dim_ms(values.ac_screen_dim_delay_ms);
170 delays->set_screen_off_ms(values.ac_screen_off_delay_ms); 161 delays->set_screen_off_ms(values.ac_screen_off_delay_ms);
171 delays->set_screen_lock_ms(values.ac_screen_lock_delay_ms); 162 delays->set_screen_lock_ms(values.ac_screen_lock_delay_ms);
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
213 values.user_activity_screen_dim_delay_factor); 204 values.user_activity_screen_dim_delay_factor);
214 prefs_policy_.set_wait_for_initial_user_activity( 205 prefs_policy_.set_wait_for_initial_user_activity(
215 values.wait_for_initial_user_activity); 206 values.wait_for_initial_user_activity);
216 207
217 honor_screen_wake_locks_ = values.allow_screen_wake_locks; 208 honor_screen_wake_locks_ = values.allow_screen_wake_locks;
218 209
219 prefs_were_set_ = true; 210 prefs_were_set_ = true;
220 SendCurrentPolicy(); 211 SendCurrentPolicy();
221 } 212 }
222 213
223 void PowerPolicyController::ClearPrefs() {
224 prefs_policy_.Clear();
225 honor_screen_wake_locks_ = true;
226 prefs_were_set_ = false;
227 SendCurrentPolicy();
228 }
229
230 int PowerPolicyController::AddScreenWakeLock(const std::string& reason) { 214 int PowerPolicyController::AddScreenWakeLock(const std::string& reason) {
231 int id = next_wake_lock_id_++; 215 int id = next_wake_lock_id_++;
232 screen_wake_locks_[id] = reason; 216 screen_wake_locks_[id] = reason;
233 SendCurrentPolicy(); 217 SendCurrentPolicy();
234 return id; 218 return id;
235 } 219 }
236 220
237 int PowerPolicyController::AddSystemWakeLock(const std::string& reason) { 221 int PowerPolicyController::AddSystemWakeLock(const std::string& reason) {
238 int id = next_wake_lock_id_++; 222 int id = next_wake_lock_id_++;
239 system_wake_locks_[id] = reason; 223 system_wake_locks_[id] = reason;
240 SendCurrentPolicy(); 224 SendCurrentPolicy();
241 return id; 225 return id;
242 } 226 }
243 227
244 void PowerPolicyController::RemoveWakeLock(int id) { 228 void PowerPolicyController::RemoveWakeLock(int id) {
245 if (!screen_wake_locks_.erase(id) && !system_wake_locks_.erase(id)) 229 if (!screen_wake_locks_.erase(id) && !system_wake_locks_.erase(id))
246 LOG(WARNING) << "Ignoring request to remove nonexistent wake lock " << id; 230 LOG(WARNING) << "Ignoring request to remove nonexistent wake lock " << id;
247 else 231 else
248 SendCurrentPolicy(); 232 SendCurrentPolicy();
249 } 233 }
250 234
251 void PowerPolicyController::OnDBusThreadManagerDestroying(
252 DBusThreadManager* manager) {
253 DCHECK_EQ(manager, manager_);
254 SendEmptyPolicy();
255 }
256
257 void PowerPolicyController::PowerManagerRestarted() { 235 void PowerPolicyController::PowerManagerRestarted() {
258 SendCurrentPolicy(); 236 SendCurrentPolicy();
259 } 237 }
260 238
261 void PowerPolicyController::SendCurrentPolicy() { 239 void PowerPolicyController::SendCurrentPolicy() {
262 std::string reason; 240 std::string reason;
263 241
264 power_manager::PowerManagementPolicy policy = prefs_policy_; 242 power_manager::PowerManagementPolicy policy = prefs_policy_;
265 if (prefs_were_set_) 243 if (prefs_were_set_)
266 reason = "Prefs"; 244 reason = "Prefs";
(...skipping 27 matching lines...) Expand all
294 for (WakeLockMap::const_iterator it = system_wake_locks_.begin(); 272 for (WakeLockMap::const_iterator it = system_wake_locks_.begin();
295 it != system_wake_locks_.end(); ++it) { 273 it != system_wake_locks_.end(); ++it) {
296 reason += (reason.empty() ? "" : ", ") + it->second; 274 reason += (reason.empty() ? "" : ", ") + it->second;
297 } 275 }
298 276
299 if (!reason.empty()) 277 if (!reason.empty())
300 policy.set_reason(reason); 278 policy.set_reason(reason);
301 client_->SetPolicy(policy); 279 client_->SetPolicy(policy);
302 } 280 }
303 281
304 void PowerPolicyController::SendEmptyPolicy() {
305 client_->SetPolicy(power_manager::PowerManagementPolicy());
306 }
307
308 } // namespace chromeos 282 } // namespace chromeos
OLDNEW
« no previous file with comments | « chromeos/dbus/power_policy_controller.h ('k') | chromeos/dbus/power_policy_controller_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698