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

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

Powered by Google App Engine
This is Rietveld 408576698