| 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 30 matching lines...) Expand all Loading... |
| 41 ScriptPromiseResolver* resolver, | 41 ScriptPromiseResolver* resolver, |
| 42 mojom::blink::WebBluetoothResult result, | 42 mojom::blink::WebBluetoothResult result, |
| 43 Optional<Vector<mojom::blink::WebBluetoothRemoteGATTCharacteristicPtr>> | 43 Optional<Vector<mojom::blink::WebBluetoothRemoteGATTCharacteristicPtr>> |
| 44 characteristics) { | 44 characteristics) { |
| 45 if (!resolver->getExecutionContext() || | 45 if (!resolver->getExecutionContext() || |
| 46 resolver->getExecutionContext()->isContextDestroyed()) | 46 resolver->getExecutionContext()->isContextDestroyed()) |
| 47 return; | 47 return; |
| 48 | 48 |
| 49 // If the device is disconnected, reject. | 49 // If the device is disconnected, reject. |
| 50 if (!m_device->gatt()->RemoveFromActiveAlgorithms(resolver)) { | 50 if (!m_device->gatt()->RemoveFromActiveAlgorithms(resolver)) { |
| 51 resolver->reject(BluetoothError::createDOMException( | 51 resolver->reject(BluetoothError::createNotConnectedException( |
| 52 mojom::blink::WebBluetoothResult:: | 52 BluetoothOperation::CharacteristicsRetrieval)); |
| 53 GATT_SERVER_DISCONNECTED_WHILE_RETRIEVING_CHARACTERISTICS)); | |
| 54 return; | 53 return; |
| 55 } | 54 } |
| 56 | 55 |
| 57 if (result == mojom::blink::WebBluetoothResult::SUCCESS) { | 56 if (result == mojom::blink::WebBluetoothResult::SUCCESS) { |
| 58 DCHECK(characteristics); | 57 DCHECK(characteristics); |
| 59 | 58 |
| 60 if (quantity == mojom::blink::WebBluetoothGATTQueryQuantity::SINGLE) { | 59 if (quantity == mojom::blink::WebBluetoothGATTQueryQuantity::SINGLE) { |
| 61 DCHECK_EQ(1u, characteristics->size()); | 60 DCHECK_EQ(1u, characteristics->size()); |
| 62 resolver->resolve(m_device->getOrCreateRemoteGATTCharacteristic( | 61 resolver->resolve(m_device->getOrCreateRemoteGATTCharacteristic( |
| 63 resolver->getExecutionContext(), | 62 resolver->getExecutionContext(), |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 120 return getCharacteristicsImpl( | 119 return getCharacteristicsImpl( |
| 121 scriptState, mojom::blink::WebBluetoothGATTQueryQuantity::MULTIPLE); | 120 scriptState, mojom::blink::WebBluetoothGATTQueryQuantity::MULTIPLE); |
| 122 } | 121 } |
| 123 | 122 |
| 124 ScriptPromise BluetoothRemoteGATTService::getCharacteristicsImpl( | 123 ScriptPromise BluetoothRemoteGATTService::getCharacteristicsImpl( |
| 125 ScriptState* scriptState, | 124 ScriptState* scriptState, |
| 126 mojom::blink::WebBluetoothGATTQueryQuantity quantity, | 125 mojom::blink::WebBluetoothGATTQueryQuantity quantity, |
| 127 const String& characteristicsUUID) { | 126 const String& characteristicsUUID) { |
| 128 if (!m_device->gatt()->connected()) { | 127 if (!m_device->gatt()->connected()) { |
| 129 return ScriptPromise::rejectWithDOMException( | 128 return ScriptPromise::rejectWithDOMException( |
| 130 scriptState, | 129 scriptState, BluetoothError::createNotConnectedException( |
| 131 BluetoothError::createDOMException( | 130 BluetoothOperation::CharacteristicsRetrieval)); |
| 132 mojom::blink::WebBluetoothResult:: | |
| 133 GATT_SERVER_NOT_CONNECTED_CANNOT_RETRIEVE_CHARACTERISTICS)); | |
| 134 } | 131 } |
| 135 | 132 |
| 136 if (!m_device->isValidService(m_service->instance_id)) { | 133 if (!m_device->isValidService(m_service->instance_id)) { |
| 137 return ScriptPromise::rejectWithDOMException( | 134 return ScriptPromise::rejectWithDOMException( |
| 138 scriptState, BluetoothError::createDOMException( | 135 scriptState, BluetoothError::createDOMException( |
| 139 BluetoothErrorCode::InvalidService, | 136 BluetoothErrorCode::InvalidService, |
| 140 "Service with UUID " + m_service->uuid + | 137 "Service with UUID " + m_service->uuid + |
| 141 " is no longer valid. Remember to retrieve " | 138 " is no longer valid. Remember to retrieve " |
| 142 "the service again after reconnecting.")); | 139 "the service again after reconnecting.")); |
| 143 } | 140 } |
| 144 | 141 |
| 145 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState); | 142 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState); |
| 146 ScriptPromise promise = resolver->promise(); | 143 ScriptPromise promise = resolver->promise(); |
| 147 m_device->gatt()->AddToActiveAlgorithms(resolver); | 144 m_device->gatt()->AddToActiveAlgorithms(resolver); |
| 148 | 145 |
| 149 mojom::blink::WebBluetoothService* service = m_device->bluetooth()->service(); | 146 mojom::blink::WebBluetoothService* service = m_device->bluetooth()->service(); |
| 150 service->RemoteServiceGetCharacteristics( | 147 service->RemoteServiceGetCharacteristics( |
| 151 m_service->instance_id, quantity, characteristicsUUID, | 148 m_service->instance_id, quantity, characteristicsUUID, |
| 152 convertToBaseCallback( | 149 convertToBaseCallback( |
| 153 WTF::bind(&BluetoothRemoteGATTService::GetCharacteristicsCallback, | 150 WTF::bind(&BluetoothRemoteGATTService::GetCharacteristicsCallback, |
| 154 wrapPersistent(this), m_service->instance_id, | 151 wrapPersistent(this), m_service->instance_id, |
| 155 characteristicsUUID, quantity, wrapPersistent(resolver)))); | 152 characteristicsUUID, quantity, wrapPersistent(resolver)))); |
| 156 | 153 |
| 157 return promise; | 154 return promise; |
| 158 } | 155 } |
| 159 | 156 |
| 160 } // namespace blink | 157 } // namespace blink |
| OLD | NEW |