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 "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" |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
115 weak_ptr_factory_.GetWeakPtr()), | 115 weak_ptr_factory_.GetWeakPtr()), |
116 base::Bind(&PowerManagerClientImpl::SignalConnected, | 116 base::Bind(&PowerManagerClientImpl::SignalConnected, |
117 weak_ptr_factory_.GetWeakPtr())); | 117 weak_ptr_factory_.GetWeakPtr())); |
118 power_manager_proxy_->ConnectToSignal( | 118 power_manager_proxy_->ConnectToSignal( |
119 chromium::kChromiumInterface, | 119 chromium::kChromiumInterface, |
120 chromium::kUnlockScreenFailedSignal, | 120 chromium::kUnlockScreenFailedSignal, |
121 base::Bind(&PowerManagerClientImpl::ScreenUnlockFailedSignalReceived, | 121 base::Bind(&PowerManagerClientImpl::ScreenUnlockFailedSignalReceived, |
122 weak_ptr_factory_.GetWeakPtr()), | 122 weak_ptr_factory_.GetWeakPtr()), |
123 base::Bind(&PowerManagerClientImpl::SignalConnected, | 123 base::Bind(&PowerManagerClientImpl::SignalConnected, |
124 weak_ptr_factory_.GetWeakPtr())); | 124 weak_ptr_factory_.GetWeakPtr())); |
| 125 |
| 126 power_manager_proxy_->ConnectToSignal( |
| 127 power_manager::kPowerManagerInterface, |
| 128 power_manager::kIdleNotifySignal, |
| 129 base::Bind(&PowerManagerClientImpl::IdleNotifySignalReceived, |
| 130 weak_ptr_factory_.GetWeakPtr()), |
| 131 base::Bind(&PowerManagerClientImpl::SignalConnected, |
| 132 weak_ptr_factory_.GetWeakPtr())); |
| 133 |
| 134 power_manager_proxy_->ConnectToSignal( |
| 135 power_manager::kPowerManagerInterface, |
| 136 power_manager::kActiveNotifySignal, |
| 137 base::Bind(&PowerManagerClientImpl::IdleNotifySignalReceived, |
| 138 weak_ptr_factory_.GetWeakPtr()), |
| 139 base::Bind(&PowerManagerClientImpl::SignalConnected, |
| 140 weak_ptr_factory_.GetWeakPtr())); |
125 } | 141 } |
126 | 142 |
127 virtual ~PowerManagerClientImpl() { | 143 virtual ~PowerManagerClientImpl() { |
128 } | 144 } |
129 | 145 |
130 // PowerManagerClient overrides: | 146 // PowerManagerClient overrides: |
131 | 147 |
132 virtual void AddObserver(Observer* observer) OVERRIDE { | 148 virtual void AddObserver(Observer* observer) OVERRIDE { |
133 observers_.AddObserver(observer); | 149 observers_.AddObserver(observer); |
134 } | 150 } |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
200 OVERRIDE { | 216 OVERRIDE { |
201 dbus::MethodCall method_call(power_manager::kPowerManagerInterface, | 217 dbus::MethodCall method_call(power_manager::kPowerManagerInterface, |
202 power_manager::kGetIdleTime); | 218 power_manager::kGetIdleTime); |
203 power_manager_proxy_->CallMethod( | 219 power_manager_proxy_->CallMethod( |
204 &method_call, | 220 &method_call, |
205 dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, | 221 dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, |
206 base::Bind(&PowerManagerClientImpl::OnGetIdleTime, | 222 base::Bind(&PowerManagerClientImpl::OnGetIdleTime, |
207 weak_ptr_factory_.GetWeakPtr(), callback)); | 223 weak_ptr_factory_.GetWeakPtr(), callback)); |
208 } | 224 } |
209 | 225 |
| 226 virtual void RequestIdleNotification(int64 threshold) OVERRIDE { |
| 227 dbus::MethodCall method_call(power_manager::kPowerManagerInterface, |
| 228 power_manager::kRequestIdleNotification); |
| 229 dbus::MessageWriter writer(&method_call); |
| 230 writer.AppendInt64(threshold); |
| 231 |
| 232 power_manager_proxy_->CallMethod( |
| 233 &method_call, |
| 234 dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, |
| 235 dbus::ObjectProxy::EmptyResponseCallback()); |
| 236 } |
| 237 |
| 238 virtual void RequestActiveNotification() OVERRIDE { |
| 239 RequestIdleNotification(0); |
| 240 } |
| 241 |
| 242 |
210 virtual void NotifyScreenLockRequested() OVERRIDE { | 243 virtual void NotifyScreenLockRequested() OVERRIDE { |
211 SimpleMethodCallToPowerManager(power_manager::kRequestLockScreenMethod); | 244 SimpleMethodCallToPowerManager(power_manager::kRequestLockScreenMethod); |
212 } | 245 } |
213 | 246 |
214 virtual void NotifyScreenLockCompleted() OVERRIDE { | 247 virtual void NotifyScreenLockCompleted() OVERRIDE { |
215 SimpleMethodCallToPowerManager(power_manager::kScreenIsLockedMethod); | 248 SimpleMethodCallToPowerManager(power_manager::kScreenIsLockedMethod); |
216 } | 249 } |
217 | 250 |
218 virtual void NotifyScreenUnlockRequested() OVERRIDE { | 251 virtual void NotifyScreenUnlockRequested() OVERRIDE { |
219 SimpleMethodCallToPowerManager(power_manager::kRequestUnlockScreenMethod); | 252 SimpleMethodCallToPowerManager(power_manager::kRequestUnlockScreenMethod); |
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
371 } | 404 } |
372 | 405 |
373 void ScreenUnlockSignalReceived(dbus::Signal* signal) { | 406 void ScreenUnlockSignalReceived(dbus::Signal* signal) { |
374 FOR_EACH_OBSERVER(Observer, observers_, UnlockScreen()); | 407 FOR_EACH_OBSERVER(Observer, observers_, UnlockScreen()); |
375 } | 408 } |
376 | 409 |
377 void ScreenUnlockFailedSignalReceived(dbus::Signal* signal) { | 410 void ScreenUnlockFailedSignalReceived(dbus::Signal* signal) { |
378 FOR_EACH_OBSERVER(Observer, observers_, UnlockScreenFailed()); | 411 FOR_EACH_OBSERVER(Observer, observers_, UnlockScreenFailed()); |
379 } | 412 } |
380 | 413 |
| 414 |
| 415 void IdleNotifySignalReceived(dbus::Signal* signal) { |
| 416 dbus::MessageReader reader(signal); |
| 417 int64 threshold = 0; |
| 418 if (!reader.PopInt64(&threshold)) { |
| 419 LOG(ERROR) << "Idle Notify signal had incorrect parameters: " |
| 420 << signal->ToString(); |
| 421 return; |
| 422 } |
| 423 |
| 424 VLOG(1) << "Idle Notify: " << threshold; |
| 425 if (threshold) |
| 426 FOR_EACH_OBSERVER(Observer, observers_, IdleNotify(threshold)); |
| 427 else |
| 428 FOR_EACH_OBSERVER(Observer, observers_, ActiveNotify()); |
| 429 } |
| 430 |
| 431 |
381 dbus::ObjectProxy* power_manager_proxy_; | 432 dbus::ObjectProxy* power_manager_proxy_; |
382 ObserverList<Observer> observers_; | 433 ObserverList<Observer> observers_; |
383 base::WeakPtrFactory<PowerManagerClientImpl> weak_ptr_factory_; | 434 base::WeakPtrFactory<PowerManagerClientImpl> weak_ptr_factory_; |
384 | 435 |
385 DISALLOW_COPY_AND_ASSIGN(PowerManagerClientImpl); | 436 DISALLOW_COPY_AND_ASSIGN(PowerManagerClientImpl); |
386 }; | 437 }; |
387 | 438 |
388 // The PowerManagerClient implementation used on Linux desktop, | 439 // The PowerManagerClient implementation used on Linux desktop, |
389 // which does nothing. | 440 // which does nothing. |
390 class PowerManagerClientStubImpl : public PowerManagerClient { | 441 class PowerManagerClientStubImpl : public PowerManagerClient { |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
432 } | 483 } |
433 | 484 |
434 virtual void RequestRestart() OVERRIDE {} | 485 virtual void RequestRestart() OVERRIDE {} |
435 virtual void RequestShutdown() OVERRIDE {} | 486 virtual void RequestShutdown() OVERRIDE {} |
436 | 487 |
437 virtual void CalculateIdleTime(const CalculateIdleTimeCallback& callback) | 488 virtual void CalculateIdleTime(const CalculateIdleTimeCallback& callback) |
438 OVERRIDE { | 489 OVERRIDE { |
439 callback.Run(0); | 490 callback.Run(0); |
440 } | 491 } |
441 | 492 |
| 493 virtual void RequestIdleNotification(int64 threshold) OVERRIDE {} |
| 494 virtual void RequestActiveNotification() OVERRIDE {} |
| 495 |
442 virtual void NotifyScreenLockRequested() OVERRIDE { | 496 virtual void NotifyScreenLockRequested() OVERRIDE { |
443 ScreenLocker::Show(); | 497 ScreenLocker::Show(); |
444 } | 498 } |
445 | |
446 virtual void NotifyScreenLockCompleted() OVERRIDE {} | 499 virtual void NotifyScreenLockCompleted() OVERRIDE {} |
447 | |
448 virtual void NotifyScreenUnlockRequested() OVERRIDE { | 500 virtual void NotifyScreenUnlockRequested() OVERRIDE { |
449 ScreenLocker::Hide(); | 501 ScreenLocker::Hide(); |
450 } | 502 } |
451 | 503 |
452 virtual void NotifyScreenUnlockCompleted() OVERRIDE {} | 504 virtual void NotifyScreenUnlockCompleted() OVERRIDE {} |
453 | 505 |
454 private: | 506 private: |
455 void Update() { | 507 void Update() { |
456 // We pause at 0 and 100% so that it's easier to check those conditions. | 508 // We pause at 0 and 100% so that it's easier to check those conditions. |
457 if (pause_count_ > 1) { | 509 if (pause_count_ > 1) { |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
502 | 554 |
503 PowerManagerClient* PowerManagerClient::Create(dbus::Bus* bus) { | 555 PowerManagerClient* PowerManagerClient::Create(dbus::Bus* bus) { |
504 if (system::runtime_environment::IsRunningOnChromeOS()) { | 556 if (system::runtime_environment::IsRunningOnChromeOS()) { |
505 return new PowerManagerClientImpl(bus); | 557 return new PowerManagerClientImpl(bus); |
506 } else { | 558 } else { |
507 return new PowerManagerClientStubImpl(); | 559 return new PowerManagerClientStubImpl(); |
508 } | 560 } |
509 } | 561 } |
510 | 562 |
511 } // namespace chromeos | 563 } // namespace chromeos |
OLD | NEW |