| 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" |
| 11 #include "base/format_macros.h" | 11 #include "base/format_macros.h" |
| 12 #include "base/logging.h" |
| 12 #include "base/memory/scoped_ptr.h" | 13 #include "base/memory/scoped_ptr.h" |
| 13 #include "base/message_loop.h" | 14 #include "base/message_loop.h" |
| 14 #include "base/observer_list.h" | 15 #include "base/observer_list.h" |
| 15 #include "base/stringprintf.h" | 16 #include "base/stringprintf.h" |
| 16 #include "base/threading/platform_thread.h" | 17 #include "base/threading/platform_thread.h" |
| 17 #include "base/time.h" | 18 #include "base/time.h" |
| 18 #include "base/timer.h" | 19 #include "base/timer.h" |
| 19 #include "chromeos/dbus/power_manager/input_event.pb.h" | 20 #include "chromeos/dbus/power_manager/input_event.pb.h" |
| 21 #include "chromeos/dbus/power_manager/policy.pb.h" |
| 20 #include "chromeos/dbus/power_manager/suspend.pb.h" | 22 #include "chromeos/dbus/power_manager/suspend.pb.h" |
| 21 #include "chromeos/dbus/power_state_control.pb.h" | 23 #include "chromeos/dbus/power_state_control.pb.h" |
| 22 #include "chromeos/dbus/power_supply_properties.pb.h" | 24 #include "chromeos/dbus/power_supply_properties.pb.h" |
| 23 #include "chromeos/dbus/video_activity_update.pb.h" | 25 #include "chromeos/dbus/video_activity_update.pb.h" |
| 24 #include "dbus/bus.h" | 26 #include "dbus/bus.h" |
| 25 #include "dbus/message.h" | 27 #include "dbus/message.h" |
| 26 #include "dbus/object_path.h" | 28 #include "dbus/object_path.h" |
| 27 #include "dbus/object_proxy.h" | 29 #include "dbus/object_proxy.h" |
| 28 #include "third_party/cros_system_api/dbus/service_constants.h" | 30 #include "third_party/cros_system_api/dbus/service_constants.h" |
| 29 | 31 |
| (...skipping 263 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 293 LOG(ERROR) << "Error calling " | 295 LOG(ERROR) << "Error calling " |
| 294 << power_manager::kHandleVideoActivityMethod; | 296 << power_manager::kHandleVideoActivityMethod; |
| 295 return; | 297 return; |
| 296 } | 298 } |
| 297 power_manager_proxy_->CallMethod( | 299 power_manager_proxy_->CallMethod( |
| 298 &method_call, | 300 &method_call, |
| 299 dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, | 301 dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, |
| 300 dbus::ObjectProxy::EmptyResponseCallback()); | 302 dbus::ObjectProxy::EmptyResponseCallback()); |
| 301 } | 303 } |
| 302 | 304 |
| 305 virtual void SetPolicy( |
| 306 const power_manager::PowerManagementPolicy& policy) OVERRIDE { |
| 307 dbus::MethodCall method_call( |
| 308 power_manager::kPowerManagerInterface, |
| 309 power_manager::kSetPolicyMethod); |
| 310 dbus::MessageWriter writer(&method_call); |
| 311 if (!writer.AppendProtoAsArrayOfBytes(policy)) { |
| 312 LOG(ERROR) << "Error calling " << power_manager::kSetPolicyMethod; |
| 313 return; |
| 314 } |
| 315 power_manager_proxy_->CallMethod( |
| 316 &method_call, |
| 317 dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, |
| 318 dbus::ObjectProxy::EmptyResponseCallback()); |
| 319 } |
| 320 |
| 303 virtual void RequestPowerStateOverrides( | 321 virtual void RequestPowerStateOverrides( |
| 304 uint32 request_id, | 322 uint32 request_id, |
| 305 base::TimeDelta duration, | 323 base::TimeDelta duration, |
| 306 int overrides, | 324 int overrides, |
| 307 const PowerStateRequestIdCallback& callback) OVERRIDE { | 325 const PowerStateRequestIdCallback& callback) OVERRIDE { |
| 308 dbus::MethodCall method_call(power_manager::kPowerManagerInterface, | 326 dbus::MethodCall method_call(power_manager::kPowerManagerInterface, |
| 309 power_manager::kStateOverrideRequest); | 327 power_manager::kStateOverrideRequest); |
| 310 dbus::MessageWriter writer(&method_call); | 328 dbus::MessageWriter writer(&method_call); |
| 311 | 329 |
| 312 PowerStateControl protobuf; | 330 PowerStateControl protobuf; |
| (...skipping 501 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 814 base::Unretained(this), | 832 base::Unretained(this), |
| 815 threshold), | 833 threshold), |
| 816 base::TimeDelta::FromMilliseconds(threshold)); | 834 base::TimeDelta::FromMilliseconds(threshold)); |
| 817 } | 835 } |
| 818 | 836 |
| 819 virtual void NotifyUserActivity( | 837 virtual void NotifyUserActivity( |
| 820 const base::TimeTicks& last_activity_time) OVERRIDE {} | 838 const base::TimeTicks& last_activity_time) OVERRIDE {} |
| 821 virtual void NotifyVideoActivity( | 839 virtual void NotifyVideoActivity( |
| 822 const base::TimeTicks& last_activity_time, | 840 const base::TimeTicks& last_activity_time, |
| 823 bool is_fullscreen) OVERRIDE {} | 841 bool is_fullscreen) OVERRIDE {} |
| 842 virtual void SetPolicy( |
| 843 const power_manager::PowerManagementPolicy& policy) OVERRIDE {} |
| 824 virtual void RequestPowerStateOverrides( | 844 virtual void RequestPowerStateOverrides( |
| 825 uint32 request_id, | 845 uint32 request_id, |
| 826 base::TimeDelta duration, | 846 base::TimeDelta duration, |
| 827 int overrides, | 847 int overrides, |
| 828 const PowerStateRequestIdCallback& callback) OVERRIDE { | 848 const PowerStateRequestIdCallback& callback) OVERRIDE { |
| 829 // Mimic the behavior of power manager w.r.t. the request_id. | 849 // Mimic the behavior of power manager w.r.t. the request_id. |
| 830 if (request_id == 0) { | 850 if (request_id == 0) { |
| 831 callback.Run(next_request_id_++); | 851 callback.Run(next_request_id_++); |
| 832 } else { | 852 } else { |
| 833 callback.Run(request_id); | 853 callback.Run(request_id); |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 901 PowerManagerClient* PowerManagerClient::Create( | 921 PowerManagerClient* PowerManagerClient::Create( |
| 902 DBusClientImplementationType type, | 922 DBusClientImplementationType type, |
| 903 dbus::Bus* bus) { | 923 dbus::Bus* bus) { |
| 904 if (type == REAL_DBUS_CLIENT_IMPLEMENTATION) | 924 if (type == REAL_DBUS_CLIENT_IMPLEMENTATION) |
| 905 return new PowerManagerClientImpl(bus); | 925 return new PowerManagerClientImpl(bus); |
| 906 DCHECK_EQ(STUB_DBUS_CLIENT_IMPLEMENTATION, type); | 926 DCHECK_EQ(STUB_DBUS_CLIENT_IMPLEMENTATION, type); |
| 907 return new PowerManagerClientStubImpl(); | 927 return new PowerManagerClientStubImpl(); |
| 908 } | 928 } |
| 909 | 929 |
| 910 } // namespace chromeos | 930 } // namespace chromeos |
| OLD | NEW |