OLD | NEW |
1 // Copyright (c) 2012 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 "chromeos/dbus/power_manager_client.h" | 5 #include "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" |
(...skipping 11 matching lines...) Expand all Loading... |
22 #include "dbus/object_proxy.h" | 22 #include "dbus/object_proxy.h" |
23 #include "third_party/cros_system_api/dbus/service_constants.h" | 23 #include "third_party/cros_system_api/dbus/service_constants.h" |
24 | 24 |
25 namespace chromeos { | 25 namespace chromeos { |
26 | 26 |
27 // The PowerManagerClient implementation used in production. | 27 // The PowerManagerClient implementation used in production. |
28 class PowerManagerClientImpl : public PowerManagerClient { | 28 class PowerManagerClientImpl : public PowerManagerClient { |
29 public: | 29 public: |
30 explicit PowerManagerClientImpl(dbus::Bus* bus) | 30 explicit PowerManagerClientImpl(dbus::Bus* bus) |
31 : power_manager_proxy_(NULL), | 31 : power_manager_proxy_(NULL), |
| 32 screen_locked_(false), |
32 weak_ptr_factory_(this) { | 33 weak_ptr_factory_(this) { |
33 power_manager_proxy_ = bus->GetObjectProxy( | 34 power_manager_proxy_ = bus->GetObjectProxy( |
34 power_manager::kPowerManagerServiceName, | 35 power_manager::kPowerManagerServiceName, |
35 dbus::ObjectPath(power_manager::kPowerManagerServicePath)); | 36 dbus::ObjectPath(power_manager::kPowerManagerServicePath)); |
36 | 37 |
37 session_manager_proxy_ = bus->GetObjectProxy( | 38 session_manager_proxy_ = bus->GetObjectProxy( |
38 login_manager::kSessionManagerServiceName, | 39 login_manager::kSessionManagerServiceName, |
39 dbus::ObjectPath(login_manager::kSessionManagerServicePath)); | 40 dbus::ObjectPath(login_manager::kSessionManagerServicePath)); |
40 | 41 |
41 // Monitor the D-Bus signal for brightness changes. Only the power | 42 // Monitor the D-Bus signal for brightness changes. Only the power |
(...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
263 } | 264 } |
264 | 265 |
265 virtual void NotifyScreenUnlockRequested() OVERRIDE { | 266 virtual void NotifyScreenUnlockRequested() OVERRIDE { |
266 SimpleMethodCallToPowerManager(power_manager::kRequestUnlockScreenMethod); | 267 SimpleMethodCallToPowerManager(power_manager::kRequestUnlockScreenMethod); |
267 } | 268 } |
268 | 269 |
269 virtual void NotifyScreenUnlockCompleted() OVERRIDE { | 270 virtual void NotifyScreenUnlockCompleted() OVERRIDE { |
270 SimpleMethodCallToPowerManager(power_manager::kScreenIsUnlockedMethod); | 271 SimpleMethodCallToPowerManager(power_manager::kScreenIsUnlockedMethod); |
271 } | 272 } |
272 | 273 |
| 274 virtual bool GetIsScreenLocked() OVERRIDE { |
| 275 return screen_locked_; |
| 276 } |
| 277 |
273 private: | 278 private: |
274 // Called when a dbus signal is initially connected. | 279 // Called when a dbus signal is initially connected. |
275 void SignalConnected(const std::string& interface_name, | 280 void SignalConnected(const std::string& interface_name, |
276 const std::string& signal_name, | 281 const std::string& signal_name, |
277 bool success) { | 282 bool success) { |
278 LOG_IF(WARNING, !success) << "Failed to connect to signal " | 283 LOG_IF(WARNING, !success) << "Failed to connect to signal " |
279 << signal_name << "."; | 284 << signal_name << "."; |
280 } | 285 } |
281 | 286 |
282 // Make a method call to power manager with no arguments and no response. | 287 // Make a method call to power manager with no arguments and no response. |
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
430 LOG(ERROR) << "Error reading response from powerd: " | 435 LOG(ERROR) << "Error reading response from powerd: " |
431 << response->ToString(); | 436 << response->ToString(); |
432 callback.Run(percent); | 437 callback.Run(percent); |
433 } | 438 } |
434 | 439 |
435 void ScreenLockSignalReceived(dbus::Signal* signal) { | 440 void ScreenLockSignalReceived(dbus::Signal* signal) { |
436 // TODO(flackr): This warning is actually a signal that things are working | 441 // TODO(flackr): This warning is actually a signal that things are working |
437 // as expected. As per http://crbug.com/126217, this will help determine | 442 // as expected. As per http://crbug.com/126217, this will help determine |
438 // if the problem is with dbus or in chrome. | 443 // if the problem is with dbus or in chrome. |
439 LOG(WARNING) << "LockScreen signal received from power manager."; | 444 LOG(WARNING) << "LockScreen signal received from power manager."; |
| 445 screen_locked_ = true; |
440 FOR_EACH_OBSERVER(Observer, observers_, LockScreen()); | 446 FOR_EACH_OBSERVER(Observer, observers_, LockScreen()); |
441 } | 447 } |
442 | 448 |
443 void ScreenUnlockSignalReceived(dbus::Signal* signal) { | 449 void ScreenUnlockSignalReceived(dbus::Signal* signal) { |
| 450 screen_locked_ = false; |
444 FOR_EACH_OBSERVER(Observer, observers_, UnlockScreen()); | 451 FOR_EACH_OBSERVER(Observer, observers_, UnlockScreen()); |
445 } | 452 } |
446 | 453 |
447 void ScreenUnlockFailedSignalReceived(dbus::Signal* signal) { | 454 void ScreenUnlockFailedSignalReceived(dbus::Signal* signal) { |
448 FOR_EACH_OBSERVER(Observer, observers_, UnlockScreenFailed()); | 455 FOR_EACH_OBSERVER(Observer, observers_, UnlockScreenFailed()); |
449 } | 456 } |
450 | 457 |
451 void IdleNotifySignalReceived(dbus::Signal* signal) { | 458 void IdleNotifySignalReceived(dbus::Signal* signal) { |
452 dbus::MessageReader reader(signal); | 459 dbus::MessageReader reader(signal); |
453 int64 threshold = 0; | 460 int64 threshold = 0; |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
495 break; | 502 break; |
496 default: | 503 default: |
497 LOG(ERROR) << "Unhandled screen dimming state " << signal_state; | 504 LOG(ERROR) << "Unhandled screen dimming state " << signal_state; |
498 } | 505 } |
499 FOR_EACH_OBSERVER(Observer, observers_, ScreenDimmingRequested(state)); | 506 FOR_EACH_OBSERVER(Observer, observers_, ScreenDimmingRequested(state)); |
500 } | 507 } |
501 | 508 |
502 dbus::ObjectProxy* power_manager_proxy_; | 509 dbus::ObjectProxy* power_manager_proxy_; |
503 dbus::ObjectProxy* session_manager_proxy_; | 510 dbus::ObjectProxy* session_manager_proxy_; |
504 ObserverList<Observer> observers_; | 511 ObserverList<Observer> observers_; |
| 512 bool screen_locked_; |
505 base::WeakPtrFactory<PowerManagerClientImpl> weak_ptr_factory_; | 513 base::WeakPtrFactory<PowerManagerClientImpl> weak_ptr_factory_; |
506 | 514 |
507 DISALLOW_COPY_AND_ASSIGN(PowerManagerClientImpl); | 515 DISALLOW_COPY_AND_ASSIGN(PowerManagerClientImpl); |
508 }; | 516 }; |
509 | 517 |
510 // The PowerManagerClient implementation used on Linux desktop, | 518 // The PowerManagerClient implementation used on Linux desktop, |
511 // which does nothing. | 519 // which does nothing. |
512 class PowerManagerClientStubImpl : public PowerManagerClient { | 520 class PowerManagerClientStubImpl : public PowerManagerClient { |
513 public: | 521 public: |
514 PowerManagerClientStubImpl() | 522 PowerManagerClientStubImpl() |
515 : discharging_(true), | 523 : discharging_(true), |
516 battery_percentage_(81), | 524 battery_percentage_(81), |
517 pause_count_(0) { | 525 pause_count_(0), |
| 526 screen_locked_(false) { |
518 } | 527 } |
519 | 528 |
520 virtual ~PowerManagerClientStubImpl() {} | 529 virtual ~PowerManagerClientStubImpl() {} |
521 | 530 |
522 // PowerManagerClient overrides: | 531 // PowerManagerClient overrides: |
523 | 532 |
524 virtual void AddObserver(Observer* observer) OVERRIDE { | 533 virtual void AddObserver(Observer* observer) OVERRIDE { |
525 observers_.AddObserver(observer); | 534 observers_.AddObserver(observer); |
526 } | 535 } |
527 | 536 |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
578 | 587 |
579 virtual void RequestIdleNotification(int64 threshold) OVERRIDE {} | 588 virtual void RequestIdleNotification(int64 threshold) OVERRIDE {} |
580 virtual void RequestActiveNotification() OVERRIDE {} | 589 virtual void RequestActiveNotification() OVERRIDE {} |
581 virtual void RequestPowerStateOverrides( | 590 virtual void RequestPowerStateOverrides( |
582 uint32 request_id, | 591 uint32 request_id, |
583 uint32 duration, | 592 uint32 duration, |
584 int overrides, | 593 int overrides, |
585 const PowerStateRequestIdCallback& callback) OVERRIDE {} | 594 const PowerStateRequestIdCallback& callback) OVERRIDE {} |
586 | 595 |
587 virtual void NotifyScreenLockRequested() OVERRIDE { | 596 virtual void NotifyScreenLockRequested() OVERRIDE { |
| 597 screen_locked_ = true; |
588 FOR_EACH_OBSERVER(Observer, observers_, LockScreen()); | 598 FOR_EACH_OBSERVER(Observer, observers_, LockScreen()); |
589 } | 599 } |
590 virtual void NotifyScreenLockCompleted() OVERRIDE {} | 600 virtual void NotifyScreenLockCompleted() OVERRIDE {} |
591 virtual void NotifyScreenUnlockRequested() OVERRIDE { | 601 virtual void NotifyScreenUnlockRequested() OVERRIDE { |
| 602 screen_locked_ = false; |
592 FOR_EACH_OBSERVER(Observer, observers_, UnlockScreen()); | 603 FOR_EACH_OBSERVER(Observer, observers_, UnlockScreen()); |
593 } | 604 } |
594 | |
595 virtual void NotifyScreenUnlockCompleted() OVERRIDE {} | 605 virtual void NotifyScreenUnlockCompleted() OVERRIDE {} |
| 606 virtual bool GetIsScreenLocked() OVERRIDE { |
| 607 return screen_locked_; |
| 608 } |
596 | 609 |
597 private: | 610 private: |
598 void Update() { | 611 void Update() { |
599 // We pause at 0 and 100% so that it's easier to check those conditions. | 612 // We pause at 0 and 100% so that it's easier to check those conditions. |
600 if (pause_count_ > 1) { | 613 if (pause_count_ > 1) { |
601 pause_count_--; | 614 pause_count_--; |
602 return; | 615 return; |
603 } | 616 } |
604 | 617 |
605 if (battery_percentage_ == 0 || battery_percentage_ == 100) { | 618 if (battery_percentage_ == 0 || battery_percentage_ == 100) { |
(...skipping 23 matching lines...) Expand all Loading... |
629 kSecondsToEmptyFullBattery - status.battery_seconds_to_empty); | 642 kSecondsToEmptyFullBattery - status.battery_seconds_to_empty); |
630 | 643 |
631 FOR_EACH_OBSERVER(Observer, observers_, PowerChanged(status)); | 644 FOR_EACH_OBSERVER(Observer, observers_, PowerChanged(status)); |
632 } | 645 } |
633 | 646 |
634 bool discharging_; | 647 bool discharging_; |
635 int battery_percentage_; | 648 int battery_percentage_; |
636 int pause_count_; | 649 int pause_count_; |
637 ObserverList<Observer> observers_; | 650 ObserverList<Observer> observers_; |
638 base::RepeatingTimer<PowerManagerClientStubImpl> timer_; | 651 base::RepeatingTimer<PowerManagerClientStubImpl> timer_; |
| 652 bool screen_locked_; |
639 }; | 653 }; |
640 | 654 |
641 PowerManagerClient::PowerManagerClient() { | 655 PowerManagerClient::PowerManagerClient() { |
642 } | 656 } |
643 | 657 |
644 PowerManagerClient::~PowerManagerClient() { | 658 PowerManagerClient::~PowerManagerClient() { |
645 } | 659 } |
646 | 660 |
647 PowerManagerClient* PowerManagerClient::Create( | 661 PowerManagerClient* PowerManagerClient::Create( |
648 DBusClientImplementationType type, | 662 DBusClientImplementationType type, |
649 dbus::Bus* bus) { | 663 dbus::Bus* bus) { |
650 if (type == REAL_DBUS_CLIENT_IMPLEMENTATION) | 664 if (type == REAL_DBUS_CLIENT_IMPLEMENTATION) |
651 return new PowerManagerClientImpl(bus); | 665 return new PowerManagerClientImpl(bus); |
652 DCHECK_EQ(STUB_DBUS_CLIENT_IMPLEMENTATION, type); | 666 DCHECK_EQ(STUB_DBUS_CLIENT_IMPLEMENTATION, type); |
653 return new PowerManagerClientStubImpl(); | 667 return new PowerManagerClientStubImpl(); |
654 } | 668 } |
655 | 669 |
656 } // namespace chromeos | 670 } // namespace chromeos |
OLD | NEW |