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

Side by Side 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, 4 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 unified diff | Download patch
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/ui/webui/chromeos/emulator/device_emulator_message_hand ler.h" 5 #include "chrome/browser/ui/webui/chromeos/emulator/device_emulator_message_hand ler.h"
6 6
7 #include <stdlib.h> 7 #include <stdlib.h>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/values.h" 10 #include "base/values.h"
11 #include "chromeos/dbus/dbus_thread_manager.h" 11 #include "chromeos/dbus/dbus_thread_manager.h"
12 #include "chromeos/dbus/fake_power_manager_client.h" 12 #include "chromeos/dbus/fake_power_manager_client.h"
13 #include "content/public/browser/web_ui.h" 13 #include "content/public/browser/web_ui.h"
14 14
15 namespace { 15 namespace {
16 16
17 // Define the name of the callback functions that will be used by JavaScript. 17 // Define the name of the callback functions that will be used by JavaScript.
18 const char kBluetoothDiscoverFunction[] = "requestBluetoothDiscover"; 18 const char kBluetoothDiscoverFunction[] = "requestBluetoothDiscover";
19 const char kBluetoothPairFunction[] = "requestBluetoothPair"; 19 const char kBluetoothPairFunction[] = "requestBluetoothPair";
20 const char kRequestPowerInfo[] = "requestPowerInfo"; 20 const char kRequestPowerInfo[] = "requestPowerInfo";
21 21
22 // Define update functions that will update the power properties to the 22 // Define update functions that will update the power properties to the
23 // variables defined in the web UI. 23 // variables defined in the web UI.
24 const char kUpdateBatteryPercent[] = "updateBatteryPercent"; 24 const char kUpdateBatteryPercent[] = "updateBatteryPercent";
25 const char kUpdateBatteryState[] = "updateBatteryState";
25 const char kUpdateExternalPower[] = "updateExternalPower"; 26 const char kUpdateExternalPower[] = "updateExternalPower";
26 const char kUpdateTimeToEmpty[] = "updateTimeToEmpty"; 27 const char kUpdateTimeToEmpty[] = "updateTimeToEmpty";
27 const char kUpdateTimeToFull[] = "updateTimeToFull"; 28 const char kUpdateTimeToFull[] = "updateTimeToFull";
28 29
29 // Define callback functions that will update the JavaScript variable 30 // Define callback functions that will update the JavaScript variable
30 // and the web UI. 31 // and the web UI.
31 const char kUpdatePowerPropertiesJSCallback[] = 32 const char kUpdatePowerPropertiesJSCallback[] =
32 "device_emulator.batterySettings.updatePowerProperties"; 33 "device_emulator.batterySettings.updatePowerProperties";
33 34
34 } // namespace 35 } // namespace
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
71 power_manager::PowerSupplyProperties props = 72 power_manager::PowerSupplyProperties props =
72 fake_power_manager_client_->props(); 73 fake_power_manager_client_->props();
73 74
74 int new_percent; 75 int new_percent;
75 if (args->GetInteger(0, &new_percent)) 76 if (args->GetInteger(0, &new_percent))
76 props.set_battery_percent(new_percent); 77 props.set_battery_percent(new_percent);
77 78
78 fake_power_manager_client_->UpdatePowerProperties(props); 79 fake_power_manager_client_->UpdatePowerProperties(props);
79 } 80 }
80 81
82 void DeviceEmulatorMessageHandler::UpdateBatteryState(
83 const base::ListValue* args) {
84 power_manager::PowerSupplyProperties props =
85 fake_power_manager_client_->props();
86
87 int battery_state;
88 if (args->GetInteger(0, &battery_state))
89 props.set_battery_state(
90 static_cast<power_manager::PowerSupplyProperties_BatteryState>(
91 battery_state));
92
93 fake_power_manager_client_->UpdatePowerProperties(props);
94 }
95
81 void DeviceEmulatorMessageHandler::UpdateExternalPower( 96 void DeviceEmulatorMessageHandler::UpdateExternalPower(
82 const base::ListValue* args) { 97 const base::ListValue* args) {
83 int power_source;
84 args->GetInteger(0, &power_source);
85
86 power_manager::PowerSupplyProperties props = 98 power_manager::PowerSupplyProperties props =
87 fake_power_manager_client_->props(); 99 fake_power_manager_client_->props();
100
101 int power_source;
102 if (args->GetInteger(0, &power_source))
88 props.set_external_power( 103 props.set_external_power(
89 static_cast<power_manager::PowerSupplyProperties_ExternalPower>( 104 static_cast<power_manager::PowerSupplyProperties_ExternalPower>(
90 power_source)); 105 power_source));
106
91 fake_power_manager_client_->UpdatePowerProperties(props); 107 fake_power_manager_client_->UpdatePowerProperties(props);
92 } 108 }
93 109
94 void DeviceEmulatorMessageHandler::UpdateTimeToEmpty( 110 void DeviceEmulatorMessageHandler::UpdateTimeToEmpty(
95 const base::ListValue* args) { 111 const base::ListValue* args) {
96 power_manager::PowerSupplyProperties props = 112 power_manager::PowerSupplyProperties props =
97 fake_power_manager_client_->props(); 113 fake_power_manager_client_->props();
98 114
99 int new_time; 115 int new_time;
100 if (args->GetInteger(0, &new_time)) 116 if (args->GetInteger(0, &new_time))
101 props.set_battery_time_to_empty_sec(new_time); 117 props.set_battery_time_to_empty_sec(new_time);
102 118
103 fake_power_manager_client_->UpdatePowerProperties(props); 119 fake_power_manager_client_->UpdatePowerProperties(props);
104 } 120 }
105 121
106 void DeviceEmulatorMessageHandler::UpdateTimeToFull( 122 void DeviceEmulatorMessageHandler::UpdateTimeToFull(
107 const base::ListValue* args) { 123 const base::ListValue* args) {
108 power_manager::PowerSupplyProperties props = 124 power_manager::PowerSupplyProperties props =
109 fake_power_manager_client_->props(); 125 fake_power_manager_client_->props();
126
110 int new_time; 127 int new_time;
111 if (args->GetInteger(0, &new_time)) 128 if (args->GetInteger(0, &new_time))
112 props.set_battery_time_to_full_sec(new_time); 129 props.set_battery_time_to_full_sec(new_time);
130
113 fake_power_manager_client_->UpdatePowerProperties(props); 131 fake_power_manager_client_->UpdatePowerProperties(props);
114 } 132 }
115 133
116 void DeviceEmulatorMessageHandler::PowerChanged( 134 void DeviceEmulatorMessageHandler::PowerChanged(
117 const power_manager::PowerSupplyProperties& proto) { 135 const power_manager::PowerSupplyProperties& proto) {
118 web_ui()->CallJavascriptFunction( 136 web_ui()->CallJavascriptFunction(
119 kUpdatePowerPropertiesJSCallback, 137 kUpdatePowerPropertiesJSCallback,
120 base::FundamentalValue(proto.battery_percent()), 138 base::FundamentalValue(proto.battery_percent()),
139 base::FundamentalValue(proto.battery_state())),
oshima 2015/07/29 00:50:48 does this compile?
mozartalouis 2015/07/29 21:06:04 Done.
121 base::FundamentalValue(proto.external_power()), 140 base::FundamentalValue(proto.external_power()),
122 base::FundamentalValue( 141 base::FundamentalValue(
123 static_cast<int>(proto.battery_time_to_empty_sec())), 142 static_cast<int>(proto.battery_time_to_empty_sec())),
124 base::FundamentalValue( 143 base::FundamentalValue(
125 static_cast<int>(proto.battery_time_to_full_sec()))); 144 static_cast<int>(proto.battery_time_to_full_sec()));
126 } 145 }
127 146
128 void DeviceEmulatorMessageHandler::RegisterMessages() { 147 void DeviceEmulatorMessageHandler::RegisterMessages() {
129 web_ui()->RegisterMessageCallback( 148 web_ui()->RegisterMessageCallback(
130 kRequestPowerInfo, 149 kRequestPowerInfo,
131 base::Bind(&DeviceEmulatorMessageHandler::RequestPowerInfo, 150 base::Bind(&DeviceEmulatorMessageHandler::RequestPowerInfo,
132 base::Unretained(this))); 151 base::Unretained(this)));
133 web_ui()->RegisterMessageCallback( 152 web_ui()->RegisterMessageCallback(
134 kUpdateBatteryPercent, 153 kUpdateBatteryPercent,
135 base::Bind(&DeviceEmulatorMessageHandler::UpdateBatteryPercent, 154 base::Bind(&DeviceEmulatorMessageHandler::UpdateBatteryPercent,
136 base::Unretained(this))); 155 base::Unretained(this)));
137 web_ui()->RegisterMessageCallback( 156 web_ui()->RegisterMessageCallback(
157 kUpdateBatteryState,
158 base::Bind(&DeviceEmulatorMessageHandler::UpdateBatteryState,
159 base::Unretained(this)));
160 web_ui()->RegisterMessageCallback(
138 kUpdateExternalPower, 161 kUpdateExternalPower,
139 base::Bind(&DeviceEmulatorMessageHandler::UpdateExternalPower, 162 base::Bind(&DeviceEmulatorMessageHandler::UpdateExternalPower,
140 base::Unretained(this))); 163 base::Unretained(this)));
141 web_ui()->RegisterMessageCallback( 164 web_ui()->RegisterMessageCallback(
142 kUpdateTimeToEmpty, 165 kUpdateTimeToEmpty,
143 base::Bind(&DeviceEmulatorMessageHandler::UpdateTimeToEmpty, 166 base::Bind(&DeviceEmulatorMessageHandler::UpdateTimeToEmpty,
144 base::Unretained(this))); 167 base::Unretained(this)));
145 web_ui()->RegisterMessageCallback( 168 web_ui()->RegisterMessageCallback(
146 kUpdateTimeToFull, 169 kUpdateTimeToFull,
147 base::Bind(&DeviceEmulatorMessageHandler::UpdateTimeToFull, 170 base::Bind(&DeviceEmulatorMessageHandler::UpdateTimeToFull,
148 base::Unretained(this))); 171 base::Unretained(this)));
149 web_ui()->RegisterMessageCallback( 172 web_ui()->RegisterMessageCallback(
150 kBluetoothDiscoverFunction, 173 kBluetoothDiscoverFunction,
151 base::Bind(&DeviceEmulatorMessageHandler::HandleRequestBluetoothDiscover, 174 base::Bind(&DeviceEmulatorMessageHandler::HandleRequestBluetoothDiscover,
152 base::Unretained(this))); 175 base::Unretained(this)));
153 web_ui()->RegisterMessageCallback( 176 web_ui()->RegisterMessageCallback(
154 kBluetoothPairFunction, 177 kBluetoothPairFunction,
155 base::Bind(&DeviceEmulatorMessageHandler::HandleRequestBluetoothPair, 178 base::Bind(&DeviceEmulatorMessageHandler::HandleRequestBluetoothPair,
156 base::Unretained(this))); 179 base::Unretained(this)));
157 } 180 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698