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

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

Issue 1270603010: bluetooth: Add histograms and logging for connectGATT (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@bluetooth-uma-requestDevice
Patch Set: Merge with ToT 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 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
110 std::set<BluetoothUUID> union_of_services(optional_services.begin(), 110 std::set<BluetoothUUID> union_of_services(optional_services.begin(),
111 optional_services.end()); 111 optional_services.end());
112 112
113 for (const content::BluetoothScanFilter& filter : filters) 113 for (const content::BluetoothScanFilter& filter : filters)
114 union_of_services.insert(filter.services.begin(), filter.services.end()); 114 union_of_services.insert(filter.services.begin(), filter.services.end());
115 115
116 UMA_HISTOGRAM_COUNTS_100("Bluetooth.Web.RequestDevice.UnionOfServices.Count", 116 UMA_HISTOGRAM_COUNTS_100("Bluetooth.Web.RequestDevice.UnionOfServices.Count",
117 union_of_services.size()); 117 union_of_services.size());
118 } 118 }
119 119
120 enum class UMAConnectGATTOutcome {
121 SUCCESS,
122 NO_DEVICE,
123 UNKNOWN,
124 IN_PROGRESS,
125 FAILED,
126 AUTH_FAILED,
127 AUTH_CANCELED,
128 AUTH_REJECTED,
129 AUTH_TIMEOUT,
130 UNSUPPORTED_DEVICE,
131 // Note: Add new ConnectGATT outcomes immediately above this line. Make sure
132 // to update the enum list in tools/metrisc/histogram/histograms.xml
133 // accordingly.
134 COUNT
135 };
136
137 void RecordConnectGATTOutcome(UMAConnectGATTOutcome outcome) {
138 UMA_HISTOGRAM_ENUMERATION("Bluetooth.Web.ConnectGATT.Outcome",
139 static_cast<int>(outcome),
140 static_cast<int>(UMAConnectGATTOutcome::COUNT));
141 }
142
143 void RecordConnectGATTTimeSuccess(const base::TimeDelta& duration) {
144 UMA_HISTOGRAM_MEDIUM_TIMES("Bluetooth.Web.ConnectGATT.TimeSuccess", duration);
145 }
146
147 void RecordConnectGATTTimeFailed(const base::TimeDelta& duration) {
148 UMA_HISTOGRAM_MEDIUM_TIMES("Bluetooth.Web.ConnectGATT.TimeFailed", duration);
149 }
150
120 enum class UMAWebBluetoothFunction { 151 enum class UMAWebBluetoothFunction {
121 REQUEST_DEVICE, 152 REQUEST_DEVICE,
122 CONNECT_GATT, 153 CONNECT_GATT,
123 GET_PRIMARY_SERVICE, 154 GET_PRIMARY_SERVICE,
124 GET_CHARACTERISTIC, 155 GET_CHARACTERISTIC,
125 CHARACTERISTIC_READ_VALUE, 156 CHARACTERISTIC_READ_VALUE,
126 CHARACTERISTIC_WRITE_VALUE, 157 CHARACTERISTIC_WRITE_VALUE,
127 // NOTE: Add new actions immediately above this line. Make sure to update the 158 // NOTE: Add new actions immediately above this line. Make sure to update the
128 // enum list in tools/metrics/histogram/histograms.xml accordingly. 159 // enum list in tools/metrics/histogram/histograms.xml accordingly.
129 COUNT 160 COUNT
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
170 201
171 void AddToHistogram(BluetoothGATTError error) { 202 void AddToHistogram(BluetoothGATTError error) {
172 UMA_HISTOGRAM_ENUMERATION("Bluetooth.GATTErrors", static_cast<int>(error), 203 UMA_HISTOGRAM_ENUMERATION("Bluetooth.GATTErrors", static_cast<int>(error),
173 static_cast<int>(BluetoothGATTError::MAX_ERROR)); 204 static_cast<int>(BluetoothGATTError::MAX_ERROR));
174 } 205 }
175 206
176 WebBluetoothError TranslateConnectError( 207 WebBluetoothError TranslateConnectError(
177 device::BluetoothDevice::ConnectErrorCode error_code) { 208 device::BluetoothDevice::ConnectErrorCode error_code) {
178 switch (error_code) { 209 switch (error_code) {
179 case device::BluetoothDevice::ERROR_UNKNOWN: 210 case device::BluetoothDevice::ERROR_UNKNOWN:
211 RecordConnectGATTOutcome(UMAConnectGATTOutcome::UNKNOWN);
180 return WebBluetoothError::ConnectUnknownError; 212 return WebBluetoothError::ConnectUnknownError;
181 case device::BluetoothDevice::ERROR_INPROGRESS: 213 case device::BluetoothDevice::ERROR_INPROGRESS:
214 RecordConnectGATTOutcome(UMAConnectGATTOutcome::IN_PROGRESS);
182 return WebBluetoothError::ConnectAlreadyInProgress; 215 return WebBluetoothError::ConnectAlreadyInProgress;
183 case device::BluetoothDevice::ERROR_FAILED: 216 case device::BluetoothDevice::ERROR_FAILED:
217 RecordConnectGATTOutcome(UMAConnectGATTOutcome::FAILED);
184 return WebBluetoothError::ConnectUnknownFailure; 218 return WebBluetoothError::ConnectUnknownFailure;
185 case device::BluetoothDevice::ERROR_AUTH_FAILED: 219 case device::BluetoothDevice::ERROR_AUTH_FAILED:
220 RecordConnectGATTOutcome(UMAConnectGATTOutcome::AUTH_FAILED);
186 return WebBluetoothError::ConnectAuthFailed; 221 return WebBluetoothError::ConnectAuthFailed;
187 case device::BluetoothDevice::ERROR_AUTH_CANCELED: 222 case device::BluetoothDevice::ERROR_AUTH_CANCELED:
223 RecordConnectGATTOutcome(UMAConnectGATTOutcome::AUTH_CANCELED);
188 return WebBluetoothError::ConnectAuthCanceled; 224 return WebBluetoothError::ConnectAuthCanceled;
189 case device::BluetoothDevice::ERROR_AUTH_REJECTED: 225 case device::BluetoothDevice::ERROR_AUTH_REJECTED:
226 RecordConnectGATTOutcome(UMAConnectGATTOutcome::AUTH_REJECTED);
190 return WebBluetoothError::ConnectAuthRejected; 227 return WebBluetoothError::ConnectAuthRejected;
191 case device::BluetoothDevice::ERROR_AUTH_TIMEOUT: 228 case device::BluetoothDevice::ERROR_AUTH_TIMEOUT:
229 RecordConnectGATTOutcome(UMAConnectGATTOutcome::AUTH_TIMEOUT);
192 return WebBluetoothError::ConnectAuthTimeout; 230 return WebBluetoothError::ConnectAuthTimeout;
193 case device::BluetoothDevice::ERROR_UNSUPPORTED_DEVICE: 231 case device::BluetoothDevice::ERROR_UNSUPPORTED_DEVICE:
232 RecordConnectGATTOutcome(UMAConnectGATTOutcome::UNSUPPORTED_DEVICE);
194 return WebBluetoothError::ConnectUnsupportedDevice; 233 return WebBluetoothError::ConnectUnsupportedDevice;
195 } 234 }
196 NOTREACHED(); 235 NOTREACHED();
197 return WebBluetoothError::UntranslatedConnectErrorCode; 236 return WebBluetoothError::UntranslatedConnectErrorCode;
198 } 237 }
199 238
200 blink::WebBluetoothError TranslateGATTError( 239 blink::WebBluetoothError TranslateGATTError(
201 BluetoothGattService::GattErrorCode error_code) { 240 BluetoothGattService::GattErrorCode error_code) {
202 switch (error_code) { 241 switch (error_code) {
203 case BluetoothGattService::GATT_ERROR_UNKNOWN: 242 case BluetoothGattService::GATT_ERROR_UNKNOWN:
(...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after
405 } 444 }
406 return; 445 return;
407 } 446 }
408 447
409 void BluetoothDispatcherHost::OnConnectGATT( 448 void BluetoothDispatcherHost::OnConnectGATT(
410 int thread_id, 449 int thread_id,
411 int request_id, 450 int request_id,
412 const std::string& device_instance_id) { 451 const std::string& device_instance_id) {
413 DCHECK_CURRENTLY_ON(BrowserThread::UI); 452 DCHECK_CURRENTLY_ON(BrowserThread::UI);
414 RecordWebBluetoothFunctionCall(UMAWebBluetoothFunction::CONNECT_GATT); 453 RecordWebBluetoothFunctionCall(UMAWebBluetoothFunction::CONNECT_GATT);
454 const base::TimeTicks start_time = base::TimeTicks::Now();
415 455
416 // TODO(ortuno): Right now it's pointless to check if the domain has access to 456 // TODO(ortuno): Right now it's pointless to check if the domain has access to
417 // the device, because any domain can connect to any device. But once 457 // the device, because any domain can connect to any device. But once
418 // permissions are implemented we should check that the domain has access to 458 // permissions are implemented we should check that the domain has access to
419 // the device. https://crbug.com/484745 459 // the device. https://crbug.com/484745
420 device::BluetoothDevice* device = adapter_->GetDevice(device_instance_id); 460 device::BluetoothDevice* device = adapter_->GetDevice(device_instance_id);
421 if (device == nullptr) { // See "NETWORK_ERROR Note" above. 461 if (device == nullptr) { // See "NETWORK_ERROR Note" above.
462 RecordConnectGATTOutcome(UMAConnectGATTOutcome::NO_DEVICE);
463 VLOG(1) << "Bluetooth Device no longer in range.";
422 Send(new BluetoothMsg_ConnectGATTError( 464 Send(new BluetoothMsg_ConnectGATTError(
423 thread_id, request_id, WebBluetoothError::DeviceNoLongerInRange)); 465 thread_id, request_id, WebBluetoothError::DeviceNoLongerInRange));
424 return; 466 return;
425 } 467 }
426 device->CreateGattConnection( 468 device->CreateGattConnection(
427 base::Bind(&BluetoothDispatcherHost::OnGATTConnectionCreated, 469 base::Bind(&BluetoothDispatcherHost::OnGATTConnectionCreated,
428 weak_ptr_factory_.GetWeakPtr(), thread_id, request_id, 470 weak_ptr_factory_.GetWeakPtr(), thread_id, request_id,
429 device_instance_id), 471 device_instance_id, start_time),
430 base::Bind(&BluetoothDispatcherHost::OnCreateGATTConnectionError, 472 base::Bind(&BluetoothDispatcherHost::OnCreateGATTConnectionError,
431 weak_ptr_factory_.GetWeakPtr(), thread_id, request_id, 473 weak_ptr_factory_.GetWeakPtr(), thread_id, request_id,
432 device_instance_id)); 474 device_instance_id, start_time));
433 } 475 }
434 476
435 void BluetoothDispatcherHost::OnGetPrimaryService( 477 void BluetoothDispatcherHost::OnGetPrimaryService(
436 int thread_id, 478 int thread_id,
437 int request_id, 479 int request_id,
438 const std::string& device_instance_id, 480 const std::string& device_instance_id,
439 const std::string& service_uuid) { 481 const std::string& service_uuid) {
440 DCHECK_CURRENTLY_ON(BrowserThread::UI); 482 DCHECK_CURRENTLY_ON(BrowserThread::UI);
441 RecordWebBluetoothFunctionCall(UMAWebBluetoothFunction::GET_PRIMARY_SERVICE); 483 RecordWebBluetoothFunctionCall(UMAWebBluetoothFunction::GET_PRIMARY_SERVICE);
442 484
(...skipping 278 matching lines...) Expand 10 before | Expand all | Expand 10 after
721 RecordRequestDeviceOutcome(UMARequestDeviceOutcome::DISCOVERY_STOP_FAILED); 763 RecordRequestDeviceOutcome(UMARequestDeviceOutcome::DISCOVERY_STOP_FAILED);
722 Send(new BluetoothMsg_RequestDeviceError( 764 Send(new BluetoothMsg_RequestDeviceError(
723 thread_id, request_id, WebBluetoothError::DiscoverySessionStopFailed)); 765 thread_id, request_id, WebBluetoothError::DiscoverySessionStopFailed));
724 request_device_sessions_.erase(std::make_pair(thread_id, request_id)); 766 request_device_sessions_.erase(std::make_pair(thread_id, request_id));
725 } 767 }
726 768
727 void BluetoothDispatcherHost::OnGATTConnectionCreated( 769 void BluetoothDispatcherHost::OnGATTConnectionCreated(
728 int thread_id, 770 int thread_id,
729 int request_id, 771 int request_id,
730 const std::string& device_instance_id, 772 const std::string& device_instance_id,
773 base::TimeTicks start_time,
731 scoped_ptr<device::BluetoothGattConnection> connection) { 774 scoped_ptr<device::BluetoothGattConnection> connection) {
732 // TODO(ortuno): Save the BluetoothGattConnection so we can disconnect 775 // TODO(ortuno): Save the BluetoothGattConnection so we can disconnect
733 // from it. 776 // from it.
777 RecordConnectGATTTimeSuccess(base::TimeTicks::Now() - start_time);
778 RecordConnectGATTOutcome(UMAConnectGATTOutcome::SUCCESS);
734 Send(new BluetoothMsg_ConnectGATTSuccess(thread_id, request_id, 779 Send(new BluetoothMsg_ConnectGATTSuccess(thread_id, request_id,
735 device_instance_id)); 780 device_instance_id));
736 } 781 }
737 782
738 void BluetoothDispatcherHost::OnCreateGATTConnectionError( 783 void BluetoothDispatcherHost::OnCreateGATTConnectionError(
739 int thread_id, 784 int thread_id,
740 int request_id, 785 int request_id,
741 const std::string& device_instance_id, 786 const std::string& device_instance_id,
787 base::TimeTicks start_time,
742 device::BluetoothDevice::ConnectErrorCode error_code) { 788 device::BluetoothDevice::ConnectErrorCode error_code) {
743 // There was an error creating the ATT Bearer so we reject with 789 // There was an error creating the ATT Bearer so we reject with
744 // NetworkError. 790 // NetworkError.
745 // https://webbluetoothchrome.github.io/web-bluetooth/#dom-bluetoothdevice-con nectgatt 791 // https://webbluetoothchrome.github.io/web-bluetooth/#dom-bluetoothdevice-con nectgatt
792 RecordConnectGATTTimeFailed(base::TimeTicks::Now() - start_time);
793 // RecordConnectGATTOutcome is called by TranslateConnectError.
746 Send(new BluetoothMsg_ConnectGATTError(thread_id, request_id, 794 Send(new BluetoothMsg_ConnectGATTError(thread_id, request_id,
747 TranslateConnectError(error_code))); 795 TranslateConnectError(error_code)));
748 } 796 }
749 797
750 void BluetoothDispatcherHost::OnServicesDiscovered( 798 void BluetoothDispatcherHost::OnServicesDiscovered(
751 int thread_id, 799 int thread_id,
752 int request_id, 800 int request_id,
753 const std::string& device_instance_id, 801 const std::string& device_instance_id,
754 const std::string& service_uuid) { 802 const std::string& service_uuid) {
755 DCHECK_CURRENTLY_ON(BrowserThread::UI); 803 DCHECK_CURRENTLY_ON(BrowserThread::UI);
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
804 852
805 void BluetoothDispatcherHost::OnWriteValueFailed( 853 void BluetoothDispatcherHost::OnWriteValueFailed(
806 int thread_id, 854 int thread_id,
807 int request_id, 855 int request_id,
808 device::BluetoothGattService::GattErrorCode error_code) { 856 device::BluetoothGattService::GattErrorCode error_code) {
809 Send(new BluetoothMsg_WriteCharacteristicValueError( 857 Send(new BluetoothMsg_WriteCharacteristicValueError(
810 thread_id, request_id, TranslateGATTError(error_code))); 858 thread_id, request_id, TranslateGATTError(error_code)));
811 } 859 }
812 860
813 } // namespace content 861 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/bluetooth/bluetooth_dispatcher_host.h ('k') | tools/metrics/histograms/histograms.xml » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698