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

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

Issue 1261593004: bluetooth: Add histograms and logging for requestDevice() (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@bluetooth-adapter-ff
Patch Set: Change macro 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
« no previous file with comments | « no previous file | tools/metrics/histograms/histograms.xml » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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
11 #include "content/browser/bluetooth/bluetooth_dispatcher_host.h" 11 #include "content/browser/bluetooth/bluetooth_dispatcher_host.h"
12 12
13 #include "base/hash.h"
13 #include "base/metrics/histogram.h" 14 #include "base/metrics/histogram.h"
Alexei Svitkine (slow) 2015/08/11 20:40:23 Nit: Change this to histogram_macros.h
ortuno 2015/08/11 20:46:48 Done.
15 #include "base/metrics/sparse_histogram.h"
16 #include "base/strings/string_util.h"
14 #include "base/strings/utf_string_conversions.h" 17 #include "base/strings/utf_string_conversions.h"
15 #include "content/browser/bad_message.h" 18 #include "content/browser/bad_message.h"
16 #include "content/browser/frame_host/render_frame_host_impl.h" 19 #include "content/browser/frame_host/render_frame_host_impl.h"
17 #include "content/common/bluetooth/bluetooth_messages.h" 20 #include "content/common/bluetooth/bluetooth_messages.h"
18 #include "device/bluetooth/bluetooth_adapter.h" 21 #include "device/bluetooth/bluetooth_adapter.h"
19 #include "device/bluetooth/bluetooth_adapter_factory.h" 22 #include "device/bluetooth/bluetooth_adapter_factory.h"
20 #include "device/bluetooth/bluetooth_device.h" 23 #include "device/bluetooth/bluetooth_device.h"
21 #include "device/bluetooth/bluetooth_discovery_session.h" 24 #include "device/bluetooth/bluetooth_discovery_session.h"
22 #include "device/bluetooth/bluetooth_gatt_characteristic.h" 25 #include "device/bluetooth/bluetooth_gatt_characteristic.h"
23 #include "device/bluetooth/bluetooth_gatt_service.h" 26 #include "device/bluetooth/bluetooth_gatt_service.h"
(...skipping 27 matching lines...) Expand all
51 NO_MATCHING_DEVICES_FOUND = 5, 54 NO_MATCHING_DEVICES_FOUND = 5,
52 BLUETOOTH_ADAPTER_NOT_PRESENT = 6, 55 BLUETOOTH_ADAPTER_NOT_PRESENT = 6,
53 BLUETOOTH_ADAPTER_OFF = 7, 56 BLUETOOTH_ADAPTER_OFF = 7,
54 // NOTE: Add new requestDevice() outcomes immediately above this line. Make 57 // NOTE: Add new requestDevice() outcomes immediately above this line. Make
55 // sure to update the enum list in 58 // sure to update the enum list in
56 // tools/metrics/histogram/histograms.xml accordingly. 59 // tools/metrics/histogram/histograms.xml accordingly.
57 COUNT 60 COUNT
58 }; 61 };
59 62
60 void RecordRequestDeviceOutcome(UMARequestDeviceOutcome outcome) { 63 void RecordRequestDeviceOutcome(UMARequestDeviceOutcome outcome) {
61 UMA_HISTOGRAM_ENUMERATION("Bluetooth.RequestDevice.Outcome", 64 UMA_HISTOGRAM_ENUMERATION("Bluetooth.Web.RequestDevice.Outcome",
62 static_cast<int>(outcome), 65 static_cast<int>(outcome),
63 static_cast<int>(UMARequestDeviceOutcome::COUNT)); 66 static_cast<int>(UMARequestDeviceOutcome::COUNT));
64 } 67 }
65 68
69 int HashUUID(const BluetoothUUID& service) {
70 uint32 data = base::Hash(service.canonical_value());
71
72 // Strip off the signed bit because UMA doesn't support negative values,
73 // but takes a signed int as input.
74 return static_cast<int>(data & 0x7fffffff);
75 }
76
77 void RecordRequestDeviceFilters(
78 const std::vector<content::BluetoothScanFilter>& filters) {
79 UMA_HISTOGRAM_COUNTS("Bluetooth.Web.RequestDevice.Filters.Count",
80 filters.size());
81 for (const content::BluetoothScanFilter& filter : filters) {
82 UMA_HISTOGRAM_COUNTS("Bluetooth.Web.RequestDevice.FilterSize",
83 filter.services.size());
84 for (const BluetoothUUID& service : filter.services) {
85 UMA_HISTOGRAM_SPARSE_SLOWLY(
86 "Bluetooth.Web.RequestDevice.Filters.Services", HashUUID(service));
87 }
88 }
89 }
90
91 void RecordRequestDeviceOptionalServices(
92 const std::vector<BluetoothUUID>& optional_services) {
93 UMA_HISTOGRAM_COUNTS("Bluetooth.Web.RequestDevice.OptionalServices.Count",
94 optional_services.size());
95 for (const BluetoothUUID& service : optional_services) {
96 UMA_HISTOGRAM_SPARSE_SLOWLY(
97 "Bluetooth.Web.RequestDevice.OptionalServices.Services",
98 HashUUID(service));
99 }
100 }
101
102 void RecordUnionOfServices(
103 const std::vector<content::BluetoothScanFilter>& filters,
104 const std::vector<BluetoothUUID>& optional_services) {
105 std::set<BluetoothUUID> union_of_services(optional_services.begin(),
106 optional_services.end());
107
108 for (const content::BluetoothScanFilter& filter : filters)
109 union_of_services.insert(filter.services.begin(), filter.services.end());
110
111 UMA_HISTOGRAM_COUNTS("Bluetooth.Web.RequestDevice.UnionOfServices.Count",
112 union_of_services.size());
113 }
114
66 enum class UMAWebBluetoothFunction { 115 enum class UMAWebBluetoothFunction {
67 REQUEST_DEVICE, 116 REQUEST_DEVICE,
68 CONNECT_GATT, 117 CONNECT_GATT,
69 GET_PRIMARY_SERVICE, 118 GET_PRIMARY_SERVICE,
70 GET_CHARACTERISTIC, 119 GET_CHARACTERISTIC,
71 CHARACTERISTIC_READ_VALUE, 120 CHARACTERISTIC_READ_VALUE,
72 CHARACTERISTIC_WRITE_VALUE, 121 CHARACTERISTIC_WRITE_VALUE,
73 // NOTE: Add new actions immediately above this line. Make sure to update the 122 // NOTE: Add new actions immediately above this line. Make sure to update the
74 // enum list in tools/metrics/histogram/histograms.xml accordingly. 123 // enum list in tools/metrics/histogram/histograms.xml accordingly.
75 COUNT 124 COUNT
(...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after
264 } 313 }
265 314
266 void BluetoothDispatcherHost::OnRequestDevice( 315 void BluetoothDispatcherHost::OnRequestDevice(
267 int thread_id, 316 int thread_id,
268 int request_id, 317 int request_id,
269 int frame_routing_id, 318 int frame_routing_id,
270 const std::vector<BluetoothScanFilter>& filters, 319 const std::vector<BluetoothScanFilter>& filters,
271 const std::vector<BluetoothUUID>& optional_services) { 320 const std::vector<BluetoothUUID>& optional_services) {
272 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 321 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
273 RecordWebBluetoothFunctionCall(UMAWebBluetoothFunction::REQUEST_DEVICE); 322 RecordWebBluetoothFunctionCall(UMAWebBluetoothFunction::REQUEST_DEVICE);
323 RecordRequestDeviceFilters(filters);
324 RecordRequestDeviceOptionalServices(optional_services);
325 RecordUnionOfServices(filters, optional_services);
326
327 VLOG(1) << "requestDevice called with the following filters: ";
328 for (const BluetoothScanFilter& filter : filters) {
329 VLOG(1) << "[";
330 for (const BluetoothUUID& service : filter.services)
331 VLOG(1) << "\t" << service.value();
332 VLOG(1) << "]";
333 }
334
335 VLOG(1) << "requestDevice called with the following optional services: ";
336 for (const BluetoothUUID& service : optional_services)
337 VLOG(1) << "\t" << service.value();
274 338
275 RenderFrameHostImpl* render_frame_host = 339 RenderFrameHostImpl* render_frame_host =
276 RenderFrameHostImpl::FromID(render_process_id_, frame_routing_id); 340 RenderFrameHostImpl::FromID(render_process_id_, frame_routing_id);
277 341
278 if (!render_frame_host) { 342 if (!render_frame_host) {
279 DLOG(WARNING) 343 DLOG(WARNING)
280 << "Got a requestDevice IPC without a matching RenderFrameHost: " 344 << "Got a requestDevice IPC without a matching RenderFrameHost: "
281 << render_process_id_ << ", " << frame_routing_id; 345 << render_process_id_ << ", " << frame_routing_id;
282 RecordRequestDeviceOutcome(UMARequestDeviceOutcome::NO_RENDER_FRAME); 346 RecordRequestDeviceOutcome(UMARequestDeviceOutcome::NO_RENDER_FRAME);
283 Send(new BluetoothMsg_RequestDeviceError( 347 Send(new BluetoothMsg_RequestDeviceError(
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
322 request_device_sessions_.erase(std::make_pair(thread_id, request_id)); 386 request_device_sessions_.erase(std::make_pair(thread_id, request_id));
323 return; 387 return;
324 } 388 }
325 adapter_->StartDiscoverySessionWithFilter( 389 adapter_->StartDiscoverySessionWithFilter(
326 ComputeScanFilter(filters), 390 ComputeScanFilter(filters),
327 base::Bind(&BluetoothDispatcherHost::OnDiscoverySessionStarted, 391 base::Bind(&BluetoothDispatcherHost::OnDiscoverySessionStarted,
328 weak_ptr_factory_.GetWeakPtr(), thread_id, request_id), 392 weak_ptr_factory_.GetWeakPtr(), thread_id, request_id),
329 base::Bind(&BluetoothDispatcherHost::OnDiscoverySessionStartedError, 393 base::Bind(&BluetoothDispatcherHost::OnDiscoverySessionStartedError,
330 weak_ptr_factory_.GetWeakPtr(), thread_id, request_id)); 394 weak_ptr_factory_.GetWeakPtr(), thread_id, request_id));
331 } else { 395 } else {
332 DLOG(WARNING) << "No BluetoothAdapter. Can't serve requestDevice."; 396 VLOG(1) << "No BluetoothAdapter. Can't serve requestDevice.";
333 RecordRequestDeviceOutcome(UMARequestDeviceOutcome::NO_BLUETOOTH_ADAPTER); 397 RecordRequestDeviceOutcome(UMARequestDeviceOutcome::NO_BLUETOOTH_ADAPTER);
334 Send(new BluetoothMsg_RequestDeviceError( 398 Send(new BluetoothMsg_RequestDeviceError(
335 thread_id, request_id, WebBluetoothError::NoBluetoothAdapter)); 399 thread_id, request_id, WebBluetoothError::NoBluetoothAdapter));
336 } 400 }
337 return; 401 return;
338 } 402 }
339 403
340 void BluetoothDispatcherHost::OnConnectGATT( 404 void BluetoothDispatcherHost::OnConnectGATT(
341 int thread_id, 405 int thread_id,
342 int request_id, 406 int request_id,
(...skipping 289 matching lines...) Expand 10 before | Expand all | Expand 10 after
632 device->GetUUIDs())); // uuids 696 device->GetUUIDs())); // uuids
633 RecordRequestDeviceOutcome(UMARequestDeviceOutcome::SUCCESS); 697 RecordRequestDeviceOutcome(UMARequestDeviceOutcome::SUCCESS);
634 Send(new BluetoothMsg_RequestDeviceSuccess(thread_id, request_id, 698 Send(new BluetoothMsg_RequestDeviceSuccess(thread_id, request_id,
635 device_ipc)); 699 device_ipc));
636 request_device_sessions_.erase(session); 700 request_device_sessions_.erase(session);
637 return; 701 return;
638 } 702 }
639 } 703 }
640 RecordRequestDeviceOutcome( 704 RecordRequestDeviceOutcome(
641 UMARequestDeviceOutcome::NO_MATCHING_DEVICES_FOUND); 705 UMARequestDeviceOutcome::NO_MATCHING_DEVICES_FOUND);
706 VLOG(1) << "No matching Bluetooth Devices found";
642 Send(new BluetoothMsg_RequestDeviceError(thread_id, request_id, 707 Send(new BluetoothMsg_RequestDeviceError(thread_id, request_id,
643 WebBluetoothError::NoDevicesFound)); 708 WebBluetoothError::NoDevicesFound));
644 request_device_sessions_.erase(session); 709 request_device_sessions_.erase(session);
645 } 710 }
646 711
647 void BluetoothDispatcherHost::OnDiscoverySessionStoppedError(int thread_id, 712 void BluetoothDispatcherHost::OnDiscoverySessionStoppedError(int thread_id,
648 int request_id) { 713 int request_id) {
649 DCHECK_CURRENTLY_ON(BrowserThread::UI); 714 DCHECK_CURRENTLY_ON(BrowserThread::UI);
650 DLOG(WARNING) << "BluetoothDispatcherHost::OnDiscoverySessionStoppedError"; 715 DLOG(WARNING) << "BluetoothDispatcherHost::OnDiscoverySessionStoppedError";
651 RecordRequestDeviceOutcome(UMARequestDeviceOutcome::DISCOVERY_STOP_FAILED); 716 RecordRequestDeviceOutcome(UMARequestDeviceOutcome::DISCOVERY_STOP_FAILED);
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
734 799
735 void BluetoothDispatcherHost::OnWriteValueFailed( 800 void BluetoothDispatcherHost::OnWriteValueFailed(
736 int thread_id, 801 int thread_id,
737 int request_id, 802 int request_id,
738 device::BluetoothGattService::GattErrorCode error_code) { 803 device::BluetoothGattService::GattErrorCode error_code) {
739 Send(new BluetoothMsg_WriteCharacteristicValueError( 804 Send(new BluetoothMsg_WriteCharacteristicValueError(
740 thread_id, request_id, TranslateGATTError(error_code))); 805 thread_id, request_id, TranslateGATTError(error_code)));
741 } 806 }
742 807
743 } // namespace content 808 } // namespace content
OLDNEW
« no previous file with comments | « no previous file | tools/metrics/histograms/histograms.xml » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698