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

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

Issue 2736433003: Clean up web bluetooth related code (Closed)
Patch Set: clean up web bluetooth related code 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 "bindings/core/v8/ScriptPromise.h" 7 #include "bindings/core/v8/ScriptPromise.h"
8 #include "bindings/core/v8/ScriptPromiseResolver.h" 8 #include "bindings/core/v8/ScriptPromiseResolver.h"
9 #include "core/dom/DOMException.h" 9 #include "core/dom/DOMException.h"
10 #include "core/events/Event.h" 10 #include "core/events/Event.h"
(...skipping 362 matching lines...) Expand 10 before | Expand all | Expand 10 after
373 mojom::blink::WebBluetoothGATTQueryQuantity quantity, 373 mojom::blink::WebBluetoothGATTQueryQuantity quantity,
374 ScriptPromiseResolver* resolver, 374 ScriptPromiseResolver* resolver,
375 mojom::blink::WebBluetoothResult result, 375 mojom::blink::WebBluetoothResult result,
376 Optional<Vector<mojom::blink::WebBluetoothRemoteGATTDescriptorPtr>> 376 Optional<Vector<mojom::blink::WebBluetoothRemoteGATTDescriptorPtr>>
377 descriptors) { 377 descriptors) {
378 if (!resolver->getExecutionContext() || 378 if (!resolver->getExecutionContext() ||
379 resolver->getExecutionContext()->isContextDestroyed()) 379 resolver->getExecutionContext()->isContextDestroyed())
380 return; 380 return;
381 381
382 // If the device is disconnected, reject. 382 // If the device is disconnected, reject.
383 if (!service()->device()->gatt()->RemoveFromActiveAlgorithms(resolver)) { 383 if (!m_service->device()->gatt()->RemoveFromActiveAlgorithms(resolver)) {
384 resolver->reject(BluetoothError::createDOMException( 384 resolver->reject(BluetoothError::createDOMException(
385 blink::mojom::WebBluetoothResult::GATT_SERVER_DISCONNECTED)); 385 blink::mojom::WebBluetoothResult::GATT_SERVER_DISCONNECTED));
386 return; 386 return;
387 } 387 }
388 388
389 if (result == mojom::blink::WebBluetoothResult::SUCCESS) { 389 if (result == mojom::blink::WebBluetoothResult::SUCCESS) {
390 DCHECK(descriptors); 390 DCHECK(descriptors);
391 391
392 if (quantity == mojom::blink::WebBluetoothGATTQueryQuantity::SINGLE) { 392 if (quantity == mojom::blink::WebBluetoothGATTQueryQuantity::SINGLE) {
393 DCHECK_EQ(1u, descriptors->size()); 393 DCHECK_EQ(1u, descriptors->size());
394 resolver->resolve( 394 resolver->resolve(
395 service()->device()->getOrCreateBluetoothRemoteGATTDescriptor( 395 m_service->device()->getOrCreateBluetoothRemoteGATTDescriptor(
396 std::move(descriptors.value()[0]), this)); 396 std::move(descriptors.value()[0]), this));
397 return; 397 return;
398 } 398 }
399 399
400 HeapVector<Member<BluetoothRemoteGATTDescriptor>> gattDescriptors; 400 HeapVector<Member<BluetoothRemoteGATTDescriptor>> gattDescriptors;
401 gattDescriptors.reserveInitialCapacity(descriptors->size()); 401 gattDescriptors.reserveInitialCapacity(descriptors->size());
402 for (auto& descriptor : descriptors.value()) { 402 for (auto& descriptor : descriptors.value()) {
403 gattDescriptors.push_back( 403 gattDescriptors.push_back(
404 service()->device()->getOrCreateBluetoothRemoteGATTDescriptor( 404 m_service->device()->getOrCreateBluetoothRemoteGATTDescriptor(
405 std::move(descriptor), this)); 405 std::move(descriptor), this));
406 } 406 }
407 resolver->resolve(gattDescriptors); 407 resolver->resolve(gattDescriptors);
408 } else { 408 } else {
409 if (result == mojom::blink::WebBluetoothResult::DESCRIPTOR_NOT_FOUND) { 409 if (result == mojom::blink::WebBluetoothResult::DESCRIPTOR_NOT_FOUND) {
410 resolver->reject(BluetoothError::createDOMException( 410 resolver->reject(BluetoothError::createDOMException(
411 BluetoothErrorCode::DescriptorNotFound, 411 BluetoothErrorCode::DescriptorNotFound,
412 "No Descriptors matching UUID " + requestedDescriptorUUID + 412 "No Descriptors matching UUID " + requestedDescriptorUUID +
413 " found in Characteristic with UUID " + uuid() + ".")); 413 " found in Characteristic with UUID " + uuid() + "."));
414 } else { 414 } else {
(...skipping 14 matching lines...) Expand all
429 DEFINE_TRACE(BluetoothRemoteGATTCharacteristic) { 429 DEFINE_TRACE(BluetoothRemoteGATTCharacteristic) {
430 visitor->trace(m_service); 430 visitor->trace(m_service);
431 visitor->trace(m_properties); 431 visitor->trace(m_properties);
432 visitor->trace(m_value); 432 visitor->trace(m_value);
433 visitor->trace(m_device); 433 visitor->trace(m_device);
434 EventTargetWithInlineData::trace(visitor); 434 EventTargetWithInlineData::trace(visitor);
435 ContextLifecycleObserver::trace(visitor); 435 ContextLifecycleObserver::trace(visitor);
436 } 436 }
437 437
438 } // namespace blink 438 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698