OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/options2/chromeos/bluetooth_options_handler2.h
" | 5 #include "chrome/browser/ui/webui/options2/chromeos/bluetooth_options_handler2.h
" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
9 #include "base/utf_string_conversions.h" | 9 #include "base/utf_string_conversions.h" |
10 #include "base/values.h" | 10 #include "base/values.h" |
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
157 void BluetoothOptionsHandler::RegisterMessages() { | 157 void BluetoothOptionsHandler::RegisterMessages() { |
158 web_ui()->RegisterMessageCallback("bluetoothEnableChange", | 158 web_ui()->RegisterMessageCallback("bluetoothEnableChange", |
159 base::Bind(&BluetoothOptionsHandler::EnableChangeCallback, | 159 base::Bind(&BluetoothOptionsHandler::EnableChangeCallback, |
160 base::Unretained(this))); | 160 base::Unretained(this))); |
161 web_ui()->RegisterMessageCallback("findBluetoothDevices", | 161 web_ui()->RegisterMessageCallback("findBluetoothDevices", |
162 base::Bind(&BluetoothOptionsHandler::FindDevicesCallback, | 162 base::Bind(&BluetoothOptionsHandler::FindDevicesCallback, |
163 base::Unretained(this))); | 163 base::Unretained(this))); |
164 web_ui()->RegisterMessageCallback("updateBluetoothDevice", | 164 web_ui()->RegisterMessageCallback("updateBluetoothDevice", |
165 base::Bind(&BluetoothOptionsHandler::UpdateDeviceCallback, | 165 base::Bind(&BluetoothOptionsHandler::UpdateDeviceCallback, |
166 base::Unretained(this))); | 166 base::Unretained(this))); |
| 167 web_ui()->RegisterMessageCallback("stopBluetoothDeviceDiscovery", |
| 168 base::Bind(&BluetoothOptionsHandler::StopDiscoveryCallback, |
| 169 base::Unretained(this))); |
| 170 web_ui()->RegisterMessageCallback("getPairedBluetoothDevices", |
| 171 base::Bind(&BluetoothOptionsHandler::GetPairedDevicesCallback, |
| 172 base::Unretained(this))); |
| 173 |
167 } | 174 } |
168 | 175 |
169 void BluetoothOptionsHandler::EnableChangeCallback( | 176 void BluetoothOptionsHandler::EnableChangeCallback( |
170 const ListValue* args) { | 177 const ListValue* args) { |
171 bool bluetooth_enabled; | 178 bool bluetooth_enabled; |
172 args->GetBoolean(0, &bluetooth_enabled); | 179 args->GetBoolean(0, &bluetooth_enabled); |
173 // TODO(kevers): Call Bluetooth API to enable or disable. | 180 // TODO(kevers): Call Bluetooth API to enable or disable. |
174 base::FundamentalValue checked(bluetooth_enabled); | 181 base::FundamentalValue checked(bluetooth_enabled); |
175 web_ui()->CallJavascriptFunction( | 182 web_ui()->CallJavascriptFunction( |
176 "options.AdvancedOptions.setBluetoothState", checked); | 183 "options.AdvancedOptions.setBluetoothState", checked); |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
215 std::string passkey; | 222 std::string passkey; |
216 args->GetString(kUpdateDevicePasskeyIndex, &passkey); | 223 args->GetString(kUpdateDevicePasskeyIndex, &passkey); |
217 DVLOG(1) << "UpdateDeviceCallback: " << address << ": " << command | 224 DVLOG(1) << "UpdateDeviceCallback: " << address << ": " << command |
218 << " [" << passkey << "]"; | 225 << " [" << passkey << "]"; |
219 } else { | 226 } else { |
220 // Initiating a device connection or disconnecting | 227 // Initiating a device connection or disconnecting |
221 DVLOG(1) << "UpdateDeviceCallback: " << address << ": " << command; | 228 DVLOG(1) << "UpdateDeviceCallback: " << address << ": " << command; |
222 } | 229 } |
223 } | 230 } |
224 | 231 |
| 232 void BluetoothOptionsHandler::StopDiscoveryCallback( |
| 233 const ListValue* args) { |
| 234 chromeos::BluetoothManager* bluetooth_manager = |
| 235 chromeos::BluetoothManager::GetInstance(); |
| 236 DCHECK(bluetooth_manager); |
| 237 |
| 238 chromeos::BluetoothAdapter* default_adapter = |
| 239 bluetooth_manager->DefaultAdapter(); |
| 240 |
| 241 ValidateDefaultAdapter(default_adapter); |
| 242 |
| 243 if (default_adapter == NULL) { |
| 244 VLOG(1) << "DiscoveryEnded: no default adapter"; |
| 245 return; |
| 246 } |
| 247 |
| 248 default_adapter->StopDiscovery(); |
| 249 } |
| 250 |
| 251 void BluetoothOptionsHandler::GetPairedDevicesCallback( |
| 252 const ListValue* args) { |
| 253 // TODO(keybuk): Iterate over list of paired devices calling |
| 254 // SetDeviceNotification for each device. |
| 255 } |
| 256 |
225 void BluetoothOptionsHandler::SendDeviceNotification( | 257 void BluetoothOptionsHandler::SendDeviceNotification( |
226 chromeos::BluetoothDevice* device, | 258 chromeos::BluetoothDevice* device, |
227 base::DictionaryValue* params) { | 259 base::DictionaryValue* params) { |
228 // Retrieve properties of the bluetooth device. The properties names are | 260 // Retrieve properties of the bluetooth device. The properties names are |
229 // in title case. Convert to camel case in accordance with our Javascript | 261 // in title case. Convert to camel case in accordance with our Javascript |
230 // naming convention. | 262 // naming convention. |
231 const DictionaryValue& properties = device->AsDictionary(); | 263 const DictionaryValue& properties = device->AsDictionary(); |
232 base::DictionaryValue js_properties; | 264 base::DictionaryValue js_properties; |
233 for (DictionaryValue::key_iterator it = properties.begin_keys(); | 265 for (DictionaryValue::key_iterator it = properties.begin_keys(); |
234 it != properties.end_keys(); ++it) { | 266 it != properties.end_keys(); ++it) { |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
320 | 352 |
321 // TODO(vlaviano): Respond to adapter change. | 353 // TODO(vlaviano): Respond to adapter change. |
322 } | 354 } |
323 | 355 |
324 void BluetoothOptionsHandler::DiscoveryStarted(const std::string& adapter_id) { | 356 void BluetoothOptionsHandler::DiscoveryStarted(const std::string& adapter_id) { |
325 VLOG(2) << "Discovery started on " << adapter_id; | 357 VLOG(2) << "Discovery started on " << adapter_id; |
326 } | 358 } |
327 | 359 |
328 void BluetoothOptionsHandler::DiscoveryEnded(const std::string& adapter_id) { | 360 void BluetoothOptionsHandler::DiscoveryEnded(const std::string& adapter_id) { |
329 VLOG(2) << "Discovery ended on " << adapter_id; | 361 VLOG(2) << "Discovery ended on " << adapter_id; |
330 | |
331 // Stop the discovery session. | |
332 // TODO(vlaviano): We may want to expose DeviceDisappeared, remove the | |
333 // "Find devices" button, and let the discovery session continue throughout | |
334 // the time that the page is visible rather than just doing a single discovery | |
335 // cycle in response to a button click. | |
336 chromeos::BluetoothManager* bluetooth_manager = | |
337 chromeos::BluetoothManager::GetInstance(); | |
338 DCHECK(bluetooth_manager); | |
339 | |
340 chromeos::BluetoothAdapter* default_adapter = | |
341 bluetooth_manager->DefaultAdapter(); | |
342 | |
343 ValidateDefaultAdapter(default_adapter); | |
344 | |
345 if (default_adapter == NULL) { | |
346 VLOG(1) << "DiscoveryEnded: no default adapter"; | |
347 return; | |
348 } | |
349 | |
350 default_adapter->StopDiscovery(); | |
351 } | 362 } |
352 | 363 |
353 void BluetoothOptionsHandler::DeviceFound(const std::string& adapter_id, | 364 void BluetoothOptionsHandler::DeviceFound(const std::string& adapter_id, |
354 chromeos::BluetoothDevice* device) { | 365 chromeos::BluetoothDevice* device) { |
355 VLOG(2) << "Device found on " << adapter_id; | 366 VLOG(2) << "Device found on " << adapter_id; |
356 DCHECK(device); | 367 DCHECK(device); |
357 SendDeviceNotification(device, NULL); | 368 SendDeviceNotification(device, NULL); |
358 } | 369 } |
359 | 370 |
360 void BluetoothOptionsHandler::ValidateDefaultAdapter( | 371 void BluetoothOptionsHandler::ValidateDefaultAdapter( |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
418 // Sending an error notification. | 429 // Sending an error notification. |
419 DictionaryValue params; | 430 DictionaryValue params; |
420 params.SetString("pairing", pairing); | 431 params.SetString("pairing", pairing); |
421 SendDeviceNotification(device, ¶ms); | 432 SendDeviceNotification(device, ¶ms); |
422 } | 433 } |
423 delete device; | 434 delete device; |
424 } | 435 } |
425 | 436 |
426 } // namespace options2 | 437 } // namespace options2 |
427 } // namespace chromeos | 438 } // namespace chromeos |
OLD | NEW |