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

Side by Side Diff: third_party/WebKit/Source/modules/bluetooth/BluetoothDevice.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 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 13 matching lines...) Expand all
24 class BluetoothRemoteGATTService; 24 class BluetoothRemoteGATTService;
25 class ScriptPromiseResolver; 25 class ScriptPromiseResolver;
26 26
27 // BluetoothDevice represents a physical bluetooth device in the DOM. See IDL. 27 // BluetoothDevice represents a physical bluetooth device in the DOM. See IDL.
28 // 28 //
29 // Callbacks providing WebBluetoothDevice objects are handled by 29 // Callbacks providing WebBluetoothDevice objects are handled by
30 // CallbackPromiseAdapter templatized with this class. See this class's 30 // CallbackPromiseAdapter templatized with this class. See this class's
31 // "Interface required by CallbackPromiseAdapter" section and the 31 // "Interface required by CallbackPromiseAdapter" section and the
32 // CallbackPromiseAdapter class comments. 32 // CallbackPromiseAdapter class comments.
33 class BluetoothDevice final : public EventTargetWithInlineData, 33 class BluetoothDevice final : public EventTargetWithInlineData,
34 public ContextLifecycleObserver { 34 public ContextLifecycleObserver {
ortuno 2017/03/09 23:16:38 Does BluetoothDevice still need to be a ContextLif
juncai 2017/03/10 03:57:02 I think so, since it is a subclass of EventTargetW
35 USING_PRE_FINALIZER(BluetoothDevice, dispose);
36 DEFINE_WRAPPERTYPEINFO(); 35 DEFINE_WRAPPERTYPEINFO();
37 USING_GARBAGE_COLLECTED_MIXIN(BluetoothDevice); 36 USING_GARBAGE_COLLECTED_MIXIN(BluetoothDevice);
38 37
39 public: 38 public:
40 BluetoothDevice(ExecutionContext*, 39 BluetoothDevice(ExecutionContext*,
41 mojom::blink::WebBluetoothDevicePtr, 40 mojom::blink::WebBluetoothDevicePtr,
42 Bluetooth*); 41 Bluetooth*);
43 42
44 // Interface required by CallbackPromiseAdapter: 43 // Interface required by CallbackPromiseAdapter:
45 static BluetoothDevice* take(ScriptPromiseResolver*, 44 static BluetoothDevice* take(ScriptPromiseResolver*,
(...skipping 19 matching lines...) Expand all
65 64
66 // We should disconnect from the device in all of the following cases: 65 // We should disconnect from the device in all of the following cases:
67 // 1. When the object gets GarbageCollected e.g. it went out of scope. 66 // 1. When the object gets GarbageCollected e.g. it went out of scope.
68 // dispose() is called in this case. 67 // dispose() is called in this case.
69 // 2. When the parent document gets detached e.g. reloading a page. 68 // 2. When the parent document gets detached e.g. reloading a page.
70 // stop() is called in this case. 69 // stop() is called in this case.
71 // TODO(ortuno): Users should be able to turn on notifications for 70 // TODO(ortuno): Users should be able to turn on notifications for
72 // events on navigator.bluetooth and still remain connected even if the 71 // events on navigator.bluetooth and still remain connected even if the
73 // BluetoothDevice object is garbage collected. 72 // BluetoothDevice object is garbage collected.
74 73
75 // USING_PRE_FINALIZER interface.
76 // Called before the object gets garbage collected.
77 void dispose();
78
79 // ContextLifecycleObserver interface.
80 void contextDestroyed(ExecutionContext*) override;
81
82 // If gatt is connected then sets gatt.connected to false and disconnects.
83 // This function only performs the necessary steps to ensure a device
84 // disconnects therefore it should only be used when the object is being
85 // garbage collected or the context is being destroyed.
86 void disconnectGATTIfConnected();
87
88 // Performs necessary cleanup when a device disconnects and fires 74 // Performs necessary cleanup when a device disconnects and fires
89 // gattserverdisconnected event. 75 // gattserverdisconnected event.
90 void cleanupDisconnectedDeviceAndFireEvent(); 76 void clearAttributeInstanceMapAndFireEvent();
91 77
92 // EventTarget methods: 78 // EventTarget methods:
93 const AtomicString& interfaceName() const override; 79 const AtomicString& interfaceName() const override;
94 ExecutionContext* getExecutionContext() const override; 80 ExecutionContext* getExecutionContext() const override;
95 81
96 void dispatchGattServerDisconnected();
97
98 Bluetooth* bluetooth() { return m_bluetooth; } 82 Bluetooth* bluetooth() { return m_bluetooth; }
99 83
100 // Interface required by Garbage Collection: 84 // Interface required by Garbage Collection:
101 DECLARE_VIRTUAL_TRACE(); 85 DECLARE_VIRTUAL_TRACE();
102 86
103 // IDL exposed interface: 87 // IDL exposed interface:
104 String id() { return m_device->id; } 88 String id() { return m_device->id; }
105 String name() { return m_device->name; } 89 String name() { return m_device->name; }
106 BluetoothRemoteGATTServer* gatt() { return m_gatt; } 90 BluetoothRemoteGATTServer* gatt() { return m_gatt; }
107 91
108 DEFINE_ATTRIBUTE_EVENT_LISTENER(gattserverdisconnected); 92 DEFINE_ATTRIBUTE_EVENT_LISTENER(gattserverdisconnected);
109 93
110 private: 94 private:
111 // Holds all GATT Attributes associated with this BluetoothDevice. 95 // Holds all GATT Attributes associated with this BluetoothDevice.
112 Member<BluetoothAttributeInstanceMap> m_attributeInstanceMap; 96 Member<BluetoothAttributeInstanceMap> m_attributeInstanceMap;
113 97
114 mojom::blink::WebBluetoothDevicePtr m_device; 98 mojom::blink::WebBluetoothDevicePtr m_device;
115 Member<BluetoothRemoteGATTServer> m_gatt; 99 Member<BluetoothRemoteGATTServer> m_gatt;
116 Member<Bluetooth> m_bluetooth; 100 Member<Bluetooth> m_bluetooth;
117 }; 101 };
118 102
119 } // namespace blink 103 } // namespace blink
120 104
121 #endif // BluetoothDevice_h 105 #endif // BluetoothDevice_h
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698