Chromium Code Reviews| 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..f03da6bb72ebf2914cb120e89ebb715d576df450 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: |
| + WeakPersistent<BluetoothRemoteGATTCharacteristic> m_webCharacteristic; |
|
ortuno
2016/08/05 01:43:44
This needs to be Persistent. Otherwise you might r
haraken
2016/08/05 04:27:58
Are you sure that the persistents don't create a c
ortuno
2016/08/05 14:35:38
Yes, it's guaranteed. If we don't ever call onSucc
|
| + 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; |
| } |