| 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..56071f73ad0adee18631316c59521029453d76fa 100644
|
| --- a/third_party/WebKit/Source/modules/bluetooth/BluetoothRemoteGATTCharacteristic.cpp
|
| +++ b/third_party/WebKit/Source/modules/bluetooth/BluetoothRemoteGATTCharacteristic.cpp
|
| @@ -31,7 +31,6 @@ BluetoothRemoteGATTCharacteristic::BluetoothRemoteGATTCharacteristic(
|
| : ContextLifecycleObserver(context),
|
| m_characteristic(std::move(characteristic)),
|
| m_service(service),
|
| - m_stopped(false),
|
| m_device(device) {
|
| m_properties =
|
| BluetoothCharacteristicProperties::Create(m_characteristic->properties);
|
| @@ -50,7 +49,7 @@ void BluetoothRemoteGATTCharacteristic::SetValue(DOMDataView* domDataView) {
|
| m_value = domDataView;
|
| }
|
|
|
| -void BluetoothRemoteGATTCharacteristic::DispatchCharacteristicValueChanged(
|
| +void BluetoothRemoteGATTCharacteristic::RemoteCharacteristicValueChanged(
|
| const Vector<uint8_t>& value) {
|
| if (!GetGatt()->connected())
|
| return;
|
| @@ -59,19 +58,11 @@ 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);
|
| - }
|
| + CloseClientBindings();
|
| }
|
|
|
| const WTF::AtomicString& BluetoothRemoteGATTCharacteristic::interfaceName()
|
| @@ -88,12 +79,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 +101,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 +243,15 @@ ScriptPromise BluetoothRemoteGATTCharacteristic::startNotifications(
|
| GetGatt()->AddToActiveAlgorithms(resolver);
|
|
|
| mojom::blink::WebBluetoothService* service = m_device->bluetooth()->Service();
|
| + mojom::blink::WebBluetoothCharacteristicClientAssociatedPtrInfo ptrInfo;
|
| + std::unique_ptr<
|
| + mojo::AssociatedBinding<mojom::blink::WebBluetoothCharacteristicClient>>
|
| + clientBinding(new mojo::AssociatedBinding<
|
| + mojom::blink::WebBluetoothCharacteristicClient>(this));
|
| + clientBinding->Bind(&ptrInfo);
|
| + m_clientBindings.push_back(std::move(clientBinding));
|
| service->RemoteCharacteristicStartNotifications(
|
| - m_characteristic->instance_id,
|
| + m_characteristic->instance_id, std::move(ptrInfo),
|
| convertToBaseCallback(
|
| WTF::bind(&BluetoothRemoteGATTCharacteristic::NotificationsCallback,
|
| wrapPersistent(this), wrapPersistent(resolver))));
|
| @@ -421,6 +414,12 @@ BluetoothRemoteGATTCharacteristic::CreateInvalidCharacteristicError() {
|
| "after reconnecting.");
|
| }
|
|
|
| +void BluetoothRemoteGATTCharacteristic::CloseClientBindings() {
|
| + for (auto& clientBinding : m_clientBindings) {
|
| + clientBinding->Close();
|
| + }
|
| +}
|
| +
|
| DEFINE_TRACE(BluetoothRemoteGATTCharacteristic) {
|
| visitor->trace(m_service);
|
| visitor->trace(m_properties);
|
|
|