| 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/options/chromeos/bluetooth_options_handler.h" | 5 #include "chrome/browser/ui/webui/options/chromeos/bluetooth_options_handler.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
| 9 #include "base/callback.h" | 9 #include "base/callback.h" |
| 10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
| (...skipping 278 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 289 << ": " << auth_token; | 289 << ": " << auth_token; |
| 290 } | 290 } |
| 291 } else { | 291 } else { |
| 292 // Connection request. | 292 // Connection request. |
| 293 VLOG(1) << "Connect: " << address; | 293 VLOG(1) << "Connect: " << address; |
| 294 device->Connect( | 294 device->Connect( |
| 295 this, | 295 this, |
| 296 base::Bind(&base::DoNothing), | 296 base::Bind(&base::DoNothing), |
| 297 base::Bind(&BluetoothOptionsHandler::ConnectError, | 297 base::Bind(&BluetoothOptionsHandler::ConnectError, |
| 298 weak_ptr_factory_.GetWeakPtr(), | 298 weak_ptr_factory_.GetWeakPtr(), |
| 299 device->address())); | 299 device->GetAddress())); |
| 300 } | 300 } |
| 301 } else if (command == kCancelCommand) { | 301 } else if (command == kCancelCommand) { |
| 302 // Cancel pairing. | 302 // Cancel pairing. |
| 303 VLOG(1) << "Cancel pairing: " << address; | 303 VLOG(1) << "Cancel pairing: " << address; |
| 304 device->CancelPairing(); | 304 device->CancelPairing(); |
| 305 } else if (command == kAcceptCommand) { | 305 } else if (command == kAcceptCommand) { |
| 306 // Confirm displayed Passkey. | 306 // Confirm displayed Passkey. |
| 307 VLOG(1) << "Confirm pairing: " << address; | 307 VLOG(1) << "Confirm pairing: " << address; |
| 308 device->ConfirmPairing(); | 308 device->ConfirmPairing(); |
| 309 } else if (command == kRejectCommand) { | 309 } else if (command == kRejectCommand) { |
| 310 // Reject displayed Passkey. | 310 // Reject displayed Passkey. |
| 311 VLOG(1) << "Reject pairing: " << address; | 311 VLOG(1) << "Reject pairing: " << address; |
| 312 device->RejectPairing(); | 312 device->RejectPairing(); |
| 313 } else if (command == kDisconnectCommand) { | 313 } else if (command == kDisconnectCommand) { |
| 314 // Disconnect from device. | 314 // Disconnect from device. |
| 315 VLOG(1) << "Disconnect device: " << address; | 315 VLOG(1) << "Disconnect device: " << address; |
| 316 device->Disconnect( | 316 device->Disconnect( |
| 317 base::Bind(&base::DoNothing), | 317 base::Bind(&base::DoNothing), |
| 318 base::Bind(&BluetoothOptionsHandler::DisconnectError, | 318 base::Bind(&BluetoothOptionsHandler::DisconnectError, |
| 319 weak_ptr_factory_.GetWeakPtr(), | 319 weak_ptr_factory_.GetWeakPtr(), |
| 320 device->address())); | 320 device->GetAddress())); |
| 321 } else if (command == kForgetCommand) { | 321 } else if (command == kForgetCommand) { |
| 322 // Disconnect from device and delete pairing information. | 322 // Disconnect from device and delete pairing information. |
| 323 VLOG(1) << "Forget device: " << address; | 323 VLOG(1) << "Forget device: " << address; |
| 324 device->Forget(base::Bind(&BluetoothOptionsHandler::ForgetError, | 324 device->Forget(base::Bind(&BluetoothOptionsHandler::ForgetError, |
| 325 weak_ptr_factory_.GetWeakPtr(), | 325 weak_ptr_factory_.GetWeakPtr(), |
| 326 device->address())); | 326 device->GetAddress())); |
| 327 } else { | 327 } else { |
| 328 LOG(WARNING) << "Unknown updateBluetoothDevice command: " << command; | 328 LOG(WARNING) << "Unknown updateBluetoothDevice command: " << command; |
| 329 } | 329 } |
| 330 } | 330 } |
| 331 | 331 |
| 332 void BluetoothOptionsHandler::ConnectError( | 332 void BluetoothOptionsHandler::ConnectError( |
| 333 const std::string& address, | 333 const std::string& address, |
| 334 device::BluetoothDevice::ConnectErrorCode error_code) { | 334 device::BluetoothDevice::ConnectErrorCode error_code) { |
| 335 const char* error_name = NULL; | 335 const char* error_name = NULL; |
| 336 | 336 |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 399 for (device::BluetoothAdapter::DeviceList::iterator iter = devices.begin(); | 399 for (device::BluetoothAdapter::DeviceList::iterator iter = devices.begin(); |
| 400 iter != devices.end(); ++iter) | 400 iter != devices.end(); ++iter) |
| 401 SendDeviceNotification(*iter, NULL); | 401 SendDeviceNotification(*iter, NULL); |
| 402 } | 402 } |
| 403 | 403 |
| 404 void BluetoothOptionsHandler::SendDeviceNotification( | 404 void BluetoothOptionsHandler::SendDeviceNotification( |
| 405 const device::BluetoothDevice* device, | 405 const device::BluetoothDevice* device, |
| 406 base::DictionaryValue* params) { | 406 base::DictionaryValue* params) { |
| 407 base::DictionaryValue js_properties; | 407 base::DictionaryValue js_properties; |
| 408 js_properties.SetString("name", device->GetName()); | 408 js_properties.SetString("name", device->GetName()); |
| 409 js_properties.SetString("address", device->address()); | 409 js_properties.SetString("address", device->GetAddress()); |
| 410 js_properties.SetBoolean("paired", device->IsPaired()); | 410 js_properties.SetBoolean("paired", device->IsPaired()); |
| 411 js_properties.SetBoolean("bonded", device->IsBonded()); | |
| 412 js_properties.SetBoolean("connected", device->IsConnected()); | 411 js_properties.SetBoolean("connected", device->IsConnected()); |
| 413 js_properties.SetBoolean("connectable", device->IsConnectable()); | 412 js_properties.SetBoolean("connectable", device->IsConnectable()); |
| 414 if (params) | 413 if (params) |
| 415 js_properties.MergeDictionary(params); | 414 js_properties.MergeDictionary(params); |
| 416 web_ui()->CallJavascriptFunction( | 415 web_ui()->CallJavascriptFunction( |
| 417 "options.BrowserOptions.addBluetoothDevice", | 416 "options.BrowserOptions.addBluetoothDevice", |
| 418 js_properties); | 417 js_properties); |
| 419 } | 418 } |
| 420 | 419 |
| 421 void BluetoothOptionsHandler::RequestPinCode(device::BluetoothDevice* device) { | 420 void BluetoothOptionsHandler::RequestPinCode(device::BluetoothDevice* device) { |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 482 DCHECK(adapter == adapter_.get()); | 481 DCHECK(adapter == adapter_.get()); |
| 483 DCHECK(device); | 482 DCHECK(device); |
| 484 SendDeviceNotification(device, NULL); | 483 SendDeviceNotification(device, NULL); |
| 485 } | 484 } |
| 486 | 485 |
| 487 void BluetoothOptionsHandler::DeviceRemoved(device::BluetoothAdapter* adapter, | 486 void BluetoothOptionsHandler::DeviceRemoved(device::BluetoothAdapter* adapter, |
| 488 device::BluetoothDevice* device) { | 487 device::BluetoothDevice* device) { |
| 489 DCHECK(adapter == adapter_.get()); | 488 DCHECK(adapter == adapter_.get()); |
| 490 DCHECK(device); | 489 DCHECK(device); |
| 491 | 490 |
| 492 base::StringValue address(device->address()); | 491 base::StringValue address(device->GetAddress()); |
| 493 web_ui()->CallJavascriptFunction( | 492 web_ui()->CallJavascriptFunction( |
| 494 "options.BrowserOptions.removeBluetoothDevice", | 493 "options.BrowserOptions.removeBluetoothDevice", |
| 495 address); | 494 address); |
| 496 } | 495 } |
| 497 | 496 |
| 498 void BluetoothOptionsHandler::DeviceConnecting( | 497 void BluetoothOptionsHandler::DeviceConnecting( |
| 499 device::BluetoothDevice* device) { | 498 device::BluetoothDevice* device) { |
| 500 DCHECK(device); | 499 DCHECK(device); |
| 501 DictionaryValue params; | 500 DictionaryValue params; |
| 502 params.SetString("pairing", kStartConnecting); | 501 params.SetString("pairing", kStartConnecting); |
| 503 SendDeviceNotification(device, ¶ms); | 502 SendDeviceNotification(device, ¶ms); |
| 504 } | 503 } |
| 505 | 504 |
| 506 } // namespace options | 505 } // namespace options |
| 507 } // namespace chromeos | 506 } // namespace chromeos |
| OLD | NEW |