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 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
104 base::Bind(&PowerManagerClientImpl::SignalConnected, | 104 base::Bind(&PowerManagerClientImpl::SignalConnected, |
105 weak_ptr_factory_.GetWeakPtr())); | 105 weak_ptr_factory_.GetWeakPtr())); |
106 | 106 |
107 power_manager_proxy_->ConnectToSignal( | 107 power_manager_proxy_->ConnectToSignal( |
108 power_manager::kPowerManagerInterface, | 108 power_manager::kPowerManagerInterface, |
109 power_manager::kActiveNotifySignal, | 109 power_manager::kActiveNotifySignal, |
110 base::Bind(&PowerManagerClientImpl::ActiveNotifySignalReceived, | 110 base::Bind(&PowerManagerClientImpl::ActiveNotifySignalReceived, |
111 weak_ptr_factory_.GetWeakPtr()), | 111 weak_ptr_factory_.GetWeakPtr()), |
112 base::Bind(&PowerManagerClientImpl::SignalConnected, | 112 base::Bind(&PowerManagerClientImpl::SignalConnected, |
113 weak_ptr_factory_.GetWeakPtr())); | 113 weak_ptr_factory_.GetWeakPtr())); |
| 114 |
| 115 power_manager_proxy_->ConnectToSignal( |
| 116 power_manager::kPowerManagerInterface, |
| 117 power_manager::kSoftwareScreenDimmingRequestedSignal, |
| 118 base::Bind( |
| 119 &PowerManagerClientImpl::SoftwareScreenDimmingRequestedReceived, |
| 120 weak_ptr_factory_.GetWeakPtr()), |
| 121 base::Bind(&PowerManagerClientImpl::SignalConnected, |
| 122 weak_ptr_factory_.GetWeakPtr())); |
114 } | 123 } |
115 | 124 |
116 virtual ~PowerManagerClientImpl() { | 125 virtual ~PowerManagerClientImpl() { |
117 } | 126 } |
118 | 127 |
119 // PowerManagerClient overrides: | 128 // PowerManagerClient overrides: |
120 | 129 |
121 virtual void AddObserver(Observer* observer) OVERRIDE { | 130 virtual void AddObserver(Observer* observer) OVERRIDE { |
122 CHECK(observer); // http://crbug.com/119976 | 131 CHECK(observer); // http://crbug.com/119976 |
123 observers_.AddObserver(observer); | 132 observers_.AddObserver(observer); |
(...skipping 304 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
428 } | 437 } |
429 | 438 |
430 void ScreenUnlockSignalReceived(dbus::Signal* signal) { | 439 void ScreenUnlockSignalReceived(dbus::Signal* signal) { |
431 FOR_EACH_OBSERVER(Observer, observers_, UnlockScreen()); | 440 FOR_EACH_OBSERVER(Observer, observers_, UnlockScreen()); |
432 } | 441 } |
433 | 442 |
434 void ScreenUnlockFailedSignalReceived(dbus::Signal* signal) { | 443 void ScreenUnlockFailedSignalReceived(dbus::Signal* signal) { |
435 FOR_EACH_OBSERVER(Observer, observers_, UnlockScreenFailed()); | 444 FOR_EACH_OBSERVER(Observer, observers_, UnlockScreenFailed()); |
436 } | 445 } |
437 | 446 |
438 | |
439 void IdleNotifySignalReceived(dbus::Signal* signal) { | 447 void IdleNotifySignalReceived(dbus::Signal* signal) { |
440 dbus::MessageReader reader(signal); | 448 dbus::MessageReader reader(signal); |
441 int64 threshold = 0; | 449 int64 threshold = 0; |
442 if (!reader.PopInt64(&threshold)) { | 450 if (!reader.PopInt64(&threshold)) { |
443 LOG(ERROR) << "Idle Notify signal had incorrect parameters: " | 451 LOG(ERROR) << "Idle Notify signal had incorrect parameters: " |
444 << signal->ToString(); | 452 << signal->ToString(); |
445 return; | 453 return; |
446 } | 454 } |
447 DCHECK_GT(threshold, 0); | 455 DCHECK_GT(threshold, 0); |
448 | 456 |
449 VLOG(1) << "Idle Notify: " << threshold; | 457 VLOG(1) << "Idle Notify: " << threshold; |
450 FOR_EACH_OBSERVER(Observer, observers_, IdleNotify(threshold)); | 458 FOR_EACH_OBSERVER(Observer, observers_, IdleNotify(threshold)); |
451 } | 459 } |
452 | 460 |
453 void ActiveNotifySignalReceived(dbus::Signal* signal) { | 461 void ActiveNotifySignalReceived(dbus::Signal* signal) { |
454 dbus::MessageReader reader(signal); | 462 dbus::MessageReader reader(signal); |
455 int64 threshold = 0; | 463 int64 threshold = 0; |
456 if (!reader.PopInt64(&threshold)) { | 464 if (!reader.PopInt64(&threshold)) { |
457 LOG(ERROR) << "Active Notify signal had incorrect parameters: " | 465 LOG(ERROR) << "Active Notify signal had incorrect parameters: " |
458 << signal->ToString(); | 466 << signal->ToString(); |
459 return; | 467 return; |
460 } | 468 } |
461 DCHECK_EQ(threshold, 0); | 469 DCHECK_EQ(threshold, 0); |
462 | 470 |
463 VLOG(1) << "Active Notify."; | 471 VLOG(1) << "Active Notify."; |
464 FOR_EACH_OBSERVER(Observer, observers_, ActiveNotify()); | 472 FOR_EACH_OBSERVER(Observer, observers_, ActiveNotify()); |
465 } | 473 } |
466 | 474 |
| 475 void SoftwareScreenDimmingRequestedReceived(dbus::Signal* signal) { |
| 476 dbus::MessageReader reader(signal); |
| 477 int32 signal_state = 0; |
| 478 if (!reader.PopInt32(&signal_state)) { |
| 479 LOG(ERROR) << "Screen dimming signal had incorrect parameters: " |
| 480 << signal->ToString(); |
| 481 return; |
| 482 } |
| 483 |
| 484 Observer::ScreenDimmingState state = Observer::SCREEN_DIMMING_NONE; |
| 485 switch (signal_state) { |
| 486 case power_manager::kSoftwareScreenDimmingNone: |
| 487 state = Observer::SCREEN_DIMMING_NONE; |
| 488 break; |
| 489 case power_manager::kSoftwareScreenDimmingIdle: |
| 490 state = Observer::SCREEN_DIMMING_IDLE; |
| 491 break; |
| 492 default: |
| 493 LOG(ERROR) << "Unhandled screen dimming state " << signal_state; |
| 494 } |
| 495 FOR_EACH_OBSERVER(Observer, observers_, ScreenDimmingRequested(state)); |
| 496 } |
467 | 497 |
468 dbus::ObjectProxy* power_manager_proxy_; | 498 dbus::ObjectProxy* power_manager_proxy_; |
469 dbus::ObjectProxy* session_manager_proxy_; | 499 dbus::ObjectProxy* session_manager_proxy_; |
470 ObserverList<Observer> observers_; | 500 ObserverList<Observer> observers_; |
471 base::WeakPtrFactory<PowerManagerClientImpl> weak_ptr_factory_; | 501 base::WeakPtrFactory<PowerManagerClientImpl> weak_ptr_factory_; |
472 | 502 |
473 DISALLOW_COPY_AND_ASSIGN(PowerManagerClientImpl); | 503 DISALLOW_COPY_AND_ASSIGN(PowerManagerClientImpl); |
474 }; | 504 }; |
475 | 505 |
476 // The PowerManagerClient implementation used on Linux desktop, | 506 // The PowerManagerClient implementation used on Linux desktop, |
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
613 PowerManagerClient* PowerManagerClient::Create( | 643 PowerManagerClient* PowerManagerClient::Create( |
614 DBusClientImplementationType type, | 644 DBusClientImplementationType type, |
615 dbus::Bus* bus) { | 645 dbus::Bus* bus) { |
616 if (type == REAL_DBUS_CLIENT_IMPLEMENTATION) | 646 if (type == REAL_DBUS_CLIENT_IMPLEMENTATION) |
617 return new PowerManagerClientImpl(bus); | 647 return new PowerManagerClientImpl(bus); |
618 DCHECK_EQ(STUB_DBUS_CLIENT_IMPLEMENTATION, type); | 648 DCHECK_EQ(STUB_DBUS_CLIENT_IMPLEMENTATION, type); |
619 return new PowerManagerClientStubImpl(); | 649 return new PowerManagerClientStubImpl(); |
620 } | 650 } |
621 | 651 |
622 } // namespace chromeos | 652 } // namespace chromeos |
OLD | NEW |