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

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: 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 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 UMAConnectGATTOutcome {
115 SUCCESS,
116 NO_DEVICE,
117 UNKNOWN,
118 IN_PROGRESS,
119 FAILED,
120 AUTH_FAILED,
121 AUTH_CANCELED,
122 AUTH_REJECTED,
123 AUTH_TIMEOUT,
124 UNSUPPORTED_DEVICE,
125 // Note: Add new ConnectGATT outcomes immediately above this line. Make sure
126 // to update the enum list in tools/metrisc/histogram/histograms.xml
127 // accordingly.
128 COUNT
129 };
130
131 void RecordConnectGATTOutcome(UMAConnectGATTOutcome outcome) {
132 UMA_HISTOGRAM_ENUMERATION("Bluetooth.Web.ConnectGATT.Outcome",
133 static_cast<int>(outcome),
134 static_cast<int>(UMAConnectGATTOutcome::COUNT));
135 }
136
137 void RecordConnectGATTTimeSuccess(const base::TimeDelta& duration) {
138 UMA_HISTOGRAM_TIMES("Bluetooth.Web.ConnectGATT.TimeSuccess", duration);
Jeffrey Yasskin 2015/08/12 00:35:45 I'm a little worried that 10 seconds won't be enou
ortuno 2015/08/12 16:34:04 Done.
139 }
140
141 void RecordConnectGATTTimeFailed(const base::TimeDelta& duration) {
142 UMA_HISTOGRAM_TIMES("Bluetooth.Web.ConnectGATT.TimeFailed", duration);
143 }
144
114 enum class UMAWebBluetoothFunction { 145 enum class UMAWebBluetoothFunction {
115 REQUEST_DEVICE, 146 REQUEST_DEVICE,
116 CONNECT_GATT, 147 CONNECT_GATT,
117 GET_PRIMARY_SERVICE, 148 GET_PRIMARY_SERVICE,
118 GET_CHARACTERISTIC, 149 GET_CHARACTERISTIC,
119 CHARACTERISTIC_READ_VALUE, 150 CHARACTERISTIC_READ_VALUE,
120 CHARACTERISTIC_WRITE_VALUE, 151 CHARACTERISTIC_WRITE_VALUE,
121 // NOTE: Add new actions immediately above this line. Make sure to update the 152 // NOTE: Add new actions immediately above this line. Make sure to update the
122 // enum list in tools/metrics/histogram/histograms.xml accordingly. 153 // enum list in tools/metrics/histogram/histograms.xml accordingly.
123 COUNT 154 COUNT
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
164 195
165 void AddToHistogram(BluetoothGATTError error) { 196 void AddToHistogram(BluetoothGATTError error) {
166 UMA_HISTOGRAM_ENUMERATION("Bluetooth.GATTErrors", static_cast<int>(error), 197 UMA_HISTOGRAM_ENUMERATION("Bluetooth.GATTErrors", static_cast<int>(error),
167 static_cast<int>(BluetoothGATTError::MAX_ERROR)); 198 static_cast<int>(BluetoothGATTError::MAX_ERROR));
168 } 199 }
169 200
170 WebBluetoothError TranslateConnectError( 201 WebBluetoothError TranslateConnectError(
171 device::BluetoothDevice::ConnectErrorCode error_code) { 202 device::BluetoothDevice::ConnectErrorCode error_code) {
172 switch (error_code) { 203 switch (error_code) {
173 case device::BluetoothDevice::ERROR_UNKNOWN: 204 case device::BluetoothDevice::ERROR_UNKNOWN:
205 RecordConnectGATTOutcome(UMAConnectGATTOutcome::UNKNOWN);
174 return WebBluetoothError::ConnectUnknownError; 206 return WebBluetoothError::ConnectUnknownError;
175 case device::BluetoothDevice::ERROR_INPROGRESS: 207 case device::BluetoothDevice::ERROR_INPROGRESS:
208 RecordConnectGATTOutcome(UMAConnectGATTOutcome::IN_PROGRESS);
176 return WebBluetoothError::ConnectAlreadyInProgress; 209 return WebBluetoothError::ConnectAlreadyInProgress;
177 case device::BluetoothDevice::ERROR_FAILED: 210 case device::BluetoothDevice::ERROR_FAILED:
211 RecordConnectGATTOutcome(UMAConnectGATTOutcome::FAILED);
178 return WebBluetoothError::ConnectUnknownFailure; 212 return WebBluetoothError::ConnectUnknownFailure;
179 case device::BluetoothDevice::ERROR_AUTH_FAILED: 213 case device::BluetoothDevice::ERROR_AUTH_FAILED:
214 RecordConnectGATTOutcome(UMAConnectGATTOutcome::AUTH_FAILED);
180 return WebBluetoothError::ConnectAuthFailed; 215 return WebBluetoothError::ConnectAuthFailed;
181 case device::BluetoothDevice::ERROR_AUTH_CANCELED: 216 case device::BluetoothDevice::ERROR_AUTH_CANCELED:
217 RecordConnectGATTOutcome(UMAConnectGATTOutcome::AUTH_CANCELED);
182 return WebBluetoothError::ConnectAuthCanceled; 218 return WebBluetoothError::ConnectAuthCanceled;
183 case device::BluetoothDevice::ERROR_AUTH_REJECTED: 219 case device::BluetoothDevice::ERROR_AUTH_REJECTED:
220 RecordConnectGATTOutcome(UMAConnectGATTOutcome::AUTH_REJECTED);
184 return WebBluetoothError::ConnectAuthRejected; 221 return WebBluetoothError::ConnectAuthRejected;
185 case device::BluetoothDevice::ERROR_AUTH_TIMEOUT: 222 case device::BluetoothDevice::ERROR_AUTH_TIMEOUT:
223 RecordConnectGATTOutcome(UMAConnectGATTOutcome::AUTH_TIMEOUT);
186 return WebBluetoothError::ConnectAuthTimeout; 224 return WebBluetoothError::ConnectAuthTimeout;
187 case device::BluetoothDevice::ERROR_UNSUPPORTED_DEVICE: 225 case device::BluetoothDevice::ERROR_UNSUPPORTED_DEVICE:
226 RecordConnectGATTOutcome(UMAConnectGATTOutcome::UNSUPPORTED_DEVICE);
188 return WebBluetoothError::ConnectUnsupportedDevice; 227 return WebBluetoothError::ConnectUnsupportedDevice;
189 } 228 }
190 NOTREACHED(); 229 NOTREACHED();
191 return WebBluetoothError::UntranslatedConnectErrorCode; 230 return WebBluetoothError::UntranslatedConnectErrorCode;
192 } 231 }
193 232
194 blink::WebBluetoothError TranslateGATTError( 233 blink::WebBluetoothError TranslateGATTError(
195 BluetoothGattService::GattErrorCode error_code) { 234 BluetoothGattService::GattErrorCode error_code) {
196 switch (error_code) { 235 switch (error_code) {
197 case BluetoothGattService::GATT_ERROR_UNKNOWN: 236 case BluetoothGattService::GATT_ERROR_UNKNOWN:
(...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after
406 const std::string& device_instance_id) { 445 const std::string& device_instance_id) {
407 DCHECK_CURRENTLY_ON(BrowserThread::UI); 446 DCHECK_CURRENTLY_ON(BrowserThread::UI);
408 RecordWebBluetoothFunctionCall(UMAWebBluetoothFunction::CONNECT_GATT); 447 RecordWebBluetoothFunctionCall(UMAWebBluetoothFunction::CONNECT_GATT);
409 448
410 // TODO(ortuno): Right now it's pointless to check if the domain has access to 449 // TODO(ortuno): Right now it's pointless to check if the domain has access to
411 // the device, because any domain can connect to any device. But once 450 // the device, because any domain can connect to any device. But once
412 // permissions are implemented we should check that the domain has access to 451 // permissions are implemented we should check that the domain has access to
413 // the device. https://crbug.com/484745 452 // the device. https://crbug.com/484745
414 device::BluetoothDevice* device = adapter_->GetDevice(device_instance_id); 453 device::BluetoothDevice* device = adapter_->GetDevice(device_instance_id);
415 if (device == nullptr) { // See "NETWORK_ERROR Note" above. 454 if (device == nullptr) { // See "NETWORK_ERROR Note" above.
455 RecordConnectGATTOutcome(UMAConnectGATTOutcome::NO_DEVICE);
456 VLOG(1) << "Bluetooth Device no longer in range.";
416 Send(new BluetoothMsg_ConnectGATTError( 457 Send(new BluetoothMsg_ConnectGATTError(
417 thread_id, request_id, WebBluetoothError::DeviceNoLongerInRange)); 458 thread_id, request_id, WebBluetoothError::DeviceNoLongerInRange));
418 return; 459 return;
419 } 460 }
420 device->CreateGattConnection( 461 device->CreateGattConnection(
421 base::Bind(&BluetoothDispatcherHost::OnGATTConnectionCreated, 462 base::Bind(&BluetoothDispatcherHost::OnGATTConnectionCreated,
422 weak_ptr_factory_.GetWeakPtr(), thread_id, request_id, 463 weak_ptr_factory_.GetWeakPtr(), thread_id, request_id,
423 device_instance_id), 464 device_instance_id, base::TimeTicks::Now()),
Jeffrey Yasskin 2015/08/12 00:35:45 Measure the starting time once at the beginning of
ortuno 2015/08/12 16:34:04 Done.
424 base::Bind(&BluetoothDispatcherHost::OnCreateGATTConnectionError, 465 base::Bind(&BluetoothDispatcherHost::OnCreateGATTConnectionError,
425 weak_ptr_factory_.GetWeakPtr(), thread_id, request_id, 466 weak_ptr_factory_.GetWeakPtr(), thread_id, request_id,
426 device_instance_id)); 467 device_instance_id, base::TimeTicks::Now()));
427 } 468 }
428 469
429 void BluetoothDispatcherHost::OnGetPrimaryService( 470 void BluetoothDispatcherHost::OnGetPrimaryService(
430 int thread_id, 471 int thread_id,
431 int request_id, 472 int request_id,
432 const std::string& device_instance_id, 473 const std::string& device_instance_id,
433 const std::string& service_uuid) { 474 const std::string& service_uuid) {
434 DCHECK_CURRENTLY_ON(BrowserThread::UI); 475 DCHECK_CURRENTLY_ON(BrowserThread::UI);
435 RecordWebBluetoothFunctionCall(UMAWebBluetoothFunction::GET_PRIMARY_SERVICE); 476 RecordWebBluetoothFunctionCall(UMAWebBluetoothFunction::GET_PRIMARY_SERVICE);
436 477
(...skipping 278 matching lines...) Expand 10 before | Expand all | Expand 10 after
715 RecordRequestDeviceOutcome(UMARequestDeviceOutcome::DISCOVERY_STOP_FAILED); 756 RecordRequestDeviceOutcome(UMARequestDeviceOutcome::DISCOVERY_STOP_FAILED);
716 Send(new BluetoothMsg_RequestDeviceError( 757 Send(new BluetoothMsg_RequestDeviceError(
717 thread_id, request_id, WebBluetoothError::DiscoverySessionStopFailed)); 758 thread_id, request_id, WebBluetoothError::DiscoverySessionStopFailed));
718 request_device_sessions_.erase(std::make_pair(thread_id, request_id)); 759 request_device_sessions_.erase(std::make_pair(thread_id, request_id));
719 } 760 }
720 761
721 void BluetoothDispatcherHost::OnGATTConnectionCreated( 762 void BluetoothDispatcherHost::OnGATTConnectionCreated(
722 int thread_id, 763 int thread_id,
723 int request_id, 764 int request_id,
724 const std::string& device_instance_id, 765 const std::string& device_instance_id,
766 base::TimeTicks start_time,
725 scoped_ptr<device::BluetoothGattConnection> connection) { 767 scoped_ptr<device::BluetoothGattConnection> connection) {
726 // TODO(ortuno): Save the BluetoothGattConnection so we can disconnect 768 // TODO(ortuno): Save the BluetoothGattConnection so we can disconnect
727 // from it. 769 // from it.
770 RecordConnectGATTTimeSuccess(base::TimeTicks::Now() - start_time);
771 RecordConnectGATTOutcome(UMAConnectGATTOutcome::SUCCESS);
728 Send(new BluetoothMsg_ConnectGATTSuccess(thread_id, request_id, 772 Send(new BluetoothMsg_ConnectGATTSuccess(thread_id, request_id,
729 device_instance_id)); 773 device_instance_id));
730 } 774 }
731 775
732 void BluetoothDispatcherHost::OnCreateGATTConnectionError( 776 void BluetoothDispatcherHost::OnCreateGATTConnectionError(
733 int thread_id, 777 int thread_id,
734 int request_id, 778 int request_id,
735 const std::string& device_instance_id, 779 const std::string& device_instance_id,
780 base::TimeTicks start_time,
736 device::BluetoothDevice::ConnectErrorCode error_code) { 781 device::BluetoothDevice::ConnectErrorCode error_code) {
737 // There was an error creating the ATT Bearer so we reject with 782 // There was an error creating the ATT Bearer so we reject with
738 // NetworkError. 783 // NetworkError.
739 // https://webbluetoothchrome.github.io/web-bluetooth/#dom-bluetoothdevice-con nectgatt 784 // https://webbluetoothchrome.github.io/web-bluetooth/#dom-bluetoothdevice-con nectgatt
785 RecordConnectGATTTimeFailed(base::TimeTicks::Now() - start_time);
740 Send(new BluetoothMsg_ConnectGATTError(thread_id, request_id, 786 Send(new BluetoothMsg_ConnectGATTError(thread_id, request_id,
Jeffrey Yasskin 2015/08/12 00:35:45 Comment that RecordConnectGATTOutcome is called by
ortuno 2015/08/12 16:34:04 Done.
741 TranslateConnectError(error_code))); 787 TranslateConnectError(error_code)));
742 } 788 }
743 789
744 void BluetoothDispatcherHost::OnServicesDiscovered( 790 void BluetoothDispatcherHost::OnServicesDiscovered(
745 int thread_id, 791 int thread_id,
746 int request_id, 792 int request_id,
747 const std::string& device_instance_id, 793 const std::string& device_instance_id,
748 const std::string& service_uuid) { 794 const std::string& service_uuid) {
749 DCHECK_CURRENTLY_ON(BrowserThread::UI); 795 DCHECK_CURRENTLY_ON(BrowserThread::UI);
750 796
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
798 844
799 void BluetoothDispatcherHost::OnWriteValueFailed( 845 void BluetoothDispatcherHost::OnWriteValueFailed(
800 int thread_id, 846 int thread_id,
801 int request_id, 847 int request_id,
802 device::BluetoothGattService::GattErrorCode error_code) { 848 device::BluetoothGattService::GattErrorCode error_code) {
803 Send(new BluetoothMsg_WriteCharacteristicValueError( 849 Send(new BluetoothMsg_WriteCharacteristicValueError(
804 thread_id, request_id, TranslateGATTError(error_code))); 850 thread_id, request_id, TranslateGATTError(error_code)));
805 } 851 }
806 852
807 } // namespace content 853 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698