Chromium Code Reviews| Index: third_party/WebKit/Source/modules/bluetooth/BluetoothRemoteGATTService.cpp |
| diff --git a/third_party/WebKit/Source/modules/bluetooth/BluetoothRemoteGATTService.cpp b/third_party/WebKit/Source/modules/bluetooth/BluetoothRemoteGATTService.cpp |
| index 9c71c576a5e39790a107066048aee00d708fb3a8..9ac9eb4e59ee6e575b9e3742c5a03b2cc5e859c1 100644 |
| --- a/third_party/WebKit/Source/modules/bluetooth/BluetoothRemoteGATTService.cpp |
| +++ b/third_party/WebKit/Source/modules/bluetooth/BluetoothRemoteGATTService.cpp |
| @@ -46,4 +46,45 @@ ScriptPromise BluetoothRemoteGATTService::getCharacteristic(ScriptState* scriptS |
| return promise; |
| } |
| +ScriptPromise BluetoothRemoteGATTService::getCharacteristics(ScriptState* scriptState, ExceptionState&) |
| +{ |
| + return getCharacteristicsImpl(scriptState, String()); |
| +} |
| + |
| +ScriptPromise BluetoothRemoteGATTService::getCharacteristics(ScriptState* scriptState, const StringOrUnsignedLong& characteristic, ExceptionState& exceptionState) |
| +{ |
| + String characteristicUUID = BluetoothUUID::getCharacteristic(characteristic, exceptionState); |
| + if (exceptionState.hadException()) |
| + return exceptionState.reject(scriptState); |
| + |
| + return getCharacteristicsImpl(scriptState, characteristicUUID); |
| +} |
| + |
| +// Class that allows us to use CallbackPromiseAdapter to resolve a promise with a |
| +// vector owning BluetoothRemoteGATTCharacteristics. |
| +class RemoteCharacteristicArray { |
| + STATIC_ONLY(RemoteCharacteristicArray); |
| +public: |
| + using WebType = OwnPtr<WebVector<WebBluetoothRemoteGATTCharacteristicInit*>>; |
| + static HeapVector<Member<BluetoothRemoteGATTCharacteristic>> take(ScriptPromiseResolver* resolver, PassOwnPtr<WebVector<WebBluetoothRemoteGATTCharacteristicInit*>> webCharacteristics) |
| + { |
| + HeapVector<Member<BluetoothRemoteGATTCharacteristic>> characteristics; |
|
Jeffrey Yasskin
2016/02/24 23:20:30
Use characteristics.reserveInitialCapacity(webChar
ortuno
2016/02/25 23:08:27
Done.
|
| + for (WebBluetoothRemoteGATTCharacteristicInit* webCharacteristic : *webCharacteristics) { |
| + characteristics.append(BluetoothRemoteGATTCharacteristic::take(resolver, adoptPtr(webCharacteristic))); |
| + } |
| + return characteristics; |
| + } |
| +}; |
| + |
| +ScriptPromise BluetoothRemoteGATTService::getCharacteristicsImpl(ScriptState* scriptState, String characteristicUUID) |
| +{ |
| + ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState); |
| + ScriptPromise promise = resolver->promise(); |
| + |
| + WebBluetooth* webbluetooth = BluetoothSupplement::fromScriptState(scriptState); |
| + webbluetooth->getCharacteristics(m_webService->serviceInstanceID, characteristicUUID, new CallbackPromiseAdapter<RemoteCharacteristicArray, BluetoothError>(resolver)); |
| + |
| + return promise; |
| +} |
| + |
| } // namespace blink |