Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(54)

Side by Side Diff: chrome/browser/chromeos/dbus/power_manager_client.cc

Issue 9318007: Adding using protobuf based communication for the power information transfer. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Rewrote the gypi rule for the protobuf, so to not leak into non-cros builds Created 8 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | chrome/chrome_browser.gypi » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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_path.h" 22 #include "dbus/object_path.h"
22 #include "dbus/object_proxy.h" 23 #include "dbus/object_proxy.h"
23 #include "third_party/cros_system_api/dbus/service_constants.h" 24 #include "third_party/cros_system_api/dbus/service_constants.h"
24 25
25 namespace chromeos { 26 namespace chromeos {
26 27
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after
174 &method_call, 175 &method_call,
175 dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, 176 dbus::ObjectProxy::TIMEOUT_USE_DEFAULT,
176 dbus::ObjectProxy::EmptyResponseCallback()); 177 dbus::ObjectProxy::EmptyResponseCallback());
177 } 178 }
178 179
179 virtual void IncreaseScreenBrightness() OVERRIDE { 180 virtual void IncreaseScreenBrightness() OVERRIDE {
180 SimpleMethodCallToPowerManager(power_manager::kIncreaseScreenBrightness); 181 SimpleMethodCallToPowerManager(power_manager::kIncreaseScreenBrightness);
181 } 182 }
182 183
183 virtual void RequestStatusUpdate(UpdateRequestType update_type) OVERRIDE { 184 virtual void RequestStatusUpdate(UpdateRequestType update_type) OVERRIDE {
184 dbus::MethodCall method_call(power_manager::kPowerManagerInterface, 185 dbus::MethodCall method_call(
185 power_manager::kGetAllPropertiesMethod); 186 power_manager::kPowerManagerInterface,
187 power_manager::kGetPowerSupplyPropertiesMethod);
186 power_manager_proxy_->CallMethod( 188 power_manager_proxy_->CallMethod(
187 &method_call, 189 &method_call,
188 dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, 190 dbus::ObjectProxy::TIMEOUT_USE_DEFAULT,
189 base::Bind(&PowerManagerClientImpl::OnGetAllPropertiesMethod, 191 base::Bind(&PowerManagerClientImpl::OnGetPowerSupplyPropertiesMethod,
190 weak_ptr_factory_.GetWeakPtr())); 192 weak_ptr_factory_.GetWeakPtr()));
191 } 193 }
192 194
193 virtual void RequestRestart() OVERRIDE { 195 virtual void RequestRestart() OVERRIDE {
194 SimpleMethodCallToPowerManager(power_manager::kRequestRestartMethod); 196 SimpleMethodCallToPowerManager(power_manager::kRequestRestartMethod);
195 }; 197 };
196 198
197 virtual void RequestShutdown() OVERRIDE { 199 virtual void RequestShutdown() OVERRIDE {
198 SimpleMethodCallToPowerManager(power_manager::kRequestShutdownMethod); 200 SimpleMethodCallToPowerManager(power_manager::kRequestShutdownMethod);
199 } 201 }
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
312 FOR_EACH_OBSERVER( 314 FOR_EACH_OBSERVER(
313 Observer, observers_, LockButtonStateChanged(down, timestamp)); 315 Observer, observers_, LockButtonStateChanged(down, timestamp));
314 } 316 }
315 } 317 }
316 318
317 void PowerSupplyPollReceived(dbus::Signal* unused_signal) { 319 void PowerSupplyPollReceived(dbus::Signal* unused_signal) {
318 VLOG(1) << "Received power supply poll signal."; 320 VLOG(1) << "Received power supply poll signal.";
319 RequestStatusUpdate(UPDATE_POLL); 321 RequestStatusUpdate(UPDATE_POLL);
320 } 322 }
321 323
322 void OnGetAllPropertiesMethod(dbus::Response* response) { 324 void OnGetPowerSupplyPropertiesMethod(dbus::Response* response) {
323 if (!response) { 325 if (!response) {
324 LOG(ERROR) << "Error calling " << power_manager::kGetAllPropertiesMethod; 326 LOG(ERROR) << "Error calling "
325 return; 327 << power_manager::kGetPowerSupplyPropertiesMethod;
326 }
327 dbus::MessageReader reader(response);
328 PowerSupplyStatus status;
329 double unused_battery_voltage = 0.0;
330 double unused_battery_energy = 0.0;
331 double unused_battery_energy_rate = 0.0;
332 if (!reader.PopBool(&status.line_power_on) ||
333 !reader.PopDouble(&unused_battery_energy) ||
334 !reader.PopDouble(&unused_battery_energy_rate) ||
335 !reader.PopDouble(&unused_battery_voltage) ||
336 !reader.PopInt64(&status.battery_seconds_to_empty) ||
337 !reader.PopInt64(&status.battery_seconds_to_full) ||
338 !reader.PopDouble(&status.battery_percentage) ||
339 !reader.PopBool(&status.battery_is_present) ||
340 !reader.PopBool(&status.battery_is_full)) {
341 LOG(ERROR) << "Error reading response from powerd: "
342 << response->ToString();
343 return; 328 return;
344 } 329 }
345 330
331 dbus::MessageReader reader(response);
332 PowerSupplyProperties protobuf;
333 reader.PopArrayOfBytesAsProto(&protobuf);
334
335 PowerSupplyStatus status;
336 status.line_power_on = protobuf.line_power_on();
337 status.battery_seconds_to_empty = protobuf.battery_time_to_empty();
338 status.battery_seconds_to_full = protobuf.battery_time_to_full();
339 status.battery_percentage = protobuf.battery_percentage();
340 status.battery_is_present = protobuf.battery_is_present();
341 status.battery_is_full = protobuf.battery_is_charged();
342
346 VLOG(1) << "Power status: " << status.ToString(); 343 VLOG(1) << "Power status: " << status.ToString();
347 FOR_EACH_OBSERVER(Observer, observers_, PowerChanged(status)); 344 FOR_EACH_OBSERVER(Observer, observers_, PowerChanged(status));
348 } 345 }
349 346
350 void OnGetIdleTime(const CalculateIdleTimeCallback& callback, 347 void OnGetIdleTime(const CalculateIdleTimeCallback& callback,
351 dbus::Response* response) { 348 dbus::Response* response) {
352 if (!response) { 349 if (!response) {
353 LOG(ERROR) << "Error calling " << power_manager::kGetIdleTime; 350 LOG(ERROR) << "Error calling " << power_manager::kGetIdleTime;
354 return; 351 return;
355 } 352 }
(...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after
541 538
542 PowerManagerClient* PowerManagerClient::Create(dbus::Bus* bus) { 539 PowerManagerClient* PowerManagerClient::Create(dbus::Bus* bus) {
543 if (system::runtime_environment::IsRunningOnChromeOS()) { 540 if (system::runtime_environment::IsRunningOnChromeOS()) {
544 return new PowerManagerClientImpl(bus); 541 return new PowerManagerClientImpl(bus);
545 } else { 542 } else {
546 return new PowerManagerClientStubImpl(); 543 return new PowerManagerClientStubImpl();
547 } 544 }
548 } 545 }
549 546
550 } // namespace chromeos 547 } // namespace chromeos
OLDNEW
« no previous file with comments | « no previous file | chrome/chrome_browser.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698