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

Side by Side Diff: third_party/WebKit/Source/modules/bluetooth/BluetoothRemoteGATTDescriptor.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 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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/BluetoothRemoteGATTDescriptor.h" 5 #include "modules/bluetooth/BluetoothRemoteGATTDescriptor.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 "modules/bluetooth/BluetoothError.h" 10 #include "modules/bluetooth/BluetoothError.h"
(...skipping 20 matching lines...) Expand all
31 void BluetoothRemoteGATTDescriptor::ReadValueCallback( 31 void BluetoothRemoteGATTDescriptor::ReadValueCallback(
32 ScriptPromiseResolver* resolver, 32 ScriptPromiseResolver* resolver,
33 mojom::blink::WebBluetoothResult result, 33 mojom::blink::WebBluetoothResult result,
34 const Optional<Vector<uint8_t>>& value) { 34 const Optional<Vector<uint8_t>>& value) {
35 if (!resolver->getExecutionContext() || 35 if (!resolver->getExecutionContext() ||
36 resolver->getExecutionContext()->isContextDestroyed()) 36 resolver->getExecutionContext()->isContextDestroyed())
37 return; 37 return;
38 38
39 // If the device is disconnected, reject. 39 // If the device is disconnected, reject.
40 if (!getGatt()->RemoveFromActiveAlgorithms(resolver)) { 40 if (!getGatt()->RemoveFromActiveAlgorithms(resolver)) {
41 resolver->reject(BluetoothError::createDOMException( 41 resolver->reject(
42 mojom::blink::WebBluetoothResult::GATT_SERVER_DISCONNECTED)); 42 BluetoothError::createNotConnectedException(BluetoothOperation::GATT));
43 return; 43 return;
44 } 44 }
45 45
46 if (result == mojom::blink::WebBluetoothResult::SUCCESS) { 46 if (result == mojom::blink::WebBluetoothResult::SUCCESS) {
47 DCHECK(value); 47 DCHECK(value);
48 DOMDataView* domDataView = 48 DOMDataView* domDataView =
49 BluetoothRemoteGATTUtils::ConvertWTFVectorToDataView(value.value()); 49 BluetoothRemoteGATTUtils::ConvertWTFVectorToDataView(value.value());
50 m_value = domDataView; 50 m_value = domDataView;
51 resolver->resolve(domDataView); 51 resolver->resolve(domDataView);
52 } else { 52 } else {
53 resolver->reject(BluetoothError::createDOMException(result)); 53 resolver->reject(BluetoothError::createDOMException(result));
54 } 54 }
55 } 55 }
56 56
57 ScriptPromise BluetoothRemoteGATTDescriptor::readValue( 57 ScriptPromise BluetoothRemoteGATTDescriptor::readValue(
58 ScriptState* scriptState) { 58 ScriptState* scriptState) {
59 if (!getGatt()->connected()) { 59 if (!getGatt()->connected()) {
60 return ScriptPromise::rejectWithDOMException( 60 return ScriptPromise::rejectWithDOMException(
61 scriptState, 61 scriptState,
62 BluetoothError::createDOMException( 62 BluetoothError::createNotConnectedException(BluetoothOperation::GATT));
63 mojom::blink::WebBluetoothResult::GATT_SERVER_NOT_CONNECTED));
64 } 63 }
65 64
66 if (!getGatt()->device()->isValidDescriptor(m_descriptor->instance_id)) { 65 if (!getGatt()->device()->isValidDescriptor(m_descriptor->instance_id)) {
67 return ScriptPromise::rejectWithDOMException( 66 return ScriptPromise::rejectWithDOMException(
68 scriptState, createInvalidDescriptorError()); 67 scriptState, createInvalidDescriptorError());
69 } 68 }
70 69
71 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState); 70 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState);
72 ScriptPromise promise = resolver->promise(); 71 ScriptPromise promise = resolver->promise();
73 getGatt()->AddToActiveAlgorithms(resolver); 72 getGatt()->AddToActiveAlgorithms(resolver);
(...skipping 10 matching lines...) Expand all
84 ScriptPromiseResolver* resolver, 83 ScriptPromiseResolver* resolver,
85 const Vector<uint8_t>& value, 84 const Vector<uint8_t>& value,
86 mojom::blink::WebBluetoothResult result) { 85 mojom::blink::WebBluetoothResult result) {
87 if (!resolver->getExecutionContext() || 86 if (!resolver->getExecutionContext() ||
88 resolver->getExecutionContext()->isContextDestroyed()) 87 resolver->getExecutionContext()->isContextDestroyed())
89 return; 88 return;
90 89
91 // If the resolver is not in the set of ActiveAlgorithms then the frame 90 // If the resolver is not in the set of ActiveAlgorithms then the frame
92 // disconnected so we reject. 91 // disconnected so we reject.
93 if (!getGatt()->RemoveFromActiveAlgorithms(resolver)) { 92 if (!getGatt()->RemoveFromActiveAlgorithms(resolver)) {
94 resolver->reject(BluetoothError::createDOMException( 93 resolver->reject(
95 mojom::blink::WebBluetoothResult::GATT_SERVER_DISCONNECTED)); 94 BluetoothError::createNotConnectedException(BluetoothOperation::GATT));
96 return; 95 return;
97 } 96 }
98 97
99 if (result == mojom::blink::WebBluetoothResult::SUCCESS) { 98 if (result == mojom::blink::WebBluetoothResult::SUCCESS) {
100 m_value = BluetoothRemoteGATTUtils::ConvertWTFVectorToDataView(value); 99 m_value = BluetoothRemoteGATTUtils::ConvertWTFVectorToDataView(value);
101 resolver->resolve(); 100 resolver->resolve();
102 } else { 101 } else {
103 resolver->reject(BluetoothError::createDOMException(result)); 102 resolver->reject(BluetoothError::createDOMException(result));
104 } 103 }
105 } 104 }
106 105
107 ScriptPromise BluetoothRemoteGATTDescriptor::writeValue( 106 ScriptPromise BluetoothRemoteGATTDescriptor::writeValue(
108 ScriptState* scriptState, 107 ScriptState* scriptState,
109 const DOMArrayPiece& value) { 108 const DOMArrayPiece& value) {
110 if (!getGatt()->connected()) { 109 if (!getGatt()->connected()) {
111 return ScriptPromise::rejectWithDOMException( 110 return ScriptPromise::rejectWithDOMException(
112 scriptState, 111 scriptState,
113 BluetoothError::createDOMException( 112 BluetoothError::createNotConnectedException(BluetoothOperation::GATT));
114 mojom::blink::WebBluetoothResult::GATT_SERVER_NOT_CONNECTED));
115 } 113 }
116 114
117 if (!getGatt()->device()->isValidDescriptor(m_descriptor->instance_id)) { 115 if (!getGatt()->device()->isValidDescriptor(m_descriptor->instance_id)) {
118 return ScriptPromise::rejectWithDOMException( 116 return ScriptPromise::rejectWithDOMException(
119 scriptState, createInvalidDescriptorError()); 117 scriptState, createInvalidDescriptorError());
120 } 118 }
121 119
122 // Partial implementation of writeValue algorithm: 120 // Partial implementation of writeValue algorithm:
123 // https://webbluetoothcg.github.io/web-bluetooth/#dom-bluetoothremotegattdesc riptor-writevalue 121 // https://webbluetoothcg.github.io/web-bluetooth/#dom-bluetoothremotegattdesc riptor-writevalue
124 122
(...skipping 29 matching lines...) Expand all
154 " is no longer valid. Remember to retrieve the Descriptor again " 152 " is no longer valid. Remember to retrieve the Descriptor again "
155 "after reconnecting."); 153 "after reconnecting.");
156 } 154 }
157 155
158 DEFINE_TRACE(BluetoothRemoteGATTDescriptor) { 156 DEFINE_TRACE(BluetoothRemoteGATTDescriptor) {
159 visitor->trace(m_characteristic); 157 visitor->trace(m_characteristic);
160 visitor->trace(m_value); 158 visitor->trace(m_value);
161 } 159 }
162 160
163 } // namespace blink 161 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698