| 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/BluetoothRemoteGATTService.h" | 5 #include "modules/bluetooth/BluetoothRemoteGATTService.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 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 59 ScriptPromiseResolver* resolver) | 59 ScriptPromiseResolver* resolver) |
| 60 : m_service(service), m_quantity(quantity), m_resolver(resolver) { | 60 : m_service(service), m_quantity(quantity), m_resolver(resolver) { |
| 61 // We always check that the device is connected before constructing this | 61 // We always check that the device is connected before constructing this |
| 62 // object. | 62 // object. |
| 63 CHECK(m_service->device()->gatt()->connected()); | 63 CHECK(m_service->device()->gatt()->connected()); |
| 64 m_service->device()->gatt()->AddToActiveAlgorithms(m_resolver.get()); | 64 m_service->device()->gatt()->AddToActiveAlgorithms(m_resolver.get()); |
| 65 } | 65 } |
| 66 | 66 |
| 67 void onSuccess(const WebVector<WebBluetoothRemoteGATTCharacteristicInit*>& | 67 void onSuccess(const WebVector<WebBluetoothRemoteGATTCharacteristicInit*>& |
| 68 webCharacteristics) override { | 68 webCharacteristics) override { |
| 69 if (!m_resolver->getExecutionContext() || | 69 if (!m_resolver->getExecutionContext()) |
| 70 m_resolver->getExecutionContext()->activeDOMObjectsAreStopped()) | |
| 71 return; | 70 return; |
| 72 | 71 |
| 73 // If the resolver is not in the set of ActiveAlgorithms then the frame | 72 // If the resolver is not in the set of ActiveAlgorithms then the frame |
| 74 // disconnected so we reject. | 73 // disconnected so we reject. |
| 75 if (!m_service->device()->gatt()->RemoveFromActiveAlgorithms( | 74 if (!m_service->device()->gatt()->RemoveFromActiveAlgorithms( |
| 76 m_resolver.get())) { | 75 m_resolver.get())) { |
| 77 m_resolver->reject( | 76 m_resolver->reject( |
| 78 DOMException::create(NetworkError, kGATTServerDisconnected)); | 77 DOMException::create(NetworkError, kGATTServerDisconnected)); |
| 79 return; | 78 return; |
| 80 } | 79 } |
| (...skipping 12 matching lines...) Expand all Loading... |
| 93 characteristics.append(BluetoothRemoteGATTCharacteristic::take( | 92 characteristics.append(BluetoothRemoteGATTCharacteristic::take( |
| 94 m_resolver, wrapUnique(webCharacteristic), m_service)); | 93 m_resolver, wrapUnique(webCharacteristic), m_service)); |
| 95 } | 94 } |
| 96 m_resolver->resolve(characteristics); | 95 m_resolver->resolve(characteristics); |
| 97 } | 96 } |
| 98 | 97 |
| 99 void onError( | 98 void onError( |
| 100 int32_t | 99 int32_t |
| 101 error /* Corresponds to WebBluetoothResult in web_bluetooth.mojom */) | 100 error /* Corresponds to WebBluetoothResult in web_bluetooth.mojom */) |
| 102 override { | 101 override { |
| 103 if (!m_resolver->getExecutionContext() || | 102 if (!m_resolver->getExecutionContext()) |
| 104 m_resolver->getExecutionContext()->activeDOMObjectsAreStopped()) | |
| 105 return; | 103 return; |
| 106 | 104 |
| 107 // If the resolver is not in the set of ActiveAlgorithms then the frame | 105 // If the resolver is not in the set of ActiveAlgorithms then the frame |
| 108 // disconnected so we reject. | 106 // disconnected so we reject. |
| 109 if (!m_service->device()->gatt()->RemoveFromActiveAlgorithms( | 107 if (!m_service->device()->gatt()->RemoveFromActiveAlgorithms( |
| 110 m_resolver.get())) { | 108 m_resolver.get())) { |
| 111 m_resolver->reject( | 109 m_resolver->reject( |
| 112 DOMException::create(NetworkError, kGATTServerDisconnected)); | 110 DOMException::create(NetworkError, kGATTServerDisconnected)); |
| 113 return; | 111 return; |
| 114 } | 112 } |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 174 BluetoothSupplement::fromScriptState(scriptState); | 172 BluetoothSupplement::fromScriptState(scriptState); |
| 175 webbluetooth->getCharacteristics( | 173 webbluetooth->getCharacteristics( |
| 176 m_webService->serviceInstanceID, static_cast<int32_t>(quantity), | 174 m_webService->serviceInstanceID, static_cast<int32_t>(quantity), |
| 177 characteristicsUUID, | 175 characteristicsUUID, |
| 178 new GetCharacteristicsCallback(this, quantity, resolver)); | 176 new GetCharacteristicsCallback(this, quantity, resolver)); |
| 179 | 177 |
| 180 return promise; | 178 return promise; |
| 181 } | 179 } |
| 182 | 180 |
| 183 } // namespace blink | 181 } // namespace blink |
| OLD | NEW |