| 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 78 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 89     return; | 89     return; | 
| 90   device()->cleanupDisconnectedDeviceAndFireEvent(); | 90   device()->cleanupDisconnectedDeviceAndFireEvent(); | 
| 91   m_device->bluetooth()->removeFromConnectedDevicesMap(device()->id()); | 91   m_device->bluetooth()->removeFromConnectedDevicesMap(device()->id()); | 
| 92   mojom::blink::WebBluetoothService* service = m_device->bluetooth()->service(); | 92   mojom::blink::WebBluetoothService* service = m_device->bluetooth()->service(); | 
| 93   service->RemoteServerDisconnect(device()->id()); | 93   service->RemoteServerDisconnect(device()->id()); | 
| 94 } | 94 } | 
| 95 | 95 | 
| 96 // Callback that allows us to resolve the promise with a single service or | 96 // Callback that allows us to resolve the promise with a single service or | 
| 97 // with a vector owning the services. | 97 // with a vector owning the services. | 
| 98 void BluetoothRemoteGATTServer::GetPrimaryServicesCallback( | 98 void BluetoothRemoteGATTServer::GetPrimaryServicesCallback( | 
|  | 99     const String& requestedServiceUUID, | 
| 99     mojom::blink::WebBluetoothGATTQueryQuantity quantity, | 100     mojom::blink::WebBluetoothGATTQueryQuantity quantity, | 
| 100     ScriptPromiseResolver* resolver, | 101     ScriptPromiseResolver* resolver, | 
| 101     mojom::blink::WebBluetoothResult result, | 102     mojom::blink::WebBluetoothResult result, | 
| 102     Optional<Vector<mojom::blink::WebBluetoothRemoteGATTServicePtr>> services) { | 103     Optional<Vector<mojom::blink::WebBluetoothRemoteGATTServicePtr>> services) { | 
| 103   if (!resolver->getExecutionContext() || | 104   if (!resolver->getExecutionContext() || | 
| 104       resolver->getExecutionContext()->isContextDestroyed()) | 105       resolver->getExecutionContext()->isContextDestroyed()) | 
| 105     return; | 106     return; | 
| 106 | 107 | 
| 107   // If the device is disconnected, reject. | 108   // If the device is disconnected, reject. | 
| 108   if (!RemoveFromActiveAlgorithms(resolver)) { | 109   if (!RemoveFromActiveAlgorithms(resolver)) { | 
| (...skipping 15 matching lines...) Expand all  Loading... | 
| 124 | 125 | 
| 125     HeapVector<Member<BluetoothRemoteGATTService>> gattServices; | 126     HeapVector<Member<BluetoothRemoteGATTService>> gattServices; | 
| 126     gattServices.reserveInitialCapacity(services->size()); | 127     gattServices.reserveInitialCapacity(services->size()); | 
| 127 | 128 | 
| 128     for (auto& service : services.value()) { | 129     for (auto& service : services.value()) { | 
| 129       gattServices.push_back(m_device->getOrCreateRemoteGATTService( | 130       gattServices.push_back(m_device->getOrCreateRemoteGATTService( | 
| 130           std::move(service), true /* isPrimary */, device()->id())); | 131           std::move(service), true /* isPrimary */, device()->id())); | 
| 131     } | 132     } | 
| 132     resolver->resolve(gattServices); | 133     resolver->resolve(gattServices); | 
| 133   } else { | 134   } else { | 
| 134     resolver->reject(BluetoothError::take(resolver, result)); | 135     if (result == mojom::blink::WebBluetoothResult::SERVICE_NOT_FOUND) { | 
|  | 136       resolver->reject(BluetoothError::take( | 
|  | 137           resolver, result, "No Services matching UUID " + | 
|  | 138                                 requestedServiceUUID + " found in Device.")); | 
|  | 139     } else { | 
|  | 140       resolver->reject(BluetoothError::take(resolver, result)); | 
|  | 141     } | 
| 135   } | 142   } | 
| 136 } | 143 } | 
| 137 | 144 | 
| 138 ScriptPromise BluetoothRemoteGATTServer::getPrimaryService( | 145 ScriptPromise BluetoothRemoteGATTServer::getPrimaryService( | 
| 139     ScriptState* scriptState, | 146     ScriptState* scriptState, | 
| 140     const StringOrUnsignedLong& service, | 147     const StringOrUnsignedLong& service, | 
| 141     ExceptionState& exceptionState) { | 148     ExceptionState& exceptionState) { | 
| 142   String serviceUUID = BluetoothUUID::getService(service, exceptionState); | 149   String serviceUUID = BluetoothUUID::getService(service, exceptionState); | 
| 143   if (exceptionState.hadException()) | 150   if (exceptionState.hadException()) | 
| 144     return exceptionState.reject(scriptState); | 151     return exceptionState.reject(scriptState); | 
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 180 | 187 | 
| 181   ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState); | 188   ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState); | 
| 182   ScriptPromise promise = resolver->promise(); | 189   ScriptPromise promise = resolver->promise(); | 
| 183   AddToActiveAlgorithms(resolver); | 190   AddToActiveAlgorithms(resolver); | 
| 184 | 191 | 
| 185   mojom::blink::WebBluetoothService* service = m_device->bluetooth()->service(); | 192   mojom::blink::WebBluetoothService* service = m_device->bluetooth()->service(); | 
| 186   service->RemoteServerGetPrimaryServices( | 193   service->RemoteServerGetPrimaryServices( | 
| 187       device()->id(), quantity, servicesUUID, | 194       device()->id(), quantity, servicesUUID, | 
| 188       convertToBaseCallback( | 195       convertToBaseCallback( | 
| 189           WTF::bind(&BluetoothRemoteGATTServer::GetPrimaryServicesCallback, | 196           WTF::bind(&BluetoothRemoteGATTServer::GetPrimaryServicesCallback, | 
| 190                     wrapPersistent(this), quantity, wrapPersistent(resolver)))); | 197                     wrapPersistent(this), servicesUUID, quantity, | 
|  | 198                     wrapPersistent(resolver)))); | 
| 191   return promise; | 199   return promise; | 
| 192 } | 200 } | 
| 193 | 201 | 
| 194 }  // namespace blink | 202 }  // namespace blink | 
| OLD | NEW | 
|---|