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

Side by Side Diff: third_party/WebKit/Source/modules/bluetooth/BluetoothError.cpp

Issue 2729433002: bluetooth: Better disconnected error messages for GATT operations. (Closed)
Patch Set: rebase Created 3 years, 9 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 unified diff | Download patch
OLDNEW
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 { 10 namespace {
11 11
12 const char kGATTServerNotConnectedBase[] = 12 const char kGATTServerNotConnectedBase[] =
13 "GATT Server is disconnected. " 13 "GATT Server is disconnected. "
14 "Cannot %s. (Re)connect first with `device.gatt.connect`."; 14 "Cannot %s. (Re)connect first with `device.gatt.connect`.";
15 } 15 }
16 16
17 namespace blink { 17 namespace blink {
18 18
19 // static 19 // static
20 DOMException* BluetoothError::createNotConnectedException( 20 DOMException* BluetoothError::createNotConnectedException(
21 BluetoothOperation operation) { 21 BluetoothOperation operation) {
22 const char* operationString = nullptr; 22 const char* operationString = nullptr;
23 switch (operation) { 23 switch (operation) {
24 case BluetoothOperation::ServicesRetrieval: 24 case BluetoothOperation::ServicesRetrieval:
25 operationString = "retrieve services"; 25 operationString = "retrieve services";
26 break; 26 break;
27 case BluetoothOperation::CharacteristicsRetrieval: 27 case BluetoothOperation::CharacteristicsRetrieval:
28 operationString = "retrieve characteristics"; 28 operationString = "retrieve characteristics";
29 break; 29 break;
30 case BluetoothOperation::GATT:
31 operationString = "perform GATT operations";
32 break;
30 } 33 }
31 34
32 return DOMException::create( 35 return DOMException::create(
33 NetworkError, 36 NetworkError,
34 String::format(kGATTServerNotConnectedBase, operationString)); 37 String::format(kGATTServerNotConnectedBase, operationString));
35 } 38 }
36 39
37 // static 40 // static
38 DOMException* BluetoothError::createDOMException( 41 DOMException* BluetoothError::createDOMException(
39 BluetoothErrorCode error, 42 BluetoothErrorCode error,
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
112 "Unsupported device."); 115 "Unsupported device.");
113 MAP_ERROR(CONNECT_WRITE_NOT_PERMITTED, NetworkError, 116 MAP_ERROR(CONNECT_WRITE_NOT_PERMITTED, NetworkError,
114 "GATT write operation is not permitted."); 117 "GATT write operation is not permitted.");
115 MAP_ERROR(DEVICE_NO_LONGER_IN_RANGE, NetworkError, 118 MAP_ERROR(DEVICE_NO_LONGER_IN_RANGE, NetworkError,
116 "Bluetooth Device is no longer in range."); 119 "Bluetooth Device is no longer in range.");
117 MAP_ERROR(GATT_NOT_PAIRED, NetworkError, "GATT Error: Not paired."); 120 MAP_ERROR(GATT_NOT_PAIRED, NetworkError, "GATT Error: Not paired.");
118 MAP_ERROR(GATT_OPERATION_IN_PROGRESS, NetworkError, 121 MAP_ERROR(GATT_OPERATION_IN_PROGRESS, NetworkError,
119 "GATT operation already in progress."); 122 "GATT operation already in progress.");
120 MAP_ERROR(UNTRANSLATED_CONNECT_ERROR_CODE, NetworkError, 123 MAP_ERROR(UNTRANSLATED_CONNECT_ERROR_CODE, NetworkError,
121 "Unknown ConnectErrorCode."); 124 "Unknown ConnectErrorCode.");
122 MAP_ERROR(GATT_SERVER_NOT_CONNECTED, NetworkError,
123 "GATT Server is disconnected. Cannot perform GATT operations.");
124 MAP_ERROR(GATT_SERVER_DISCONNECTED, NetworkError,
125 "GATT Server disconnected while performing a GATT operation.");
126 125
127 // NotFoundErrors: 126 // NotFoundErrors:
128 MAP_ERROR(WEB_BLUETOOTH_NOT_SUPPORTED, NotFoundError, 127 MAP_ERROR(WEB_BLUETOOTH_NOT_SUPPORTED, NotFoundError,
129 "Web Bluetooth is not supported on this platform. For a list " 128 "Web Bluetooth is not supported on this platform. For a list "
130 "of supported platforms see: https://goo.gl/J6ASzs"); 129 "of supported platforms see: https://goo.gl/J6ASzs");
131 MAP_ERROR(NO_BLUETOOTH_ADAPTER, NotFoundError, 130 MAP_ERROR(NO_BLUETOOTH_ADAPTER, NotFoundError,
132 "Bluetooth adapter not available."); 131 "Bluetooth adapter not available.");
133 MAP_ERROR(CHOSEN_DEVICE_VANISHED, NotFoundError, 132 MAP_ERROR(CHOSEN_DEVICE_VANISHED, NotFoundError,
134 "User selected a device that doesn't exist anymore."); 133 "User selected a device that doesn't exist anymore.");
135 MAP_ERROR(CHOOSER_CANCELLED, NotFoundError, 134 MAP_ERROR(CHOOSER_CANCELLED, NotFoundError,
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
191 "requestDevice() called from cross-origin iframe."); 190 "requestDevice() called from cross-origin iframe.");
192 191
193 #undef MAP_ERROR 192 #undef MAP_ERROR
194 } 193 }
195 194
196 NOTREACHED(); 195 NOTREACHED();
197 return DOMException::create(UnknownError); 196 return DOMException::create(UnknownError);
198 } 197 }
199 198
200 } // namespace blink 199 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698