Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "modules/bluetooth/BluetoothError.h" | 5 #include "modules/bluetooth/BluetoothError.h" |
| 6 | 6 |
| 7 #include "core/dom/DOMException.h" | 7 #include "core/dom/DOMException.h" |
| 8 #include "core/dom/ExceptionCode.h" | 8 #include "core/dom/ExceptionCode.h" |
| 9 | 9 |
| 10 namespace { | |
| 11 | |
| 12 const char kGATTServerNotConnectedBase[] = | |
| 13 "GATT Server is disconnected. " | |
| 14 "Cannot %s. (Re)connect first with `device.gatt.connect`."; | |
| 15 } | |
|
dcheng
2017/03/07 08:19:36
Super minor nit:
Add // namespace
And a new line b
ortuno
2017/03/07 22:24:00
Done.
| |
| 16 | |
| 10 namespace blink { | 17 namespace blink { |
| 11 | 18 |
| 12 // static | 19 // static |
| 20 DOMException* BluetoothError::createNotConnectedException( | |
| 21 BluetoothOperation operation) { | |
| 22 const char* operationString = nullptr; | |
| 23 switch (operation) { | |
| 24 case BluetoothOperation::ServicesRetrieval: | |
| 25 operationString = "retrieve services"; | |
| 26 break; | |
| 27 case BluetoothOperation::CharacteristicsRetrieval: | |
| 28 operationString = "retrieve characteristics"; | |
| 29 break; | |
| 30 } | |
| 31 | |
| 32 return DOMException::create( | |
| 33 NetworkError, | |
| 34 String::format(kGATTServerNotConnectedBase, operationString)); | |
| 35 } | |
| 36 | |
| 37 // static | |
| 13 DOMException* BluetoothError::createDOMException( | 38 DOMException* BluetoothError::createDOMException( |
| 14 BluetoothErrorCode error, | 39 BluetoothErrorCode error, |
| 15 const String& detailedMessage) { | 40 const String& detailedMessage) { |
| 16 switch (error) { | 41 switch (error) { |
| 17 case BluetoothErrorCode::InvalidService: | 42 case BluetoothErrorCode::InvalidService: |
| 18 case BluetoothErrorCode::InvalidCharacteristic: | 43 case BluetoothErrorCode::InvalidCharacteristic: |
| 19 case BluetoothErrorCode::InvalidDescriptor: | 44 case BluetoothErrorCode::InvalidDescriptor: |
| 20 return DOMException::create(InvalidStateError, detailedMessage); | 45 return DOMException::create(InvalidStateError, detailedMessage); |
| 21 case BluetoothErrorCode::ServiceNotFound: | 46 case BluetoothErrorCode::ServiceNotFound: |
| 22 case BluetoothErrorCode::CharacteristicNotFound: | 47 case BluetoothErrorCode::CharacteristicNotFound: |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 91 "Bluetooth Device is no longer in range."); | 116 "Bluetooth Device is no longer in range."); |
| 92 MAP_ERROR(GATT_NOT_PAIRED, NetworkError, "GATT Error: Not paired."); | 117 MAP_ERROR(GATT_NOT_PAIRED, NetworkError, "GATT Error: Not paired."); |
| 93 MAP_ERROR(GATT_OPERATION_IN_PROGRESS, NetworkError, | 118 MAP_ERROR(GATT_OPERATION_IN_PROGRESS, NetworkError, |
| 94 "GATT operation already in progress."); | 119 "GATT operation already in progress."); |
| 95 MAP_ERROR(UNTRANSLATED_CONNECT_ERROR_CODE, NetworkError, | 120 MAP_ERROR(UNTRANSLATED_CONNECT_ERROR_CODE, NetworkError, |
| 96 "Unknown ConnectErrorCode."); | 121 "Unknown ConnectErrorCode."); |
| 97 MAP_ERROR(GATT_SERVER_NOT_CONNECTED, NetworkError, | 122 MAP_ERROR(GATT_SERVER_NOT_CONNECTED, NetworkError, |
| 98 "GATT Server is disconnected. Cannot perform GATT operations."); | 123 "GATT Server is disconnected. Cannot perform GATT operations."); |
| 99 MAP_ERROR(GATT_SERVER_DISCONNECTED, NetworkError, | 124 MAP_ERROR(GATT_SERVER_DISCONNECTED, NetworkError, |
| 100 "GATT Server disconnected while performing a GATT operation."); | 125 "GATT Server disconnected while performing a GATT operation."); |
| 101 MAP_ERROR(GATT_SERVER_DISCONNECTED_WHILE_RETRIEVING_CHARACTERISTICS, | |
| 102 NetworkError, | |
| 103 "GATT Server disconnected while retrieving characteristics."); | |
| 104 MAP_ERROR( | |
| 105 GATT_SERVER_NOT_CONNECTED_CANNOT_RETRIEVE_CHARACTERISTICS, | |
| 106 NetworkError, | |
| 107 "GATT Server is disconnected. Cannot retrieve characteristics."); | |
| 108 | 126 |
| 109 // NotFoundErrors: | 127 // NotFoundErrors: |
| 110 MAP_ERROR(WEB_BLUETOOTH_NOT_SUPPORTED, NotFoundError, | 128 MAP_ERROR(WEB_BLUETOOTH_NOT_SUPPORTED, NotFoundError, |
| 111 "Web Bluetooth is not supported on this platform. For a list " | 129 "Web Bluetooth is not supported on this platform. For a list " |
| 112 "of supported platforms see: https://goo.gl/J6ASzs"); | 130 "of supported platforms see: https://goo.gl/J6ASzs"); |
| 113 MAP_ERROR(NO_BLUETOOTH_ADAPTER, NotFoundError, | 131 MAP_ERROR(NO_BLUETOOTH_ADAPTER, NotFoundError, |
| 114 "Bluetooth adapter not available."); | 132 "Bluetooth adapter not available."); |
| 115 MAP_ERROR(CHOSEN_DEVICE_VANISHED, NotFoundError, | 133 MAP_ERROR(CHOSEN_DEVICE_VANISHED, NotFoundError, |
| 116 "User selected a device that doesn't exist anymore."); | 134 "User selected a device that doesn't exist anymore."); |
| 117 MAP_ERROR(CHOOSER_CANCELLED, NotFoundError, | 135 MAP_ERROR(CHOOSER_CANCELLED, NotFoundError, |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 173 "requestDevice() called from cross-origin iframe."); | 191 "requestDevice() called from cross-origin iframe."); |
| 174 | 192 |
| 175 #undef MAP_ERROR | 193 #undef MAP_ERROR |
| 176 } | 194 } |
| 177 | 195 |
| 178 NOTREACHED(); | 196 NOTREACHED(); |
| 179 return DOMException::create(UnknownError); | 197 return DOMException::create(UnknownError); |
| 180 } | 198 } |
| 181 | 199 |
| 182 } // namespace blink | 200 } // namespace blink |
| OLD | NEW |