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

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

Issue 2718583002: Refactor WebBluetoothServiceClient in the web_bluetooth.mojom (Closed)
Patch Set: address comments from: https://codereview.chromium.org/2751293002/ Created 3 years, 9 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 1c386003578feff3e054182e966c08b99d9f42e7..0971a3ecbd774dfd6f253fc1d378a14662d5ba0c 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) {
dcheng 2017/03/16 22:20:29 Nit: No WTF:: is needed (this is not currently the
juncai 2017/03/17 00:53:56 Done.
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())
dcheng 2017/03/16 22:20:29 Nit: no is_bound()
juncai 2017/03/17 00:53:56 Done.
+ 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));
@@ -257,8 +245,10 @@ ScriptPromise BluetoothRemoteGATTCharacteristic::startNotifications(
GetGatt()->AddToActiveAlgorithms(resolver);
mojom::blink::WebBluetoothService* service = m_device->bluetooth()->Service();
+ mojom::blink::WebBluetoothCharacteristicClientAssociatedPtrInfo ptrInfo;
+ m_clientBinding.Bind(&ptrInfo);
service->RemoteCharacteristicStartNotifications(
- m_characteristic->instance_id,
+ m_characteristic->instance_id, std::move(ptrInfo),
convertToBaseCallback(
WTF::bind(&BluetoothRemoteGATTCharacteristic::NotificationsCallback,
wrapPersistent(this), wrapPersistent(resolver))));

Powered by Google App Engine
This is Rietveld 408576698