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