| 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 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 66 resolver->reject( | 66 resolver->reject( |
| 67 DOMException::create(NetworkError, kGATTServerDisconnected)); | 67 DOMException::create(NetworkError, kGATTServerDisconnected)); |
| 68 return; | 68 return; |
| 69 } | 69 } |
| 70 | 70 |
| 71 if (result == mojom::blink::WebBluetoothResult::SUCCESS) { | 71 if (result == mojom::blink::WebBluetoothResult::SUCCESS) { |
| 72 DCHECK(characteristics); | 72 DCHECK(characteristics); |
| 73 | 73 |
| 74 if (quantity == mojom::blink::WebBluetoothGATTQueryQuantity::SINGLE) { | 74 if (quantity == mojom::blink::WebBluetoothGATTQueryQuantity::SINGLE) { |
| 75 DCHECK_EQ(1u, characteristics->size()); | 75 DCHECK_EQ(1u, characteristics->size()); |
| 76 resolver->resolve(device()->getOrCreateBluetoothRemoteGATTCharacteristic( | 76 resolver->resolve(device()->getOrCreateRemoteGATTCharacteristic( |
| 77 resolver->getExecutionContext(), | 77 resolver->getExecutionContext(), |
| 78 characteristics.value()[0]->instance_id, serviceInstanceId, | 78 characteristics.value()[0]->instance_id, serviceInstanceId, |
| 79 characteristics.value()[0]->uuid, | 79 characteristics.value()[0]->uuid, |
| 80 characteristics.value()[0]->properties, this)); | 80 characteristics.value()[0]->properties, this)); |
| 81 return; | 81 return; |
| 82 } | 82 } |
| 83 | 83 |
| 84 HeapVector<Member<BluetoothRemoteGATTCharacteristic>> gattCharacteristics; | 84 HeapVector<Member<BluetoothRemoteGATTCharacteristic>> gattCharacteristics; |
| 85 gattCharacteristics.reserveInitialCapacity(characteristics->size()); | 85 gattCharacteristics.reserveInitialCapacity(characteristics->size()); |
| 86 for (const auto& characteristic : characteristics.value()) { | 86 for (const auto& characteristic : characteristics.value()) { |
| 87 gattCharacteristics.append( | 87 gattCharacteristics.append(device()->getOrCreateRemoteGATTCharacteristic( |
| 88 device()->getOrCreateBluetoothRemoteGATTCharacteristic( | 88 resolver->getExecutionContext(), characteristic->instance_id, |
| 89 resolver->getExecutionContext(), characteristic->instance_id, | 89 serviceInstanceId, characteristic->uuid, characteristic->properties, |
| 90 serviceInstanceId, characteristic->uuid, | 90 this)); |
| 91 characteristic->properties, this)); | |
| 92 } | 91 } |
| 93 resolver->resolve(gattCharacteristics); | 92 resolver->resolve(gattCharacteristics); |
| 94 } else { | 93 } else { |
| 95 resolver->reject(BluetoothError::take(resolver, result)); | 94 resolver->reject(BluetoothError::take(resolver, result)); |
| 96 } | 95 } |
| 97 } | 96 } |
| 98 | 97 |
| 99 ScriptPromise BluetoothRemoteGATTService::getCharacteristic( | 98 ScriptPromise BluetoothRemoteGATTService::getCharacteristic( |
| 100 ScriptState* scriptState, | 99 ScriptState* scriptState, |
| 101 const StringOrUnsignedLong& characteristic, | 100 const StringOrUnsignedLong& characteristic, |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 160 m_serviceInstanceId, quantity, uuid, | 159 m_serviceInstanceId, quantity, uuid, |
| 161 convertToBaseCallback( | 160 convertToBaseCallback( |
| 162 WTF::bind(&BluetoothRemoteGATTService::GetCharacteristicsCallback, | 161 WTF::bind(&BluetoothRemoteGATTService::GetCharacteristicsCallback, |
| 163 wrapPersistent(this), m_serviceInstanceId, quantity, | 162 wrapPersistent(this), m_serviceInstanceId, quantity, |
| 164 wrapPersistent(resolver)))); | 163 wrapPersistent(resolver)))); |
| 165 | 164 |
| 166 return promise; | 165 return promise; |
| 167 } | 166 } |
| 168 | 167 |
| 169 } // namespace blink | 168 } // namespace blink |
| OLD | NEW |