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

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

Issue 1611443002: bluetooth: Update BluetoothGATTCharacteristic.value on writeValue (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@useDataview
Patch Set: Created 4 years, 11 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/BluetoothGATTCharacteristic.cpp
diff --git a/third_party/WebKit/Source/modules/bluetooth/BluetoothGATTCharacteristic.cpp b/third_party/WebKit/Source/modules/bluetooth/BluetoothGATTCharacteristic.cpp
index 837734b60d2118145379c2573d4d6e7699e2f618..27bcfc1ceb80711e4ae14f621127dcb8c86c2e23 100644
--- a/third_party/WebKit/Source/modules/bluetooth/BluetoothGATTCharacteristic.cpp
+++ b/third_party/WebKit/Source/modules/bluetooth/BluetoothGATTCharacteristic.cpp
@@ -145,6 +145,33 @@ ScriptPromise BluetoothGATTCharacteristic::readValue(ScriptState* scriptState)
return promise;
}
+class WriteValueCallback : public WebBluetoothWriteValueCallbacks {
+public:
+ WriteValueCallback(BluetoothGATTCharacteristic* characteristic, ScriptPromiseResolver* resolver) : m_webCharacteristic(characteristic), m_resolver(resolver) {}
+
+ void onSuccess(const WebVector<uint8_t>& value) override
+ {
+ if (!m_resolver->executionContext() || m_resolver->executionContext()->activeDOMObjectsAreStopped())
+ return;
+
+ if (m_webCharacteristic) {
+ m_webCharacteristic->setValue(ConvertWebVectorToDataView(value));
+ }
+ m_resolver->resolve();
+ }
+
+ void onError(const WebBluetoothError& e) override
+ {
+ if (!m_resolver->executionContext() || m_resolver->executionContext()->activeDOMObjectsAreStopped())
+ return;
+ m_resolver->reject(BluetoothError::take(m_resolver, e));
+ }
+
+private:
+ WeakPersistent<BluetoothGATTCharacteristic> m_webCharacteristic;
+ Persistent<ScriptPromiseResolver> m_resolver;
+};
+
ScriptPromise BluetoothGATTCharacteristic::writeValue(ScriptState* scriptState, const DOMArrayPiece& value)
{
WebBluetooth* webbluetooth = BluetoothSupplement::fromScriptState(scriptState);
@@ -163,7 +190,7 @@ ScriptPromise BluetoothGATTCharacteristic::writeValue(ScriptState* scriptState,
ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState);
ScriptPromise promise = resolver->promise();
- webbluetooth->writeValue(m_webCharacteristic->characteristicInstanceID, valueVector, new CallbackPromiseAdapter<void, BluetoothError>(resolver));
+ webbluetooth->writeValue(m_webCharacteristic->characteristicInstanceID, valueVector, new WriteValueCallback(this, resolver));
return promise;
}

Powered by Google App Engine
This is Rietveld 408576698