Index: third_party/WebKit/Source/modules/bluetooth/BluetoothRemoteGATTServer.h |
diff --git a/third_party/WebKit/Source/modules/bluetooth/BluetoothRemoteGATTServer.h b/third_party/WebKit/Source/modules/bluetooth/BluetoothRemoteGATTServer.h |
index 7379ad61cc6b7bffd6a2711f5d9922f5bfc17b29..022513ef6269ae4ae1b7ec78bf966d1a6913e855 100644 |
--- a/third_party/WebKit/Source/modules/bluetooth/BluetoothRemoteGATTServer.h |
+++ b/third_party/WebKit/Source/modules/bluetooth/BluetoothRemoteGATTServer.h |
@@ -7,7 +7,9 @@ |
#include "bindings/core/v8/ScriptWrappable.h" |
#include "bindings/modules/v8/StringOrUnsignedLong.h" |
+#include "core/dom/ContextLifecycleObserver.h" |
#include "modules/bluetooth/BluetoothDevice.h" |
+#include "mojo/public/cpp/bindings/associated_binding.h" |
#include "platform/heap/Heap.h" |
#include "public/platform/modules/bluetooth/web_bluetooth.mojom-blink.h" |
#include "wtf/text/WTFString.h" |
@@ -21,15 +23,25 @@ class ScriptState; |
// BluetoothRemoteGATTServer provides a way to interact with a connected |
// bluetooth peripheral. |
-class BluetoothRemoteGATTServer final |
- : public GarbageCollected<BluetoothRemoteGATTServer>, |
- public ScriptWrappable { |
+class BluetoothRemoteGATTServer |
+ : public GarbageCollectedFinalized<BluetoothRemoteGATTServer>, |
+ public ScriptWrappable, |
+ public ContextLifecycleObserver, |
+ public mojom::blink::WebBluetoothServerClient { |
+ USING_PRE_FINALIZER(BluetoothRemoteGATTServer, dispose); |
DEFINE_WRAPPERTYPEINFO(); |
+ USING_GARBAGE_COLLECTED_MIXIN(BluetoothRemoteGATTServer); |
public: |
- BluetoothRemoteGATTServer(BluetoothDevice*); |
+ BluetoothRemoteGATTServer(ExecutionContext*, BluetoothDevice*); |
- static BluetoothRemoteGATTServer* create(BluetoothDevice*); |
+ static BluetoothRemoteGATTServer* create(ExecutionContext*, BluetoothDevice*); |
+ |
+ // ContextLifecycleObserver: |
+ void contextDestroyed(ExecutionContext*) override; |
+ |
+ // mojom::blink::WebBluetoothServerClient: |
+ void GATTServerDisconnected() override; |
void setConnected(bool connected) { m_connected = connected; } |
@@ -47,6 +59,22 @@ class BluetoothRemoteGATTServer final |
// Removes all ScriptPromiseResolvers from the set of Active Algorithms. |
void ClearActiveAlgorithms() { m_activeAlgorithms.clear(); } |
+ // If gatt is connected then sets gatt.connected to false and disconnects. |
+ // This function only performs the necessary steps to ensure a device |
+ // disconnects therefore it should only be used when the object is being |
+ // garbage collected or the context is being destroyed. |
+ void disconnectIfConnected(); |
+ |
+ // Performs necessary cleanup when a device disconnects and fires |
+ // gattserverdisconnected event. |
+ void cleanupDisconnectedDeviceAndFireEvent(); |
+ |
+ void dispatchDisconnected(); |
+ |
+ // USING_PRE_FINALIZER interface. |
+ // Called before the object gets garbage collected. |
+ void dispose(); |
+ |
// Interface required by Garbage Collectoin: |
DECLARE_VIRTUAL_TRACE(); |
@@ -70,7 +98,8 @@ class BluetoothRemoteGATTServer final |
String serviceUUID = String()); |
void ConnectCallback(ScriptPromiseResolver*, |
- mojom::blink::WebBluetoothResult); |
+ mojom::blink::WebBluetoothResult, |
+ mojom::blink::WebBluetoothServerClientAssociatedRequest); |
void GetPrimaryServicesCallback( |
const String& requestedServiceUUID, |
mojom::blink::WebBluetoothGATTQueryQuantity, |
@@ -83,6 +112,9 @@ class BluetoothRemoteGATTServer final |
// using this server’s connection. |
HeapHashSet<Member<ScriptPromiseResolver>> m_activeAlgorithms; |
+ mojo::AssociatedBinding<mojom::blink::WebBluetoothServerClient> |
+ m_clientBinding; |
+ |
Member<BluetoothDevice> m_device; |
bool m_connected; |
}; |