Chromium Code Reviews| 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 DVLOG(2) << "Stop searching for Bluetooth devices"; | |
|
James Hawkins
2012/01/31 18:14:27
Did you intend to leave these logging statements i
kevers
2012/01/31 18:20:31
Intend to pull most of the logging out. I should
| |
| 235 chromeos::BluetoothManager* bluetooth_manager = | |
| 236 chromeos::BluetoothManager::GetInstance(); | |
| 237 DCHECK(bluetooth_manager); | |
| 238 | |
| 239 chromeos::BluetoothAdapter* default_adapter = | |
| 240 bluetooth_manager->DefaultAdapter(); | |
| 241 | |
| 242 ValidateDefaultAdapter(default_adapter); | |
| 243 | |
| 244 if (default_adapter == NULL) { | |
| 245 VLOG(1) << "DiscoveryEnded: no default adapter"; | |
| 246 return; | |
| 247 } | |
| 248 | |
| 249 default_adapter->StopDiscovery(); | |
| 250 } | |
| 251 | |
| 252 void BluetoothOptionsHandler::GetPairedDevicesCallback( | |
| 253 const ListValue* args) { | |
| 254 // TODO(keybuk): Iterate over list of paired devices calling | |
| 255 // SetDeviceNotification for each device. | |
| 256 DVLOG(2) << "Get paired Bluetooth devices"; | |
| 257 } | |
| 258 | |
| 225 void BluetoothOptionsHandler::SendDeviceNotification( | 259 void BluetoothOptionsHandler::SendDeviceNotification( |
| 226 chromeos::BluetoothDevice* device, | 260 chromeos::BluetoothDevice* device, |
| 227 base::DictionaryValue* params) { | 261 base::DictionaryValue* params) { |
| 228 // Retrieve properties of the bluetooth device. The properties names are | 262 // Retrieve properties of the bluetooth device. The properties names are |
| 229 // in title case. Convert to camel case in accordance with our Javascript | 263 // in title case. Convert to camel case in accordance with our Javascript |
| 230 // naming convention. | 264 // naming convention. |
| 231 const DictionaryValue& properties = device->AsDictionary(); | 265 const DictionaryValue& properties = device->AsDictionary(); |
| 232 base::DictionaryValue js_properties; | 266 base::DictionaryValue js_properties; |
| 233 for (DictionaryValue::key_iterator it = properties.begin_keys(); | 267 for (DictionaryValue::key_iterator it = properties.begin_keys(); |
| 234 it != properties.end_keys(); ++it) { | 268 it != properties.end_keys(); ++it) { |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 320 | 354 |
| 321 // TODO(vlaviano): Respond to adapter change. | 355 // TODO(vlaviano): Respond to adapter change. |
| 322 } | 356 } |
| 323 | 357 |
| 324 void BluetoothOptionsHandler::DiscoveryStarted(const std::string& adapter_id) { | 358 void BluetoothOptionsHandler::DiscoveryStarted(const std::string& adapter_id) { |
| 325 VLOG(2) << "Discovery started on " << adapter_id; | 359 VLOG(2) << "Discovery started on " << adapter_id; |
| 326 } | 360 } |
| 327 | 361 |
| 328 void BluetoothOptionsHandler::DiscoveryEnded(const std::string& adapter_id) { | 362 void BluetoothOptionsHandler::DiscoveryEnded(const std::string& adapter_id) { |
| 329 VLOG(2) << "Discovery ended on " << adapter_id; | 363 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 } | 364 } |
| 352 | 365 |
| 353 void BluetoothOptionsHandler::DeviceFound(const std::string& adapter_id, | 366 void BluetoothOptionsHandler::DeviceFound(const std::string& adapter_id, |
| 354 chromeos::BluetoothDevice* device) { | 367 chromeos::BluetoothDevice* device) { |
| 355 VLOG(2) << "Device found on " << adapter_id; | 368 VLOG(2) << "Device found on " << adapter_id; |
| 356 DCHECK(device); | 369 DCHECK(device); |
| 357 SendDeviceNotification(device, NULL); | 370 SendDeviceNotification(device, NULL); |
| 358 } | 371 } |
| 359 | 372 |
| 360 void BluetoothOptionsHandler::ValidateDefaultAdapter( | 373 void BluetoothOptionsHandler::ValidateDefaultAdapter( |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 418 // Sending an error notification. | 431 // Sending an error notification. |
| 419 DictionaryValue params; | 432 DictionaryValue params; |
| 420 params.SetString("pairing", pairing); | 433 params.SetString("pairing", pairing); |
| 421 SendDeviceNotification(device, ¶ms); | 434 SendDeviceNotification(device, ¶ms); |
| 422 } | 435 } |
| 423 delete device; | 436 delete device; |
| 424 } | 437 } |
| 425 | 438 |
| 426 } // namespace options2 | 439 } // namespace options2 |
| 427 } // namespace chromeos | 440 } // namespace chromeos |
| OLD | NEW |