| 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/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 "core/dom/ExceptionCode.h" | 10 #include "core/dom/ExceptionCode.h" | 
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 50     const String& serviceInstanceId, | 50     const String& serviceInstanceId, | 
| 51     mojom::blink::WebBluetoothGATTQueryQuantity quantity, | 51     mojom::blink::WebBluetoothGATTQueryQuantity quantity, | 
| 52     ScriptPromiseResolver* resolver, | 52     ScriptPromiseResolver* resolver, | 
| 53     mojom::blink::WebBluetoothResult result, | 53     mojom::blink::WebBluetoothResult result, | 
| 54     Optional<Vector<mojom::blink::WebBluetoothRemoteGATTCharacteristicPtr>> | 54     Optional<Vector<mojom::blink::WebBluetoothRemoteGATTCharacteristicPtr>> | 
| 55         characteristics) { | 55         characteristics) { | 
| 56   if (!resolver->getExecutionContext() || | 56   if (!resolver->getExecutionContext() || | 
| 57       resolver->getExecutionContext()->isContextDestroyed()) | 57       resolver->getExecutionContext()->isContextDestroyed()) | 
| 58     return; | 58     return; | 
| 59 | 59 | 
| 60   // If the resolver is not in the set of ActiveAlgorithms then the frame | 60   // If the device is disconnected, reject. | 
| 61   // disconnected so we reject. |  | 
| 62   if (!device()->gatt()->RemoveFromActiveAlgorithms(resolver)) { | 61   if (!device()->gatt()->RemoveFromActiveAlgorithms(resolver)) { | 
| 63     resolver->reject( | 62     resolver->reject( | 
| 64         DOMException::create(NetworkError, kGATTServerDisconnected)); | 63         DOMException::create(NetworkError, kGATTServerDisconnected)); | 
| 65     return; | 64     return; | 
| 66   } | 65   } | 
| 67 | 66 | 
| 68   if (result == mojom::blink::WebBluetoothResult::SUCCESS) { | 67   if (result == mojom::blink::WebBluetoothResult::SUCCESS) { | 
| 69     DCHECK(characteristics); | 68     DCHECK(characteristics); | 
| 70 | 69 | 
| 71     if (quantity == mojom::blink::WebBluetoothGATTQueryQuantity::SINGLE) { | 70     if (quantity == mojom::blink::WebBluetoothGATTQueryQuantity::SINGLE) { | 
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 122     ScriptState* scriptState, | 121     ScriptState* scriptState, | 
| 123     ExceptionState&) { | 122     ExceptionState&) { | 
| 124   return getCharacteristicsImpl( | 123   return getCharacteristicsImpl( | 
| 125       scriptState, mojom::blink::WebBluetoothGATTQueryQuantity::MULTIPLE); | 124       scriptState, mojom::blink::WebBluetoothGATTQueryQuantity::MULTIPLE); | 
| 126 } | 125 } | 
| 127 | 126 | 
| 128 ScriptPromise BluetoothRemoteGATTService::getCharacteristicsImpl( | 127 ScriptPromise BluetoothRemoteGATTService::getCharacteristicsImpl( | 
| 129     ScriptState* scriptState, | 128     ScriptState* scriptState, | 
| 130     mojom::blink::WebBluetoothGATTQueryQuantity quantity, | 129     mojom::blink::WebBluetoothGATTQueryQuantity quantity, | 
| 131     const String& characteristicsUUID) { | 130     const String& characteristicsUUID) { | 
| 132   // We always check that the device is connected. |  | 
| 133   if (!device()->gatt()->connected()) { | 131   if (!device()->gatt()->connected()) { | 
| 134     return ScriptPromise::rejectWithDOMException( | 132     return ScriptPromise::rejectWithDOMException( | 
| 135         scriptState, | 133         scriptState, | 
| 136         DOMException::create(NetworkError, kGATTServerNotConnected)); | 134         DOMException::create(NetworkError, kGATTServerNotConnected)); | 
| 137   } | 135   } | 
| 138 | 136 | 
| 139   if (!device()->isValidService(m_service->instance_id)) { | 137   if (!device()->isValidService(m_service->instance_id)) { | 
| 140     return ScriptPromise::rejectWithDOMException( | 138     return ScriptPromise::rejectWithDOMException( | 
| 141         scriptState, DOMException::create(InvalidStateError, kInvalidService)); | 139         scriptState, DOMException::create(InvalidStateError, kInvalidService)); | 
| 142   } | 140   } | 
| (...skipping 11 matching lines...) Expand all  Loading... | 
| 154       m_service->instance_id, quantity, uuid, | 152       m_service->instance_id, quantity, uuid, | 
| 155       convertToBaseCallback( | 153       convertToBaseCallback( | 
| 156           WTF::bind(&BluetoothRemoteGATTService::GetCharacteristicsCallback, | 154           WTF::bind(&BluetoothRemoteGATTService::GetCharacteristicsCallback, | 
| 157                     wrapPersistent(this), m_service->instance_id, quantity, | 155                     wrapPersistent(this), m_service->instance_id, quantity, | 
| 158                     wrapPersistent(resolver)))); | 156                     wrapPersistent(resolver)))); | 
| 159 | 157 | 
| 160   return promise; | 158   return promise; | 
| 161 } | 159 } | 
| 162 | 160 | 
| 163 }  // namespace blink | 161 }  // namespace blink | 
| OLD | NEW | 
|---|