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

Side by Side 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, 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 unified diff | Download patch
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 #ifndef BluetoothRemoteGATTServer_h 5 #ifndef BluetoothRemoteGATTServer_h
6 #define BluetoothRemoteGATTServer_h 6 #define BluetoothRemoteGATTServer_h
7 7
8 #include "bindings/core/v8/ScriptWrappable.h" 8 #include "bindings/core/v8/ScriptWrappable.h"
9 #include "bindings/modules/v8/StringOrUnsignedLong.h" 9 #include "bindings/modules/v8/StringOrUnsignedLong.h"
10 #include "modules/bluetooth/BluetoothDevice.h" 10 #include "modules/bluetooth/BluetoothDevice.h"
11 #include "mojo/public/cpp/bindings/associated_binding.h"
11 #include "platform/heap/Heap.h" 12 #include "platform/heap/Heap.h"
12 #include "public/platform/modules/bluetooth/web_bluetooth.mojom-blink.h" 13 #include "public/platform/modules/bluetooth/web_bluetooth.mojom-blink.h"
13 #include "wtf/text/WTFString.h" 14 #include "wtf/text/WTFString.h"
14 15
15 namespace blink { 16 namespace blink {
16 17
17 class BluetoothDevice; 18 class BluetoothDevice;
18 class ScriptPromise; 19 class ScriptPromise;
19 class ScriptPromiseResolver; 20 class ScriptPromiseResolver;
20 class ScriptState; 21 class ScriptState;
21 22
22 // BluetoothRemoteGATTServer provides a way to interact with a connected 23 // BluetoothRemoteGATTServer provides a way to interact with a connected
23 // bluetooth peripheral. 24 // bluetooth peripheral.
24 class BluetoothRemoteGATTServer final 25 class BluetoothRemoteGATTServer
25 : public GarbageCollected<BluetoothRemoteGATTServer>, 26 : public GarbageCollectedFinalized<BluetoothRemoteGATTServer>,
26 public ScriptWrappable { 27 public ScriptWrappable,
28 public mojom::blink::WebBluetoothServerClient {
29 USING_PRE_FINALIZER(BluetoothRemoteGATTServer, dispose);
27 DEFINE_WRAPPERTYPEINFO(); 30 DEFINE_WRAPPERTYPEINFO();
28 31
29 public: 32 public:
30 BluetoothRemoteGATTServer(BluetoothDevice*); 33 BluetoothRemoteGATTServer(BluetoothDevice*);
31 34
32 static BluetoothRemoteGATTServer* create(BluetoothDevice*); 35 static BluetoothRemoteGATTServer* create(BluetoothDevice*);
33 36
37 // mojom::blink::WebBluetoothServerClient:
38 void GATTServerDisconnected() override;
39
34 void setConnected(bool connected) { m_connected = connected; } 40 void setConnected(bool connected) { m_connected = connected; }
35 41
36 // The Active Algorithms set is maintained so that disconnection, i.e. 42 // The Active Algorithms set is maintained so that disconnection, i.e.
37 // disconnect() method or the device disconnecting by itself, can be detected 43 // disconnect() method or the device disconnecting by itself, can be detected
38 // by algorithms. They check via RemoveFromActiveAlgorithms that their 44 // by algorithms. They check via RemoveFromActiveAlgorithms that their
39 // resolvers is still in the set of active algorithms. 45 // resolvers is still in the set of active algorithms.
40 // 46 //
41 // Adds |resolver| to the set of Active Algorithms. CHECK-fails if 47 // Adds |resolver| to the set of Active Algorithms. CHECK-fails if
42 // |resolver| was already added. 48 // |resolver| was already added.
43 void AddToActiveAlgorithms(ScriptPromiseResolver*); 49 void AddToActiveAlgorithms(ScriptPromiseResolver*);
44 // Removes |resolver| from the set of Active Algorithms if it was in the set 50 // Removes |resolver| from the set of Active Algorithms if it was in the set
45 // and returns true, false otherwise. 51 // and returns true, false otherwise.
46 bool RemoveFromActiveAlgorithms(ScriptPromiseResolver*); 52 bool RemoveFromActiveAlgorithms(ScriptPromiseResolver*);
47 // Removes all ScriptPromiseResolvers from the set of Active Algorithms. 53 // Removes all ScriptPromiseResolvers from the set of Active Algorithms.
48 void ClearActiveAlgorithms() { m_activeAlgorithms.clear(); } 54 void ClearActiveAlgorithms() { m_activeAlgorithms.clear(); }
49 55
56 // If gatt is connected then sets gatt.connected to false and disconnects.
57 // This function only performs the necessary steps to ensure a device
58 // disconnects therefore it should only be used when the object is being
59 // garbage collected or the context is being destroyed.
60 void disconnectIfConnected();
61
62 // Performs necessary cleanup when a device disconnects and fires
63 // gattserverdisconnected event.
64 void cleanupDisconnectedDeviceAndFireEvent();
65
66 void dispatchDisconnected();
67
68 // USING_PRE_FINALIZER interface.
69 // Called before the object gets garbage collected.
70 void dispose();
71
50 // Interface required by Garbage Collectoin: 72 // Interface required by Garbage Collectoin:
51 DECLARE_VIRTUAL_TRACE(); 73 DECLARE_VIRTUAL_TRACE();
52 74
53 // IDL exposed interface: 75 // IDL exposed interface:
54 BluetoothDevice* device() { return m_device; } 76 BluetoothDevice* device() { return m_device; }
55 bool connected() { return m_connected; } 77 bool connected() { return m_connected; }
56 ScriptPromise connect(ScriptState*); 78 ScriptPromise connect(ScriptState*);
57 void disconnect(ScriptState*); 79 void disconnect(ScriptState*);
58 ScriptPromise getPrimaryService(ScriptState*, 80 ScriptPromise getPrimaryService(ScriptState*,
59 const StringOrUnsignedLong& service, 81 const StringOrUnsignedLong& service,
60 ExceptionState&); 82 ExceptionState&);
61 ScriptPromise getPrimaryServices(ScriptState*, 83 ScriptPromise getPrimaryServices(ScriptState*,
62 const StringOrUnsignedLong& service, 84 const StringOrUnsignedLong& service,
63 ExceptionState&); 85 ExceptionState&);
64 ScriptPromise getPrimaryServices(ScriptState*, ExceptionState&); 86 ScriptPromise getPrimaryServices(ScriptState*, ExceptionState&);
65 87
66 private: 88 private:
67 ScriptPromise getPrimaryServicesImpl( 89 ScriptPromise getPrimaryServicesImpl(
68 ScriptState*, 90 ScriptState*,
69 mojom::blink::WebBluetoothGATTQueryQuantity, 91 mojom::blink::WebBluetoothGATTQueryQuantity,
70 String serviceUUID = String()); 92 String serviceUUID = String());
71 93
72 void ConnectCallback(ScriptPromiseResolver*, 94 void ConnectCallback(ScriptPromiseResolver*,
73 mojom::blink::WebBluetoothResult); 95 mojom::blink::WebBluetoothResult,
96 mojom::blink::WebBluetoothServerClientAssociatedRequest);
74 void GetPrimaryServicesCallback( 97 void GetPrimaryServicesCallback(
75 const String& requestedServiceUUID, 98 const String& requestedServiceUUID,
76 mojom::blink::WebBluetoothGATTQueryQuantity, 99 mojom::blink::WebBluetoothGATTQueryQuantity,
77 ScriptPromiseResolver*, 100 ScriptPromiseResolver*,
78 mojom::blink::WebBluetoothResult, 101 mojom::blink::WebBluetoothResult,
79 Optional<Vector<mojom::blink::WebBluetoothRemoteGATTServicePtr>> 102 Optional<Vector<mojom::blink::WebBluetoothRemoteGATTServicePtr>>
80 services); 103 services);
81 104
82 // Contains a ScriptPromiseResolver corresponding to each active algorithm 105 // Contains a ScriptPromiseResolver corresponding to each active algorithm
83 // using this server’s connection. 106 // using this server’s connection.
84 HeapHashSet<Member<ScriptPromiseResolver>> m_activeAlgorithms; 107 HeapHashSet<Member<ScriptPromiseResolver>> m_activeAlgorithms;
85 108
109 mojo::AssociatedBinding<mojom::blink::WebBluetoothServerClient>
110 m_clientBinding;
111
86 Member<BluetoothDevice> m_device; 112 Member<BluetoothDevice> m_device;
87 bool m_connected; 113 bool m_connected;
88 }; 114 };
89 115
90 } // namespace blink 116 } // namespace blink
91 117
92 #endif // BluetoothDevice_h 118 #endif // BluetoothDevice_h
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698