Chromium Code Reviews| 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..95f73b3671837c8e98af1ad83271c46ba12e4037 100644 |
| --- a/third_party/WebKit/Source/modules/bluetooth/BluetoothGATTCharacteristic.cpp |
| +++ b/third_party/WebKit/Source/modules/bluetooth/BluetoothGATTCharacteristic.cpp |
| @@ -145,6 +145,34 @@ 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) { |
| + RefPtr<DOMDataView> domDataView = ConvertWebVectorToDataView(value); |
| + m_webCharacteristic->setValue(domDataView); |
|
ortuno
2016/01/21 16:41:32
nit: You can just pass the result of ConvertWebVec
|
| + } |
| + 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 +191,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; |
| } |