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

Unified Diff: third_party/WebKit/Source/modules/bluetooth/BluetoothRemoteGATTServer.h

Issue 2718583002: Refactor WebBluetoothServiceClient in the web_bluetooth.mojom (Closed)
Patch Set: rebase 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/BluetoothRemoteGATTServer.h
diff --git a/third_party/WebKit/Source/modules/bluetooth/BluetoothRemoteGATTServer.h b/third_party/WebKit/Source/modules/bluetooth/BluetoothRemoteGATTServer.h
index 805e50afcef1480a9f48ee947ca2d9982c863887..99c3efaf4dd9cce53d1c95f1a4cb91374576e00b 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_set.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();
@@ -83,6 +111,9 @@ class BluetoothRemoteGATTServer final
// using this server’s connection.
HeapHashSet<Member<ScriptPromiseResolver>> m_activeAlgorithms;
+ mojo::AssociatedBindingSet<mojom::blink::WebBluetoothServerClient>
+ m_clientBindings;
+
Member<BluetoothDevice> m_device;
bool m_connected;
};

Powered by Google App Engine
This is Rietveld 408576698