OLD | NEW |
---|---|
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 #include "content/browser/bluetooth/bluetooth_metrics.h" | 5 #include "content/browser/bluetooth/bluetooth_metrics.h" |
6 | 6 |
7 #include <stdint.h> | 7 #include <stdint.h> |
8 | 8 |
9 #include <map> | 9 #include <map> |
10 #include <set> | 10 #include <set> |
11 #include "base/hash.h" | 11 #include "base/hash.h" |
12 #include "base/metrics/histogram_macros.h" | 12 #include "base/metrics/histogram_macros.h" |
13 #include "base/metrics/sparse_histogram.h" | 13 #include "base/metrics/sparse_histogram.h" |
14 #include "content/common/bluetooth/bluetooth_scan_filter.h" | |
15 #include "device/bluetooth/bluetooth_uuid.h" | 14 #include "device/bluetooth/bluetooth_uuid.h" |
16 | 15 |
17 using device::BluetoothUUID; | 16 using device::BluetoothUUID; |
18 | 17 |
19 namespace { | 18 namespace { |
20 | 19 |
21 // Generates a hash from a canonical UUID string suitable for | 20 // Generates a hash from a canonical UUID string suitable for |
22 // UMA_HISTOGRAM_SPARSE_SLOWLY (positive int). | 21 // UMA_HISTOGRAM_SPARSE_SLOWLY (positive int). |
23 // | 22 // |
24 // Hash values can be produced manually using tool: bluetooth_metrics_hash. | 23 // Hash values can be produced manually using tool: bluetooth_metrics_hash. |
(...skipping 23 matching lines...) Expand all Loading... | |
48 | 47 |
49 // requestDevice() | 48 // requestDevice() |
50 | 49 |
51 void RecordRequestDeviceOutcome(UMARequestDeviceOutcome outcome) { | 50 void RecordRequestDeviceOutcome(UMARequestDeviceOutcome outcome) { |
52 UMA_HISTOGRAM_ENUMERATION("Bluetooth.Web.RequestDevice.Outcome", | 51 UMA_HISTOGRAM_ENUMERATION("Bluetooth.Web.RequestDevice.Outcome", |
53 static_cast<int>(outcome), | 52 static_cast<int>(outcome), |
54 static_cast<int>(UMARequestDeviceOutcome::COUNT)); | 53 static_cast<int>(UMARequestDeviceOutcome::COUNT)); |
55 } | 54 } |
56 | 55 |
57 static void RecordRequestDeviceFilters( | 56 static void RecordRequestDeviceFilters( |
58 const std::vector<content::BluetoothScanFilter>& filters) { | 57 const mojo::Array<blink::mojom::WebBluetoothScanFilterPtr>& filters) { |
59 UMA_HISTOGRAM_COUNTS_100("Bluetooth.Web.RequestDevice.Filters.Count", | 58 UMA_HISTOGRAM_COUNTS_100("Bluetooth.Web.RequestDevice.Filters.Count", |
60 filters.size()); | 59 filters.size()); |
61 for (const content::BluetoothScanFilter& filter : filters) { | 60 for (const auto& filter : filters) { |
62 UMA_HISTOGRAM_COUNTS_100("Bluetooth.Web.RequestDevice.FilterSize", | 61 UMA_HISTOGRAM_COUNTS_100("Bluetooth.Web.RequestDevice.FilterSize", |
63 filter.services.size()); | 62 filter->services.size()); |
Jeffrey Yasskin
2016/05/13 04:41:59
I'm worried about these unchecked dereferences. It
ortuno
2016/05/13 20:11:18
Mojo actually guarantees that members won't be nul
Jeffrey Yasskin
2016/05/13 21:36:55
Oh, I see. It just doesn't change the type of the
| |
64 for (const BluetoothUUID& service : filter.services) { | 63 for (const std::string& service : filter->services) { |
65 // TODO(ortuno): Use a macro to histogram strings. | 64 // TODO(ortuno): Use a macro to histogram strings. |
66 // http://crbug.com/520284 | 65 // http://crbug.com/520284 |
67 UMA_HISTOGRAM_SPARSE_SLOWLY( | 66 UMA_HISTOGRAM_SPARSE_SLOWLY( |
68 "Bluetooth.Web.RequestDevice.Filters.Services", | 67 "Bluetooth.Web.RequestDevice.Filters.Services", HashUUID(service)); |
69 HashUUID(service.canonical_value())); | |
70 } | 68 } |
71 } | 69 } |
72 } | 70 } |
73 | 71 |
74 static void RecordRequestDeviceOptionalServices( | 72 static void RecordRequestDeviceOptionalServices( |
75 const std::vector<BluetoothUUID>& optional_services) { | 73 const mojo::Array<mojo::String>& optional_services) { |
76 UMA_HISTOGRAM_COUNTS_100("Bluetooth.Web.RequestDevice.OptionalServices.Count", | 74 UMA_HISTOGRAM_COUNTS_100("Bluetooth.Web.RequestDevice.OptionalServices.Count", |
77 optional_services.size()); | 75 optional_services.size()); |
78 for (const BluetoothUUID& service : optional_services) { | 76 for (const std::string& service : optional_services) { |
79 // TODO(ortuno): Use a macro to histogram strings. | 77 // TODO(ortuno): Use a macro to histogram strings. |
80 // http://crbug.com/520284 | 78 // http://crbug.com/520284 |
81 UMA_HISTOGRAM_SPARSE_SLOWLY( | 79 UMA_HISTOGRAM_SPARSE_SLOWLY( |
82 "Bluetooth.Web.RequestDevice.OptionalServices.Services", | 80 "Bluetooth.Web.RequestDevice.OptionalServices.Services", |
83 HashUUID(service.canonical_value())); | 81 HashUUID(service)); |
84 } | 82 } |
85 } | 83 } |
86 | 84 |
87 static void RecordUnionOfServices( | 85 static void RecordUnionOfServices( |
88 const std::vector<content::BluetoothScanFilter>& filters, | 86 const blink::mojom::WebBluetoothRequestDeviceOptionsPtr& options) { |
89 const std::vector<BluetoothUUID>& optional_services) { | 87 std::set<mojo::String> union_of_services(options->optional_services.begin(), |
90 std::set<BluetoothUUID> union_of_services(optional_services.begin(), | 88 options->optional_services.end()); |
91 optional_services.end()); | |
92 | 89 |
93 for (const content::BluetoothScanFilter& filter : filters) | 90 for (const auto& filter : options->filters) |
94 union_of_services.insert(filter.services.begin(), filter.services.end()); | 91 union_of_services.insert(filter->services.begin(), filter->services.end()); |
95 | 92 |
96 UMA_HISTOGRAM_COUNTS_100("Bluetooth.Web.RequestDevice.UnionOfServices.Count", | 93 UMA_HISTOGRAM_COUNTS_100("Bluetooth.Web.RequestDevice.UnionOfServices.Count", |
97 union_of_services.size()); | 94 union_of_services.size()); |
98 } | 95 } |
99 | 96 |
100 void RecordRequestDeviceArguments( | 97 void RecordRequestDeviceOptions( |
101 const std::vector<content::BluetoothScanFilter>& filters, | 98 const blink::mojom::WebBluetoothRequestDeviceOptionsPtr& options) { |
102 const std::vector<device::BluetoothUUID>& optional_services) { | 99 RecordRequestDeviceFilters(options->filters); |
103 RecordRequestDeviceFilters(filters); | 100 RecordRequestDeviceOptionalServices(options->optional_services); |
104 RecordRequestDeviceOptionalServices(optional_services); | 101 RecordUnionOfServices(options); |
105 RecordUnionOfServices(filters, optional_services); | |
106 } | 102 } |
107 | 103 |
108 // GATTServer.Connect | 104 // GATTServer.Connect |
109 | 105 |
110 void RecordConnectGATTOutcome(UMAConnectGATTOutcome outcome) { | 106 void RecordConnectGATTOutcome(UMAConnectGATTOutcome outcome) { |
111 UMA_HISTOGRAM_ENUMERATION("Bluetooth.Web.ConnectGATT.Outcome", | 107 UMA_HISTOGRAM_ENUMERATION("Bluetooth.Web.ConnectGATT.Outcome", |
112 static_cast<int>(outcome), | 108 static_cast<int>(outcome), |
113 static_cast<int>(UMAConnectGATTOutcome::COUNT)); | 109 static_cast<int>(UMAConnectGATTOutcome::COUNT)); |
114 } | 110 } |
115 | 111 |
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
279 static_cast<int>(outcome), | 275 static_cast<int>(outcome), |
280 static_cast<int>(UMAGATTOperationOutcome::COUNT)); | 276 static_cast<int>(UMAGATTOperationOutcome::COUNT)); |
281 } | 277 } |
282 | 278 |
283 void RecordStartNotificationsOutcome(CacheQueryOutcome outcome) { | 279 void RecordStartNotificationsOutcome(CacheQueryOutcome outcome) { |
284 RecordStartNotificationsOutcome( | 280 RecordStartNotificationsOutcome( |
285 TranslateCacheQueryOutcomeToGATTOperationOutcome(outcome)); | 281 TranslateCacheQueryOutcomeToGATTOperationOutcome(outcome)); |
286 } | 282 } |
287 | 283 |
288 } // namespace content | 284 } // namespace content |
OLD | NEW |