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

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

Issue 2771893002: Move Bluetooth.Web.FunctionCall.Count UMA from browser to WebKit (Closed)
Patch Set: move Bluetooth.Web.FunctionCall.Count UMA from browser to WebKit 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 #include "modules/bluetooth/BluetoothRemoteGATTCharacteristic.h" 5 #include "modules/bluetooth/BluetoothRemoteGATTCharacteristic.h"
6 6
7 #include <memory>
8 #include <utility>
7 #include "bindings/core/v8/ScriptPromise.h" 9 #include "bindings/core/v8/ScriptPromise.h"
8 #include "bindings/core/v8/ScriptPromiseResolver.h" 10 #include "bindings/core/v8/ScriptPromiseResolver.h"
9 #include "core/dom/DOMException.h" 11 #include "core/dom/DOMException.h"
10 #include "core/events/Event.h" 12 #include "core/events/Event.h"
11 #include "core/inspector/ConsoleMessage.h" 13 #include "core/inspector/ConsoleMessage.h"
12 #include "modules/bluetooth/Bluetooth.h" 14 #include "modules/bluetooth/Bluetooth.h"
13 #include "modules/bluetooth/BluetoothCharacteristicProperties.h" 15 #include "modules/bluetooth/BluetoothCharacteristicProperties.h"
14 #include "modules/bluetooth/BluetoothDevice.h" 16 #include "modules/bluetooth/BluetoothDevice.h"
15 #include "modules/bluetooth/BluetoothError.h" 17 #include "modules/bluetooth/BluetoothError.h"
18 #include "modules/bluetooth/BluetoothMetrics.h"
16 #include "modules/bluetooth/BluetoothRemoteGATTDescriptor.h" 19 #include "modules/bluetooth/BluetoothRemoteGATTDescriptor.h"
17 #include "modules/bluetooth/BluetoothRemoteGATTService.h" 20 #include "modules/bluetooth/BluetoothRemoteGATTService.h"
18 #include "modules/bluetooth/BluetoothRemoteGATTUtils.h" 21 #include "modules/bluetooth/BluetoothRemoteGATTUtils.h"
19 #include "modules/bluetooth/BluetoothUUID.h" 22 #include "modules/bluetooth/BluetoothUUID.h"
20 23
21 #include <memory>
22 #include <utility>
23
24 namespace blink { 24 namespace blink {
25 25
26 BluetoothRemoteGATTCharacteristic::BluetoothRemoteGATTCharacteristic( 26 BluetoothRemoteGATTCharacteristic::BluetoothRemoteGATTCharacteristic(
27 ExecutionContext* context, 27 ExecutionContext* context,
28 mojom::blink::WebBluetoothRemoteGATTCharacteristicPtr characteristic, 28 mojom::blink::WebBluetoothRemoteGATTCharacteristicPtr characteristic,
29 BluetoothRemoteGATTService* service, 29 BluetoothRemoteGATTService* service,
30 BluetoothDevice* device) 30 BluetoothDevice* device)
31 : ContextLifecycleObserver(context), 31 : ContextLifecycleObserver(context),
32 m_characteristic(std::move(characteristic)), 32 m_characteristic(std::move(characteristic)),
33 m_service(service), 33 m_service(service),
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
117 BluetoothRemoteGATTUtils::ConvertWTFVectorToDataView(value.value()); 117 BluetoothRemoteGATTUtils::ConvertWTFVectorToDataView(value.value());
118 SetValue(domDataView); 118 SetValue(domDataView);
119 resolver->resolve(domDataView); 119 resolver->resolve(domDataView);
120 } else { 120 } else {
121 resolver->reject(BluetoothError::CreateDOMException(result)); 121 resolver->reject(BluetoothError::CreateDOMException(result));
122 } 122 }
123 } 123 }
124 124
125 ScriptPromise BluetoothRemoteGATTCharacteristic::readValue( 125 ScriptPromise BluetoothRemoteGATTCharacteristic::readValue(
126 ScriptState* scriptState) { 126 ScriptState* scriptState) {
127 RecordWebBluetoothFunctionCall(
128 UMAWebBluetoothFunction::CHARACTERISTIC_READ_VALUE);
129
127 if (!GetGatt()->connected()) { 130 if (!GetGatt()->connected()) {
128 return ScriptPromise::rejectWithDOMException( 131 return ScriptPromise::rejectWithDOMException(
129 scriptState, 132 scriptState,
130 BluetoothError::CreateNotConnectedException(BluetoothOperation::GATT)); 133 BluetoothError::CreateNotConnectedException(BluetoothOperation::GATT));
131 } 134 }
132 135
133 if (!GetGatt()->device()->IsValidCharacteristic( 136 if (!GetGatt()->device()->IsValidCharacteristic(
134 m_characteristic->instance_id)) { 137 m_characteristic->instance_id)) {
135 return ScriptPromise::rejectWithDOMException( 138 return ScriptPromise::rejectWithDOMException(
136 scriptState, CreateInvalidCharacteristicError()); 139 scriptState, CreateInvalidCharacteristicError());
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
169 SetValue(BluetoothRemoteGATTUtils::ConvertWTFVectorToDataView(value)); 172 SetValue(BluetoothRemoteGATTUtils::ConvertWTFVectorToDataView(value));
170 resolver->resolve(); 173 resolver->resolve();
171 } else { 174 } else {
172 resolver->reject(BluetoothError::CreateDOMException(result)); 175 resolver->reject(BluetoothError::CreateDOMException(result));
173 } 176 }
174 } 177 }
175 178
176 ScriptPromise BluetoothRemoteGATTCharacteristic::writeValue( 179 ScriptPromise BluetoothRemoteGATTCharacteristic::writeValue(
177 ScriptState* scriptState, 180 ScriptState* scriptState,
178 const DOMArrayPiece& value) { 181 const DOMArrayPiece& value) {
182 RecordWebBluetoothFunctionCall(
183 UMAWebBluetoothFunction::CHARACTERISTIC_WRITE_VALUE);
184
179 if (!GetGatt()->connected()) { 185 if (!GetGatt()->connected()) {
180 return ScriptPromise::rejectWithDOMException( 186 return ScriptPromise::rejectWithDOMException(
181 scriptState, 187 scriptState,
182 BluetoothError::CreateNotConnectedException(BluetoothOperation::GATT)); 188 BluetoothError::CreateNotConnectedException(BluetoothOperation::GATT));
183 } 189 }
184 190
185 if (!GetGatt()->device()->IsValidCharacteristic( 191 if (!GetGatt()->device()->IsValidCharacteristic(
186 m_characteristic->instance_id)) { 192 m_characteristic->instance_id)) {
187 return ScriptPromise::rejectWithDOMException( 193 return ScriptPromise::rejectWithDOMException(
188 scriptState, CreateInvalidCharacteristicError()); 194 scriptState, CreateInvalidCharacteristicError());
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
233 239
234 if (result == mojom::blink::WebBluetoothResult::SUCCESS) { 240 if (result == mojom::blink::WebBluetoothResult::SUCCESS) {
235 resolver->resolve(this); 241 resolver->resolve(this);
236 } else { 242 } else {
237 resolver->reject(BluetoothError::CreateDOMException(result)); 243 resolver->reject(BluetoothError::CreateDOMException(result));
238 } 244 }
239 } 245 }
240 246
241 ScriptPromise BluetoothRemoteGATTCharacteristic::startNotifications( 247 ScriptPromise BluetoothRemoteGATTCharacteristic::startNotifications(
242 ScriptState* scriptState) { 248 ScriptState* scriptState) {
249 RecordWebBluetoothFunctionCall(
250 UMAWebBluetoothFunction::CHARACTERISTIC_START_NOTIFICATIONS);
251
243 if (!GetGatt()->connected()) { 252 if (!GetGatt()->connected()) {
244 return ScriptPromise::rejectWithDOMException( 253 return ScriptPromise::rejectWithDOMException(
245 scriptState, 254 scriptState,
246 BluetoothError::CreateNotConnectedException(BluetoothOperation::GATT)); 255 BluetoothError::CreateNotConnectedException(BluetoothOperation::GATT));
247 } 256 }
248 257
249 if (!GetGatt()->device()->IsValidCharacteristic( 258 if (!GetGatt()->device()->IsValidCharacteristic(
250 m_characteristic->instance_id)) { 259 m_characteristic->instance_id)) {
251 return ScriptPromise::rejectWithDOMException( 260 return ScriptPromise::rejectWithDOMException(
252 scriptState, CreateInvalidCharacteristicError()); 261 scriptState, CreateInvalidCharacteristicError());
253 } 262 }
254 263
255 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState); 264 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState);
256 ScriptPromise promise = resolver->promise(); 265 ScriptPromise promise = resolver->promise();
257 GetGatt()->AddToActiveAlgorithms(resolver); 266 GetGatt()->AddToActiveAlgorithms(resolver);
258 267
259 mojom::blink::WebBluetoothService* service = m_device->bluetooth()->Service(); 268 mojom::blink::WebBluetoothService* service = m_device->bluetooth()->Service();
260 service->RemoteCharacteristicStartNotifications( 269 service->RemoteCharacteristicStartNotifications(
261 m_characteristic->instance_id, 270 m_characteristic->instance_id,
262 convertToBaseCallback( 271 convertToBaseCallback(
263 WTF::bind(&BluetoothRemoteGATTCharacteristic::NotificationsCallback, 272 WTF::bind(&BluetoothRemoteGATTCharacteristic::NotificationsCallback,
264 wrapPersistent(this), wrapPersistent(resolver)))); 273 wrapPersistent(this), wrapPersistent(resolver))));
265 274
266 return promise; 275 return promise;
267 } 276 }
268 277
269 ScriptPromise BluetoothRemoteGATTCharacteristic::stopNotifications( 278 ScriptPromise BluetoothRemoteGATTCharacteristic::stopNotifications(
270 ScriptState* scriptState) { 279 ScriptState* scriptState) {
280 RecordWebBluetoothFunctionCall(
281 UMAWebBluetoothFunction::CHARACTERISTIC_STOP_NOTIFICATIONS);
282
271 if (!GetGatt()->connected()) { 283 if (!GetGatt()->connected()) {
272 return ScriptPromise::rejectWithDOMException( 284 return ScriptPromise::rejectWithDOMException(
273 scriptState, 285 scriptState,
274 BluetoothError::CreateNotConnectedException(BluetoothOperation::GATT)); 286 BluetoothError::CreateNotConnectedException(BluetoothOperation::GATT));
275 } 287 }
276 288
277 if (!GetGatt()->device()->IsValidCharacteristic( 289 if (!GetGatt()->device()->IsValidCharacteristic(
278 m_characteristic->instance_id)) { 290 m_characteristic->instance_id)) {
279 return ScriptPromise::rejectWithDOMException( 291 return ScriptPromise::rejectWithDOMException(
280 scriptState, CreateInvalidCharacteristicError()); 292 scriptState, CreateInvalidCharacteristicError());
(...skipping 10 matching lines...) Expand all
291 WTF::bind(&BluetoothRemoteGATTCharacteristic::NotificationsCallback, 303 WTF::bind(&BluetoothRemoteGATTCharacteristic::NotificationsCallback,
292 wrapPersistent(this), wrapPersistent(resolver), 304 wrapPersistent(this), wrapPersistent(resolver),
293 mojom::blink::WebBluetoothResult::SUCCESS))); 305 mojom::blink::WebBluetoothResult::SUCCESS)));
294 return promise; 306 return promise;
295 } 307 }
296 308
297 ScriptPromise BluetoothRemoteGATTCharacteristic::getDescriptor( 309 ScriptPromise BluetoothRemoteGATTCharacteristic::getDescriptor(
298 ScriptState* scriptState, 310 ScriptState* scriptState,
299 const StringOrUnsignedLong& descriptorUUID, 311 const StringOrUnsignedLong& descriptorUUID,
300 ExceptionState& exceptionState) { 312 ExceptionState& exceptionState) {
313 RecordWebBluetoothFunctionCall(
314 UMAWebBluetoothFunction::CHARACTERISTIC_GET_DESCRIPTOR);
315
301 String descriptor = 316 String descriptor =
302 BluetoothUUID::getDescriptor(descriptorUUID, exceptionState); 317 BluetoothUUID::getDescriptor(descriptorUUID, exceptionState);
303 if (exceptionState.hadException()) 318 if (exceptionState.hadException())
304 return exceptionState.reject(scriptState); 319 return exceptionState.reject(scriptState);
305 320
306 return GetDescriptorsImpl(scriptState, 321 return GetDescriptorsImpl(scriptState,
307 mojom::blink::WebBluetoothGATTQueryQuantity::SINGLE, 322 mojom::blink::WebBluetoothGATTQueryQuantity::SINGLE,
308 descriptor); 323 descriptor);
309 } 324 }
310 325
311 ScriptPromise BluetoothRemoteGATTCharacteristic::getDescriptors( 326 ScriptPromise BluetoothRemoteGATTCharacteristic::getDescriptors(
312 ScriptState* scriptState, 327 ScriptState* scriptState,
313 ExceptionState&) { 328 ExceptionState&) {
329 RecordWebBluetoothFunctionCall(
330 UMAWebBluetoothFunction::CHARACTERISTIC_GET_DESCRIPTORS);
331
314 return GetDescriptorsImpl( 332 return GetDescriptorsImpl(
315 scriptState, mojom::blink::WebBluetoothGATTQueryQuantity::MULTIPLE); 333 scriptState, mojom::blink::WebBluetoothGATTQueryQuantity::MULTIPLE);
316 } 334 }
317 335
318 ScriptPromise BluetoothRemoteGATTCharacteristic::getDescriptors( 336 ScriptPromise BluetoothRemoteGATTCharacteristic::getDescriptors(
319 ScriptState* scriptState, 337 ScriptState* scriptState,
320 const StringOrUnsignedLong& descriptorUUID, 338 const StringOrUnsignedLong& descriptorUUID,
321 ExceptionState& exceptionState) { 339 ExceptionState& exceptionState) {
340 RecordWebBluetoothFunctionCall(
341 UMAWebBluetoothFunction::CHARACTERISTIC_GET_DESCRIPTORS);
342
322 String descriptor = 343 String descriptor =
323 BluetoothUUID::getDescriptor(descriptorUUID, exceptionState); 344 BluetoothUUID::getDescriptor(descriptorUUID, exceptionState);
324 if (exceptionState.hadException()) 345 if (exceptionState.hadException())
325 return exceptionState.reject(scriptState); 346 return exceptionState.reject(scriptState);
326 347
327 return GetDescriptorsImpl( 348 return GetDescriptorsImpl(
328 scriptState, mojom::blink::WebBluetoothGATTQueryQuantity::MULTIPLE, 349 scriptState, mojom::blink::WebBluetoothGATTQueryQuantity::MULTIPLE,
329 descriptor); 350 descriptor);
330 } 351 }
331 352
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
424 DEFINE_TRACE(BluetoothRemoteGATTCharacteristic) { 445 DEFINE_TRACE(BluetoothRemoteGATTCharacteristic) {
425 visitor->trace(m_service); 446 visitor->trace(m_service);
426 visitor->trace(m_properties); 447 visitor->trace(m_properties);
427 visitor->trace(m_value); 448 visitor->trace(m_value);
428 visitor->trace(m_device); 449 visitor->trace(m_device);
429 EventTargetWithInlineData::trace(visitor); 450 EventTargetWithInlineData::trace(visitor);
430 ContextLifecycleObserver::trace(visitor); 451 ContextLifecycleObserver::trace(visitor);
431 } 452 }
432 453
433 } // namespace blink 454 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698