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

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

Issue 2216623002: bluetooth: {start,stop}Notifications() return the characteristic (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Change WeakPersistent to Persistent Created 4 years, 4 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/BluetoothRemoteGATTCharacteristic.cpp
diff --git a/third_party/WebKit/Source/modules/bluetooth/BluetoothRemoteGATTCharacteristic.cpp b/third_party/WebKit/Source/modules/bluetooth/BluetoothRemoteGATTCharacteristic.cpp
index b0ec4cd4b83d32eaf271d801427356099afb4460..75bbed0d9ec7df466b586c82cddce8e473decafd 100644
--- a/third_party/WebKit/Source/modules/bluetooth/BluetoothRemoteGATTCharacteristic.cpp
+++ b/third_party/WebKit/Source/modules/bluetooth/BluetoothRemoteGATTCharacteristic.cpp
@@ -195,12 +195,36 @@ ScriptPromise BluetoothRemoteGATTCharacteristic::writeValue(ScriptState* scriptS
return promise;
}
+class NotificationsCallback : public WebBluetoothNotificationsCallbacks {
+public:
+ NotificationsCallback(BluetoothRemoteGATTCharacteristic* characteristic, ScriptPromiseResolver* resolver) : m_webCharacteristic(characteristic), m_resolver(resolver) {}
+
+ void onSuccess() override
+ {
+ if (!m_resolver->getExecutionContext() || m_resolver->getExecutionContext()->activeDOMObjectsAreStopped())
+ return;
+
+ m_resolver->resolve(m_webCharacteristic);
+ }
+
+ void onError(int32_t error /* Corresponds to WebBluetoothError in web_bluetooth.mojom */) override
+ {
+ if (!m_resolver->getExecutionContext() || m_resolver->getExecutionContext()->activeDOMObjectsAreStopped())
+ return;
+ m_resolver->reject(BluetoothError::take(m_resolver, error));
+ }
+
+private:
+ Persistent<BluetoothRemoteGATTCharacteristic> m_webCharacteristic;
+ Persistent<ScriptPromiseResolver> m_resolver;
+};
+
ScriptPromise BluetoothRemoteGATTCharacteristic::startNotifications(ScriptState* scriptState)
{
WebBluetooth* webbluetooth = BluetoothSupplement::fromScriptState(scriptState);
ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState);
ScriptPromise promise = resolver->promise();
- webbluetooth->startNotifications(m_webCharacteristic->characteristicInstanceID, new CallbackPromiseAdapter<void, BluetoothError>(resolver));
+ webbluetooth->startNotifications(m_webCharacteristic->characteristicInstanceID, new NotificationsCallback(this, resolver));
return promise;
}
@@ -217,7 +241,7 @@ ScriptPromise BluetoothRemoteGATTCharacteristic::stopNotifications(ScriptState*
WebBluetooth* webbluetooth = BluetoothSupplement::fromScriptState(scriptState);
ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState);
ScriptPromise promise = resolver->promise();
- webbluetooth->stopNotifications(m_webCharacteristic->characteristicInstanceID, new CallbackPromiseAdapter<void, BluetoothError>(resolver));
+ webbluetooth->stopNotifications(m_webCharacteristic->characteristicInstanceID, new NotificationsCallback(this, resolver));
return promise;
}

Powered by Google App Engine
This is Rietveld 408576698