Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(140)

Unified Diff: third_party/WebKit/Source/modules/bluetooth/BluetoothRemoteGATTService.cpp

Issue 1723723002: bluetooth: Implement Service.getCharacteristics (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@my-origin
Patch Set: Clean up Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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

Powered by Google App Engine
This is Rietveld 408576698