Chromium Code Reviews| Index: content/browser/bluetooth/bluetooth_dispatcher_host.cc |
| diff --git a/content/browser/bluetooth/bluetooth_dispatcher_host.cc b/content/browser/bluetooth/bluetooth_dispatcher_host.cc |
| index d512ffb2ba8c72399ebf3afc622ac1001f89f0de..017f8564e38ce995b813026476d2ec06365be9cb 100644 |
| --- a/content/browser/bluetooth/bluetooth_dispatcher_host.cc |
| +++ b/content/browser/bluetooth/bluetooth_dispatcher_host.cc |
| @@ -10,7 +10,10 @@ |
| #include "content/browser/bluetooth/bluetooth_dispatcher_host.h" |
| +#include "base/hash.h" |
| #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.
|
| +#include "base/metrics/sparse_histogram.h" |
| +#include "base/strings/string_util.h" |
| #include "base/strings/utf_string_conversions.h" |
| #include "content/browser/bad_message.h" |
| #include "content/browser/frame_host/render_frame_host_impl.h" |
| @@ -58,11 +61,57 @@ enum class UMARequestDeviceOutcome { |
| }; |
| void RecordRequestDeviceOutcome(UMARequestDeviceOutcome outcome) { |
| - UMA_HISTOGRAM_ENUMERATION("Bluetooth.RequestDevice.Outcome", |
| + UMA_HISTOGRAM_ENUMERATION("Bluetooth.Web.RequestDevice.Outcome", |
| static_cast<int>(outcome), |
| static_cast<int>(UMARequestDeviceOutcome::COUNT)); |
| } |
| +int HashUUID(const BluetoothUUID& service) { |
| + uint32 data = base::Hash(service.canonical_value()); |
| + |
| + // Strip off the signed bit because UMA doesn't support negative values, |
| + // but takes a signed int as input. |
| + return static_cast<int>(data & 0x7fffffff); |
| +} |
| + |
| +void RecordRequestDeviceFilters( |
| + const std::vector<content::BluetoothScanFilter>& filters) { |
| + UMA_HISTOGRAM_COUNTS("Bluetooth.Web.RequestDevice.Filters.Count", |
| + filters.size()); |
| + for (const content::BluetoothScanFilter& filter : filters) { |
| + UMA_HISTOGRAM_COUNTS("Bluetooth.Web.RequestDevice.FilterSize", |
| + filter.services.size()); |
| + for (const BluetoothUUID& service : filter.services) { |
| + UMA_HISTOGRAM_SPARSE_SLOWLY( |
| + "Bluetooth.Web.RequestDevice.Filters.Services", HashUUID(service)); |
| + } |
| + } |
| +} |
| + |
| +void RecordRequestDeviceOptionalServices( |
| + const std::vector<BluetoothUUID>& optional_services) { |
| + UMA_HISTOGRAM_COUNTS("Bluetooth.Web.RequestDevice.OptionalServices.Count", |
| + optional_services.size()); |
| + for (const BluetoothUUID& service : optional_services) { |
| + UMA_HISTOGRAM_SPARSE_SLOWLY( |
| + "Bluetooth.Web.RequestDevice.OptionalServices.Services", |
| + HashUUID(service)); |
| + } |
| +} |
| + |
| +void RecordUnionOfServices( |
| + const std::vector<content::BluetoothScanFilter>& filters, |
| + const std::vector<BluetoothUUID>& optional_services) { |
| + std::set<BluetoothUUID> union_of_services(optional_services.begin(), |
| + optional_services.end()); |
| + |
| + for (const content::BluetoothScanFilter& filter : filters) |
| + union_of_services.insert(filter.services.begin(), filter.services.end()); |
| + |
| + UMA_HISTOGRAM_COUNTS("Bluetooth.Web.RequestDevice.UnionOfServices.Count", |
| + union_of_services.size()); |
| +} |
| + |
| enum class UMAWebBluetoothFunction { |
| REQUEST_DEVICE, |
| CONNECT_GATT, |
| @@ -271,6 +320,21 @@ void BluetoothDispatcherHost::OnRequestDevice( |
| const std::vector<BluetoothUUID>& optional_services) { |
| DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| RecordWebBluetoothFunctionCall(UMAWebBluetoothFunction::REQUEST_DEVICE); |
| + RecordRequestDeviceFilters(filters); |
| + RecordRequestDeviceOptionalServices(optional_services); |
| + RecordUnionOfServices(filters, optional_services); |
| + |
| + VLOG(1) << "requestDevice called with the following filters: "; |
| + for (const BluetoothScanFilter& filter : filters) { |
| + VLOG(1) << "["; |
| + for (const BluetoothUUID& service : filter.services) |
| + VLOG(1) << "\t" << service.value(); |
| + VLOG(1) << "]"; |
| + } |
| + |
| + VLOG(1) << "requestDevice called with the following optional services: "; |
| + for (const BluetoothUUID& service : optional_services) |
| + VLOG(1) << "\t" << service.value(); |
| RenderFrameHostImpl* render_frame_host = |
| RenderFrameHostImpl::FromID(render_process_id_, frame_routing_id); |
| @@ -329,7 +393,7 @@ void BluetoothDispatcherHost::OnRequestDevice( |
| base::Bind(&BluetoothDispatcherHost::OnDiscoverySessionStartedError, |
| weak_ptr_factory_.GetWeakPtr(), thread_id, request_id)); |
| } else { |
| - DLOG(WARNING) << "No BluetoothAdapter. Can't serve requestDevice."; |
| + VLOG(1) << "No BluetoothAdapter. Can't serve requestDevice."; |
| RecordRequestDeviceOutcome(UMARequestDeviceOutcome::NO_BLUETOOTH_ADAPTER); |
| Send(new BluetoothMsg_RequestDeviceError( |
| thread_id, request_id, WebBluetoothError::NoBluetoothAdapter)); |
| @@ -639,6 +703,7 @@ void BluetoothDispatcherHost::OnDiscoverySessionStopped(int thread_id, |
| } |
| RecordRequestDeviceOutcome( |
| UMARequestDeviceOutcome::NO_MATCHING_DEVICES_FOUND); |
| + VLOG(1) << "No matching Bluetooth Devices found"; |
| Send(new BluetoothMsg_RequestDeviceError(thread_id, request_id, |
| WebBluetoothError::NoDevicesFound)); |
| request_device_sessions_.erase(session); |