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

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

Issue 2718583002: Refactor WebBluetoothServiceClient in the web_bluetooth.mojom (Closed)
Patch Set: address comments Created 3 years, 10 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 0088df16c6780168063af4f5f0230a209b6ed3f5..a9fe0119f43a6056d7e4af859dc3bc2c1e027502 100644
--- a/third_party/WebKit/Source/modules/bluetooth/BluetoothRemoteGATTCharacteristic.cpp
+++ b/third_party/WebKit/Source/modules/bluetooth/BluetoothRemoteGATTCharacteristic.cpp
@@ -31,7 +31,7 @@ BluetoothRemoteGATTCharacteristic::BluetoothRemoteGATTCharacteristic(
: ContextLifecycleObserver(context),
m_characteristic(std::move(characteristic)),
m_service(service),
- m_stopped(false),
+ m_clientBinding(this),
m_device(device) {
m_properties =
BluetoothCharacteristicProperties::create(m_characteristic->properties);
@@ -50,28 +50,25 @@ void BluetoothRemoteGATTCharacteristic::setValue(DOMDataView* domDataView) {
m_value = domDataView;
}
-void BluetoothRemoteGATTCharacteristic::dispatchCharacteristicValueChanged(
- const Vector<uint8_t>& value) {
+void BluetoothRemoteGATTCharacteristic::contextDestroyed(ExecutionContext*) {
+ notifyCharacteristicObjectRemoved();
+}
+
+void BluetoothRemoteGATTCharacteristic::RemoteCharacteristicValueChanged(
+ const WTF::Vector<uint8_t>& value) {
if (!getGatt()->connected())
return;
this->setValue(BluetoothRemoteGATTUtils::ConvertWTFVectorToDataView(value));
dispatchEvent(Event::create(EventTypeNames::characteristicvaluechanged));
}
-void BluetoothRemoteGATTCharacteristic::contextDestroyed(ExecutionContext*) {
- notifyCharacteristicObjectRemoved();
-}
-
void BluetoothRemoteGATTCharacteristic::dispose() {
notifyCharacteristicObjectRemoved();
}
void BluetoothRemoteGATTCharacteristic::notifyCharacteristicObjectRemoved() {
ortuno 2017/03/01 04:52:06 Can you change the name of this function? It doesn
juncai 2017/03/02 03:23:49 Done.
- if (!m_stopped) {
- m_stopped = true;
- m_device->bluetooth()->characteristicObjectRemoved(
- m_characteristic->instance_id);
- }
+ if (m_clientBinding.is_bound())
+ m_clientBinding.Close();
}
const WTF::AtomicString& BluetoothRemoteGATTCharacteristic::interfaceName()
@@ -88,12 +85,6 @@ void BluetoothRemoteGATTCharacteristic::addedEventListener(
const AtomicString& eventType,
RegisteredEventListener& registeredListener) {
EventTargetWithInlineData::addedEventListener(eventType, registeredListener);
- // We will also need to unregister a characteristic once all the event
- // listeners have been removed. See http://crbug.com/541390
- if (eventType == EventTypeNames::characteristicvaluechanged) {
ortuno 2017/03/01 04:52:06 Forgot about this. We should keep an eye out for h
juncai 2017/03/02 03:23:49 Thanks!
- m_device->bluetooth()->registerCharacteristicObject(
- m_characteristic->instance_id, this);
- }
}
void BluetoothRemoteGATTCharacteristic::ReadValueCallback(
@@ -116,6 +107,7 @@ void BluetoothRemoteGATTCharacteristic::ReadValueCallback(
DOMDataView* domDataView =
BluetoothRemoteGATTUtils::ConvertWTFVectorToDataView(value.value());
setValue(domDataView);
+ dispatchEvent(Event::create(EventTypeNames::characteristicvaluechanged));
ortuno 2017/03/01 04:52:06 This test https://cs.chromium.org/chromium/src/thi
juncai 2017/03/02 03:23:48 I opened an issue for it: https://bugs.chromium.or
resolver->resolve(domDataView);
} else {
resolver->reject(BluetoothError::createDOMException(result));
@@ -221,7 +213,8 @@ ScriptPromise BluetoothRemoteGATTCharacteristic::writeValue(
void BluetoothRemoteGATTCharacteristic::NotificationsCallback(
ScriptPromiseResolver* resolver,
- mojom::blink::WebBluetoothResult result) {
+ mojom::blink::WebBluetoothResult result,
+ mojom::blink::WebBluetoothCharacteristicClientAssociatedRequest request) {
if (!resolver->getExecutionContext() ||
resolver->getExecutionContext()->isContextDestroyed())
return;
@@ -233,6 +226,8 @@ void BluetoothRemoteGATTCharacteristic::NotificationsCallback(
return;
}
+ m_clientBinding.Bind(std::move(request));
+
if (result == mojom::blink::WebBluetoothResult::SUCCESS) {
resolver->resolve(this);
} else {
@@ -294,7 +289,7 @@ ScriptPromise BluetoothRemoteGATTCharacteristic::stopNotifications(
convertToBaseCallback(
WTF::bind(&BluetoothRemoteGATTCharacteristic::NotificationsCallback,
wrapPersistent(this), wrapPersistent(resolver),
- mojom::blink::WebBluetoothResult::SUCCESS)));
+ mojom::blink::WebBluetoothResult::SUCCESS, nullptr)));
return promise;
}

Powered by Google App Engine
This is Rietveld 408576698