| Index: extensions/browser/api/bluetooth_low_energy/bluetooth_low_energy_event_router.cc
|
| diff --git a/extensions/browser/api/bluetooth_low_energy/bluetooth_low_energy_event_router.cc b/extensions/browser/api/bluetooth_low_energy/bluetooth_low_energy_event_router.cc
|
| index 817f3726aa6b16235dde7dd78df84352724a4ee5..5e98444bc835d242b4fcb4f1a9fe5d38c81dadf2 100644
|
| --- a/extensions/browser/api/bluetooth_low_energy/bluetooth_low_energy_event_router.cc
|
| +++ b/extensions/browser/api/bluetooth_low_energy/bluetooth_low_energy_event_router.cc
|
| @@ -151,6 +151,34 @@ NotifySessionResourceManager* GetNotifySessionResourceManager(
|
| return manager;
|
| }
|
|
|
| +// Translates GattErrorCodes to RouterError Codes
|
| +extensions::BluetoothLowEnergyEventRouter::Status GattErrorToRouterError(
|
| + BluetoothGattService::GattErrorCode error_code) {
|
| + extensions::BluetoothLowEnergyEventRouter::Status error_status =
|
| + extensions::BluetoothLowEnergyEventRouter::kStatusErrorFailed;
|
| + if (error_code == BluetoothGattService::GATT_ERROR_IN_PROGRESS) {
|
| + error_status =
|
| + extensions::BluetoothLowEnergyEventRouter::kStatusErrorInProgress;
|
| + } else if (error_code == BluetoothGattService::GATT_ERROR_INVALID_LENGTH) {
|
| + error_status =
|
| + extensions::BluetoothLowEnergyEventRouter::kStatusErrorInvalidLength;
|
| + } else if (error_code == BluetoothGattService::GATT_ERROR_NOT_PERMITTED) {
|
| + error_status =
|
| + extensions::BluetoothLowEnergyEventRouter::kStatusErrorPermissionDenied;
|
| + } else if (error_code == BluetoothGattService::GATT_ERROR_NOT_AUTHORIZED) {
|
| + error_status =
|
| + extensions::BluetoothLowEnergyEventRouter::kStatusErrorPermissionDenied;
|
| + } else if (error_code == BluetoothGattService::GATT_ERROR_NOT_PAIRED) {
|
| + error_status =
|
| + extensions::BluetoothLowEnergyEventRouter::kStatusErrorNotConnected;
|
| + } else if (error_code == BluetoothGattService::GATT_ERROR_NOT_SUPPORTED) {
|
| + error_status =
|
| + extensions::BluetoothLowEnergyEventRouter::kStatusErrorGattNotSupported;
|
| + }
|
| +
|
| + return error_status;
|
| +}
|
| +
|
| } // namespace
|
|
|
| namespace extensions {
|
| @@ -1270,9 +1298,9 @@ void BluetoothLowEnergyEventRouter::OnDisconnect(
|
| void BluetoothLowEnergyEventRouter::OnError(
|
| const ErrorCallback& error_callback,
|
| BluetoothGattService::GattErrorCode error_code) {
|
| - // TODO(jamuraa): do something with |error_code| (crbug.com/277232)
|
| VLOG(2) << "Remote characteristic/descriptor value read/write failed.";
|
| - error_callback.Run(kStatusErrorFailed);
|
| +
|
| + error_callback.Run(GattErrorToRouterError(error_code));
|
| }
|
|
|
| void BluetoothLowEnergyEventRouter::OnConnectError(
|
| @@ -1280,14 +1308,28 @@ void BluetoothLowEnergyEventRouter::OnConnectError(
|
| const std::string& device_address,
|
| const ErrorCallback& error_callback,
|
| BluetoothDevice::ConnectErrorCode error_code) {
|
| - // TODO(jamuraa): do something with |error_code| (crbug.com/277232)
|
| VLOG(2) << "Failed to create GATT connection: " << error_code;
|
|
|
| const std::string connect_id = extension_id + device_address;
|
| DCHECK_NE(0U, connecting_devices_.count(connect_id));
|
|
|
| connecting_devices_.erase(connect_id);
|
| - error_callback.Run(kStatusErrorFailed);
|
| + Status error_status = kStatusErrorFailed;
|
| + if (error_code == BluetoothDevice::ERROR_INPROGRESS) {
|
| + error_status = kStatusErrorInProgress;
|
| + } else if (error_code == BluetoothDevice::ERROR_AUTH_FAILED ||
|
| + error_code == BluetoothDevice::ERROR_AUTH_REJECTED) {
|
| + error_status = kStatusErrorAuthenticationFailed;
|
| + } else if (error_code == BluetoothDevice::ERROR_AUTH_CANCELED) {
|
| + error_status = kStatusErrorCanceled;
|
| + } else if (error_code == BluetoothDevice::ERROR_AUTH_TIMEOUT) {
|
| + error_status = kStatusErrorTimeout;
|
| + } else if (error_code == BluetoothDevice::ERROR_UNSUPPORTED_DEVICE) {
|
| + error_status = kStatusErrorUnsupportedDevice;
|
| + }
|
| + // ERROR_UNKNOWN and ERROR_FAILED defaulted to kStatusErrorFailed
|
| +
|
| + error_callback.Run(error_status);
|
| }
|
|
|
| void BluetoothLowEnergyEventRouter::OnStartNotifySession(
|
| @@ -1322,7 +1364,6 @@ void BluetoothLowEnergyEventRouter::OnStartNotifySessionError(
|
| const std::string& characteristic_id,
|
| const ErrorCallback& error_callback,
|
| device::BluetoothGattService::GattErrorCode error_code) {
|
| - // TODO(jamuraa): do something with |error_code| (crbug.com/277232)
|
| VLOG(2) << "Failed to create value update session for characteristic: "
|
| << characteristic_id;
|
|
|
| @@ -1330,7 +1371,7 @@ void BluetoothLowEnergyEventRouter::OnStartNotifySessionError(
|
| DCHECK_NE(0U, pending_session_calls_.count(session_id));
|
|
|
| pending_session_calls_.erase(session_id);
|
| - error_callback.Run(kStatusErrorFailed);
|
| + error_callback.Run(GattErrorToRouterError(error_code));
|
| }
|
|
|
| void BluetoothLowEnergyEventRouter::OnStopNotifySession(
|
|
|