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

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

Issue 2718583002: Refactor WebBluetoothServiceClient in the web_bluetooth.mojom (Closed)
Patch Set: address more 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..dad5f859013f00a4c3ff1625d6ff324d374bb648 100644
--- a/third_party/WebKit/Source/modules/bluetooth/BluetoothRemoteGATTCharacteristic.cpp
+++ b/third_party/WebKit/Source/modules/bluetooth/BluetoothRemoteGATTCharacteristic.cpp
@@ -31,8 +31,8 @@ BluetoothRemoteGATTCharacteristic::BluetoothRemoteGATTCharacteristic(
: ContextLifecycleObserver(context),
m_characteristic(std::move(characteristic)),
m_service(service),
- m_stopped(false),
- m_device(device) {
+ m_device(device),
+ m_clientBinding(this) {
m_properties =
BluetoothCharacteristicProperties::create(m_characteristic->properties);
}
@@ -50,8 +50,8 @@ void BluetoothRemoteGATTCharacteristic::setValue(DOMDataView* domDataView) {
m_value = domDataView;
}
-void BluetoothRemoteGATTCharacteristic::dispatchCharacteristicValueChanged(
- const Vector<uint8_t>& value) {
+void BluetoothRemoteGATTCharacteristic::RemoteCharacteristicValueChanged(
+ const WTF::Vector<uint8_t>& value) {
if (!getGatt()->connected())
return;
this->setValue(BluetoothRemoteGATTUtils::ConvertWTFVectorToDataView(value));
@@ -59,19 +59,12 @@ void BluetoothRemoteGATTCharacteristic::dispatchCharacteristicValueChanged(
}
void BluetoothRemoteGATTCharacteristic::contextDestroyed(ExecutionContext*) {
- notifyCharacteristicObjectRemoved();
+ dispose();
}
void BluetoothRemoteGATTCharacteristic::dispose() {
- notifyCharacteristicObjectRemoved();
-}
-
-void BluetoothRemoteGATTCharacteristic::notifyCharacteristicObjectRemoved() {
- 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 +81,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) {
- m_device->bluetooth()->registerCharacteristicObject(
- m_characteristic->instance_id, this);
- }
}
void BluetoothRemoteGATTCharacteristic::ReadValueCallback(
@@ -116,6 +103,7 @@ void BluetoothRemoteGATTCharacteristic::ReadValueCallback(
DOMDataView* domDataView =
BluetoothRemoteGATTUtils::ConvertWTFVectorToDataView(value.value());
setValue(domDataView);
+ dispatchEvent(Event::create(EventTypeNames::characteristicvaluechanged));
resolver->resolve(domDataView);
} else {
resolver->reject(BluetoothError::createDOMException(result));
@@ -221,7 +209,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 +222,8 @@ void BluetoothRemoteGATTCharacteristic::NotificationsCallback(
return;
}
+ m_clientBinding.Bind(std::move(request));
ortuno 2017/03/06 11:31:20 Wouldn't we bind an invalid request for: startNot
juncai 2017/03/09 07:30:57 Done.
+
if (result == mojom::blink::WebBluetoothResult::SUCCESS) {
resolver->resolve(this);
} else {
@@ -294,7 +285,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