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

Unified Diff: chrome/browser/ui/webui/chromeos/emulator/device_emulator_message_handler.cc

Issue 1256303002: Creating Ui for Battery State Option in Chrome Os Emulator (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Indents Created 5 years, 5 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/browser/ui/webui/chromeos/emulator/device_emulator_message_handler.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/ui/webui/chromeos/emulator/device_emulator_message_handler.cc
diff --git a/chrome/browser/ui/webui/chromeos/emulator/device_emulator_message_handler.cc b/chrome/browser/ui/webui/chromeos/emulator/device_emulator_message_handler.cc
index 83b0af469c120e9e1f88e6de44394d81965bded6..7a6b7c03af6b4579eaf2e11797d1a8bd2b58e846 100644
--- a/chrome/browser/ui/webui/chromeos/emulator/device_emulator_message_handler.cc
+++ b/chrome/browser/ui/webui/chromeos/emulator/device_emulator_message_handler.cc
@@ -22,6 +22,7 @@ const char kRequestPowerInfo[] = "requestPowerInfo";
// Define update functions that will update the power properties to the
// variables defined in the web UI.
const char kUpdateBatteryPercent[] = "updateBatteryPercent";
+const char kUpdateBatteryState[] = "updateBatteryState";
const char kUpdateExternalPower[] = "updateExternalPower";
const char kUpdateTimeToEmpty[] = "updateTimeToEmpty";
const char kUpdateTimeToFull[] = "updateTimeToFull";
@@ -68,61 +69,77 @@ void DeviceEmulatorMessageHandler::HandleRequestBluetoothPair(
void DeviceEmulatorMessageHandler::UpdateBatteryPercent(
const base::ListValue* args) {
- power_manager::PowerSupplyProperties props =
- fake_power_manager_client_->props();
-
int new_percent;
- if (args->GetInteger(0, &new_percent))
+ if (args->GetInteger(0, &new_percent)) {
+ power_manager::PowerSupplyProperties props =
+ fake_power_manager_client_->props();
props.set_battery_percent(new_percent);
+ fake_power_manager_client_->UpdatePowerProperties(props);
+ }
+}
- fake_power_manager_client_->UpdatePowerProperties(props);
+void DeviceEmulatorMessageHandler::UpdateBatteryState(
+ const base::ListValue* args) {
+ int battery_state;
+ if (args->GetInteger(0, &battery_state)) {
+ power_manager::PowerSupplyProperties props =
+ fake_power_manager_client_->props();
+ props.set_battery_state(
+ static_cast<power_manager::PowerSupplyProperties_BatteryState>(
+ battery_state));
+ fake_power_manager_client_->UpdatePowerProperties(props);
+ }
}
void DeviceEmulatorMessageHandler::UpdateExternalPower(
const base::ListValue* args) {
int power_source;
- args->GetInteger(0, &power_source);
-
- power_manager::PowerSupplyProperties props =
- fake_power_manager_client_->props();
- props.set_external_power(
- static_cast<power_manager::PowerSupplyProperties_ExternalPower>(
- power_source));
- fake_power_manager_client_->UpdatePowerProperties(props);
+ if (args->GetInteger(0, &power_source)) {
+ power_manager::PowerSupplyProperties props =
+ fake_power_manager_client_->props();
+ props.set_external_power(
+ static_cast<power_manager::PowerSupplyProperties_ExternalPower>(
+ power_source));
+ fake_power_manager_client_->UpdatePowerProperties(props);
+ }
}
void DeviceEmulatorMessageHandler::UpdateTimeToEmpty(
const base::ListValue* args) {
- power_manager::PowerSupplyProperties props =
- fake_power_manager_client_->props();
-
int new_time;
- if (args->GetInteger(0, &new_time))
+ if (args->GetInteger(0, &new_time)) {
+ power_manager::PowerSupplyProperties props =
+ fake_power_manager_client_->props();
props.set_battery_time_to_empty_sec(new_time);
-
- fake_power_manager_client_->UpdatePowerProperties(props);
+ fake_power_manager_client_->UpdatePowerProperties(props);
+ }
}
void DeviceEmulatorMessageHandler::UpdateTimeToFull(
const base::ListValue* args) {
- power_manager::PowerSupplyProperties props =
- fake_power_manager_client_->props();
int new_time;
- if (args->GetInteger(0, &new_time))
+ if (args->GetInteger(0, &new_time)) {
+ power_manager::PowerSupplyProperties props =
+ fake_power_manager_client_->props();
props.set_battery_time_to_full_sec(new_time);
- fake_power_manager_client_->UpdatePowerProperties(props);
+ fake_power_manager_client_->UpdatePowerProperties(props);
+ }
}
void DeviceEmulatorMessageHandler::PowerChanged(
const power_manager::PowerSupplyProperties& proto) {
- web_ui()->CallJavascriptFunction(
- kUpdatePowerPropertiesJSCallback,
- base::FundamentalValue(proto.battery_percent()),
- base::FundamentalValue(proto.external_power()),
- base::FundamentalValue(
- static_cast<int>(proto.battery_time_to_empty_sec())),
- base::FundamentalValue(
- static_cast<int>(proto.battery_time_to_full_sec())));
+ base::DictionaryValue power_properties;
+
+ power_properties.SetInteger("battery_percent", proto.battery_percent());
+ power_properties.SetInteger("battery_state", proto.battery_state());
+ power_properties.SetInteger("external_power", proto.external_power());
+ power_properties.SetInteger("battery_time_to_empty_sec",
+ proto.battery_time_to_empty_sec());
+ power_properties.SetInteger("battery_time_to_full_sec",
+ proto.battery_time_to_full_sec());
+
+ web_ui()->CallJavascriptFunction(kUpdatePowerPropertiesJSCallback,
+ power_properties);
}
void DeviceEmulatorMessageHandler::RegisterMessages() {
@@ -135,6 +152,10 @@ void DeviceEmulatorMessageHandler::RegisterMessages() {
base::Bind(&DeviceEmulatorMessageHandler::UpdateBatteryPercent,
base::Unretained(this)));
web_ui()->RegisterMessageCallback(
+ kUpdateBatteryState,
+ base::Bind(&DeviceEmulatorMessageHandler::UpdateBatteryState,
+ base::Unretained(this)));
+ web_ui()->RegisterMessageCallback(
kUpdateExternalPower,
base::Bind(&DeviceEmulatorMessageHandler::UpdateExternalPower,
base::Unretained(this)));
« no previous file with comments | « chrome/browser/ui/webui/chromeos/emulator/device_emulator_message_handler.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698