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

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

Issue 2564283004: bluetooth: web: Include the UUID in the error message. (Closed)
Patch Set: Addressed issues in code review. Created 4 years 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 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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/BluetoothRemoteGATTServer.h" 5 #include "modules/bluetooth/BluetoothRemoteGATTServer.h"
6 6
7 #include "bindings/core/v8/CallbackPromiseAdapter.h" 7 #include "bindings/core/v8/CallbackPromiseAdapter.h"
8 #include "bindings/core/v8/ScriptPromise.h" 8 #include "bindings/core/v8/ScriptPromise.h"
9 #include "bindings/core/v8/ScriptPromiseResolver.h" 9 #include "bindings/core/v8/ScriptPromiseResolver.h"
10 #include "core/dom/DOMException.h" 10 #include "core/dom/DOMException.h"
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
106 webbluetooth->disconnect(device()->id()); 106 webbluetooth->disconnect(device()->id());
107 } 107 }
108 108
109 // Class that allows us to resolve the promise with a single service or 109 // Class that allows us to resolve the promise with a single service or
110 // with a vector owning the services. 110 // with a vector owning the services.
111 class GetPrimaryServicesCallback 111 class GetPrimaryServicesCallback
112 : public WebBluetoothGetPrimaryServicesCallbacks { 112 : public WebBluetoothGetPrimaryServicesCallbacks {
113 public: 113 public:
114 GetPrimaryServicesCallback( 114 GetPrimaryServicesCallback(
115 BluetoothDevice* device, 115 BluetoothDevice* device,
116 String servicesUUID,
116 mojom::blink::WebBluetoothGATTQueryQuantity quantity, 117 mojom::blink::WebBluetoothGATTQueryQuantity quantity,
117 ScriptPromiseResolver* resolver) 118 ScriptPromiseResolver* resolver)
118 : m_device(device), m_quantity(quantity), m_resolver(resolver) { 119 : m_device(device),
120 m_servicesUUID(servicesUUID),
121 m_quantity(quantity),
122 m_resolver(resolver) {
119 // We always check that the device is connected before constructing this 123 // We always check that the device is connected before constructing this
120 // object. 124 // object.
121 CHECK(m_device->gatt()->connected()); 125 CHECK(m_device->gatt()->connected());
122 m_device->gatt()->AddToActiveAlgorithms(m_resolver.get()); 126 m_device->gatt()->AddToActiveAlgorithms(m_resolver.get());
123 } 127 }
124 128
125 void onSuccess( 129 void onSuccess(
126 const WebVector<WebBluetoothRemoteGATTService*>& webServices) override { 130 const WebVector<WebBluetoothRemoteGATTService*>& webServices) override {
127 if (!m_resolver->getExecutionContext() || 131 if (!m_resolver->getExecutionContext() ||
128 m_resolver->getExecutionContext()->isContextDestroyed()) 132 m_resolver->getExecutionContext()->isContextDestroyed())
(...skipping 30 matching lines...) Expand all
159 if (!m_resolver->getExecutionContext() || 163 if (!m_resolver->getExecutionContext() ||
160 m_resolver->getExecutionContext()->isContextDestroyed()) 164 m_resolver->getExecutionContext()->isContextDestroyed())
161 return; 165 return;
162 166
163 if (!m_device->gatt()->RemoveFromActiveAlgorithms(m_resolver.get())) { 167 if (!m_device->gatt()->RemoveFromActiveAlgorithms(m_resolver.get())) {
164 m_resolver->reject( 168 m_resolver->reject(
165 DOMException::create(NetworkError, kGATTServerDisconnected)); 169 DOMException::create(NetworkError, kGATTServerDisconnected));
166 return; 170 return;
167 } 171 }
168 172
169 m_resolver->reject(BluetoothError::take(m_resolver, error)); 173 if (!m_servicesUUID.isEmpty() &&
174 BluetoothError::isSameError(
175 error, mojom::blink::WebBluetoothResult::SERVICE_NOT_FOUND)) {
176 m_resolver->reject(BluetoothError::take(
177 m_resolver, error,
178 "No Services matching UUID " + m_servicesUUID + " found in Device."));
179 } else {
180 m_resolver->reject(BluetoothError::take(m_resolver, error));
181 }
170 } 182 }
171 183
172 private: 184 private:
173 Persistent<BluetoothDevice> m_device; 185 Persistent<BluetoothDevice> m_device;
186 const String m_servicesUUID;
174 mojom::blink::WebBluetoothGATTQueryQuantity m_quantity; 187 mojom::blink::WebBluetoothGATTQueryQuantity m_quantity;
175 const Persistent<ScriptPromiseResolver> m_resolver; 188 const Persistent<ScriptPromiseResolver> m_resolver;
176 }; 189 };
177 190
178 ScriptPromise BluetoothRemoteGATTServer::getPrimaryService( 191 ScriptPromise BluetoothRemoteGATTServer::getPrimaryService(
179 ScriptState* scriptState, 192 ScriptState* scriptState,
180 const StringOrUnsignedLong& service, 193 const StringOrUnsignedLong& service,
181 ExceptionState& exceptionState) { 194 ExceptionState& exceptionState) {
182 String serviceUUID = BluetoothUUID::getService(service, exceptionState); 195 String serviceUUID = BluetoothUUID::getService(service, exceptionState);
183 if (exceptionState.hadException()) 196 if (exceptionState.hadException())
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
218 DOMException::create(NetworkError, kGATTServerNotConnected)); 231 DOMException::create(NetworkError, kGATTServerNotConnected));
219 } 232 }
220 233
221 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState); 234 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState);
222 ScriptPromise promise = resolver->promise(); 235 ScriptPromise promise = resolver->promise();
223 236
224 WebBluetooth* webbluetooth = 237 WebBluetooth* webbluetooth =
225 BluetoothSupplement::fromScriptState(scriptState); 238 BluetoothSupplement::fromScriptState(scriptState);
226 webbluetooth->getPrimaryServices( 239 webbluetooth->getPrimaryServices(
227 device()->id(), static_cast<int32_t>(quantity), servicesUUID, 240 device()->id(), static_cast<int32_t>(quantity), servicesUUID,
228 new GetPrimaryServicesCallback(device(), quantity, resolver)); 241 new GetPrimaryServicesCallback(device(), servicesUUID, quantity,
242 resolver));
229 243
230 return promise; 244 return promise;
231 } 245 }
232 246
233 } // namespace blink 247 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698