OLD | NEW |
---|---|
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 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
104 std::set<BluetoothUUID> union_of_services(optional_services.begin(), | 104 std::set<BluetoothUUID> union_of_services(optional_services.begin(), |
105 optional_services.end()); | 105 optional_services.end()); |
106 | 106 |
107 for (const content::BluetoothScanFilter& filter : filters) | 107 for (const content::BluetoothScanFilter& filter : filters) |
108 union_of_services.insert(filter.services.begin(), filter.services.end()); | 108 union_of_services.insert(filter.services.begin(), filter.services.end()); |
109 | 109 |
110 UMA_HISTOGRAM_COUNTS_100("Bluetooth.Web.RequestDevice.UnionOfServices.Count", | 110 UMA_HISTOGRAM_COUNTS_100("Bluetooth.Web.RequestDevice.UnionOfServices.Count", |
111 union_of_services.size()); | 111 union_of_services.size()); |
112 } | 112 } |
113 | 113 |
114 enum class UMAGetPrimaryServiceOutcome { | |
115 SUCCESS, | |
116 NO_DEVICE, | |
117 NOT_FOUND, | |
118 // Note: Add new GetPrimaryService outcomes immediately above this line. Make | |
119 // sure to update the enum list in tools/metrics/histograms/histograms.xml | |
120 // accordingly. | |
121 COUNT | |
122 }; | |
123 | |
124 void RecordGetPrimaryServiceService(const BluetoothUUID& service) { | |
125 UMA_HISTOGRAM_SPARSE_SLOWLY("Bluetooth.Web.GetPrimaryService.Services", | |
126 HashUUID(service)); | |
127 } | |
128 | |
129 void RecordGetPrimaryServiceOutcome(UMAGetPrimaryServiceOutcome outcome) { | |
130 UMA_HISTOGRAM_ENUMERATION( | |
131 "Bluetooth.Web.GetPrimaryService.Outcome", static_cast<int>(outcome), | |
132 static_cast<int>(UMAGetPrimaryServiceOutcome::COUNT)); | |
133 } | |
134 | |
135 void RecordGetPrimaryServiceTime(const base::TimeDelta& duration) { | |
136 UMA_HISTOGRAM_MEDIUM_TIMES("Bluetooth.Web.GetPrimaryService.Time", duration); | |
Jeffrey Yasskin
2015/08/12 17:00:04
This is more the ServiceDiscoveryTime or the GetPr
ortuno
2015/08/12 18:18:05
Histogram removed.
| |
137 } | |
138 | |
114 enum class UMAConnectGATTOutcome { | 139 enum class UMAConnectGATTOutcome { |
115 SUCCESS, | 140 SUCCESS, |
116 NO_DEVICE, | 141 NO_DEVICE, |
117 UNKNOWN, | 142 UNKNOWN, |
118 IN_PROGRESS, | 143 IN_PROGRESS, |
119 FAILED, | 144 FAILED, |
120 AUTH_FAILED, | 145 AUTH_FAILED, |
121 AUTH_CANCELED, | 146 AUTH_CANCELED, |
122 AUTH_REJECTED, | 147 AUTH_REJECTED, |
123 AUTH_TIMEOUT, | 148 AUTH_TIMEOUT, |
(...skipping 344 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
468 device_instance_id, start_time)); | 493 device_instance_id, start_time)); |
469 } | 494 } |
470 | 495 |
471 void BluetoothDispatcherHost::OnGetPrimaryService( | 496 void BluetoothDispatcherHost::OnGetPrimaryService( |
472 int thread_id, | 497 int thread_id, |
473 int request_id, | 498 int request_id, |
474 const std::string& device_instance_id, | 499 const std::string& device_instance_id, |
475 const std::string& service_uuid) { | 500 const std::string& service_uuid) { |
476 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 501 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
477 RecordWebBluetoothFunctionCall(UMAWebBluetoothFunction::GET_PRIMARY_SERVICE); | 502 RecordWebBluetoothFunctionCall(UMAWebBluetoothFunction::GET_PRIMARY_SERVICE); |
503 RecordGetPrimaryServiceService(BluetoothUUID(service_uuid)); | |
504 base::TimeTicks start_time = base::TimeTicks::Now(); | |
478 | 505 |
479 // TODO(ortuno): Check if device_instance_id is in "allowed devices" | 506 // TODO(ortuno): Check if device_instance_id is in "allowed devices" |
480 // https://crbug.com/493459 | 507 // https://crbug.com/493459 |
481 // TODO(ortuno): Check if service_uuid is in "allowed services" | 508 // TODO(ortuno): Check if service_uuid is in "allowed services" |
482 // https://crbug.com/493460 | 509 // https://crbug.com/493460 |
483 // For now just wait a fixed time and call OnServiceDiscovered. | 510 // For now just wait a fixed time and call OnServiceDiscovered. |
484 // TODO(ortuno): Use callback once it's implemented http://crbug.com/484504 | 511 // TODO(ortuno): Use callback once it's implemented http://crbug.com/484504 |
485 BrowserThread::PostDelayedTask( | 512 BrowserThread::PostDelayedTask( |
486 BrowserThread::UI, FROM_HERE, | 513 BrowserThread::UI, FROM_HERE, |
487 base::Bind(&BluetoothDispatcherHost::OnServicesDiscovered, | 514 base::Bind(&BluetoothDispatcherHost::OnServicesDiscovered, |
488 weak_ptr_factory_.GetWeakPtr(), thread_id, request_id, | 515 weak_ptr_factory_.GetWeakPtr(), thread_id, request_id, |
489 device_instance_id, service_uuid), | 516 device_instance_id, service_uuid, start_time), |
Jeffrey Yasskin
2015/08/12 17:00:04
Right now, this isn't a useful time to record sinc
ortuno
2015/08/12 18:18:05
Histogram removed.
| |
490 base::TimeDelta::FromSeconds(current_delay_time_)); | 517 base::TimeDelta::FromSeconds(current_delay_time_)); |
491 } | 518 } |
492 | 519 |
493 void BluetoothDispatcherHost::OnGetCharacteristic( | 520 void BluetoothDispatcherHost::OnGetCharacteristic( |
494 int thread_id, | 521 int thread_id, |
495 int request_id, | 522 int request_id, |
496 const std::string& service_instance_id, | 523 const std::string& service_instance_id, |
497 const std::string& characteristic_uuid) { | 524 const std::string& characteristic_uuid) { |
498 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 525 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
499 RecordWebBluetoothFunctionCall(UMAWebBluetoothFunction::GET_CHARACTERISTIC); | 526 RecordWebBluetoothFunctionCall(UMAWebBluetoothFunction::GET_CHARACTERISTIC); |
(...skipping 286 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
786 RecordConnectGATTTimeFailed(base::TimeTicks::Now() - start_time); | 813 RecordConnectGATTTimeFailed(base::TimeTicks::Now() - start_time); |
787 // RecordConnectGATTOutcome is called by TranslateConnectError. | 814 // RecordConnectGATTOutcome is called by TranslateConnectError. |
788 Send(new BluetoothMsg_ConnectGATTError(thread_id, request_id, | 815 Send(new BluetoothMsg_ConnectGATTError(thread_id, request_id, |
789 TranslateConnectError(error_code))); | 816 TranslateConnectError(error_code))); |
790 } | 817 } |
791 | 818 |
792 void BluetoothDispatcherHost::OnServicesDiscovered( | 819 void BluetoothDispatcherHost::OnServicesDiscovered( |
793 int thread_id, | 820 int thread_id, |
794 int request_id, | 821 int request_id, |
795 const std::string& device_instance_id, | 822 const std::string& device_instance_id, |
796 const std::string& service_uuid) { | 823 const std::string& service_uuid, |
824 base::TimeTicks start_time) { | |
797 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 825 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
826 RecordGetPrimaryServiceTime(base::TimeTicks::Now() - start_time); | |
798 | 827 |
799 device::BluetoothDevice* device = adapter_->GetDevice(device_instance_id); | 828 device::BluetoothDevice* device = adapter_->GetDevice(device_instance_id); |
800 if (device == nullptr) { // See "NETWORK_ERROR Note" above. | 829 if (device == nullptr) { // See "NETWORK_ERROR Note" above. |
830 RecordGetPrimaryServiceOutcome(UMAGetPrimaryServiceOutcome::NO_DEVICE); | |
831 VLOG(1) << "Bluetooth Device is no longer in range."; | |
801 Send(new BluetoothMsg_GetPrimaryServiceError( | 832 Send(new BluetoothMsg_GetPrimaryServiceError( |
802 thread_id, request_id, WebBluetoothError::DeviceNoLongerInRange)); | 833 thread_id, request_id, WebBluetoothError::DeviceNoLongerInRange)); |
803 return; | 834 return; |
804 } | 835 } |
805 for (BluetoothGattService* service : device->GetGattServices()) { | 836 for (BluetoothGattService* service : device->GetGattServices()) { |
806 if (service->GetUUID().canonical_value() == service_uuid) { | 837 if (service->GetUUID().canonical_value() == service_uuid) { |
807 // TODO(ortuno): Use generated instance ID instead. | 838 // TODO(ortuno): Use generated instance ID instead. |
808 // https://crbug.com/495379 | 839 // https://crbug.com/495379 |
809 const std::string& service_identifier = service->GetIdentifier(); | 840 const std::string& service_identifier = service->GetIdentifier(); |
810 auto insert_result = service_to_device_.insert( | 841 auto insert_result = service_to_device_.insert( |
811 make_pair(service_identifier, device_instance_id)); | 842 make_pair(service_identifier, device_instance_id)); |
812 | 843 |
813 // If a value is already in map, DCHECK it's valid. | 844 // If a value is already in map, DCHECK it's valid. |
814 if (!insert_result.second) | 845 if (!insert_result.second) |
815 DCHECK(insert_result.first->second == device_instance_id); | 846 DCHECK(insert_result.first->second == device_instance_id); |
816 | 847 |
848 RecordGetPrimaryServiceOutcome(UMAGetPrimaryServiceOutcome::SUCCESS); | |
817 Send(new BluetoothMsg_GetPrimaryServiceSuccess(thread_id, request_id, | 849 Send(new BluetoothMsg_GetPrimaryServiceSuccess(thread_id, request_id, |
818 service_identifier)); | 850 service_identifier)); |
819 return; | 851 return; |
820 } | 852 } |
821 } | 853 } |
854 RecordGetPrimaryServiceOutcome(UMAGetPrimaryServiceOutcome::NOT_FOUND); | |
855 VLOG(1) << "No GATT services with UUID: " << service_uuid; | |
822 Send(new BluetoothMsg_GetPrimaryServiceError( | 856 Send(new BluetoothMsg_GetPrimaryServiceError( |
823 thread_id, request_id, WebBluetoothError::ServiceNotFound)); | 857 thread_id, request_id, WebBluetoothError::ServiceNotFound)); |
824 } | 858 } |
825 | 859 |
826 void BluetoothDispatcherHost::OnCharacteristicValueRead( | 860 void BluetoothDispatcherHost::OnCharacteristicValueRead( |
827 int thread_id, | 861 int thread_id, |
828 int request_id, | 862 int request_id, |
829 const std::vector<uint8>& value) { | 863 const std::vector<uint8>& value) { |
830 Send(new BluetoothMsg_ReadCharacteristicValueSuccess(thread_id, request_id, | 864 Send(new BluetoothMsg_ReadCharacteristicValueSuccess(thread_id, request_id, |
831 value)); | 865 value)); |
(...skipping 14 matching lines...) Expand all Loading... | |
846 | 880 |
847 void BluetoothDispatcherHost::OnWriteValueFailed( | 881 void BluetoothDispatcherHost::OnWriteValueFailed( |
848 int thread_id, | 882 int thread_id, |
849 int request_id, | 883 int request_id, |
850 device::BluetoothGattService::GattErrorCode error_code) { | 884 device::BluetoothGattService::GattErrorCode error_code) { |
851 Send(new BluetoothMsg_WriteCharacteristicValueError( | 885 Send(new BluetoothMsg_WriteCharacteristicValueError( |
852 thread_id, request_id, TranslateGATTError(error_code))); | 886 thread_id, request_id, TranslateGATTError(error_code))); |
853 } | 887 } |
854 | 888 |
855 } // namespace content | 889 } // namespace content |
OLD | NEW |