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

Side by Side Diff: content/browser/bluetooth/bluetooth_dispatcher_host.cc

Issue 1294473006: bluetooth: Add histograms for readValue and writeValue outcomes (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@bluetooth-uma-get-characteristic
Patch Set: Created 5 years, 4 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 // NETWORK_ERROR Note: 5 // NETWORK_ERROR Note:
6 // When a device can't be found in the BluetoothAdapter, that generally 6 // When a device can't be found in the BluetoothAdapter, that generally
7 // indicates that it's gone out of range. We reject with a NetworkError in that 7 // indicates that it's gone out of range. We reject with a NetworkError in that
8 // case. 8 // case.
9 // https://webbluetoothchrome.github.io/web-bluetooth/#dom-bluetoothdevice-conne ctgatt 9 // https://webbluetoothchrome.github.io/web-bluetooth/#dom-bluetoothdevice-conne ctgatt
10 10
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
92 return WebBluetoothError::ConnectAuthTimeout; 92 return WebBluetoothError::ConnectAuthTimeout;
93 case device::BluetoothDevice::ERROR_UNSUPPORTED_DEVICE: 93 case device::BluetoothDevice::ERROR_UNSUPPORTED_DEVICE:
94 RecordConnectGATTOutcome(UMAConnectGATTOutcome::UNSUPPORTED_DEVICE); 94 RecordConnectGATTOutcome(UMAConnectGATTOutcome::UNSUPPORTED_DEVICE);
95 return WebBluetoothError::ConnectUnsupportedDevice; 95 return WebBluetoothError::ConnectUnsupportedDevice;
96 } 96 }
97 NOTREACHED(); 97 NOTREACHED();
98 return WebBluetoothError::UntranslatedConnectErrorCode; 98 return WebBluetoothError::UntranslatedConnectErrorCode;
99 } 99 }
100 100
101 blink::WebBluetoothError TranslateGATTError( 101 blink::WebBluetoothError TranslateGATTError(
102 BluetoothGattService::GattErrorCode error_code) { 102 BluetoothGattService::GattErrorCode error_code,
103 UMAGATTOperation operation) {
103 switch (error_code) { 104 switch (error_code) {
104 case BluetoothGattService::GATT_ERROR_UNKNOWN: 105 case BluetoothGattService::GATT_ERROR_UNKNOWN:
105 RecordGATTError(UMAGATTError::UNKNOWN); 106 RecordGATTOperationOutcome(operation, UMAGATTOperationOutcome::UNKNOWN);
106 return blink::WebBluetoothError::GATTUnknownError; 107 return blink::WebBluetoothError::GATTUnknownError;
107 case BluetoothGattService::GATT_ERROR_FAILED: 108 case BluetoothGattService::GATT_ERROR_FAILED:
108 RecordGATTError(UMAGATTError::FAILED); 109 RecordGATTOperationOutcome(operation, UMAGATTOperationOutcome::FAILED);
109 return blink::WebBluetoothError::GATTUnknownFailure; 110 return blink::WebBluetoothError::GATTUnknownFailure;
110 case BluetoothGattService::GATT_ERROR_IN_PROGRESS: 111 case BluetoothGattService::GATT_ERROR_IN_PROGRESS:
111 RecordGATTError(UMAGATTError::IN_PROGRESS); 112 RecordGATTOperationOutcome(operation,
113 UMAGATTOperationOutcome::IN_PROGRESS);
112 return blink::WebBluetoothError::GATTOperationInProgress; 114 return blink::WebBluetoothError::GATTOperationInProgress;
113 case BluetoothGattService::GATT_ERROR_INVALID_LENGTH: 115 case BluetoothGattService::GATT_ERROR_INVALID_LENGTH:
116 RecordGATTOperationOutcome(operation,
117 UMAGATTOperationOutcome::INVALID_LENGTH);
114 return blink::WebBluetoothError::GATTInvalidAttributeLength; 118 return blink::WebBluetoothError::GATTInvalidAttributeLength;
115 case BluetoothGattService::GATT_ERROR_NOT_PERMITTED: 119 case BluetoothGattService::GATT_ERROR_NOT_PERMITTED:
120 RecordGATTOperationOutcome(operation,
121 UMAGATTOperationOutcome::NOT_PERMITTED);
116 return blink::WebBluetoothError::GATTNotPermitted; 122 return blink::WebBluetoothError::GATTNotPermitted;
117 case BluetoothGattService::GATT_ERROR_NOT_AUTHORIZED: 123 case BluetoothGattService::GATT_ERROR_NOT_AUTHORIZED:
124 RecordGATTOperationOutcome(operation,
125 UMAGATTOperationOutcome::NOT_AUTHORIZED);
118 return blink::WebBluetoothError::GATTNotAuthorized; 126 return blink::WebBluetoothError::GATTNotAuthorized;
119 case BluetoothGattService::GATT_ERROR_NOT_PAIRED: 127 case BluetoothGattService::GATT_ERROR_NOT_PAIRED:
120 RecordGATTError(UMAGATTError::NOT_PAIRED); 128 RecordGATTOperationOutcome(operation,
129 UMAGATTOperationOutcome::NOT_PAIRED);
121 return blink::WebBluetoothError::GATTNotPaired; 130 return blink::WebBluetoothError::GATTNotPaired;
122 case BluetoothGattService::GATT_ERROR_NOT_SUPPORTED: 131 case BluetoothGattService::GATT_ERROR_NOT_SUPPORTED:
132 RecordGATTOperationOutcome(operation,
133 UMAGATTOperationOutcome::NOT_SUPPORTED);
123 return blink::WebBluetoothError::GATTNotSupported; 134 return blink::WebBluetoothError::GATTNotSupported;
124 } 135 }
125 NOTREACHED(); 136 NOTREACHED();
126 return blink::WebBluetoothError::GATTUntranslatedErrorCode; 137 return blink::WebBluetoothError::GATTUntranslatedErrorCode;
127 } 138 }
128 139
129 } // namespace 140 } // namespace
130 141
131 BluetoothDispatcherHost::BluetoothDispatcherHost(int render_process_id) 142 BluetoothDispatcherHost::BluetoothDispatcherHost(int render_process_id)
132 : BrowserMessageFilter(BluetoothMsgStart), 143 : BrowserMessageFilter(BluetoothMsgStart),
(...skipping 309 matching lines...) Expand 10 before | Expand all | Expand 10 after
442 } 453 }
443 const std::string& service_instance_id = characteristic_iter->second; 454 const std::string& service_instance_id = characteristic_iter->second;
444 455
445 auto device_iter = service_to_device_.find(service_instance_id); 456 auto device_iter = service_to_device_.find(service_instance_id);
446 457
447 CHECK(device_iter != service_to_device_.end()); 458 CHECK(device_iter != service_to_device_.end());
448 459
449 device::BluetoothDevice* device = 460 device::BluetoothDevice* device =
450 adapter_->GetDevice(device_iter->second /* device_instance_id */); 461 adapter_->GetDevice(device_iter->second /* device_instance_id */);
451 if (device == nullptr) { // See "NETWORK_ERROR Note" above. 462 if (device == nullptr) { // See "NETWORK_ERROR Note" above.
463 RecordCharacteristicReadValueOutcome(UMAGATTOperationOutcome::NO_DEVICE);
452 Send(new BluetoothMsg_ReadCharacteristicValueError( 464 Send(new BluetoothMsg_ReadCharacteristicValueError(
453 thread_id, request_id, WebBluetoothError::DeviceNoLongerInRange)); 465 thread_id, request_id, WebBluetoothError::DeviceNoLongerInRange));
454 return; 466 return;
455 } 467 }
456 468
457 BluetoothGattService* service = device->GetGattService(service_instance_id); 469 BluetoothGattService* service = device->GetGattService(service_instance_id);
458 if (service == nullptr) { 470 if (service == nullptr) {
471 RecordCharacteristicReadValueOutcome(UMAGATTOperationOutcome::NO_SERVICE);
459 Send(new BluetoothMsg_ReadCharacteristicValueError( 472 Send(new BluetoothMsg_ReadCharacteristicValueError(
460 thread_id, request_id, WebBluetoothError::ServiceNoLongerExists)); 473 thread_id, request_id, WebBluetoothError::ServiceNoLongerExists));
461 return; 474 return;
462 } 475 }
463 476
464 BluetoothGattCharacteristic* characteristic = 477 BluetoothGattCharacteristic* characteristic =
465 service->GetCharacteristic(characteristic_instance_id); 478 service->GetCharacteristic(characteristic_instance_id);
466 if (characteristic == nullptr) { 479 if (characteristic == nullptr) {
480 RecordCharacteristicReadValueOutcome(
481 UMAGATTOperationOutcome::NO_CHARACTERISTIC);
467 Send(new BluetoothMsg_ReadCharacteristicValueError( 482 Send(new BluetoothMsg_ReadCharacteristicValueError(
468 thread_id, request_id, 483 thread_id, request_id,
469 WebBluetoothError::CharacteristicNoLongerExists)); 484 WebBluetoothError::CharacteristicNoLongerExists));
470 return; 485 return;
471 } 486 }
472 487
473 characteristic->ReadRemoteCharacteristic( 488 characteristic->ReadRemoteCharacteristic(
474 base::Bind(&BluetoothDispatcherHost::OnCharacteristicValueRead, 489 base::Bind(&BluetoothDispatcherHost::OnCharacteristicValueRead,
475 weak_ptr_factory_.GetWeakPtr(), thread_id, request_id), 490 weak_ptr_factory_.GetWeakPtr(), thread_id, request_id),
476 base::Bind(&BluetoothDispatcherHost::OnCharacteristicReadValueError, 491 base::Bind(&BluetoothDispatcherHost::OnCharacteristicReadValueError,
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
509 } 524 }
510 const std::string& service_instance_id = characteristic_iter->second; 525 const std::string& service_instance_id = characteristic_iter->second;
511 526
512 auto device_iter = service_to_device_.find(service_instance_id); 527 auto device_iter = service_to_device_.find(service_instance_id);
513 528
514 CHECK(device_iter != service_to_device_.end()); 529 CHECK(device_iter != service_to_device_.end());
515 530
516 device::BluetoothDevice* device = 531 device::BluetoothDevice* device =
517 adapter_->GetDevice(device_iter->second /* device_instance_id */); 532 adapter_->GetDevice(device_iter->second /* device_instance_id */);
518 if (device == nullptr) { // See "NETWORK_ERROR Note" above. 533 if (device == nullptr) { // See "NETWORK_ERROR Note" above.
534 RecordCharacteristicWriteValueOutcome(UMAGATTOperationOutcome::NO_DEVICE);
519 Send(new BluetoothMsg_WriteCharacteristicValueError( 535 Send(new BluetoothMsg_WriteCharacteristicValueError(
520 thread_id, request_id, WebBluetoothError::DeviceNoLongerInRange)); 536 thread_id, request_id, WebBluetoothError::DeviceNoLongerInRange));
521 return; 537 return;
522 } 538 }
523 539
524 BluetoothGattService* service = device->GetGattService(service_instance_id); 540 BluetoothGattService* service = device->GetGattService(service_instance_id);
525 if (service == nullptr) { 541 if (service == nullptr) {
542 RecordCharacteristicWriteValueOutcome(UMAGATTOperationOutcome::NO_SERVICE);
526 Send(new BluetoothMsg_WriteCharacteristicValueError( 543 Send(new BluetoothMsg_WriteCharacteristicValueError(
527 thread_id, request_id, WebBluetoothError::ServiceNoLongerExists)); 544 thread_id, request_id, WebBluetoothError::ServiceNoLongerExists));
528 return; 545 return;
529 } 546 }
530 547
531 BluetoothGattCharacteristic* characteristic = 548 BluetoothGattCharacteristic* characteristic =
532 service->GetCharacteristic(characteristic_instance_id); 549 service->GetCharacteristic(characteristic_instance_id);
533 if (characteristic == nullptr) { 550 if (characteristic == nullptr) {
551 RecordCharacteristicWriteValueOutcome(
552 UMAGATTOperationOutcome::NO_CHARACTERISTIC);
534 Send(new BluetoothMsg_WriteCharacteristicValueError( 553 Send(new BluetoothMsg_WriteCharacteristicValueError(
535 thread_id, request_id, 554 thread_id, request_id,
536 WebBluetoothError::CharacteristicNoLongerExists)); 555 WebBluetoothError::CharacteristicNoLongerExists));
537 return; 556 return;
538 } 557 }
539 characteristic->WriteRemoteCharacteristic( 558 characteristic->WriteRemoteCharacteristic(
540 value, base::Bind(&BluetoothDispatcherHost::OnWriteValueSuccess, 559 value, base::Bind(&BluetoothDispatcherHost::OnWriteValueSuccess,
541 weak_ptr_factory_.GetWeakPtr(), thread_id, request_id), 560 weak_ptr_factory_.GetWeakPtr(), thread_id, request_id),
542 base::Bind(&BluetoothDispatcherHost::OnWriteValueFailed, 561 base::Bind(&BluetoothDispatcherHost::OnWriteValueFailed,
543 weak_ptr_factory_.GetWeakPtr(), thread_id, request_id)); 562 weak_ptr_factory_.GetWeakPtr(), thread_id, request_id));
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after
689 } 708 }
690 RecordGetPrimaryServiceOutcome(UMAGetPrimaryServiceOutcome::NOT_FOUND); 709 RecordGetPrimaryServiceOutcome(UMAGetPrimaryServiceOutcome::NOT_FOUND);
691 Send(new BluetoothMsg_GetPrimaryServiceError( 710 Send(new BluetoothMsg_GetPrimaryServiceError(
692 thread_id, request_id, WebBluetoothError::ServiceNotFound)); 711 thread_id, request_id, WebBluetoothError::ServiceNotFound));
693 } 712 }
694 713
695 void BluetoothDispatcherHost::OnCharacteristicValueRead( 714 void BluetoothDispatcherHost::OnCharacteristicValueRead(
696 int thread_id, 715 int thread_id,
697 int request_id, 716 int request_id,
698 const std::vector<uint8>& value) { 717 const std::vector<uint8>& value) {
718 RecordCharacteristicReadValueOutcome(UMAGATTOperationOutcome::SUCCESS);
699 Send(new BluetoothMsg_ReadCharacteristicValueSuccess(thread_id, request_id, 719 Send(new BluetoothMsg_ReadCharacteristicValueSuccess(thread_id, request_id,
700 value)); 720 value));
701 } 721 }
702 722
703 void BluetoothDispatcherHost::OnCharacteristicReadValueError( 723 void BluetoothDispatcherHost::OnCharacteristicReadValueError(
704 int thread_id, 724 int thread_id,
705 int request_id, 725 int request_id,
706 device::BluetoothGattService::GattErrorCode error_code) { 726 device::BluetoothGattService::GattErrorCode error_code) {
727 // TranslateGATTError calls RecordGATTOperationOutcome with
Jeffrey Yasskin 2015/08/14 21:33:22 This comment could be shorter: "TranslateGATTError
ortuno 2015/08/14 21:42:20 Done.
728 // UMAGATTOperation::CHARACTERISTIC_READ as a parameter.
729 // This should take care of recording the outcome for this readValue call.
707 Send(new BluetoothMsg_ReadCharacteristicValueError( 730 Send(new BluetoothMsg_ReadCharacteristicValueError(
708 thread_id, request_id, TranslateGATTError(error_code))); 731 thread_id, request_id,
732 TranslateGATTError(error_code, UMAGATTOperation::CHARACTERISTIC_READ)));
709 } 733 }
710 734
711 void BluetoothDispatcherHost::OnWriteValueSuccess(int thread_id, 735 void BluetoothDispatcherHost::OnWriteValueSuccess(int thread_id,
712 int request_id) { 736 int request_id) {
737 RecordCharacteristicWriteValueOutcome(UMAGATTOperationOutcome::SUCCESS);
713 Send(new BluetoothMsg_WriteCharacteristicValueSuccess(thread_id, request_id)); 738 Send(new BluetoothMsg_WriteCharacteristicValueSuccess(thread_id, request_id));
714 } 739 }
715 740
716 void BluetoothDispatcherHost::OnWriteValueFailed( 741 void BluetoothDispatcherHost::OnWriteValueFailed(
717 int thread_id, 742 int thread_id,
718 int request_id, 743 int request_id,
719 device::BluetoothGattService::GattErrorCode error_code) { 744 device::BluetoothGattService::GattErrorCode error_code) {
745 // TranslateGATTError calls RecordGATTOperationOutcome with
746 // UMAGATTOperation::CHARACTERISTIC_WRITE as a parameter.
747 // This should take care of recording the outcome for this writeValue call.
720 Send(new BluetoothMsg_WriteCharacteristicValueError( 748 Send(new BluetoothMsg_WriteCharacteristicValueError(
721 thread_id, request_id, TranslateGATTError(error_code))); 749 thread_id, request_id,
750 TranslateGATTError(error_code, UMAGATTOperation::CHARACTERISTIC_WRITE)));
722 } 751 }
723 752
724 } // namespace content 753 } // namespace content
OLDNEW
« no previous file with comments | « no previous file | content/browser/bluetooth/bluetooth_metrics.h » ('j') | content/browser/bluetooth/bluetooth_metrics.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698