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

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

Issue 2680783002: bluetooth: show better error messages for services, characteristics and descriptors (Closed)
Patch Set: Created 3 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 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/BluetoothRemoteGATTService.h" 5 #include "modules/bluetooth/BluetoothRemoteGATTService.h"
6 6
7 #include "bindings/core/v8/ScriptPromise.h" 7 #include "bindings/core/v8/ScriptPromise.h"
8 #include "bindings/core/v8/ScriptPromiseResolver.h" 8 #include "bindings/core/v8/ScriptPromiseResolver.h"
9 #include "core/dom/DOMException.h" 9 #include "core/dom/DOMException.h"
10 #include "core/dom/ExceptionCode.h" 10 #include "core/dom/ExceptionCode.h"
(...skipping 30 matching lines...) Expand all
41 m_device(device) {} 41 m_device(device) {}
42 42
43 DEFINE_TRACE(BluetoothRemoteGATTService) { 43 DEFINE_TRACE(BluetoothRemoteGATTService) {
44 visitor->trace(m_device); 44 visitor->trace(m_device);
45 } 45 }
46 46
47 // Callback that allows us to resolve the promise with a single characteristic 47 // Callback that allows us to resolve the promise with a single characteristic
48 // or with a vector owning the characteristics. 48 // or with a vector owning the characteristics.
49 void BluetoothRemoteGATTService::GetCharacteristicsCallback( 49 void BluetoothRemoteGATTService::GetCharacteristicsCallback(
50 const String& serviceInstanceId, 50 const String& serviceInstanceId,
51 const String& requestedCharacteristicUUID,
51 mojom::blink::WebBluetoothGATTQueryQuantity quantity, 52 mojom::blink::WebBluetoothGATTQueryQuantity quantity,
52 ScriptPromiseResolver* resolver, 53 ScriptPromiseResolver* resolver,
53 mojom::blink::WebBluetoothResult result, 54 mojom::blink::WebBluetoothResult result,
54 Optional<Vector<mojom::blink::WebBluetoothRemoteGATTCharacteristicPtr>> 55 Optional<Vector<mojom::blink::WebBluetoothRemoteGATTCharacteristicPtr>>
55 characteristics) { 56 characteristics) {
56 if (!resolver->getExecutionContext() || 57 if (!resolver->getExecutionContext() ||
57 resolver->getExecutionContext()->isContextDestroyed()) 58 resolver->getExecutionContext()->isContextDestroyed())
58 return; 59 return;
59 60
60 // If the device is disconnected, reject. 61 // If the device is disconnected, reject.
(...skipping 17 matching lines...) Expand all
78 HeapVector<Member<BluetoothRemoteGATTCharacteristic>> gattCharacteristics; 79 HeapVector<Member<BluetoothRemoteGATTCharacteristic>> gattCharacteristics;
79 gattCharacteristics.reserveInitialCapacity(characteristics->size()); 80 gattCharacteristics.reserveInitialCapacity(characteristics->size());
80 for (auto& characteristic : characteristics.value()) { 81 for (auto& characteristic : characteristics.value()) {
81 gattCharacteristics.push_back( 82 gattCharacteristics.push_back(
82 device()->getOrCreateRemoteGATTCharacteristic( 83 device()->getOrCreateRemoteGATTCharacteristic(
83 resolver->getExecutionContext(), std::move(characteristic), 84 resolver->getExecutionContext(), std::move(characteristic),
84 this)); 85 this));
85 } 86 }
86 resolver->resolve(gattCharacteristics); 87 resolver->resolve(gattCharacteristics);
87 } else { 88 } else {
88 resolver->reject(BluetoothError::take(resolver, result)); 89 if (result == mojom::blink::WebBluetoothResult::CHARACTERISTIC_NOT_FOUND) {
90 resolver->reject(BluetoothError::take(
91 resolver, result, "No Characteristics matching UUID " +
92 requestedCharacteristicUUID +
93 " found in Service with UUID " + uuid() + "."));
94 } else {
95 resolver->reject(BluetoothError::take(resolver, result));
96 }
89 } 97 }
90 } 98 }
91 99
92 ScriptPromise BluetoothRemoteGATTService::getCharacteristic( 100 ScriptPromise BluetoothRemoteGATTService::getCharacteristic(
93 ScriptState* scriptState, 101 ScriptState* scriptState,
94 const StringOrUnsignedLong& characteristic, 102 const StringOrUnsignedLong& characteristic,
95 ExceptionState& exceptionState) { 103 ExceptionState& exceptionState) {
96 String characteristicUUID = 104 String characteristicUUID =
97 BluetoothUUID::getCharacteristic(characteristic, exceptionState); 105 BluetoothUUID::getCharacteristic(characteristic, exceptionState);
98 if (exceptionState.hadException()) 106 if (exceptionState.hadException())
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
141 149
142 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState); 150 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState);
143 ScriptPromise promise = resolver->promise(); 151 ScriptPromise promise = resolver->promise();
144 device()->gatt()->AddToActiveAlgorithms(resolver); 152 device()->gatt()->AddToActiveAlgorithms(resolver);
145 153
146 mojom::blink::WebBluetoothService* service = m_device->bluetooth()->service(); 154 mojom::blink::WebBluetoothService* service = m_device->bluetooth()->service();
147 service->RemoteServiceGetCharacteristics( 155 service->RemoteServiceGetCharacteristics(
148 m_service->instance_id, quantity, characteristicsUUID, 156 m_service->instance_id, quantity, characteristicsUUID,
149 convertToBaseCallback( 157 convertToBaseCallback(
150 WTF::bind(&BluetoothRemoteGATTService::GetCharacteristicsCallback, 158 WTF::bind(&BluetoothRemoteGATTService::GetCharacteristicsCallback,
151 wrapPersistent(this), m_service->instance_id, quantity, 159 wrapPersistent(this), m_service->instance_id,
152 wrapPersistent(resolver)))); 160 characteristicsUUID, quantity, wrapPersistent(resolver))));
153 161
154 return promise; 162 return promise;
155 } 163 }
156 164
157 } // namespace blink 165 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698