| OLD | NEW |
| 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 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 99 // with a vector owning the services. | 99 // with a vector owning the services. |
| 100 void BluetoothRemoteGATTServer::GetPrimaryServicesCallback( | 100 void BluetoothRemoteGATTServer::GetPrimaryServicesCallback( |
| 101 mojom::blink::WebBluetoothGATTQueryQuantity quantity, | 101 mojom::blink::WebBluetoothGATTQueryQuantity quantity, |
| 102 ScriptPromiseResolver* resolver, | 102 ScriptPromiseResolver* resolver, |
| 103 mojom::blink::WebBluetoothResult result, | 103 mojom::blink::WebBluetoothResult result, |
| 104 Optional<Vector<mojom::blink::WebBluetoothRemoteGATTServicePtr>> services) { | 104 Optional<Vector<mojom::blink::WebBluetoothRemoteGATTServicePtr>> services) { |
| 105 if (!resolver->getExecutionContext() || | 105 if (!resolver->getExecutionContext() || |
| 106 resolver->getExecutionContext()->isContextDestroyed()) | 106 resolver->getExecutionContext()->isContextDestroyed()) |
| 107 return; | 107 return; |
| 108 | 108 |
| 109 // If the resolver is not in the set of ActiveAlgorithms then the frame | 109 // If the device is disconnected, reject. |
| 110 // disconnected so we reject. | |
| 111 if (!RemoveFromActiveAlgorithms(resolver)) { | 110 if (!RemoveFromActiveAlgorithms(resolver)) { |
| 112 resolver->reject( | 111 resolver->reject( |
| 113 DOMException::create(NetworkError, kGATTServerDisconnected)); | 112 DOMException::create(NetworkError, kGATTServerDisconnected)); |
| 114 return; | 113 return; |
| 115 } | 114 } |
| 116 | 115 |
| 117 if (result == mojom::blink::WebBluetoothResult::SUCCESS) { | 116 if (result == mojom::blink::WebBluetoothResult::SUCCESS) { |
| 118 DCHECK(services); | 117 DCHECK(services); |
| 119 | 118 |
| 120 if (quantity == mojom::blink::WebBluetoothGATTQueryQuantity::SINGLE) { | 119 if (quantity == mojom::blink::WebBluetoothGATTQueryQuantity::SINGLE) { |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 168 ScriptState* scriptState, | 167 ScriptState* scriptState, |
| 169 ExceptionState&) { | 168 ExceptionState&) { |
| 170 return getPrimaryServicesImpl( | 169 return getPrimaryServicesImpl( |
| 171 scriptState, mojom::blink::WebBluetoothGATTQueryQuantity::MULTIPLE); | 170 scriptState, mojom::blink::WebBluetoothGATTQueryQuantity::MULTIPLE); |
| 172 } | 171 } |
| 173 | 172 |
| 174 ScriptPromise BluetoothRemoteGATTServer::getPrimaryServicesImpl( | 173 ScriptPromise BluetoothRemoteGATTServer::getPrimaryServicesImpl( |
| 175 ScriptState* scriptState, | 174 ScriptState* scriptState, |
| 176 mojom::blink::WebBluetoothGATTQueryQuantity quantity, | 175 mojom::blink::WebBluetoothGATTQueryQuantity quantity, |
| 177 String servicesUUID) { | 176 String servicesUUID) { |
| 178 // We always check that the device is connected. | |
| 179 if (!connected()) { | 177 if (!connected()) { |
| 180 return ScriptPromise::rejectWithDOMException( | 178 return ScriptPromise::rejectWithDOMException( |
| 181 scriptState, | 179 scriptState, |
| 182 DOMException::create(NetworkError, kGATTServerNotConnected)); | 180 DOMException::create(NetworkError, kGATTServerNotConnected)); |
| 183 } | 181 } |
| 184 | 182 |
| 185 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState); | 183 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState); |
| 186 ScriptPromise promise = resolver->promise(); | 184 ScriptPromise promise = resolver->promise(); |
| 187 AddToActiveAlgorithms(resolver); | 185 AddToActiveAlgorithms(resolver); |
| 188 | 186 |
| 189 mojom::blink::WebBluetoothService* service = m_device->bluetooth()->service(); | 187 mojom::blink::WebBluetoothService* service = m_device->bluetooth()->service(); |
| 190 WTF::Optional<String> uuid = WTF::nullopt; | 188 WTF::Optional<String> uuid = WTF::nullopt; |
| 191 if (!servicesUUID.isEmpty()) | 189 if (!servicesUUID.isEmpty()) |
| 192 uuid = servicesUUID; | 190 uuid = servicesUUID; |
| 193 | 191 |
| 194 service->RemoteServerGetPrimaryServices( | 192 service->RemoteServerGetPrimaryServices( |
| 195 device()->id(), quantity, uuid, | 193 device()->id(), quantity, uuid, |
| 196 convertToBaseCallback( | 194 convertToBaseCallback( |
| 197 WTF::bind(&BluetoothRemoteGATTServer::GetPrimaryServicesCallback, | 195 WTF::bind(&BluetoothRemoteGATTServer::GetPrimaryServicesCallback, |
| 198 wrapPersistent(this), quantity, wrapPersistent(resolver)))); | 196 wrapPersistent(this), quantity, wrapPersistent(resolver)))); |
| 199 return promise; | 197 return promise; |
| 200 } | 198 } |
| 201 | 199 |
| 202 } // namespace blink | 200 } // namespace blink |
| OLD | NEW |