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

Side by Side Diff: chrome/browser/chromeos/dbus/power_manager_client.cc

Issue 8976012: chromeos: Implement power button animations for Aura. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: update copyright year to 2012 Created 8 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) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "chrome/browser/chromeos/dbus/power_manager_client.h" 5 #include "chrome/browser/chromeos/dbus/power_manager_client.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/callback.h" 10 #include "base/callback.h"
11 #include "base/format_macros.h" 11 #include "base/format_macros.h"
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
68 // manager knows the actual brightness level. We don't cache the 68 // manager knows the actual brightness level. We don't cache the
69 // brightness level in Chrome as it'll make things less reliable. 69 // brightness level in Chrome as it'll make things less reliable.
70 power_manager_proxy_->ConnectToSignal( 70 power_manager_proxy_->ConnectToSignal(
71 power_manager::kPowerManagerInterface, 71 power_manager::kPowerManagerInterface,
72 power_manager::kBrightnessChangedSignal, 72 power_manager::kBrightnessChangedSignal,
73 base::Bind(&PowerManagerClientImpl::BrightnessChangedReceived, 73 base::Bind(&PowerManagerClientImpl::BrightnessChangedReceived,
74 weak_ptr_factory_.GetWeakPtr()), 74 weak_ptr_factory_.GetWeakPtr()),
75 base::Bind(&PowerManagerClientImpl::SignalConnected, 75 base::Bind(&PowerManagerClientImpl::SignalConnected,
76 weak_ptr_factory_.GetWeakPtr())); 76 weak_ptr_factory_.GetWeakPtr()));
77 77
78 // Monitor the D-Bus signal for power supply polling signals.
79 power_manager_proxy_->ConnectToSignal( 78 power_manager_proxy_->ConnectToSignal(
80 power_manager::kPowerManagerInterface, 79 power_manager::kPowerManagerInterface,
81 power_manager::kPowerSupplyPollSignal, 80 power_manager::kPowerSupplyPollSignal,
82 base::Bind(&PowerManagerClientImpl::PowerSupplyPollReceived, 81 base::Bind(&PowerManagerClientImpl::PowerSupplyPollReceived,
83 weak_ptr_factory_.GetWeakPtr()), 82 weak_ptr_factory_.GetWeakPtr()),
84 base::Bind(&PowerManagerClientImpl::SignalConnected, 83 base::Bind(&PowerManagerClientImpl::SignalConnected,
85 weak_ptr_factory_.GetWeakPtr())); 84 weak_ptr_factory_.GetWeakPtr()));
86 85
87 // Monitor the D-Bus signal for power state changed signals.
88 power_manager_proxy_->ConnectToSignal( 86 power_manager_proxy_->ConnectToSignal(
89 power_manager::kPowerManagerInterface, 87 power_manager::kPowerManagerInterface,
90 power_manager::kPowerStateChangedSignal, 88 power_manager::kPowerStateChangedSignal,
91 base::Bind(&PowerManagerClientImpl::PowerStateChangedSignalReceived, 89 base::Bind(&PowerManagerClientImpl::PowerStateChangedSignalReceived,
92 weak_ptr_factory_.GetWeakPtr()), 90 weak_ptr_factory_.GetWeakPtr()),
93 base::Bind(&PowerManagerClientImpl::SignalConnected, 91 base::Bind(&PowerManagerClientImpl::SignalConnected,
94 weak_ptr_factory_.GetWeakPtr())); 92 weak_ptr_factory_.GetWeakPtr()));
95 93
96 // Monitor the D-Bus signal for screen lock and unlock signals. 94 power_manager_proxy_->ConnectToSignal(
95 power_manager::kPowerManagerInterface,
96 power_manager::kButtonEventSignal,
97 base::Bind(&PowerManagerClientImpl::ButtonEventSignalReceived,
98 weak_ptr_factory_.GetWeakPtr()),
99 base::Bind(&PowerManagerClientImpl::SignalConnected,
100 weak_ptr_factory_.GetWeakPtr()));
101
97 power_manager_proxy_->ConnectToSignal( 102 power_manager_proxy_->ConnectToSignal(
98 chromium::kChromiumInterface, 103 chromium::kChromiumInterface,
99 chromium::kLockScreenSignal, 104 chromium::kLockScreenSignal,
100 base::Bind(&PowerManagerClientImpl::ScreenLockSignalReceived, 105 base::Bind(&PowerManagerClientImpl::ScreenLockSignalReceived,
101 weak_ptr_factory_.GetWeakPtr()), 106 weak_ptr_factory_.GetWeakPtr()),
102 base::Bind(&PowerManagerClientImpl::SignalConnected, 107 base::Bind(&PowerManagerClientImpl::SignalConnected,
103 weak_ptr_factory_.GetWeakPtr())); 108 weak_ptr_factory_.GetWeakPtr()));
109
104 power_manager_proxy_->ConnectToSignal( 110 power_manager_proxy_->ConnectToSignal(
105 chromium::kChromiumInterface, 111 chromium::kChromiumInterface,
106 chromium::kUnlockScreenSignal, 112 chromium::kUnlockScreenSignal,
107 base::Bind(&PowerManagerClientImpl::ScreenUnlockSignalReceived, 113 base::Bind(&PowerManagerClientImpl::ScreenUnlockSignalReceived,
108 weak_ptr_factory_.GetWeakPtr()), 114 weak_ptr_factory_.GetWeakPtr()),
109 base::Bind(&PowerManagerClientImpl::SignalConnected, 115 base::Bind(&PowerManagerClientImpl::SignalConnected,
110 weak_ptr_factory_.GetWeakPtr())); 116 weak_ptr_factory_.GetWeakPtr()));
111 power_manager_proxy_->ConnectToSignal( 117 power_manager_proxy_->ConnectToSignal(
112 chromium::kChromiumInterface, 118 chromium::kChromiumInterface,
113 chromium::kUnlockScreenFailedSignal, 119 chromium::kUnlockScreenFailedSignal,
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
228 // Make a method call to power manager with no arguments and no response. 234 // Make a method call to power manager with no arguments and no response.
229 void SimpleMethodCallToPowerManager(const std::string& method_name) { 235 void SimpleMethodCallToPowerManager(const std::string& method_name) {
230 dbus::MethodCall method_call(power_manager::kPowerManagerInterface, 236 dbus::MethodCall method_call(power_manager::kPowerManagerInterface,
231 method_name); 237 method_name);
232 power_manager_proxy_->CallMethod( 238 power_manager_proxy_->CallMethod(
233 &method_call, 239 &method_call,
234 dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, 240 dbus::ObjectProxy::TIMEOUT_USE_DEFAULT,
235 dbus::ObjectProxy::EmptyResponseCallback()); 241 dbus::ObjectProxy::EmptyResponseCallback());
236 } 242 }
237 243
238 // Called when a brightness change signal is received.
239 void BrightnessChangedReceived(dbus::Signal* signal) { 244 void BrightnessChangedReceived(dbus::Signal* signal) {
240 dbus::MessageReader reader(signal); 245 dbus::MessageReader reader(signal);
241 int32 brightness_level = 0; 246 int32 brightness_level = 0;
242 bool user_initiated = 0; 247 bool user_initiated = 0;
243 if (!(reader.PopInt32(&brightness_level) && 248 if (!(reader.PopInt32(&brightness_level) &&
244 reader.PopBool(&user_initiated))) { 249 reader.PopBool(&user_initiated))) {
245 LOG(ERROR) << "Brightness changed signal had incorrect parameters: " 250 LOG(ERROR) << "Brightness changed signal had incorrect parameters: "
246 << signal->ToString(); 251 << signal->ToString();
247 return; 252 return;
248 } 253 }
249 VLOG(1) << "Brightness changed to " << brightness_level 254 VLOG(1) << "Brightness changed to " << brightness_level
250 << ": user initiated " << user_initiated; 255 << ": user initiated " << user_initiated;
251 FOR_EACH_OBSERVER(Observer, observers_, 256 FOR_EACH_OBSERVER(Observer, observers_,
252 BrightnessChanged(brightness_level, user_initiated)); 257 BrightnessChanged(brightness_level, user_initiated));
253 } 258 }
254 259
255 // Called when a response for DecreaseScreenBrightness() is received.
256 void OnDecreaseScreenBrightness(dbus::Response* response) { 260 void OnDecreaseScreenBrightness(dbus::Response* response) {
257 if (!response) { 261 if (!response) {
258 LOG(ERROR) << "Failed to decrease screen brightness"; 262 LOG(ERROR) << "Failed to decrease screen brightness";
259 return; 263 return;
260 } 264 }
261 VLOG(1) << "screen brightness increased: " << response->ToString(); 265 VLOG(1) << "screen brightness increased: " << response->ToString();
262 } 266 }
263 267
264 // Called when a response for IncreaseScreenBrightness() is received.
265 void OnIncreaseScreenBrightness(dbus::Response* response) { 268 void OnIncreaseScreenBrightness(dbus::Response* response) {
266 if (!response) { 269 if (!response) {
267 LOG(ERROR) << "Failed to increase screen brightness"; 270 LOG(ERROR) << "Failed to increase screen brightness";
268 return; 271 return;
269 } 272 }
270 VLOG(1) << "screen brightness increased: " << response->ToString(); 273 VLOG(1) << "screen brightness increased: " << response->ToString();
271 } 274 }
272 275
273 // Called when a power state changed signal is received.
274 void PowerStateChangedSignalReceived(dbus::Signal* signal) { 276 void PowerStateChangedSignalReceived(dbus::Signal* signal) {
275 VLOG(1) << "Received power state changed signal."; 277 VLOG(1) << "Received power state changed signal.";
276 dbus::MessageReader reader(signal); 278 dbus::MessageReader reader(signal);
277 std::string power_state_string; 279 std::string power_state_string;
278 if (!reader.PopString(&power_state_string)) { 280 if (!reader.PopString(&power_state_string)) {
279 LOG(ERROR) << "Error reading signal args: " << signal->ToString(); 281 LOG(ERROR) << "Error reading signal args: " << signal->ToString();
280 return; 282 return;
281 } 283 }
282 if (power_state_string != "on") 284 if (power_state_string != "on")
283 return; 285 return;
284 // Notify all observers of resume event.
285 FOR_EACH_OBSERVER(Observer, observers_, SystemResumed()); 286 FOR_EACH_OBSERVER(Observer, observers_, SystemResumed());
286 } 287 }
287 288
288 // Called when a power supply polling signal is received. 289 void ButtonEventSignalReceived(dbus::Signal* signal) {
290 dbus::MessageReader reader(signal);
291 std::string button_name;
292 bool down = false;
293 int64 timestamp_internal = 0;
294 if (!reader.PopString(&button_name) ||
295 !reader.PopBool(&down) ||
296 !reader.PopInt64(&timestamp_internal)) {
297 LOG(ERROR) << "Button signal had incorrect parameters: "
298 << signal->ToString();
299 return;
300 }
301 base::TimeTicks timestamp =
302 base::TimeTicks::FromInternalValue(timestamp_internal);
303
304 if (button_name == power_manager::kPowerButtonName) {
305 FOR_EACH_OBSERVER(
306 Observer, observers_, PowerButtonStateChanged(down, timestamp));
307 } else if (button_name == power_manager::kLockButtonName) {
308 FOR_EACH_OBSERVER(
309 Observer, observers_, LockButtonStateChanged(down, timestamp));
310 }
311 }
312
289 void PowerSupplyPollReceived(dbus::Signal* unused_signal) { 313 void PowerSupplyPollReceived(dbus::Signal* unused_signal) {
290 VLOG(1) << "Received power supply poll signal."; 314 VLOG(1) << "Received power supply poll signal.";
291 RequestStatusUpdate(); 315 RequestStatusUpdate();
292 } 316 }
293 317
294 // Called when GetAllPropertiesMethod call is complete.
295 void OnGetAllPropertiesMethod(dbus::Response* response) { 318 void OnGetAllPropertiesMethod(dbus::Response* response) {
296 if (!response) { 319 if (!response) {
297 LOG(ERROR) << "Error calling " << power_manager::kGetAllPropertiesMethod; 320 LOG(ERROR) << "Error calling " << power_manager::kGetAllPropertiesMethod;
298 return; 321 return;
299 } 322 }
300 dbus::MessageReader reader(response); 323 dbus::MessageReader reader(response);
301 PowerSupplyStatus status; 324 PowerSupplyStatus status;
302 double unused_battery_voltage = 0.0; 325 double unused_battery_voltage = 0.0;
303 double unused_battery_energy = 0.0; 326 double unused_battery_energy = 0.0;
304 double unused_battery_energy_rate = 0.0; 327 double unused_battery_energy_rate = 0.0;
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
401 FROM_HERE, 424 FROM_HERE,
402 base::TimeDelta::FromMilliseconds(1000), 425 base::TimeDelta::FromMilliseconds(1000),
403 this, 426 this,
404 &PowerManagerClientStubImpl::Update); 427 &PowerManagerClientStubImpl::Update);
405 } else { 428 } else {
406 timer_.Stop(); 429 timer_.Stop();
407 } 430 }
408 } 431 }
409 432
410 virtual void RequestRestart() OVERRIDE {} 433 virtual void RequestRestart() OVERRIDE {}
411
412 virtual void RequestShutdown() OVERRIDE {} 434 virtual void RequestShutdown() OVERRIDE {}
413 435
414 virtual void CalculateIdleTime(const CalculateIdleTimeCallback& callback) 436 virtual void CalculateIdleTime(const CalculateIdleTimeCallback& callback)
415 OVERRIDE { 437 OVERRIDE {
416 callback.Run(0); 438 callback.Run(0);
417 } 439 }
418 440
419 virtual void NotifyScreenLockRequested() OVERRIDE {} 441 virtual void NotifyScreenLockRequested() OVERRIDE {}
420
421 virtual void NotifyScreenLockCompleted() OVERRIDE {} 442 virtual void NotifyScreenLockCompleted() OVERRIDE {}
422
423 virtual void NotifyScreenUnlockRequested() OVERRIDE {} 443 virtual void NotifyScreenUnlockRequested() OVERRIDE {}
424
425 virtual void NotifyScreenUnlockCompleted() OVERRIDE {} 444 virtual void NotifyScreenUnlockCompleted() OVERRIDE {}
426 445
427 private: 446 private:
428 void Update() { 447 void Update() {
429 // We pause at 0 and 100% so that it's easier to check those conditions. 448 // We pause at 0 and 100% so that it's easier to check those conditions.
430 if (pause_count_ > 1) { 449 if (pause_count_ > 1) {
431 pause_count_--; 450 pause_count_--;
432 return; 451 return;
433 } 452 }
434 453
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
475 494
476 PowerManagerClient* PowerManagerClient::Create(dbus::Bus* bus) { 495 PowerManagerClient* PowerManagerClient::Create(dbus::Bus* bus) {
477 if (system::runtime_environment::IsRunningOnChromeOS()) { 496 if (system::runtime_environment::IsRunningOnChromeOS()) {
478 return new PowerManagerClientImpl(bus); 497 return new PowerManagerClientImpl(bus);
479 } else { 498 } else {
480 return new PowerManagerClientStubImpl(); 499 return new PowerManagerClientStubImpl();
481 } 500 }
482 } 501 }
483 502
484 } // namespace chromeos 503 } // namespace chromeos
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/dbus/power_manager_client.h ('k') | chrome/browser/chromeos/login/screen_locker.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698