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

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: Updated nits and fixed device_emulator undefined 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
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..db492a4abf518b5c349aa5bd032a766d64f60efa 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";
@@ -78,16 +79,31 @@ void DeviceEmulatorMessageHandler::UpdateBatteryPercent(
fake_power_manager_client_->UpdatePowerProperties(props);
}
-void DeviceEmulatorMessageHandler::UpdateExternalPower(
+void DeviceEmulatorMessageHandler::UpdateBatteryState(
const base::ListValue* args) {
- int power_source;
- args->GetInteger(0, &power_source);
+ power_manager::PowerSupplyProperties props =
+ fake_power_manager_client_->props();
+
+ int battery_state;
+ if (args->GetInteger(0, &battery_state))
+ 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) {
power_manager::PowerSupplyProperties props =
fake_power_manager_client_->props();
+
+ int power_source;
+ if (args->GetInteger(0, &power_source))
props.set_external_power(
static_cast<power_manager::PowerSupplyProperties_ExternalPower>(
power_source));
+
fake_power_manager_client_->UpdatePowerProperties(props);
}
@@ -107,9 +123,11 @@ 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))
props.set_battery_time_to_full_sec(new_time);
+
fake_power_manager_client_->UpdatePowerProperties(props);
}
@@ -118,11 +136,12 @@ void DeviceEmulatorMessageHandler::PowerChanged(
web_ui()->CallJavascriptFunction(
kUpdatePowerPropertiesJSCallback,
base::FundamentalValue(proto.battery_percent()),
+ base::FundamentalValue(proto.battery_state())),
oshima 2015/07/29 00:50:48 does this compile?
mozartalouis 2015/07/29 21:06:04 Done.
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())));
+ static_cast<int>(proto.battery_time_to_full_sec()));
}
void DeviceEmulatorMessageHandler::RegisterMessages() {
@@ -135,6 +154,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)));

Powered by Google App Engine
This is Rietveld 408576698