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

Side by Side Diff: third_party/WebKit/Source/modules/bluetooth/BluetoothRemoteGATTCharacteristic.cpp

Issue 1773813007: blink: Rename modules/ method to prefix with get when they collide. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: clash-modules: rebase-fixes Created 4 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 #include "modules/bluetooth/BluetoothRemoteGATTCharacteristic.h" 5 #include "modules/bluetooth/BluetoothRemoteGATTCharacteristic.h"
6 6
7 #include "bindings/core/v8/CallbackPromiseAdapter.h" 7 #include "bindings/core/v8/CallbackPromiseAdapter.h"
8 #include "bindings/core/v8/ScriptPromise.h" 8 #include "bindings/core/v8/ScriptPromise.h"
9 #include "bindings/core/v8/ScriptPromiseResolver.h" 9 #include "bindings/core/v8/ScriptPromiseResolver.h"
10 #include "core/dom/DOMDataView.h" 10 #include "core/dom/DOMDataView.h"
(...skipping 28 matching lines...) Expand all
39 m_properties = BluetoothCharacteristicProperties::create(m_webCharacteristic ->characteristicProperties); 39 m_properties = BluetoothCharacteristicProperties::create(m_webCharacteristic ->characteristicProperties);
40 // See example in Source/platform/heap/ThreadState.h 40 // See example in Source/platform/heap/ThreadState.h
41 ThreadState::current()->registerPreFinalizer(this); 41 ThreadState::current()->registerPreFinalizer(this);
42 } 42 }
43 43
44 BluetoothRemoteGATTCharacteristic* BluetoothRemoteGATTCharacteristic::take(Scrip tPromiseResolver* resolver, PassOwnPtr<WebBluetoothRemoteGATTCharacteristicInit> webCharacteristic) 44 BluetoothRemoteGATTCharacteristic* BluetoothRemoteGATTCharacteristic::take(Scrip tPromiseResolver* resolver, PassOwnPtr<WebBluetoothRemoteGATTCharacteristicInit> webCharacteristic)
45 { 45 {
46 if (!webCharacteristic) { 46 if (!webCharacteristic) {
47 return nullptr; 47 return nullptr;
48 } 48 }
49 BluetoothRemoteGATTCharacteristic* characteristic = new BluetoothRemoteGATTC haracteristic(resolver->executionContext(), webCharacteristic); 49 BluetoothRemoteGATTCharacteristic* characteristic = new BluetoothRemoteGATTC haracteristic(resolver->getExecutionContext(), webCharacteristic);
50 // See note in ActiveDOMObject about suspendIfNeeded. 50 // See note in ActiveDOMObject about suspendIfNeeded.
51 characteristic->suspendIfNeeded(); 51 characteristic->suspendIfNeeded();
52 return characteristic; 52 return characteristic;
53 } 53 }
54 54
55 void BluetoothRemoteGATTCharacteristic::setValue( 55 void BluetoothRemoteGATTCharacteristic::setValue(
56 const PassRefPtr<DOMDataView>& domDataView) 56 const PassRefPtr<DOMDataView>& domDataView)
57 { 57 {
58 m_value = domDataView; 58 m_value = domDataView;
59 } 59 }
(...skipping 13 matching lines...) Expand all
73 73
74 void BluetoothRemoteGATTCharacteristic::dispose() 74 void BluetoothRemoteGATTCharacteristic::dispose()
75 { 75 {
76 notifyCharacteristicObjectRemoved(); 76 notifyCharacteristicObjectRemoved();
77 } 77 }
78 78
79 void BluetoothRemoteGATTCharacteristic::notifyCharacteristicObjectRemoved() 79 void BluetoothRemoteGATTCharacteristic::notifyCharacteristicObjectRemoved()
80 { 80 {
81 if (!m_stopped) { 81 if (!m_stopped) {
82 m_stopped = true; 82 m_stopped = true;
83 WebBluetooth* webbluetooth = BluetoothSupplement::fromExecutionContext(A ctiveDOMObject::executionContext()); 83 WebBluetooth* webbluetooth = BluetoothSupplement::fromExecutionContext(A ctiveDOMObject::getExecutionContext());
84 webbluetooth->characteristicObjectRemoved(m_webCharacteristic->character isticInstanceID, this); 84 webbluetooth->characteristicObjectRemoved(m_webCharacteristic->character isticInstanceID, this);
85 } 85 }
86 } 86 }
87 87
88 const WTF::AtomicString& BluetoothRemoteGATTCharacteristic::interfaceName() cons t 88 const WTF::AtomicString& BluetoothRemoteGATTCharacteristic::interfaceName() cons t
89 { 89 {
90 return EventTargetNames::BluetoothRemoteGATTCharacteristic; 90 return EventTargetNames::BluetoothRemoteGATTCharacteristic;
91 } 91 }
92 92
93 ExecutionContext* BluetoothRemoteGATTCharacteristic::executionContext() const 93 ExecutionContext* BluetoothRemoteGATTCharacteristic::getExecutionContext() const
94 { 94 {
95 return ActiveDOMObject::executionContext(); 95 return ActiveDOMObject::getExecutionContext();
96 } 96 }
97 97
98 bool BluetoothRemoteGATTCharacteristic::addEventListenerInternal(const AtomicStr ing& eventType, PassRefPtrWillBeRawPtr<EventListener> listener, const EventListe nerOptions& options) 98 bool BluetoothRemoteGATTCharacteristic::addEventListenerInternal(const AtomicStr ing& eventType, PassRefPtrWillBeRawPtr<EventListener> listener, const EventListe nerOptions& options)
99 { 99 {
100 // We will also need to unregister a characteristic once all the event 100 // We will also need to unregister a characteristic once all the event
101 // listeners have been removed. See http://crbug.com/541390 101 // listeners have been removed. See http://crbug.com/541390
102 if (eventType == EventTypeNames::characteristicvaluechanged) { 102 if (eventType == EventTypeNames::characteristicvaluechanged) {
103 WebBluetooth* webbluetooth = BluetoothSupplement::fromExecutionContext(e xecutionContext()); 103 WebBluetooth* webbluetooth = BluetoothSupplement::fromExecutionContext(g etExecutionContext());
104 webbluetooth->registerCharacteristicObject(m_webCharacteristic->characte risticInstanceID, this); 104 webbluetooth->registerCharacteristicObject(m_webCharacteristic->characte risticInstanceID, this);
105 } 105 }
106 return EventTarget::addEventListenerInternal(eventType, listener, options); 106 return EventTarget::addEventListenerInternal(eventType, listener, options);
107 } 107 }
108 108
109 class ReadValueCallback : public WebBluetoothReadValueCallbacks { 109 class ReadValueCallback : public WebBluetoothReadValueCallbacks {
110 public: 110 public:
111 ReadValueCallback(BluetoothRemoteGATTCharacteristic* characteristic, ScriptP romiseResolver* resolver) : m_webCharacteristic(characteristic), m_resolver(reso lver) {} 111 ReadValueCallback(BluetoothRemoteGATTCharacteristic* characteristic, ScriptP romiseResolver* resolver) : m_webCharacteristic(characteristic), m_resolver(reso lver) {}
112 112
113 void onSuccess(const WebVector<uint8_t>& value) override 113 void onSuccess(const WebVector<uint8_t>& value) override
114 { 114 {
115 if (!m_resolver->executionContext() || m_resolver->executionContext()->a ctiveDOMObjectsAreStopped()) 115 if (!m_resolver->getExecutionContext() || m_resolver->getExecutionContex t()->activeDOMObjectsAreStopped())
116 return; 116 return;
117 117
118 RefPtr<DOMDataView> domDataView = ConvertWebVectorToDataView(value); 118 RefPtr<DOMDataView> domDataView = ConvertWebVectorToDataView(value);
119 if (m_webCharacteristic) { 119 if (m_webCharacteristic) {
120 m_webCharacteristic->setValue(domDataView); 120 m_webCharacteristic->setValue(domDataView);
121 } 121 }
122 m_resolver->resolve(domDataView); 122 m_resolver->resolve(domDataView);
123 } 123 }
124 124
125 void onError(const WebBluetoothError& e) override 125 void onError(const WebBluetoothError& e) override
126 { 126 {
127 if (!m_resolver->executionContext() || m_resolver->executionContext()->a ctiveDOMObjectsAreStopped()) 127 if (!m_resolver->getExecutionContext() || m_resolver->getExecutionContex t()->activeDOMObjectsAreStopped())
128 return; 128 return;
129 m_resolver->reject(BluetoothError::take(m_resolver, e)); 129 m_resolver->reject(BluetoothError::take(m_resolver, e));
130 } 130 }
131 131
132 private: 132 private:
133 WeakPersistent<BluetoothRemoteGATTCharacteristic> m_webCharacteristic; 133 WeakPersistent<BluetoothRemoteGATTCharacteristic> m_webCharacteristic;
134 Persistent<ScriptPromiseResolver> m_resolver; 134 Persistent<ScriptPromiseResolver> m_resolver;
135 }; 135 };
136 136
137 ScriptPromise BluetoothRemoteGATTCharacteristic::readValue(ScriptState* scriptSt ate) 137 ScriptPromise BluetoothRemoteGATTCharacteristic::readValue(ScriptState* scriptSt ate)
138 { 138 {
139 WebBluetooth* webbluetooth = BluetoothSupplement::fromScriptState(scriptStat e); 139 WebBluetooth* webbluetooth = BluetoothSupplement::fromScriptState(scriptStat e);
140 140
141 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState) ; 141 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState) ;
142 ScriptPromise promise = resolver->promise(); 142 ScriptPromise promise = resolver->promise();
143 webbluetooth->readValue(m_webCharacteristic->characteristicInstanceID, new R eadValueCallback(this, resolver)); 143 webbluetooth->readValue(m_webCharacteristic->characteristicInstanceID, new R eadValueCallback(this, resolver));
144 144
145 return promise; 145 return promise;
146 } 146 }
147 147
148 class WriteValueCallback : public WebBluetoothWriteValueCallbacks { 148 class WriteValueCallback : public WebBluetoothWriteValueCallbacks {
149 public: 149 public:
150 WriteValueCallback(BluetoothRemoteGATTCharacteristic* characteristic, Script PromiseResolver* resolver) : m_webCharacteristic(characteristic), m_resolver(res olver) {} 150 WriteValueCallback(BluetoothRemoteGATTCharacteristic* characteristic, Script PromiseResolver* resolver) : m_webCharacteristic(characteristic), m_resolver(res olver) {}
151 151
152 void onSuccess(const WebVector<uint8_t>& value) override 152 void onSuccess(const WebVector<uint8_t>& value) override
153 { 153 {
154 if (!m_resolver->executionContext() || m_resolver->executionContext()->a ctiveDOMObjectsAreStopped()) 154 if (!m_resolver->getExecutionContext() || m_resolver->getExecutionContex t()->activeDOMObjectsAreStopped())
155 return; 155 return;
156 156
157 if (m_webCharacteristic) { 157 if (m_webCharacteristic) {
158 m_webCharacteristic->setValue(ConvertWebVectorToDataView(value)); 158 m_webCharacteristic->setValue(ConvertWebVectorToDataView(value));
159 } 159 }
160 m_resolver->resolve(); 160 m_resolver->resolve();
161 } 161 }
162 162
163 void onError(const WebBluetoothError& e) override 163 void onError(const WebBluetoothError& e) override
164 { 164 {
165 if (!m_resolver->executionContext() || m_resolver->executionContext()->a ctiveDOMObjectsAreStopped()) 165 if (!m_resolver->getExecutionContext() || m_resolver->getExecutionContex t()->activeDOMObjectsAreStopped())
166 return; 166 return;
167 m_resolver->reject(BluetoothError::take(m_resolver, e)); 167 m_resolver->reject(BluetoothError::take(m_resolver, e));
168 } 168 }
169 169
170 private: 170 private:
171 WeakPersistent<BluetoothRemoteGATTCharacteristic> m_webCharacteristic; 171 WeakPersistent<BluetoothRemoteGATTCharacteristic> m_webCharacteristic;
172 Persistent<ScriptPromiseResolver> m_resolver; 172 Persistent<ScriptPromiseResolver> m_resolver;
173 }; 173 };
174 174
175 ScriptPromise BluetoothRemoteGATTCharacteristic::writeValue(ScriptState* scriptS tate, const DOMArrayPiece& value) 175 ScriptPromise BluetoothRemoteGATTCharacteristic::writeValue(ScriptState* scriptS tate, const DOMArrayPiece& value)
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
214 } 214 }
215 215
216 DEFINE_TRACE(BluetoothRemoteGATTCharacteristic) 216 DEFINE_TRACE(BluetoothRemoteGATTCharacteristic)
217 { 217 {
218 RefCountedGarbageCollectedEventTargetWithInlineData<BluetoothRemoteGATTChara cteristic>::trace(visitor); 218 RefCountedGarbageCollectedEventTargetWithInlineData<BluetoothRemoteGATTChara cteristic>::trace(visitor);
219 ActiveDOMObject::trace(visitor); 219 ActiveDOMObject::trace(visitor);
220 visitor->trace(m_properties); 220 visitor->trace(m_properties);
221 } 221 }
222 222
223 } // namespace blink 223 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698