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