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" | 14 #include "content/common/bluetooth/bluetooth_scan_filter.h" |
15 #include "device/bluetooth/bluetooth_uuid.h" | 15 #include "device/bluetooth/bluetooth_uuid.h" |
16 | 16 |
17 using device::BluetoothUUID; | 17 using device::BluetoothUUID; |
18 | 18 |
19 namespace { | 19 namespace { |
| 20 // TODO(ortuno): Remove once we have a macro to histogram strings. |
| 21 // http://crbug.com/520284 |
| 22 int HashUUID(const std::string& uuid) { |
| 23 uint32_t data = base::SuperFastHash(uuid.data(), uuid.size()); |
20 | 24 |
21 // Generates a hash from a canonical UUID string suitable for | 25 // Strip off the signed bit because UMA doesn't support negative values, |
22 // UMA_HISTOGRAM_SPARSE_SLOWLY (positive int). | |
23 // | |
24 // Hash values can be produced manually using tool: bluetooth_metrics_hash. | |
25 int HashUUID(const std::string& canonical_uuid) { | |
26 DCHECK(canonical_uuid == BluetoothUUID(canonical_uuid).canonical_value()); | |
27 | |
28 // TODO(520284): Other than verifying that uuid is canonical, this logic | |
29 // should be migrated to a dedicated histogram macro for hashed strings. | |
30 uint32_t data = | |
31 base::SuperFastHash(canonical_uuid.data(), canonical_uuid.size()); | |
32 | |
33 // Strip off the sign bit because UMA doesn't support negative values, | |
34 // but takes a signed int as input. | 26 // but takes a signed int as input. |
35 return static_cast<int>(data & 0x7fffffff); | 27 return static_cast<int>(data & 0x7fffffff); |
36 } | 28 } |
37 } // namespace | 29 } // namespace |
38 | 30 |
39 namespace content { | 31 namespace content { |
40 | 32 |
41 // General | 33 // General |
42 | 34 |
43 void RecordWebBluetoothFunctionCall(UMAWebBluetoothFunction function) { | 35 void RecordWebBluetoothFunctionCall(UMAWebBluetoothFunction function) { |
(...skipping 240 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
284 static_cast<int>(outcome), | 276 static_cast<int>(outcome), |
285 static_cast<int>(UMAGATTOperationOutcome::COUNT)); | 277 static_cast<int>(UMAGATTOperationOutcome::COUNT)); |
286 } | 278 } |
287 | 279 |
288 void RecordStartNotificationsOutcome(CacheQueryOutcome outcome) { | 280 void RecordStartNotificationsOutcome(CacheQueryOutcome outcome) { |
289 RecordStartNotificationsOutcome( | 281 RecordStartNotificationsOutcome( |
290 TranslateCacheQueryOutcomeToGATTOperationOutcome(outcome)); | 282 TranslateCacheQueryOutcomeToGATTOperationOutcome(outcome)); |
291 } | 283 } |
292 | 284 |
293 } // namespace content | 285 } // namespace content |
OLD | NEW |