Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2369)

Unified Diff: device/bluetooth/bluetooth_adapter_mac.mm

Issue 1685963003: Adding the last test related with connect/disconnect (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@connectdisconnect
Patch Set: Using FAILED instead of UNKNOWN error code Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: device/bluetooth/bluetooth_adapter_mac.mm
diff --git a/device/bluetooth/bluetooth_adapter_mac.mm b/device/bluetooth/bluetooth_adapter_mac.mm
index e542e4275199779237ab7a490a4cc2e7e7cc5c2a..aae6ad14a3c498ea9925c1d9b4c7f387d3487397 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(
@@ -571,10 +572,12 @@ void BluetoothAdapterMac::DidFailToConnectPeripheral(CBPeripheral* peripheral,
[low_energy_central_manager_ cancelPeripheralConnection:peripheral];
return;
}
+ BluetoothDevice::ConnectErrorCode error_code =
+ BluetoothAdapterMac::GetConnectErrorCodeFromNSError(error);
VLOG(1) << "Bluetooth error, domain: " << error.domain.UTF8String
- << ", error code: " << error.code;
- // TODO(http://crbug.com/585894): Need to convert the error.
- device_mac->DidFailToConnectGatt(BluetoothClassicDeviceMac::ERROR_UNKNOWN);
+ << ", error code: " << error.code
+ << ", converted into: " << error_code;
+ device_mac->DidFailToConnectGatt(error_code);
}
void BluetoothAdapterMac::DidDisconnectPeripheral(CBPeripheral* peripheral,
@@ -585,8 +588,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*
@@ -600,4 +604,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) {
+ 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_FAILED;
+ }
+ }
+ // TODO(http://crbug.com/585894): Need to convert the error.
+ return BluetoothDevice::ERROR_FAILED;
+}
+
} // namespace device

Powered by Google App Engine
This is Rietveld 408576698