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