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 "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" |
| 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/observer_list.h" | 13 #include "base/observer_list.h" |
| 14 #include "base/stringprintf.h" | 14 #include "base/stringprintf.h" |
| 15 #include "base/time.h" | 15 #include "base/time.h" |
| 16 #include "base/timer.h" | 16 #include "base/timer.h" |
| 17 #include "chrome/browser/chromeos/dbus/power_supply_properties.pb.h" | |
| 17 #include "chrome/browser/chromeos/login/screen_locker.h" | 18 #include "chrome/browser/chromeos/login/screen_locker.h" |
| 18 #include "chrome/browser/chromeos/system/runtime_environment.h" | 19 #include "chrome/browser/chromeos/system/runtime_environment.h" |
| 19 #include "dbus/bus.h" | 20 #include "dbus/bus.h" |
| 20 #include "dbus/message.h" | 21 #include "dbus/message.h" |
| 21 #include "dbus/object_proxy.h" | 22 #include "dbus/object_proxy.h" |
| 22 #include "third_party/cros_system_api/dbus/service_constants.h" | 23 #include "third_party/cros_system_api/dbus/service_constants.h" |
| 23 | 24 |
| 24 namespace chromeos { | 25 namespace chromeos { |
| 25 | 26 |
| 26 PowerSupplyStatus::PowerSupplyStatus() | 27 PowerSupplyStatus::PowerSupplyStatus() |
| (...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 160 power_manager::kPowerManagerInterface, | 161 power_manager::kPowerManagerInterface, |
| 161 power_manager::kIncreaseScreenBrightness); | 162 power_manager::kIncreaseScreenBrightness); |
| 162 power_manager_proxy_->CallMethod( | 163 power_manager_proxy_->CallMethod( |
| 163 &method_call, | 164 &method_call, |
| 164 dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, | 165 dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, |
| 165 base::Bind(&PowerManagerClientImpl::OnIncreaseScreenBrightness, | 166 base::Bind(&PowerManagerClientImpl::OnIncreaseScreenBrightness, |
| 166 weak_ptr_factory_.GetWeakPtr())); | 167 weak_ptr_factory_.GetWeakPtr())); |
| 167 } | 168 } |
| 168 | 169 |
| 169 virtual void RequestStatusUpdate() OVERRIDE { | 170 virtual void RequestStatusUpdate() OVERRIDE { |
| 170 dbus::MethodCall method_call(power_manager::kPowerManagerInterface, | 171 dbus::MethodCall get_all_method_call(power_manager::kPowerManagerInterface, |
|
satorux1
2012/02/07 21:16:49
Do we still need to call the older method? I thoug
rharrison
2012/02/14 17:03:09
Done.
| |
| 171 power_manager::kGetAllPropertiesMethod); | 172 power_manager::kGetAllPropertiesMethod); |
|
satorux1
2012/02/07 21:16:49
nit: please align parameters vertically:
dbus::Me
rharrison
2012/02/14 17:03:09
Done.
| |
| 172 power_manager_proxy_->CallMethod( | 173 power_manager_proxy_->CallMethod( |
| 173 &method_call, | 174 &get_all_method_call, |
| 174 dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, | 175 dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, |
| 175 base::Bind(&PowerManagerClientImpl::OnGetAllPropertiesMethod, | 176 base::Bind(&PowerManagerClientImpl::OnGetAllPropertiesMethod, |
| 176 weak_ptr_factory_.GetWeakPtr())); | 177 weak_ptr_factory_.GetWeakPtr())); |
| 178 | |
| 179 dbus::MethodCall get_power_method_call( | |
| 180 power_manager::kPowerManagerInterface, | |
| 181 power_manager::kGetPowerSupplyPropertiesMethod); | |
| 182 power_manager_proxy_->CallMethod( | |
| 183 &get_power_method_call, | |
| 184 dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, | |
| 185 base::Bind(&PowerManagerClientImpl::OnGetPowerSupplyPropertiesMethod, | |
| 186 weak_ptr_factory_.GetWeakPtr())); | |
| 187 | |
| 177 } | 188 } |
| 178 | 189 |
| 179 // Requests restart of the system. | 190 // Requests restart of the system. |
| 180 virtual void RequestRestart() OVERRIDE { | 191 virtual void RequestRestart() OVERRIDE { |
| 181 dbus::MethodCall method_call(power_manager::kPowerManagerInterface, | 192 dbus::MethodCall method_call(power_manager::kPowerManagerInterface, |
| 182 power_manager::kRequestRestartMethod); | 193 power_manager::kRequestRestartMethod); |
| 183 power_manager_proxy_->CallMethod( | 194 power_manager_proxy_->CallMethod( |
| 184 &method_call, | 195 &method_call, |
| 185 dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, | 196 dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, |
| 186 dbus::ObjectProxy::EmptyResponseCallback()); | 197 dbus::ObjectProxy::EmptyResponseCallback()); |
| (...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 337 !reader.PopBool(&status.battery_is_full)) { | 348 !reader.PopBool(&status.battery_is_full)) { |
| 338 LOG(ERROR) << "Error reading response from powerd: " | 349 LOG(ERROR) << "Error reading response from powerd: " |
| 339 << response->ToString(); | 350 << response->ToString(); |
| 340 return; | 351 return; |
| 341 } | 352 } |
| 342 | 353 |
| 343 VLOG(1) << "Power status: " << status.ToString(); | 354 VLOG(1) << "Power status: " << status.ToString(); |
| 344 FOR_EACH_OBSERVER(Observer, observers_, PowerChanged(status)); | 355 FOR_EACH_OBSERVER(Observer, observers_, PowerChanged(status)); |
| 345 } | 356 } |
| 346 | 357 |
| 358 | |
| 359 void OnGetPowerSupplyPropertiesMethod(dbus::Response* response) { | |
| 360 if (!response) { | |
| 361 LOG(ERROR) << "Error calling " | |
| 362 << power_manager::kGetPowerSupplyPropertiesMethod; | |
| 363 return; | |
| 364 } | |
| 365 | |
| 366 dbus::MessageReader reader(response); | |
| 367 PowerSupplyProperties protobuf; | |
| 368 reader.PopArrayOfBytesAsProto(&protobuf); | |
| 369 | |
| 370 PowerSupplyStatus status; | |
| 371 status.line_power_on = protobuf.line_power_on(); | |
| 372 status.battery_seconds_to_empty = protobuf.battery_time_to_empty(); | |
| 373 status.battery_seconds_to_full = protobuf.battery_time_to_full(); | |
| 374 status.battery_percentage = protobuf.battery_percentage(); | |
| 375 status.battery_is_present = protobuf.battery_is_present(); | |
| 376 status.battery_is_full = protobuf.battery_is_charged(); | |
| 377 | |
| 378 VLOG(1) << "Power status: " << status.ToString(); | |
| 379 FOR_EACH_OBSERVER(Observer, observers_, PowerChanged(status)); | |
| 380 } | |
| 381 | |
| 347 void OnGetIdleTime(const CalculateIdleTimeCallback& callback, | 382 void OnGetIdleTime(const CalculateIdleTimeCallback& callback, |
| 348 dbus::Response* response) { | 383 dbus::Response* response) { |
| 349 if (!response) { | 384 if (!response) { |
| 350 LOG(ERROR) << "Error calling " << power_manager::kGetIdleTime; | 385 LOG(ERROR) << "Error calling " << power_manager::kGetIdleTime; |
| 351 return; | 386 return; |
| 352 } | 387 } |
| 353 dbus::MessageReader reader(response); | 388 dbus::MessageReader reader(response); |
| 354 int64 idle_time_ms = 0; | 389 int64 idle_time_ms = 0; |
| 355 if (!reader.PopInt64(&idle_time_ms)) { | 390 if (!reader.PopInt64(&idle_time_ms)) { |
| 356 LOG(ERROR) << "Error reading response from powerd: " | 391 LOG(ERROR) << "Error reading response from powerd: " |
| (...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 502 | 537 |
| 503 PowerManagerClient* PowerManagerClient::Create(dbus::Bus* bus) { | 538 PowerManagerClient* PowerManagerClient::Create(dbus::Bus* bus) { |
| 504 if (system::runtime_environment::IsRunningOnChromeOS()) { | 539 if (system::runtime_environment::IsRunningOnChromeOS()) { |
| 505 return new PowerManagerClientImpl(bus); | 540 return new PowerManagerClientImpl(bus); |
| 506 } else { | 541 } else { |
| 507 return new PowerManagerClientStubImpl(); | 542 return new PowerManagerClientStubImpl(); |
| 508 } | 543 } |
| 509 } | 544 } |
| 510 | 545 |
| 511 } // namespace chromeos | 546 } // namespace chromeos |
| OLD | NEW |