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

Side by Side Diff: third_party/WebKit/Source/modules/bluetooth/BluetoothRemoteGATTCharacteristic.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 BluetoothRemoteGATTCharacteristic_h 5 #ifndef BluetoothRemoteGATTCharacteristic_h
6 #define BluetoothRemoteGATTCharacteristic_h 6 #define BluetoothRemoteGATTCharacteristic_h
7 7
8 #include <memory>
8 #include "bindings/core/v8/ScriptWrappable.h" 9 #include "bindings/core/v8/ScriptWrappable.h"
9 #include "core/dom/ContextLifecycleObserver.h" 10 #include "core/dom/ContextLifecycleObserver.h"
10 #include "core/dom/DOMArrayPiece.h" 11 #include "core/dom/DOMArrayPiece.h"
11 #include "core/dom/DOMDataView.h" 12 #include "core/dom/DOMDataView.h"
12 #include "modules/EventTargetModules.h" 13 #include "modules/EventTargetModules.h"
13 #include "modules/bluetooth/BluetoothRemoteGATTService.h" 14 #include "modules/bluetooth/BluetoothRemoteGATTService.h"
15 #include "mojo/public/cpp/bindings/associated_binding.h"
14 #include "platform/heap/Handle.h" 16 #include "platform/heap/Handle.h"
15 #include "public/platform/modules/bluetooth/web_bluetooth.mojom-blink.h" 17 #include "public/platform/modules/bluetooth/web_bluetooth.mojom-blink.h"
16 #include "wtf/text/WTFString.h" 18 #include "wtf/text/WTFString.h"
17 #include <memory>
18 19
19 namespace blink { 20 namespace blink {
20 21
21 class BluetoothCharacteristicProperties; 22 class BluetoothCharacteristicProperties;
22 class BluetoothDevice; 23 class BluetoothDevice;
23 class ExecutionContext; 24 class ExecutionContext;
24 class ScriptPromise; 25 class ScriptPromise;
25 class ScriptState; 26 class ScriptState;
26 27
27 // BluetoothRemoteGATTCharacteristic represents a GATT Characteristic, which is 28 // BluetoothRemoteGATTCharacteristic represents a GATT Characteristic, which is
28 // a basic data element that provides further information about a peripheral's 29 // a basic data element that provides further information about a peripheral's
29 // service. 30 // service.
30 // 31 //
31 // Callbacks providing WebBluetoothRemoteGATTCharacteristicInit objects are 32 // Callbacks providing WebBluetoothRemoteGATTCharacteristicInit objects are
32 // handled by CallbackPromiseAdapter templatized with this class. See this 33 // handled by CallbackPromiseAdapter templatized with this class. See this
33 // class's "Interface required by CallbackPromiseAdapter" section and the 34 // class's "Interface required by CallbackPromiseAdapter" section and the
34 // CallbackPromiseAdapter class comments. 35 // CallbackPromiseAdapter class comments.
35 class BluetoothRemoteGATTCharacteristic final 36 class BluetoothRemoteGATTCharacteristic final
36 : public EventTargetWithInlineData, 37 : public EventTargetWithInlineData,
37 public ContextLifecycleObserver { 38 public ContextLifecycleObserver,
39 public mojom::blink::WebBluetoothCharacteristicClient {
38 USING_PRE_FINALIZER(BluetoothRemoteGATTCharacteristic, dispose); 40 USING_PRE_FINALIZER(BluetoothRemoteGATTCharacteristic, dispose);
39 DEFINE_WRAPPERTYPEINFO(); 41 DEFINE_WRAPPERTYPEINFO();
40 USING_GARBAGE_COLLECTED_MIXIN(BluetoothRemoteGATTCharacteristic); 42 USING_GARBAGE_COLLECTED_MIXIN(BluetoothRemoteGATTCharacteristic);
41 43
42 public: 44 public:
43 explicit BluetoothRemoteGATTCharacteristic( 45 explicit BluetoothRemoteGATTCharacteristic(
44 ExecutionContext*, 46 ExecutionContext*,
45 mojom::blink::WebBluetoothRemoteGATTCharacteristicPtr, 47 mojom::blink::WebBluetoothRemoteGATTCharacteristicPtr,
46 BluetoothRemoteGATTService*, 48 BluetoothRemoteGATTService*,
47 BluetoothDevice*); 49 BluetoothDevice*);
48 50
49 static BluetoothRemoteGATTCharacteristic* create( 51 static BluetoothRemoteGATTCharacteristic* create(
50 ExecutionContext*, 52 ExecutionContext*,
51 mojom::blink::WebBluetoothRemoteGATTCharacteristicPtr, 53 mojom::blink::WebBluetoothRemoteGATTCharacteristicPtr,
52 BluetoothRemoteGATTService*, 54 BluetoothRemoteGATTService*,
53 BluetoothDevice*); 55 BluetoothDevice*);
54 56
55 // Save value. 57 // Save value.
56 void setValue(DOMDataView*); 58 void setValue(DOMDataView*);
57 59
58 void dispatchCharacteristicValueChanged(const Vector<uint8_t>& value); 60 // mojom::blink::WebBluetoothCharacteristicClient:
61 void RemoteCharacteristicValueChanged(
62 const WTF::Vector<uint8_t>& value) override;
59 63
60 // ContextLifecycleObserver interface. 64 // ContextLifecycleObserver interface.
61 void contextDestroyed(ExecutionContext*) override; 65 void contextDestroyed(ExecutionContext*) override;
62 66
63 // USING_PRE_FINALIZER interface. 67 // USING_PRE_FINALIZER interface.
64 // Called before the object gets garbage collected. 68 // Called before the object gets garbage collected.
65 void dispose(); 69 void dispose();
66 70
67 // Notify our embedder that we should stop any notifications.
68 // The function only notifies the embedder once.
69 void notifyCharacteristicObjectRemoved();
70
71 // EventTarget methods: 71 // EventTarget methods:
72 const AtomicString& interfaceName() const override; 72 const AtomicString& interfaceName() const override;
73 ExecutionContext* getExecutionContext() const; 73 ExecutionContext* getExecutionContext() const;
74 74
75 // Interface required by garbage collection. 75 // Interface required by garbage collection.
76 DECLARE_VIRTUAL_TRACE(); 76 DECLARE_VIRTUAL_TRACE();
77 77
78 // IDL exposed interface: 78 // IDL exposed interface:
79 BluetoothRemoteGATTService* service() { return m_service; } 79 BluetoothRemoteGATTService* service() { return m_service; }
80 String uuid() { return m_characteristic->uuid; } 80 String uuid() { return m_characteristic->uuid; }
(...skipping 22 matching lines...) Expand all
103 friend class BluetoothRemoteGATTDescriptor; 103 friend class BluetoothRemoteGATTDescriptor;
104 104
105 BluetoothRemoteGATTServer* getGatt() { return m_service->device()->gatt(); } 105 BluetoothRemoteGATTServer* getGatt() { return m_service->device()->gatt(); }
106 106
107 void ReadValueCallback(ScriptPromiseResolver*, 107 void ReadValueCallback(ScriptPromiseResolver*,
108 mojom::blink::WebBluetoothResult, 108 mojom::blink::WebBluetoothResult,
109 const Optional<Vector<uint8_t>>& value); 109 const Optional<Vector<uint8_t>>& value);
110 void WriteValueCallback(ScriptPromiseResolver*, 110 void WriteValueCallback(ScriptPromiseResolver*,
111 const Vector<uint8_t>& value, 111 const Vector<uint8_t>& value,
112 mojom::blink::WebBluetoothResult); 112 mojom::blink::WebBluetoothResult);
113 void NotificationsCallback(ScriptPromiseResolver*, 113 void NotificationsCallback(
114 mojom::blink::WebBluetoothResult); 114 ScriptPromiseResolver*,
115 mojom::blink::WebBluetoothResult,
116 mojom::blink::WebBluetoothCharacteristicClientAssociatedRequest);
115 117
116 ScriptPromise getDescriptorsImpl(ScriptState*, 118 ScriptPromise getDescriptorsImpl(ScriptState*,
117 mojom::blink::WebBluetoothGATTQueryQuantity, 119 mojom::blink::WebBluetoothGATTQueryQuantity,
118 const String& descriptorUUID = String()); 120 const String& descriptorUUID = String());
119 121
120 void GetDescriptorsCallback( 122 void GetDescriptorsCallback(
121 const String& requestedDescriptorUUID, 123 const String& requestedDescriptorUUID,
122 const String& characteristicInstanceId, 124 const String& characteristicInstanceId,
123 mojom::blink::WebBluetoothGATTQueryQuantity, 125 mojom::blink::WebBluetoothGATTQueryQuantity,
124 ScriptPromiseResolver*, 126 ScriptPromiseResolver*,
125 mojom::blink::WebBluetoothResult, 127 mojom::blink::WebBluetoothResult,
126 Optional<Vector<mojom::blink::WebBluetoothRemoteGATTDescriptorPtr>> 128 Optional<Vector<mojom::blink::WebBluetoothRemoteGATTDescriptorPtr>>
127 descriptors); 129 descriptors);
128 130
129 DOMException* createInvalidCharacteristicError(); 131 DOMException* createInvalidCharacteristicError();
130 132
131 mojom::blink::WebBluetoothRemoteGATTCharacteristicPtr m_characteristic; 133 mojom::blink::WebBluetoothRemoteGATTCharacteristicPtr m_characteristic;
132 Member<BluetoothRemoteGATTService> m_service; 134 Member<BluetoothRemoteGATTService> m_service;
133 bool m_stopped;
134 Member<BluetoothCharacteristicProperties> m_properties; 135 Member<BluetoothCharacteristicProperties> m_properties;
135 Member<DOMDataView> m_value; 136 Member<DOMDataView> m_value;
136 Member<BluetoothDevice> m_device; 137 Member<BluetoothDevice> m_device;
138 mojo::AssociatedBinding<mojom::blink::WebBluetoothCharacteristicClient>
139 m_clientBinding;
137 }; 140 };
138 141
139 } // namespace blink 142 } // namespace blink
140 143
141 #endif // BluetoothRemoteGATTCharacteristic_h 144 #endif // BluetoothRemoteGATTCharacteristic_h
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698