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

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

Issue 1334763002: bluetooth: Subscribe to notifications (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@bluetooth-origin
Patch Set: Fix global interface test Created 5 years, 2 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 0e1f50a187aafb8e1519f77d97d9f17a4d637d88..fa4b8b6581ab760ffa7131cab4118991f958868c 100644
--- a/third_party/WebKit/Source/modules/bluetooth/BluetoothGATTCharacteristic.cpp
+++ b/third_party/WebKit/Source/modules/bluetooth/BluetoothGATTCharacteristic.cpp
@@ -17,17 +17,43 @@
namespace blink {
-BluetoothGATTCharacteristic::BluetoothGATTCharacteristic(PassOwnPtr<WebBluetoothGATTCharacteristicInit> webCharacteristic)
- : m_webCharacteristic(webCharacteristic)
+BluetoothGATTCharacteristic::BluetoothGATTCharacteristic(ExecutionContext* context, PassOwnPtr<WebBluetoothGATTCharacteristicInit> webCharacteristic)
+ : ActiveDOMObject(context)
+ , m_webCharacteristic(webCharacteristic)
+ , m_stopped(false)
{
+ // See example in Source/platform/heap/ThreadState.h
+ ThreadState::current()->registerPreFinalizer(this);
}
-BluetoothGATTCharacteristic* BluetoothGATTCharacteristic::take(ScriptPromiseResolver*, PassOwnPtr<WebBluetoothGATTCharacteristicInit> webCharacteristic)
+BluetoothGATTCharacteristic* BluetoothGATTCharacteristic::take(ScriptPromiseResolver* resolver, PassOwnPtr<WebBluetoothGATTCharacteristicInit> webCharacteristic)
{
if (!webCharacteristic) {
return nullptr;
}
- return new BluetoothGATTCharacteristic(webCharacteristic);
+ BluetoothGATTCharacteristic* characteristic = new BluetoothGATTCharacteristic(resolver->executionContext(), webCharacteristic);
+ // See note in ActiveDOMObject about suspendIfNeeded.
+ characteristic->suspendIfNeeded();
+ return characteristic;
+}
+
+void BluetoothGATTCharacteristic::stop()
+{
+ notifyCharacteristicObjectRemoved();
+}
+
+void BluetoothGATTCharacteristic::dispose()
+{
+ notifyCharacteristicObjectRemoved();
+}
+
+void BluetoothGATTCharacteristic::notifyCharacteristicObjectRemoved()
+{
+ if (!m_stopped) {
+ m_stopped = true;
+ WebBluetooth* webbluetooth = BluetoothSupplement::fromExecutionContext(ActiveDOMObject::executionContext());
+ webbluetooth->characteristicObjectRemoved(m_webCharacteristic->characteristicInstanceID, this);
+ }
}
ScriptPromise BluetoothGATTCharacteristic::readValue(ScriptState* scriptState)
@@ -63,4 +89,27 @@ ScriptPromise BluetoothGATTCharacteristic::writeValue(ScriptState* scriptState,
return promise;
}
+ScriptPromise BluetoothGATTCharacteristic::startNotifications(ScriptState* scriptState)
+{
+ WebBluetooth* webbluetooth = BluetoothSupplement::fromScriptState(scriptState);
+ ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState);
+ ScriptPromise promise = resolver->promise();
+ webbluetooth->startNotifications(m_webCharacteristic->characteristicInstanceID, this, new CallbackPromiseAdapter<void, BluetoothError>(resolver));
+ return promise;
+}
+
+ScriptPromise BluetoothGATTCharacteristic::stopNotifications(ScriptState* scriptState)
+{
+ WebBluetooth* webbluetooth = BluetoothSupplement::fromScriptState(scriptState);
+ ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState);
+ ScriptPromise promise = resolver->promise();
+ webbluetooth->stopNotifications(m_webCharacteristic->characteristicInstanceID, this, new CallbackPromiseAdapter<void, BluetoothError>(resolver));
+ return promise;
+}
+
+DEFINE_TRACE(BluetoothGATTCharacteristic)
+{
+ ActiveDOMObject::trace(visitor);
+}
+
} // namespace blink

Powered by Google App Engine
This is Rietveld 408576698