Adding using protobuf based communication for the power information transfer.

Added in gyp rule for building the needed protobuf. Added secondary code path that calls the PopArrayOfBytesAsProto command and then passes the value up to the rest of Chrome. Removed the old code path.

BUG=chromium-os:25489
TEST=Build image using new code path ChromeOS and Chrome.      Then test that is
     working on a device.


Review URL: http://codereview.chromium.org/9318007

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@125005 0039d316-1c4b-4281-b951-d872f2087c98
parent d1f1b75f
...@@ -14,6 +14,7 @@ ...@@ -14,6 +14,7 @@
#include "base/stringprintf.h" #include "base/stringprintf.h"
#include "base/time.h" #include "base/time.h"
#include "base/timer.h" #include "base/timer.h"
#include "chrome/browser/chromeos/dbus/power_supply_properties.pb.h"
#include "chrome/browser/chromeos/login/screen_locker.h" #include "chrome/browser/chromeos/login/screen_locker.h"
#include "chrome/browser/chromeos/system/runtime_environment.h" #include "chrome/browser/chromeos/system/runtime_environment.h"
#include "dbus/bus.h" #include "dbus/bus.h"
...@@ -181,12 +182,13 @@ class PowerManagerClientImpl : public PowerManagerClient { ...@@ -181,12 +182,13 @@ class PowerManagerClientImpl : public PowerManagerClient {
} }
virtual void RequestStatusUpdate(UpdateRequestType update_type) OVERRIDE { virtual void RequestStatusUpdate(UpdateRequestType update_type) OVERRIDE {
dbus::MethodCall method_call(power_manager::kPowerManagerInterface, dbus::MethodCall method_call(
power_manager::kGetAllPropertiesMethod); power_manager::kPowerManagerInterface,
power_manager::kGetPowerSupplyPropertiesMethod);
power_manager_proxy_->CallMethod( power_manager_proxy_->CallMethod(
&method_call, &method_call,
dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT,
base::Bind(&PowerManagerClientImpl::OnGetAllPropertiesMethod, base::Bind(&PowerManagerClientImpl::OnGetPowerSupplyPropertiesMethod,
weak_ptr_factory_.GetWeakPtr())); weak_ptr_factory_.GetWeakPtr()));
} }
...@@ -319,29 +321,24 @@ class PowerManagerClientImpl : public PowerManagerClient { ...@@ -319,29 +321,24 @@ class PowerManagerClientImpl : public PowerManagerClient {
RequestStatusUpdate(UPDATE_POLL); RequestStatusUpdate(UPDATE_POLL);
} }
void OnGetAllPropertiesMethod(dbus::Response* response) { void OnGetPowerSupplyPropertiesMethod(dbus::Response* response) {
if (!response) { if (!response) {
LOG(ERROR) << "Error calling " << power_manager::kGetAllPropertiesMethod; LOG(ERROR) << "Error calling "
<< power_manager::kGetPowerSupplyPropertiesMethod;
return; return;
} }
dbus::MessageReader reader(response); dbus::MessageReader reader(response);
PowerSupplyProperties protobuf;
reader.PopArrayOfBytesAsProto(&protobuf);
PowerSupplyStatus status; PowerSupplyStatus status;
double unused_battery_voltage = 0.0; status.line_power_on = protobuf.line_power_on();
double unused_battery_energy = 0.0; status.battery_seconds_to_empty = protobuf.battery_time_to_empty();
double unused_battery_energy_rate = 0.0; status.battery_seconds_to_full = protobuf.battery_time_to_full();
if (!reader.PopBool(&status.line_power_on) || status.battery_percentage = protobuf.battery_percentage();
!reader.PopDouble(&unused_battery_energy) || status.battery_is_present = protobuf.battery_is_present();
!reader.PopDouble(&unused_battery_energy_rate) || status.battery_is_full = protobuf.battery_is_charged();
!reader.PopDouble(&unused_battery_voltage) ||
!reader.PopInt64(&status.battery_seconds_to_empty) ||
!reader.PopInt64(&status.battery_seconds_to_full) ||
!reader.PopDouble(&status.battery_percentage) ||
!reader.PopBool(&status.battery_is_present) ||
!reader.PopBool(&status.battery_is_full)) {
LOG(ERROR) << "Error reading response from powerd: "
<< response->ToString();
return;
}
VLOG(1) << "Power status: " << status.ToString(); VLOG(1) << "Power status: " << status.ToString();
FOR_EACH_OBSERVER(Observer, observers_, PowerChanged(status)); FOR_EACH_OBSERVER(Observer, observers_, PowerChanged(status));
......
...@@ -4484,6 +4484,7 @@ ...@@ -4484,6 +4484,7 @@
'../third_party/libevent/libevent.gyp:libevent', '../third_party/libevent/libevent.gyp:libevent',
'../third_party/mozc/chrome/chromeos/renderer/chromeos_renderer.gyp:mozc_candidates_proto', '../third_party/mozc/chrome/chromeos/renderer/chromeos_renderer.gyp:mozc_candidates_proto',
'browser/chromeos/input_method/input_method.gyp:gencode', 'browser/chromeos/input_method/input_method.gyp:gencode',
'power_supply_properties_proto',
], ],
'sources!': [ 'sources!': [
'browser/background/background_mode_manager_gtk.cc', 'browser/background/background_mode_manager_gtk.cc',
...@@ -5677,5 +5678,23 @@ ...@@ -5677,5 +5678,23 @@
}, },
'includes': [ '../build/protoc.gypi' ] 'includes': [ '../build/protoc.gypi' ]
}, },
{
# Protobuf compiler / generator for the PowerSupplyProperties protocol
# buffer.
'target_name': 'power_supply_properties_proto',
'type': 'static_library',
'conditions': [
['chromeos==1', {
'sources': [
'../third_party/cros_system_api/dbus/power_supply_properties.proto',
],
'variables': {
'proto_in_dir': '../third_party/cros_system_api/dbus/',
'proto_out_dir': 'chrome/browser/chromeos/dbus',
},
'includes': ['../build/protoc.gypi'],
}],
],
},
], ],
} }
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment