| Index: extensions/browser/api/bluetooth/bluetooth_private_api.cc
|
| diff --git a/extensions/browser/api/bluetooth/bluetooth_private_api.cc b/extensions/browser/api/bluetooth/bluetooth_private_api.cc
|
| index 8729f73b108488a895bd50d54e6f093b6118634e..27353c42a27257090fab9c5a55ebe4f2227bb029 100644
|
| --- a/extensions/browser/api/bluetooth/bluetooth_private_api.cc
|
| +++ b/extensions/browser/api/bluetooth/bluetooth_private_api.cc
|
| @@ -71,6 +71,8 @@ const char kSetAdapterPropertyError[] = "Error setting adapter properties: $1";
|
| const char kDeviceNotFoundError[] =
|
| "Given address is not a valid Bluetooth device.";
|
|
|
| +const char kDeviceNotConnectedError[] = "Device is not connected";
|
| +
|
| const char kPairingNotEnabled[] =
|
| "Pairing must be enabled to set a pairing response.";
|
|
|
| @@ -80,6 +82,8 @@ const char kInvalidPairingResponseOptions[] =
|
| const char kAdapterNotPresent[] =
|
| "Could not find a Bluetooth adapter.";
|
|
|
| +const char kDisconnectError[] = "Failed to disconnect device";
|
| +
|
| // Returns true if the pairing response options passed into the
|
| // setPairingResponse function are valid.
|
| bool ValidatePairingResponseOptions(
|
| @@ -285,6 +289,60 @@ bool BluetoothPrivateSetPairingResponseFunction::DoWork(
|
| return true;
|
| }
|
|
|
| +BluetoothPrivateDisconnectAllFunction::BluetoothPrivateDisconnectAllFunction() {
|
| +}
|
| +
|
| +BluetoothPrivateDisconnectAllFunction::
|
| + ~BluetoothPrivateDisconnectAllFunction() {
|
| +}
|
| +
|
| +bool BluetoothPrivateDisconnectAllFunction::DoWork(
|
| + scoped_refptr<device::BluetoothAdapter> adapter) {
|
| + scoped_ptr<bt_private::DisconnectAll::Params> params(
|
| + bt_private::DisconnectAll::Params::Create(*args_));
|
| + EXTENSION_FUNCTION_VALIDATE(params.get());
|
| +
|
| + device::BluetoothDevice* device = adapter->GetDevice(params->device_address);
|
| + if (!device) {
|
| + SetError(kDeviceNotFoundError);
|
| + SendResponse(false);
|
| + return true;
|
| + }
|
| +
|
| + if (!device->IsConnected()) {
|
| + SetError(kDeviceNotConnectedError);
|
| + SendResponse(false);
|
| + return true;
|
| + }
|
| +
|
| + device->Disconnect(
|
| + base::Bind(&BluetoothPrivateDisconnectAllFunction::OnSuccessCallback,
|
| + this),
|
| + base::Bind(&BluetoothPrivateDisconnectAllFunction::OnErrorCallback, this,
|
| + adapter, params->device_address));
|
| +
|
| + return true;
|
| +}
|
| +
|
| +void BluetoothPrivateDisconnectAllFunction::OnSuccessCallback() {
|
| + SendResponse(true);
|
| +}
|
| +
|
| +void BluetoothPrivateDisconnectAllFunction::OnErrorCallback(
|
| + scoped_refptr<device::BluetoothAdapter> adapter,
|
| + const std::string& device_address) {
|
| + // The call to Disconnect may report an error if the device was disconnected
|
| + // due to an external reason. In this case, report "Not Connected" as the
|
| + // error.
|
| + device::BluetoothDevice* device = adapter->GetDevice(device_address);
|
| + if (device && !device->IsConnected())
|
| + SetError(kDeviceNotConnectedError);
|
| + else
|
| + SetError(kDisconnectError);
|
| +
|
| + SendResponse(false);
|
| +}
|
| +
|
| } // namespace core_api
|
|
|
| } // namespace extensions
|
|
|