| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "extensions/browser/api/bluetooth/bluetooth_private_api.h" | 5 #include "extensions/browser/api/bluetooth/bluetooth_private_api.h" |
| 6 | 6 |
| 7 #include "base/callback.h" | 7 #include "base/callback.h" |
| 8 #include "base/lazy_instance.h" | 8 #include "base/lazy_instance.h" |
| 9 #include "base/strings/string_util.h" | 9 #include "base/strings/string_util.h" |
| 10 #include "device/bluetooth/bluetooth_adapter.h" | 10 #include "device/bluetooth/bluetooth_adapter.h" |
| (...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 245 | 245 |
| 246 bool BluetoothPrivateSetPairingResponseFunction::DoWork( | 246 bool BluetoothPrivateSetPairingResponseFunction::DoWork( |
| 247 scoped_refptr<device::BluetoothAdapter> adapter) { | 247 scoped_refptr<device::BluetoothAdapter> adapter) { |
| 248 scoped_ptr<bt_private::SetPairingResponse::Params> params( | 248 scoped_ptr<bt_private::SetPairingResponse::Params> params( |
| 249 bt_private::SetPairingResponse::Params::Create(*args_)); | 249 bt_private::SetPairingResponse::Params::Create(*args_)); |
| 250 EXTENSION_FUNCTION_VALIDATE(params.get()); | 250 EXTENSION_FUNCTION_VALIDATE(params.get()); |
| 251 const bt_private::SetPairingResponseOptions& options = params->options; | 251 const bt_private::SetPairingResponseOptions& options = params->options; |
| 252 | 252 |
| 253 BluetoothEventRouter* router = | 253 BluetoothEventRouter* router = |
| 254 BluetoothAPI::Get(browser_context())->event_router(); | 254 BluetoothAPI::Get(browser_context())->event_router(); |
| 255 if (!router->GetPairingDelegate(extension_id())) { | 255 if (!router->GetPairingDelegate(GetExtensionId())) { |
| 256 SetError(kPairingNotEnabled); | 256 SetError(kPairingNotEnabled); |
| 257 SendResponse(false); | 257 SendResponse(false); |
| 258 return true; | 258 return true; |
| 259 } | 259 } |
| 260 | 260 |
| 261 const std::string& device_address = options.device.address; | 261 const std::string& device_address = options.device.address; |
| 262 device::BluetoothDevice* device = adapter->GetDevice(device_address); | 262 device::BluetoothDevice* device = adapter->GetDevice(device_address); |
| 263 if (!device) { | 263 if (!device) { |
| 264 SetError(kDeviceNotFoundError); | 264 SetError(kDeviceNotFoundError); |
| 265 SendResponse(false); | 265 SendResponse(false); |
| (...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 400 } | 400 } |
| 401 } | 401 } |
| 402 | 402 |
| 403 if (df_param.rssi.get()) | 403 if (df_param.rssi.get()) |
| 404 discovery_filter->SetRSSI(*df_param.rssi); | 404 discovery_filter->SetRSSI(*df_param.rssi); |
| 405 | 405 |
| 406 if (df_param.pathloss.get()) | 406 if (df_param.pathloss.get()) |
| 407 discovery_filter->SetPathloss(*df_param.pathloss); | 407 discovery_filter->SetPathloss(*df_param.pathloss); |
| 408 } | 408 } |
| 409 | 409 |
| 410 BluetoothAPI::Get(browser_context())->event_router()->SetDiscoveryFilter( | 410 BluetoothAPI::Get(browser_context()) |
| 411 discovery_filter.Pass(), adapter.get(), extension_id(), | 411 ->event_router() |
| 412 ->SetDiscoveryFilter( |
| 413 discovery_filter.Pass(), adapter.get(), GetExtensionId(), |
| 412 base::Bind( | 414 base::Bind( |
| 413 &BluetoothPrivateSetDiscoveryFilterFunction::OnSuccessCallback, | 415 &BluetoothPrivateSetDiscoveryFilterFunction::OnSuccessCallback, |
| 414 this), | 416 this), |
| 415 base::Bind( | 417 base::Bind( |
| 416 &BluetoothPrivateSetDiscoveryFilterFunction::OnErrorCallback, | 418 &BluetoothPrivateSetDiscoveryFilterFunction::OnErrorCallback, |
| 417 this)); | 419 this)); |
| 418 return true; | 420 return true; |
| 419 } | 421 } |
| 420 | 422 |
| 421 BluetoothPrivatePairFunction::BluetoothPrivatePairFunction() {} | 423 BluetoothPrivatePairFunction::BluetoothPrivatePairFunction() {} |
| (...skipping 17 matching lines...) Expand all Loading... |
| 439 | 441 |
| 440 device::BluetoothDevice* device = adapter->GetDevice(params->device_address); | 442 device::BluetoothDevice* device = adapter->GetDevice(params->device_address); |
| 441 if (!device) { | 443 if (!device) { |
| 442 SetError(kDeviceNotFoundError); | 444 SetError(kDeviceNotFoundError); |
| 443 SendResponse(false); | 445 SendResponse(false); |
| 444 return true; | 446 return true; |
| 445 } | 447 } |
| 446 | 448 |
| 447 BluetoothEventRouter* router = | 449 BluetoothEventRouter* router = |
| 448 BluetoothAPI::Get(browser_context())->event_router(); | 450 BluetoothAPI::Get(browser_context())->event_router(); |
| 449 if (!router->GetPairingDelegate(extension_id())) { | 451 if (!router->GetPairingDelegate(GetExtensionId())) { |
| 450 SetError(kPairingNotEnabled); | 452 SetError(kPairingNotEnabled); |
| 451 SendResponse(false); | 453 SendResponse(false); |
| 452 return true; | 454 return true; |
| 453 } | 455 } |
| 454 | 456 |
| 455 device->Pair( | 457 device->Pair( |
| 456 router->GetPairingDelegate(extension_id()), | 458 router->GetPairingDelegate(GetExtensionId()), |
| 457 base::Bind(&BluetoothPrivatePairFunction::OnSuccessCallback, this), | 459 base::Bind(&BluetoothPrivatePairFunction::OnSuccessCallback, this), |
| 458 base::Bind(&BluetoothPrivatePairFunction::OnErrorCallback, this)); | 460 base::Bind(&BluetoothPrivatePairFunction::OnErrorCallback, this)); |
| 459 return true; | 461 return true; |
| 460 } | 462 } |
| 461 | 463 |
| 462 } // namespace api | 464 } // namespace api |
| 463 | 465 |
| 464 } // namespace extensions | 466 } // namespace extensions |
| OLD | NEW |