| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "modules/bluetooth/BluetoothDevice.h" | 5 #include "modules/bluetooth/BluetoothDevice.h" |
| 6 | 6 |
| 7 #include "bindings/core/v8/CallbackPromiseAdapter.h" | 7 #include "bindings/core/v8/CallbackPromiseAdapter.h" |
| 8 #include "bindings/core/v8/ScriptPromise.h" | 8 #include "bindings/core/v8/ScriptPromise.h" |
| 9 #include "bindings/core/v8/ScriptPromiseResolver.h" | 9 #include "bindings/core/v8/ScriptPromiseResolver.h" |
| 10 #include "core/dom/DOMException.h" | 10 #include "core/dom/DOMException.h" |
| (...skipping 27 matching lines...) Expand all Loading... |
| 38 std::move(webDevice)); | 38 std::move(webDevice)); |
| 39 } | 39 } |
| 40 | 40 |
| 41 BluetoothRemoteGATTService* | 41 BluetoothRemoteGATTService* |
| 42 BluetoothDevice::getOrCreateBluetoothRemoteGATTService( | 42 BluetoothDevice::getOrCreateBluetoothRemoteGATTService( |
| 43 std::unique_ptr<WebBluetoothRemoteGATTService> webService) { | 43 std::unique_ptr<WebBluetoothRemoteGATTService> webService) { |
| 44 return m_attributeInstanceMap->getOrCreateBluetoothRemoteGATTService( | 44 return m_attributeInstanceMap->getOrCreateBluetoothRemoteGATTService( |
| 45 std::move(webService)); | 45 std::move(webService)); |
| 46 } | 46 } |
| 47 | 47 |
| 48 bool BluetoothDevice::isValidService(const String& serviceInstanceId) { |
| 49 return m_attributeInstanceMap->containsService(serviceInstanceId); |
| 50 } |
| 51 |
| 48 void BluetoothDevice::dispose() { | 52 void BluetoothDevice::dispose() { |
| 49 disconnectGATTIfConnected(); | 53 disconnectGATTIfConnected(); |
| 50 } | 54 } |
| 51 | 55 |
| 52 void BluetoothDevice::contextDestroyed() { | 56 void BluetoothDevice::contextDestroyed() { |
| 53 disconnectGATTIfConnected(); | 57 disconnectGATTIfConnected(); |
| 54 } | 58 } |
| 55 | 59 |
| 56 bool BluetoothDevice::disconnectGATTIfConnected() { | 60 void BluetoothDevice::disconnectGATTIfConnected() { |
| 57 if (m_gatt->connected()) { | 61 if (m_gatt->connected()) { |
| 58 m_gatt->setConnected(false); | 62 m_gatt->setConnected(false); |
| 59 m_gatt->ClearActiveAlgorithms(); | 63 m_gatt->ClearActiveAlgorithms(); |
| 60 BluetoothSupplement::fromExecutionContext(getExecutionContext()) | 64 BluetoothSupplement::fromExecutionContext(getExecutionContext()) |
| 61 ->disconnect(id()); | 65 ->disconnect(id()); |
| 62 return true; | |
| 63 } | 66 } |
| 64 return false; | 67 } |
| 68 |
| 69 void BluetoothDevice::cleanupDisconnectedDeviceAndFireEvent() { |
| 70 DCHECK(m_gatt->connected()); |
| 71 m_gatt->setConnected(false); |
| 72 m_gatt->ClearActiveAlgorithms(); |
| 73 m_attributeInstanceMap->Clear(); |
| 74 dispatchEvent(Event::createBubble(EventTypeNames::gattserverdisconnected)); |
| 65 } | 75 } |
| 66 | 76 |
| 67 const WTF::AtomicString& BluetoothDevice::interfaceName() const { | 77 const WTF::AtomicString& BluetoothDevice::interfaceName() const { |
| 68 return EventTargetNames::BluetoothDevice; | 78 return EventTargetNames::BluetoothDevice; |
| 69 } | 79 } |
| 70 | 80 |
| 71 ExecutionContext* BluetoothDevice::getExecutionContext() const { | 81 ExecutionContext* BluetoothDevice::getExecutionContext() const { |
| 72 return ContextLifecycleObserver::getExecutionContext(); | 82 return ContextLifecycleObserver::getExecutionContext(); |
| 73 } | 83 } |
| 74 | 84 |
| 75 void BluetoothDevice::dispatchGattServerDisconnected() { | 85 void BluetoothDevice::dispatchGattServerDisconnected() { |
| 76 if (m_gatt->connected()) { | 86 if (!m_gatt->connected()) { |
| 77 m_gatt->setConnected(false); | 87 return; |
| 78 m_gatt->ClearActiveAlgorithms(); | |
| 79 dispatchEvent(Event::createBubble(EventTypeNames::gattserverdisconnected)); | |
| 80 } | 88 } |
| 89 cleanupDisconnectedDeviceAndFireEvent(); |
| 81 } | 90 } |
| 82 | 91 |
| 83 DEFINE_TRACE(BluetoothDevice) { | 92 DEFINE_TRACE(BluetoothDevice) { |
| 84 EventTargetWithInlineData::trace(visitor); | 93 EventTargetWithInlineData::trace(visitor); |
| 85 ContextLifecycleObserver::trace(visitor); | 94 ContextLifecycleObserver::trace(visitor); |
| 86 visitor->trace(m_attributeInstanceMap); | 95 visitor->trace(m_attributeInstanceMap); |
| 87 visitor->trace(m_gatt); | 96 visitor->trace(m_gatt); |
| 88 } | 97 } |
| 89 | 98 |
| 90 } // namespace blink | 99 } // namespace blink |
| OLD | NEW |