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

Side by Side Diff: third_party/WebKit/Source/modules/bluetooth/BluetoothDevice.h

Issue 2478013002: bluetooth: Invalidate services upon disconnection (Closed)
Patch Set: Address scheib's comments Created 4 years, 1 month 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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 BluetoothDevice_h 5 #ifndef BluetoothDevice_h
6 #define BluetoothDevice_h 6 #define BluetoothDevice_h
7 7
8 #include "bindings/core/v8/ScriptWrappable.h" 8 #include "bindings/core/v8/ScriptWrappable.h"
9 #include "core/dom/ContextLifecycleObserver.h" 9 #include "core/dom/ContextLifecycleObserver.h"
10 #include "modules/EventTargetModules.h" 10 #include "modules/EventTargetModules.h"
(...skipping 30 matching lines...) Expand all
41 public: 41 public:
42 BluetoothDevice(ExecutionContext*, std::unique_ptr<WebBluetoothDeviceInit>); 42 BluetoothDevice(ExecutionContext*, std::unique_ptr<WebBluetoothDeviceInit>);
43 43
44 // Interface required by CallbackPromiseAdapter: 44 // Interface required by CallbackPromiseAdapter:
45 using WebType = std::unique_ptr<WebBluetoothDeviceInit>; 45 using WebType = std::unique_ptr<WebBluetoothDeviceInit>;
46 static BluetoothDevice* take(ScriptPromiseResolver*, 46 static BluetoothDevice* take(ScriptPromiseResolver*,
47 std::unique_ptr<WebBluetoothDeviceInit>); 47 std::unique_ptr<WebBluetoothDeviceInit>);
48 48
49 BluetoothRemoteGATTService* getOrCreateBluetoothRemoteGATTService( 49 BluetoothRemoteGATTService* getOrCreateBluetoothRemoteGATTService(
50 std::unique_ptr<WebBluetoothRemoteGATTService>); 50 std::unique_ptr<WebBluetoothRemoteGATTService>);
51 bool isValidService(const String& serviceInstanceId);
51 52
52 // We should disconnect from the device in all of the following cases: 53 // We should disconnect from the device in all of the following cases:
53 // 1. When the object gets GarbageCollected e.g. it went out of scope. 54 // 1. When the object gets GarbageCollected e.g. it went out of scope.
54 // dispose() is called in this case. 55 // dispose() is called in this case.
55 // 2. When the parent document gets detached e.g. reloading a page. 56 // 2. When the parent document gets detached e.g. reloading a page.
56 // stop() is called in this case. 57 // stop() is called in this case.
57 // TODO(ortuno): Users should be able to turn on notifications for 58 // TODO(ortuno): Users should be able to turn on notifications for
58 // events on navigator.bluetooth and still remain connected even if the 59 // events on navigator.bluetooth and still remain connected even if the
59 // BluetoothDevice object is garbage collected. 60 // BluetoothDevice object is garbage collected.
60 61
61 // USING_PRE_FINALIZER interface. 62 // USING_PRE_FINALIZER interface.
62 // Called before the object gets garbage collected. 63 // Called before the object gets garbage collected.
63 void dispose(); 64 void dispose();
64 65
65 // ContextLifecycleObserver interface. 66 // ContextLifecycleObserver interface.
66 void contextDestroyed() override; 67 void contextDestroyed() override;
67 68
68 // If gatt is connected then disconnects and sets gatt.connected to false. 69 // If gatt is connected then sets gatt.connected to false and disconnects.
69 // Returns true if gatt was disconnected. 70 // This function only performs the necessary steps to ensure a device
70 bool disconnectGATTIfConnected(); 71 // disconnects therefore it should only be used when the object is being
72 // garbage collected or the context is being destroyed.
73 void disconnectGATTIfConnected();
74
75 // Performs necessary cleanup when a device disconnects and fires
76 // gattserverdisconnected event.
77 void cleanupDisconnectedDeviceAndFireEvent();
71 78
72 // EventTarget methods: 79 // EventTarget methods:
73 const AtomicString& interfaceName() const override; 80 const AtomicString& interfaceName() const override;
74 ExecutionContext* getExecutionContext() const override; 81 ExecutionContext* getExecutionContext() const override;
75 82
76 // WebBluetoothDevice interface: 83 // WebBluetoothDevice interface:
77 void dispatchGattServerDisconnected() override; 84 void dispatchGattServerDisconnected() override;
78 85
79 // Interface required by Garbage Collection: 86 // Interface required by Garbage Collection:
80 DECLARE_VIRTUAL_TRACE(); 87 DECLARE_VIRTUAL_TRACE();
81 88
82 // IDL exposed interface: 89 // IDL exposed interface:
83 String id() { return m_webDevice->id; } 90 String id() { return m_webDevice->id; }
84 String name() { return m_webDevice->name; } 91 String name() { return m_webDevice->name; }
85 BluetoothRemoteGATTServer* gatt() { return m_gatt; } 92 BluetoothRemoteGATTServer* gatt() { return m_gatt; }
86 93
87 DEFINE_ATTRIBUTE_EVENT_LISTENER(gattserverdisconnected); 94 DEFINE_ATTRIBUTE_EVENT_LISTENER(gattserverdisconnected);
88 95
89 private: 96 private:
90 // Holds all GATT Attributes associated with this BluetoothDevice. 97 // Holds all GATT Attributes associated with this BluetoothDevice.
91 Member<BluetoothAttributeInstanceMap> m_attributeInstanceMap; 98 Member<BluetoothAttributeInstanceMap> m_attributeInstanceMap;
92 99
93 std::unique_ptr<WebBluetoothDeviceInit> m_webDevice; 100 std::unique_ptr<WebBluetoothDeviceInit> m_webDevice;
94 Member<BluetoothRemoteGATTServer> m_gatt; 101 Member<BluetoothRemoteGATTServer> m_gatt;
95 }; 102 };
96 103
97 } // namespace blink 104 } // namespace blink
98 105
99 #endif // BluetoothDevice_h 106 #endif // BluetoothDevice_h
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698