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 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
61 // manager knows the actual brightness level. We don't cache the | 61 // manager knows the actual brightness level. We don't cache the |
62 // brightness level in Chrome as it'll make things less reliable. | 62 // brightness level in Chrome as it'll make things less reliable. |
63 power_manager_proxy_->ConnectToSignal( | 63 power_manager_proxy_->ConnectToSignal( |
64 power_manager::kPowerManagerInterface, | 64 power_manager::kPowerManagerInterface, |
65 power_manager::kBrightnessChangedSignal, | 65 power_manager::kBrightnessChangedSignal, |
66 base::Bind(&PowerManagerClientImpl::BrightnessChangedReceived, | 66 base::Bind(&PowerManagerClientImpl::BrightnessChangedReceived, |
67 weak_ptr_factory_.GetWeakPtr()), | 67 weak_ptr_factory_.GetWeakPtr()), |
68 base::Bind(&PowerManagerClientImpl::SignalConnected, | 68 base::Bind(&PowerManagerClientImpl::SignalConnected, |
69 weak_ptr_factory_.GetWeakPtr())); | 69 weak_ptr_factory_.GetWeakPtr())); |
70 | 70 |
71 // TODO(derat): Stop listening for this. | |
72 power_manager_proxy_->ConnectToSignal( | |
73 power_manager::kPowerManagerInterface, | |
74 power_manager::kSetScreenPowerSignal, | |
75 base::Bind(&PowerManagerClientImpl::ScreenPowerSignalReceived, | |
76 weak_ptr_factory_.GetWeakPtr()), | |
77 base::Bind(&PowerManagerClientImpl::SignalConnected, | |
78 weak_ptr_factory_.GetWeakPtr())); | |
79 | |
80 power_manager_proxy_->ConnectToSignal( | 71 power_manager_proxy_->ConnectToSignal( |
81 power_manager::kPowerManagerInterface, | 72 power_manager::kPowerManagerInterface, |
82 power_manager::kPowerSupplyPollSignal, | 73 power_manager::kPowerSupplyPollSignal, |
83 base::Bind(&PowerManagerClientImpl::PowerSupplyPollReceived, | 74 base::Bind(&PowerManagerClientImpl::PowerSupplyPollReceived, |
84 weak_ptr_factory_.GetWeakPtr()), | 75 weak_ptr_factory_.GetWeakPtr()), |
85 base::Bind(&PowerManagerClientImpl::SignalConnected, | 76 base::Bind(&PowerManagerClientImpl::SignalConnected, |
86 weak_ptr_factory_.GetWeakPtr())); | 77 weak_ptr_factory_.GetWeakPtr())); |
87 | 78 |
88 power_manager_proxy_->ConnectToSignal( | 79 power_manager_proxy_->ConnectToSignal( |
89 power_manager::kPowerManagerInterface, | 80 power_manager::kPowerManagerInterface, |
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
248 power_manager::kRequestIdleNotification); | 239 power_manager::kRequestIdleNotification); |
249 dbus::MessageWriter writer(&method_call); | 240 dbus::MessageWriter writer(&method_call); |
250 writer.AppendInt64(threshold); | 241 writer.AppendInt64(threshold); |
251 | 242 |
252 power_manager_proxy_->CallMethod( | 243 power_manager_proxy_->CallMethod( |
253 &method_call, | 244 &method_call, |
254 dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, | 245 dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, |
255 dbus::ObjectProxy::EmptyResponseCallback()); | 246 dbus::ObjectProxy::EmptyResponseCallback()); |
256 } | 247 } |
257 | 248 |
258 virtual void NotifyUserActivity( | 249 virtual void NotifyUserActivity() OVERRIDE { |
259 const base::TimeTicks& last_activity_time) OVERRIDE { | 250 SimpleMethodCallToPowerManager(power_manager::kHandleUserActivityMethod); |
260 dbus::MethodCall method_call( | |
261 power_manager::kPowerManagerInterface, | |
262 power_manager::kHandleUserActivityMethod); | |
263 dbus::MessageWriter writer(&method_call); | |
264 writer.AppendInt64(last_activity_time.ToInternalValue()); | |
265 power_manager_proxy_->CallMethod( | |
266 &method_call, | |
267 dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, | |
268 dbus::ObjectProxy::EmptyResponseCallback()); | |
269 } | 251 } |
270 | 252 |
271 virtual void NotifyVideoActivity( | 253 virtual void NotifyVideoActivity( |
272 const base::TimeTicks& last_activity_time, | 254 const base::TimeTicks& last_activity_time, |
273 bool is_fullscreen) OVERRIDE { | 255 bool is_fullscreen) OVERRIDE { |
274 dbus::MethodCall method_call( | 256 dbus::MethodCall method_call( |
275 power_manager::kPowerManagerInterface, | 257 power_manager::kPowerManagerInterface, |
276 power_manager::kHandleVideoActivityMethod); | 258 power_manager::kHandleVideoActivityMethod); |
277 dbus::MessageWriter writer(&method_call); | 259 dbus::MessageWriter writer(&method_call); |
278 | 260 |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
366 LOG(ERROR) << "Brightness changed signal had incorrect parameters: " | 348 LOG(ERROR) << "Brightness changed signal had incorrect parameters: " |
367 << signal->ToString(); | 349 << signal->ToString(); |
368 return; | 350 return; |
369 } | 351 } |
370 VLOG(1) << "Brightness changed to " << brightness_level | 352 VLOG(1) << "Brightness changed to " << brightness_level |
371 << ": user initiated " << user_initiated; | 353 << ": user initiated " << user_initiated; |
372 FOR_EACH_OBSERVER(Observer, observers_, | 354 FOR_EACH_OBSERVER(Observer, observers_, |
373 BrightnessChanged(brightness_level, user_initiated)); | 355 BrightnessChanged(brightness_level, user_initiated)); |
374 } | 356 } |
375 | 357 |
376 void ScreenPowerSignalReceived(dbus::Signal* signal) { | |
377 dbus::MessageReader reader(signal); | |
378 bool dbus_power_on = false; | |
379 bool dbus_all_displays = false; | |
380 if (reader.PopBool(&dbus_power_on) && | |
381 reader.PopBool(&dbus_all_displays)) { | |
382 VLOG(1) << "Screen power set to " << dbus_power_on | |
383 << " for all displays " << dbus_all_displays; | |
384 FOR_EACH_OBSERVER(Observer, observers_, | |
385 ScreenPowerSet(dbus_power_on, dbus_all_displays)); | |
386 } else { | |
387 LOG(ERROR) << "screen power signal had incorrect parameters: " | |
388 << signal->ToString(); | |
389 } | |
390 } | |
391 | |
392 void PowerSupplyPollReceived(dbus::Signal* unused_signal) { | 358 void PowerSupplyPollReceived(dbus::Signal* unused_signal) { |
393 VLOG(1) << "Received power supply poll signal."; | 359 VLOG(1) << "Received power supply poll signal."; |
394 RequestStatusUpdate(UPDATE_POLL); | 360 RequestStatusUpdate(UPDATE_POLL); |
395 } | 361 } |
396 | 362 |
397 void OnGetPowerSupplyPropertiesMethod(dbus::Response* response) { | 363 void OnGetPowerSupplyPropertiesMethod(dbus::Response* response) { |
398 if (!response) { | 364 if (!response) { |
399 LOG(ERROR) << "Error calling " | 365 LOG(ERROR) << "Error calling " |
400 << power_manager::kGetPowerSupplyPropertiesMethod; | 366 << power_manager::kGetPowerSupplyPropertiesMethod; |
401 return; | 367 return; |
(...skipping 377 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
779 | 745 |
780 virtual void RequestIdleNotification(int64 threshold) OVERRIDE { | 746 virtual void RequestIdleNotification(int64 threshold) OVERRIDE { |
781 MessageLoop::current()->PostDelayedTask( | 747 MessageLoop::current()->PostDelayedTask( |
782 FROM_HERE, | 748 FROM_HERE, |
783 base::Bind(&PowerManagerClientStubImpl::TriggerIdleNotify, | 749 base::Bind(&PowerManagerClientStubImpl::TriggerIdleNotify, |
784 base::Unretained(this), | 750 base::Unretained(this), |
785 threshold), | 751 threshold), |
786 base::TimeDelta::FromMilliseconds(threshold)); | 752 base::TimeDelta::FromMilliseconds(threshold)); |
787 } | 753 } |
788 | 754 |
789 virtual void NotifyUserActivity( | 755 virtual void NotifyUserActivity() OVERRIDE {} |
790 const base::TimeTicks& last_activity_time) OVERRIDE {} | |
791 virtual void NotifyVideoActivity( | 756 virtual void NotifyVideoActivity( |
792 const base::TimeTicks& last_activity_time, | 757 const base::TimeTicks& last_activity_time, |
793 bool is_fullscreen) OVERRIDE {} | 758 bool is_fullscreen) OVERRIDE {} |
794 virtual void SetPolicy( | 759 virtual void SetPolicy( |
795 const power_manager::PowerManagementPolicy& policy) OVERRIDE {} | 760 const power_manager::PowerManagementPolicy& policy) OVERRIDE {} |
796 virtual void SetIsProjecting(bool is_projecting) OVERRIDE {} | 761 virtual void SetIsProjecting(bool is_projecting) OVERRIDE {} |
797 virtual base::Closure GetSuspendReadinessCallback() OVERRIDE { | 762 virtual base::Closure GetSuspendReadinessCallback() OVERRIDE { |
798 return base::Closure(); | 763 return base::Closure(); |
799 } | 764 } |
800 | 765 |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
860 PowerManagerClient* PowerManagerClient::Create( | 825 PowerManagerClient* PowerManagerClient::Create( |
861 DBusClientImplementationType type, | 826 DBusClientImplementationType type, |
862 dbus::Bus* bus) { | 827 dbus::Bus* bus) { |
863 if (type == REAL_DBUS_CLIENT_IMPLEMENTATION) | 828 if (type == REAL_DBUS_CLIENT_IMPLEMENTATION) |
864 return new PowerManagerClientImpl(bus); | 829 return new PowerManagerClientImpl(bus); |
865 DCHECK_EQ(STUB_DBUS_CLIENT_IMPLEMENTATION, type); | 830 DCHECK_EQ(STUB_DBUS_CLIENT_IMPLEMENTATION, type); |
866 return new PowerManagerClientStubImpl(); | 831 return new PowerManagerClientStubImpl(); |
867 } | 832 } |
868 | 833 |
869 } // namespace chromeos | 834 } // namespace chromeos |
OLD | NEW |