Chromium Code Reviews| 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..21c0e9d43e576543558c1a3d95426fcfa6ac275e 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)) |
|
oshima
2015/07/29 21:25:12
nit: you need {} in this case
mozartalouis
2015/07/29 21:55:47
Done.
|
| + 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( |
|
oshima
2015/07/29 21:25:12
nit: indent and {}
mozartalouis
2015/07/29 21:55:47
Done.
|
| static_cast<power_manager::PowerSupplyProperties_ExternalPower>( |
| power_source)); |
| + |
| fake_power_manager_client_->UpdatePowerProperties(props); |
| } |
| @@ -107,22 +123,30 @@ 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); |
| } |
| 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()))); |
| + // Create a list that holds all the values that the ui will need |
| + // when this function is called. |
|
oshima
2015/07/29 21:25:13
This comment isn't much useful. You can omit it.
mozartalouis
2015/07/29 21:55:47
Done.
|
| + scoped_ptr<base::ListValue> power_properties(new base::ListValue); |
|
oshima
2015/07/29 21:25:13
you can just create an object on stack like
base:
mozartalouis
2015/07/29 21:55:47
Done.
|
| + |
| + power_properties->AppendInteger(static_cast<int>(proto.battery_percent())); |
| + power_properties->AppendInteger(static_cast<int>(proto.battery_state())); |
| + power_properties->AppendInteger(static_cast<int>(proto.external_power())); |
| + power_properties->AppendInteger( |
| + static_cast<int>(proto.battery_time_to_empty_sec())); |
| + power_properties->AppendInteger( |
| + static_cast<int>(proto.battery_time_to_full_sec())); |
| + |
| + web_ui()->CallJavascriptFunction(kUpdatePowerPropertiesJSCallback, |
| + *power_properties); |
|
oshima
2015/07/29 21:25:13
I thought you wanted to use
CallJavascriptFunctio
mozartalouis
2015/07/29 21:55:47
Done.
|
| } |
| void DeviceEmulatorMessageHandler::RegisterMessages() { |
| @@ -135,6 +159,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))); |