| 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 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 155 } | 155 } |
| 156 | 156 |
| 157 void onError( | 157 void onError( |
| 158 int32_t | 158 int32_t |
| 159 error /* Corresponds to WebBluetoothError in web_bluetooth.mojom */) | 159 error /* Corresponds to WebBluetoothError in web_bluetooth.mojom */) |
| 160 override { | 160 override { |
| 161 if (!m_resolver->getExecutionContext() || | 161 if (!m_resolver->getExecutionContext() || |
| 162 m_resolver->getExecutionContext()->activeDOMObjectsAreStopped()) | 162 m_resolver->getExecutionContext()->activeDOMObjectsAreStopped()) |
| 163 return; | 163 return; |
| 164 | 164 |
| 165 m_device->gatt()->RemoveFromActiveAlgorithms(m_resolver.get()); | 165 if (!m_device->gatt()->RemoveFromActiveAlgorithms(m_resolver.get())) { |
| 166 m_resolver->reject( |
| 167 DOMException::create(NetworkError, kGATTServerDisconnected)); |
| 168 return; |
| 169 } |
| 170 |
| 166 m_resolver->reject(BluetoothError::take(m_resolver, error)); | 171 m_resolver->reject(BluetoothError::take(m_resolver, error)); |
| 167 } | 172 } |
| 168 | 173 |
| 169 private: | 174 private: |
| 170 Persistent<BluetoothDevice> m_device; | 175 Persistent<BluetoothDevice> m_device; |
| 171 mojom::blink::WebBluetoothGATTQueryQuantity m_quantity; | 176 mojom::blink::WebBluetoothGATTQueryQuantity m_quantity; |
| 172 Persistent<ScriptPromiseResolver> m_resolver; | 177 const Persistent<ScriptPromiseResolver> m_resolver; |
| 173 }; | 178 }; |
| 174 | 179 |
| 175 ScriptPromise BluetoothRemoteGATTServer::getPrimaryService( | 180 ScriptPromise BluetoothRemoteGATTServer::getPrimaryService( |
| 176 ScriptState* scriptState, | 181 ScriptState* scriptState, |
| 177 const StringOrUnsignedLong& service, | 182 const StringOrUnsignedLong& service, |
| 178 ExceptionState& exceptionState) { | 183 ExceptionState& exceptionState) { |
| 179 String serviceUUID = BluetoothUUID::getService(service, exceptionState); | 184 String serviceUUID = BluetoothUUID::getService(service, exceptionState); |
| 180 if (exceptionState.hadException()) | 185 if (exceptionState.hadException()) |
| 181 return exceptionState.reject(scriptState); | 186 return exceptionState.reject(scriptState); |
| 182 | 187 |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 221 WebBluetooth* webbluetooth = | 226 WebBluetooth* webbluetooth = |
| 222 BluetoothSupplement::fromScriptState(scriptState); | 227 BluetoothSupplement::fromScriptState(scriptState); |
| 223 webbluetooth->getPrimaryServices( | 228 webbluetooth->getPrimaryServices( |
| 224 device()->id(), static_cast<int32_t>(quantity), servicesUUID, | 229 device()->id(), static_cast<int32_t>(quantity), servicesUUID, |
| 225 new GetPrimaryServicesCallback(device(), quantity, resolver)); | 230 new GetPrimaryServicesCallback(device(), quantity, resolver)); |
| 226 | 231 |
| 227 return promise; | 232 return promise; |
| 228 } | 233 } |
| 229 | 234 |
| 230 } // namespace blink | 235 } // namespace blink |
| OLD | NEW |