| OLD | NEW |
| 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_set.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, |
| (...skipping 16 matching lines...) Expand all Loading... |
| 76 mojom::blink::WebBluetoothGATTQueryQuantity, | 104 mojom::blink::WebBluetoothGATTQueryQuantity, |
| 77 ScriptPromiseResolver*, | 105 ScriptPromiseResolver*, |
| 78 mojom::blink::WebBluetoothResult, | 106 mojom::blink::WebBluetoothResult, |
| 79 Optional<Vector<mojom::blink::WebBluetoothRemoteGATTServicePtr>> | 107 Optional<Vector<mojom::blink::WebBluetoothRemoteGATTServicePtr>> |
| 80 services); | 108 services); |
| 81 | 109 |
| 82 // Contains a ScriptPromiseResolver corresponding to each active algorithm | 110 // Contains a ScriptPromiseResolver corresponding to each active algorithm |
| 83 // using this server’s connection. | 111 // using this server’s connection. |
| 84 HeapHashSet<Member<ScriptPromiseResolver>> m_activeAlgorithms; | 112 HeapHashSet<Member<ScriptPromiseResolver>> m_activeAlgorithms; |
| 85 | 113 |
| 114 mojo::AssociatedBindingSet<mojom::blink::WebBluetoothServerClient> |
| 115 m_clientBindings; |
| 116 |
| 86 Member<BluetoothDevice> m_device; | 117 Member<BluetoothDevice> m_device; |
| 87 bool m_connected; | 118 bool m_connected; |
| 88 }; | 119 }; |
| 89 | 120 |
| 90 } // namespace blink | 121 } // namespace blink |
| 91 | 122 |
| 92 #endif // BluetoothDevice_h | 123 #endif // BluetoothDevice_h |
| OLD | NEW |