Chromium Code Reviews| 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/logging.h" |
| 13 #include "base/memory/scoped_ptr.h" | 13 #include "base/memory/scoped_ptr.h" |
| 14 #include "base/message_loop.h" | 14 #include "base/message_loop.h" |
| 15 #include "base/observer_list.h" | 15 #include "base/observer_list.h" |
| 16 #include "base/stringprintf.h" | 16 #include "base/stringprintf.h" |
| 17 #include "base/threading/platform_thread.h" | 17 #include "base/threading/platform_thread.h" |
| 18 #include "base/time.h" | 18 #include "base/time.h" |
| 19 #include "base/timer.h" | 19 #include "base/timer.h" |
| 20 #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" | 21 #include "chromeos/dbus/power_manager/policy.pb.h" |
| 22 #include "chromeos/dbus/power_manager/suspend.pb.h" | 22 #include "chromeos/dbus/power_manager/suspend.pb.h" |
| 23 #include "chromeos/dbus/power_state_control.pb.h" | 23 #include "chromeos/dbus/power_state_control.pb.h" |
|
bartfab (slow)
2013/03/21 14:22:26
No longer needed.
Daniel Erat
2013/03/21 14:48:46
Done (also updated chromeos.gyp).
| |
| 24 #include "chromeos/dbus/power_supply_properties.pb.h" | 24 #include "chromeos/dbus/power_supply_properties.pb.h" |
| 25 #include "chromeos/dbus/video_activity_update.pb.h" | 25 #include "chromeos/dbus/video_activity_update.pb.h" |
| 26 #include "dbus/bus.h" | 26 #include "dbus/bus.h" |
| 27 #include "dbus/message.h" | 27 #include "dbus/message.h" |
| 28 #include "dbus/object_path.h" | 28 #include "dbus/object_path.h" |
| 29 #include "dbus/object_proxy.h" | 29 #include "dbus/object_proxy.h" |
| 30 #include "third_party/cros_system_api/dbus/service_constants.h" | 30 #include "third_party/cros_system_api/dbus/service_constants.h" |
| 31 | 31 |
| 32 namespace chromeos { | 32 namespace chromeos { |
| 33 | 33 |
| (...skipping 278 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 312 if (!writer.AppendProtoAsArrayOfBytes(policy)) { | 312 if (!writer.AppendProtoAsArrayOfBytes(policy)) { |
| 313 LOG(ERROR) << "Error calling " << power_manager::kSetPolicyMethod; | 313 LOG(ERROR) << "Error calling " << power_manager::kSetPolicyMethod; |
| 314 return; | 314 return; |
| 315 } | 315 } |
| 316 power_manager_proxy_->CallMethod( | 316 power_manager_proxy_->CallMethod( |
| 317 &method_call, | 317 &method_call, |
| 318 dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, | 318 dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, |
| 319 dbus::ObjectProxy::EmptyResponseCallback()); | 319 dbus::ObjectProxy::EmptyResponseCallback()); |
| 320 } | 320 } |
| 321 | 321 |
| 322 virtual void RequestPowerStateOverrides( | |
| 323 uint32 request_id, | |
| 324 base::TimeDelta duration, | |
| 325 int overrides, | |
| 326 const PowerStateRequestIdCallback& callback) OVERRIDE { | |
| 327 dbus::MethodCall method_call(power_manager::kPowerManagerInterface, | |
| 328 power_manager::kStateOverrideRequest); | |
| 329 dbus::MessageWriter writer(&method_call); | |
| 330 | |
| 331 PowerStateControl protobuf; | |
| 332 protobuf.set_request_id(request_id); | |
| 333 protobuf.set_duration(duration.InSeconds()); | |
| 334 protobuf.set_disable_idle_dim(overrides & DISABLE_IDLE_DIM); | |
| 335 protobuf.set_disable_idle_blank(overrides & DISABLE_IDLE_BLANK); | |
| 336 protobuf.set_disable_idle_suspend(overrides & DISABLE_IDLE_SUSPEND); | |
| 337 protobuf.set_disable_lid_suspend(overrides & DISABLE_LID_SUSPEND); | |
| 338 | |
| 339 if (!writer.AppendProtoAsArrayOfBytes(protobuf)) { | |
| 340 LOG(ERROR) << "Error calling " | |
| 341 << power_manager::kStateOverrideRequest; | |
| 342 return; | |
| 343 } | |
| 344 power_manager_proxy_->CallMethod( | |
| 345 &method_call, | |
| 346 dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, | |
| 347 base::Bind(&PowerManagerClientImpl::OnPowerStateOverride, | |
| 348 weak_ptr_factory_.GetWeakPtr(), callback)); | |
| 349 } | |
| 350 | |
| 351 virtual void CancelPowerStateOverrides(uint32 request_id) OVERRIDE { | |
| 352 dbus::MethodCall method_call(power_manager::kPowerManagerInterface, | |
| 353 power_manager::kStateOverrideCancel); | |
| 354 dbus::MessageWriter writer(&method_call); | |
| 355 writer.AppendInt32(request_id); | |
| 356 power_manager_proxy_->CallMethod( | |
| 357 &method_call, | |
| 358 dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, | |
| 359 dbus::ObjectProxy::EmptyResponseCallback()); | |
| 360 } | |
| 361 | |
| 362 virtual void SetIsProjecting(bool is_projecting) OVERRIDE { | 322 virtual void SetIsProjecting(bool is_projecting) OVERRIDE { |
| 363 dbus::MethodCall method_call( | 323 dbus::MethodCall method_call( |
| 364 power_manager::kPowerManagerInterface, | 324 power_manager::kPowerManagerInterface, |
| 365 power_manager::kSetIsProjectingMethod); | 325 power_manager::kSetIsProjectingMethod); |
| 366 dbus::MessageWriter writer(&method_call); | 326 dbus::MessageWriter writer(&method_call); |
| 367 writer.AppendBool(is_projecting); | 327 writer.AppendBool(is_projecting); |
| 368 power_manager_proxy_->CallMethod( | 328 power_manager_proxy_->CallMethod( |
| 369 &method_call, | 329 &method_call, |
| 370 dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, | 330 dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, |
| 371 dbus::ObjectProxy::EmptyResponseCallback()); | 331 dbus::ObjectProxy::EmptyResponseCallback()); |
| (...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 495 return; | 455 return; |
| 496 } | 456 } |
| 497 if (idle_time_ms < 0) { | 457 if (idle_time_ms < 0) { |
| 498 LOG(ERROR) << "Power manager failed to calculate idle time."; | 458 LOG(ERROR) << "Power manager failed to calculate idle time."; |
| 499 callback.Run(-1); | 459 callback.Run(-1); |
| 500 return; | 460 return; |
| 501 } | 461 } |
| 502 callback.Run(idle_time_ms/1000); | 462 callback.Run(idle_time_ms/1000); |
| 503 } | 463 } |
| 504 | 464 |
| 505 void OnPowerStateOverride(const PowerStateRequestIdCallback& callback, | |
| 506 dbus::Response* response) { | |
| 507 if (!response) { | |
| 508 LOG(ERROR) << "Error calling " << power_manager::kStateOverrideRequest; | |
| 509 return; | |
| 510 } | |
| 511 | |
| 512 dbus::MessageReader reader(response); | |
| 513 int32 request_id = 0; | |
| 514 if (!reader.PopInt32(&request_id)) { | |
| 515 LOG(ERROR) << "Error reading response from powerd: " | |
| 516 << response->ToString(); | |
| 517 callback.Run(0); | |
| 518 return; | |
| 519 } | |
| 520 | |
| 521 callback.Run(request_id); | |
| 522 } | |
| 523 | |
| 524 void OnGetScreenBrightnessPercent( | 465 void OnGetScreenBrightnessPercent( |
| 525 const GetScreenBrightnessPercentCallback& callback, | 466 const GetScreenBrightnessPercentCallback& callback, |
| 526 dbus::Response* response) { | 467 dbus::Response* response) { |
| 527 if (!response) { | 468 if (!response) { |
| 528 LOG(ERROR) << "Error calling " | 469 LOG(ERROR) << "Error calling " |
| 529 << power_manager::kGetScreenBrightnessPercent; | 470 << power_manager::kGetScreenBrightnessPercent; |
| 530 return; | 471 return; |
| 531 } | 472 } |
| 532 dbus::MessageReader reader(response); | 473 dbus::MessageReader reader(response); |
| 533 double percent = 0.0; | 474 double percent = 0.0; |
| (...skipping 428 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 962 PowerSupplyStatus status_; | 903 PowerSupplyStatus status_; |
| 963 uint32 next_request_id_; | 904 uint32 next_request_id_; |
| 964 }; | 905 }; |
| 965 | 906 |
| 966 PowerManagerClient::PowerManagerClient() { | 907 PowerManagerClient::PowerManagerClient() { |
| 967 } | 908 } |
| 968 | 909 |
| 969 PowerManagerClient::~PowerManagerClient() { | 910 PowerManagerClient::~PowerManagerClient() { |
| 970 } | 911 } |
| 971 | 912 |
| 913 // static | |
| 972 PowerManagerClient* PowerManagerClient::Create( | 914 PowerManagerClient* PowerManagerClient::Create( |
| 973 DBusClientImplementationType type, | 915 DBusClientImplementationType type, |
| 974 dbus::Bus* bus) { | 916 dbus::Bus* bus) { |
| 975 if (type == REAL_DBUS_CLIENT_IMPLEMENTATION) | 917 if (type == REAL_DBUS_CLIENT_IMPLEMENTATION) |
| 976 return new PowerManagerClientImpl(bus); | 918 return new PowerManagerClientImpl(bus); |
| 977 DCHECK_EQ(STUB_DBUS_CLIENT_IMPLEMENTATION, type); | 919 DCHECK_EQ(STUB_DBUS_CLIENT_IMPLEMENTATION, type); |
| 978 return new PowerManagerClientStubImpl(); | 920 return new PowerManagerClientStubImpl(); |
| 979 } | 921 } |
| 980 | 922 |
| 981 } // namespace chromeos | 923 } // namespace chromeos |
| OLD | NEW |