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_(40), | 524 battery_percentage_(40), |
517 brightness_(50.0), | 525 brightness_(50.0), |
518 pause_count_(2) { | 526 pause_count_(2), |
| 527 screen_locked_(false) { |
519 } | 528 } |
520 | 529 |
521 virtual ~PowerManagerClientStubImpl() {} | 530 virtual ~PowerManagerClientStubImpl() {} |
522 | 531 |
523 // PowerManagerClient overrides: | 532 // PowerManagerClient overrides: |
524 | 533 |
525 virtual void AddObserver(Observer* observer) OVERRIDE { | 534 virtual void AddObserver(Observer* observer) OVERRIDE { |
526 observers_.AddObserver(observer); | 535 observers_.AddObserver(observer); |
527 } | 536 } |
528 | 537 |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
582 | 591 |
583 virtual void RequestIdleNotification(int64 threshold) OVERRIDE {} | 592 virtual void RequestIdleNotification(int64 threshold) OVERRIDE {} |
584 virtual void RequestActiveNotification() OVERRIDE {} | 593 virtual void RequestActiveNotification() OVERRIDE {} |
585 virtual void RequestPowerStateOverrides( | 594 virtual void RequestPowerStateOverrides( |
586 uint32 request_id, | 595 uint32 request_id, |
587 uint32 duration, | 596 uint32 duration, |
588 int overrides, | 597 int overrides, |
589 const PowerStateRequestIdCallback& callback) OVERRIDE {} | 598 const PowerStateRequestIdCallback& callback) OVERRIDE {} |
590 | 599 |
591 virtual void NotifyScreenLockRequested() OVERRIDE { | 600 virtual void NotifyScreenLockRequested() OVERRIDE { |
| 601 screen_locked_ = true; |
592 FOR_EACH_OBSERVER(Observer, observers_, LockScreen()); | 602 FOR_EACH_OBSERVER(Observer, observers_, LockScreen()); |
593 } | 603 } |
594 virtual void NotifyScreenLockCompleted() OVERRIDE {} | 604 virtual void NotifyScreenLockCompleted() OVERRIDE {} |
595 virtual void NotifyScreenUnlockRequested() OVERRIDE { | 605 virtual void NotifyScreenUnlockRequested() OVERRIDE { |
| 606 screen_locked_ = false; |
596 FOR_EACH_OBSERVER(Observer, observers_, UnlockScreen()); | 607 FOR_EACH_OBSERVER(Observer, observers_, UnlockScreen()); |
597 } | 608 } |
598 | |
599 virtual void NotifyScreenUnlockCompleted() OVERRIDE {} | 609 virtual void NotifyScreenUnlockCompleted() OVERRIDE {} |
| 610 virtual bool GetIsScreenLocked() OVERRIDE { |
| 611 return screen_locked_; |
| 612 } |
600 | 613 |
601 private: | 614 private: |
602 void Update() { | 615 void Update() { |
603 if (pause_count_ > 0) { | 616 if (pause_count_ > 0) { |
604 pause_count_--; | 617 pause_count_--; |
605 } else { | 618 } else { |
606 int discharge_amt = battery_percentage_ <= 10 ? 1 : 10; | 619 int discharge_amt = battery_percentage_ <= 10 ? 1 : 10; |
607 battery_percentage_ += (discharging_ ? -discharge_amt : discharge_amt); | 620 battery_percentage_ += (discharging_ ? -discharge_amt : discharge_amt); |
608 battery_percentage_ = std::min(std::max(battery_percentage_, 0), 100); | 621 battery_percentage_ = std::min(std::max(battery_percentage_, 0), 100); |
609 // We pause at 0 and 100% so that it's easier to check those conditions. | 622 // We pause at 0 and 100% so that it's easier to check those conditions. |
(...skipping 27 matching lines...) Expand all Loading... |
637 BrightnessChanged(brightness_level, user_initiated)); | 650 BrightnessChanged(brightness_level, user_initiated)); |
638 } | 651 } |
639 | 652 |
640 bool discharging_; | 653 bool discharging_; |
641 int battery_percentage_; | 654 int battery_percentage_; |
642 double brightness_; | 655 double brightness_; |
643 int pause_count_; | 656 int pause_count_; |
644 ObserverList<Observer> observers_; | 657 ObserverList<Observer> observers_; |
645 base::RepeatingTimer<PowerManagerClientStubImpl> timer_; | 658 base::RepeatingTimer<PowerManagerClientStubImpl> timer_; |
646 PowerSupplyStatus status_; | 659 PowerSupplyStatus status_; |
| 660 bool screen_locked_; |
647 }; | 661 }; |
648 | 662 |
649 PowerManagerClient::PowerManagerClient() { | 663 PowerManagerClient::PowerManagerClient() { |
650 } | 664 } |
651 | 665 |
652 PowerManagerClient::~PowerManagerClient() { | 666 PowerManagerClient::~PowerManagerClient() { |
653 } | 667 } |
654 | 668 |
655 PowerManagerClient* PowerManagerClient::Create( | 669 PowerManagerClient* PowerManagerClient::Create( |
656 DBusClientImplementationType type, | 670 DBusClientImplementationType type, |
657 dbus::Bus* bus) { | 671 dbus::Bus* bus) { |
658 if (type == REAL_DBUS_CLIENT_IMPLEMENTATION) | 672 if (type == REAL_DBUS_CLIENT_IMPLEMENTATION) |
659 return new PowerManagerClientImpl(bus); | 673 return new PowerManagerClientImpl(bus); |
660 DCHECK_EQ(STUB_DBUS_CLIENT_IMPLEMENTATION, type); | 674 DCHECK_EQ(STUB_DBUS_CLIENT_IMPLEMENTATION, type); |
661 return new PowerManagerClientStubImpl(); | 675 return new PowerManagerClientStubImpl(); |
662 } | 676 } |
663 | 677 |
664 } // namespace chromeos | 678 } // namespace chromeos |
OLD | NEW |