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..3f7ac610f6a9df4fdfea91015b3bfbd7f775135a 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,47 @@ bool BluetoothPrivateSetPairingResponseFunction::DoWork( |
return true; |
} |
+BluetoothPrivateDisconnectFunction::BluetoothPrivateDisconnectFunction() { |
+} |
+ |
+BluetoothPrivateDisconnectFunction::~BluetoothPrivateDisconnectFunction() { |
+} |
+ |
+bool BluetoothPrivateDisconnectFunction::DoWork( |
+ scoped_refptr<device::BluetoothAdapter> adapter) { |
+ scoped_ptr<bt_private::Disconnect::Params> params( |
+ bt_private::Disconnect::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(&BluetoothPrivateDisconnectFunction::OnSuccessCallback, this), |
+ base::Bind(&BluetoothPrivateDisconnectFunction::OnErrorCallback, this)); |
+ |
+ return true; |
+} |
+ |
+void BluetoothPrivateDisconnectFunction::OnSuccessCallback() { |
+ SendResponse(true); |
+} |
+ |
+void BluetoothPrivateDisconnectFunction::OnErrorCallback() { |
+ SetError(kDisconnectError); |
Jeffrey Yasskin
2014/12/20 01:48:56
[Moving over to the API implementation.]
On 2014/
|
+ SendResponse(false); |
+} |
+ |
} // namespace core_api |
} // namespace extensions |