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

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

Issue 2718583002: Refactor WebBluetoothServiceClient in the web_bluetooth.mojom (Closed)
Patch Set: address more comments Created 3 years, 10 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 7379ad61cc6b7bffd6a2711f5d9922f5bfc17b29..839f4ec019f66d90e3eda799340319fbdc118f33 100644
--- a/third_party/WebKit/Source/modules/bluetooth/BluetoothRemoteGATTServer.h
+++ b/third_party/WebKit/Source/modules/bluetooth/BluetoothRemoteGATTServer.h
@@ -8,6 +8,7 @@
#include "bindings/core/v8/ScriptWrappable.h"
#include "bindings/modules/v8/StringOrUnsignedLong.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,9 +22,11 @@ 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 mojom::blink::WebBluetoothServerClient {
+ USING_PRE_FINALIZER(BluetoothRemoteGATTServer, dispose);
DEFINE_WRAPPERTYPEINFO();
public:
@@ -31,6 +34,9 @@ class BluetoothRemoteGATTServer final
static BluetoothRemoteGATTServer* create(BluetoothDevice*);
+ // mojom::blink::WebBluetoothServerClient:
+ void GATTServerDisconnected() override;
+
void setConnected(bool connected) { m_connected = connected; }
// The Active Algorithms set is maintained so that disconnection, i.e.
@@ -47,6 +53,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 +92,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 +106,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;
};

Powered by Google App Engine
This is Rietveld 408576698