Index: device/bluetooth/bluetooth_adapter_mac.mm |
diff --git a/device/bluetooth/bluetooth_adapter_mac.mm b/device/bluetooth/bluetooth_adapter_mac.mm |
index 875a567c9ac8a645d2fa663bd492a6016e583c4a..49c0a1df3dc57e8fdfa783999f0b5939e42b4d2a 100644 |
--- a/device/bluetooth/bluetooth_adapter_mac.mm |
+++ b/device/bluetooth/bluetooth_adapter_mac.mm |
@@ -42,6 +42,7 @@ namespace device { |
// static |
const NSTimeInterval BluetoothAdapterMac::kDiscoveryTimeoutSec = |
180; // 3 minutes |
+static NSString* const kErrorDomain = @"ConnectErrorCode"; |
// static |
base::WeakPtr<BluetoothAdapter> BluetoothAdapter::CreateAdapter( |
@@ -573,8 +574,9 @@ void BluetoothAdapterMac::DidFailToConnectPeripheral(CBPeripheral* peripheral, |
[low_energy_central_manager_ cancelPeripheralConnection:peripheral]; |
return; |
} |
- // TODO(http://crbug.com/585894): Need to convert the error. |
- device_mac->DidFailToConnectGatt(BluetoothClassicDeviceMac::ERROR_UNKNOWN); |
+ BluetoothDevice::ConnectErrorCode error_code = |
+ BluetoothAdapterMac::GetConnectErrorCodeFromNSError(error); |
+ device_mac->DidFailToConnectGatt(error_code); |
} |
void BluetoothAdapterMac::DidDisconnectPeripheral(CBPeripheral* peripheral, |
@@ -585,8 +587,9 @@ void BluetoothAdapterMac::DidDisconnectPeripheral(CBPeripheral* peripheral, |
[low_energy_central_manager_ cancelPeripheralConnection:peripheral]; |
return; |
} |
- // TODO(http://crbug.com/585897): Need to pass the error. |
- device_mac->DidDisconnectPeripheral(); |
+ BluetoothDevice::ConnectErrorCode error_code = |
+ BluetoothAdapterMac::GetConnectErrorCodeFromNSError(error); |
+ device_mac->DidDisconnectPeripheral(error_code); |
} |
BluetoothLowEnergyDeviceMac* |
@@ -602,4 +605,53 @@ BluetoothAdapterMac::GetBluetoothLowEnergyDeviceMac(CBPeripheral* peripheral) { |
return static_cast<BluetoothLowEnergyDeviceMac*>(iter->second); |
} |
+NSError* BluetoothAdapterMac::GetNSErrorFromConnectErrorCode( |
+ BluetoothDevice::ConnectErrorCode error_code) { |
+ // TODO(http://crbug.com/585894): Need to convert the error. |
+ return [NSError errorWithDomain:kErrorDomain code:error_code userInfo:nil]; |
+} |
+ |
+BluetoothDevice::ConnectErrorCode |
+BluetoothAdapterMac::GetConnectErrorCodeFromNSError(NSError* error) { |
+ if ([error.domain isEqualToString:kErrorDomain]) { |
+ switch ((BluetoothDevice::ConnectErrorCode)error.code) { |
scheib
2016/02/10 23:48:16
I don't think this static cast will work. The Blue
jlebel
2016/02/11 00:03:43
I'm not sure to understand. This switch is execute
scheib
2016/03/02 05:33:22
OK, I didn't see or properly understand the NSErro
jlebel
2016/03/02 15:34:32
Yes, of course!
|
+ case BluetoothDevice::ERROR_ATTRIBUTE_LENGTH_INVALID: |
+ return BluetoothDevice::ERROR_ATTRIBUTE_LENGTH_INVALID; |
+ case BluetoothDevice::ERROR_AUTH_CANCELED: |
+ return BluetoothDevice::ERROR_AUTH_CANCELED; |
+ case BluetoothDevice::ERROR_AUTH_FAILED: |
+ return BluetoothDevice::ERROR_AUTH_FAILED; |
+ case BluetoothDevice::ERROR_AUTH_REJECTED: |
+ return BluetoothDevice::ERROR_AUTH_REJECTED; |
+ case BluetoothDevice::ERROR_AUTH_TIMEOUT: |
+ return BluetoothDevice::ERROR_AUTH_TIMEOUT; |
+ case BluetoothDevice::ERROR_CONNECTION_CONGESTED: |
+ return BluetoothDevice::ERROR_CONNECTION_CONGESTED; |
+ case BluetoothDevice::ERROR_FAILED: |
+ return BluetoothDevice::ERROR_FAILED; |
+ case BluetoothDevice::ERROR_INPROGRESS: |
+ return BluetoothDevice::ERROR_INPROGRESS; |
+ case BluetoothDevice::ERROR_INSUFFICIENT_ENCRYPTION: |
+ return BluetoothDevice::ERROR_INSUFFICIENT_ENCRYPTION; |
+ case BluetoothDevice::ERROR_OFFSET_INVALID: |
+ return BluetoothDevice::ERROR_OFFSET_INVALID; |
+ case BluetoothDevice::ERROR_READ_NOT_PERMITTED: |
+ return BluetoothDevice::ERROR_READ_NOT_PERMITTED; |
+ case BluetoothDevice::ERROR_REQUEST_NOT_SUPPORTED: |
+ return BluetoothDevice::ERROR_REQUEST_NOT_SUPPORTED; |
+ case BluetoothDevice::ERROR_UNKNOWN: |
+ return BluetoothDevice::ERROR_UNKNOWN; |
+ case BluetoothDevice::ERROR_UNSUPPORTED_DEVICE: |
+ return BluetoothDevice::ERROR_UNSUPPORTED_DEVICE; |
+ case BluetoothDevice::ERROR_WRITE_NOT_PERMITTED: |
+ return BluetoothDevice::ERROR_WRITE_NOT_PERMITTED; |
+ case BluetoothDevice::NUM_CONNECT_ERROR_CODES: |
+ DCHECK(false); |
+ return BluetoothDevice::ERROR_UNKNOWN; |
+ } |
+ } |
+ // TODO(http://crbug.com/585894): Need to convert the error. |
+ return BluetoothDevice::ERROR_UNKNOWN; |
+} |
+ |
} // namespace device |