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

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: Added radio group for battery state with functionality 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 ce7f8bb1fd5e57fc242523856eb5898ab248d1ba..0b65a89e6d8c45965e6a3a503b77cec50f3ee28a 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
@@ -21,6 +21,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";
@@ -62,6 +63,19 @@ void DeviceEmulatorMessageHandler::UpdateBatteryPercent(
fake_power_manager_client_->UpdatePowerProperties(props);
}
+void DeviceEmulatorMessageHandler::UpdateBatteryState(
+ const base::ListValue* args) {
+ int battery_state;
+ 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;
@@ -102,11 +116,12 @@ void DeviceEmulatorMessageHandler::PowerChanged(
web_ui()->CallJavascriptFunction(
kUpdatePowerPropertiesJSCallback,
base::FundamentalValue(proto.battery_percent()),
+ base::FundamentalValue(proto.battery_state())),
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() {
@@ -119,6 +134,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