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 "components/proximity_auth/metrics.h" | 5 #include "components/proximity_auth/metrics.h" |
6 | 6 |
7 #include <stdint.h> | 7 #include <stdint.h> |
8 | 8 |
9 #include <algorithm> | 9 #include <algorithm> |
10 | 10 |
11 #include "base/logging.h" | 11 #include "base/logging.h" |
12 #include "base/macros.h" | 12 #include "base/macros.h" |
13 #include "base/md5.h" | 13 #include "base/md5.h" |
14 #include "base/metrics/histogram_macros.h" | 14 #include "base/metrics/histogram_macros.h" |
15 #include "base/metrics/sparse_histogram.h" | 15 #include "base/metrics/sparse_histogram.h" |
16 #include "base/sys_byteorder.h" | 16 #include "base/sys_byteorder.h" |
| 17 #include "device/bluetooth/bluetooth_device.h" |
17 | 18 |
18 namespace proximity_auth { | 19 namespace proximity_auth { |
19 namespace metrics { | 20 namespace metrics { |
20 | 21 |
21 namespace { | 22 namespace { |
22 | 23 |
23 // Converts the 4-byte prefix of an MD5 hash into a int32_t value. | 24 // Converts the 4-byte prefix of an MD5 hash into a int32_t value. |
24 int32_t DigestToInt32(const base::MD5Digest& digest) { | 25 int32_t DigestToInt32(const base::MD5Digest& digest) { |
25 // First, copy to a uint32_t, since byte swapping and endianness conversions | 26 // First, copy to a uint32_t, since byte swapping and endianness conversions |
26 // expect unsigned integers. | 27 // expect unsigned integers. |
(...skipping 12 matching lines...) Expand all Loading... |
39 // Returns a hash of the given |name|, encoded as a 32-bit signed integer. | 40 // Returns a hash of the given |name|, encoded as a 32-bit signed integer. |
40 int32_t HashDeviceModelName(const std::string& name) { | 41 int32_t HashDeviceModelName(const std::string& name) { |
41 base::MD5Digest digest; | 42 base::MD5Digest digest; |
42 base::MD5Sum(name.c_str(), name.size(), &digest); | 43 base::MD5Sum(name.c_str(), name.size(), &digest); |
43 return DigestToInt32(digest); | 44 return DigestToInt32(digest); |
44 } | 45 } |
45 | 46 |
46 } // namespace | 47 } // namespace |
47 | 48 |
48 const char kUnknownDeviceModel[] = "Unknown"; | 49 const char kUnknownDeviceModel[] = "Unknown"; |
49 const int kUnknownProximityValue = 127; | |
50 | 50 |
51 void RecordAuthProximityRollingRssi(int rolling_rssi) { | 51 void RecordAuthProximityRollingRssi(int rolling_rssi) { |
52 if (rolling_rssi != kUnknownProximityValue) | 52 if (rolling_rssi != device::BluetoothDevice::kUnknownRSSI) |
53 rolling_rssi = std::min(50, std::max(-100, rolling_rssi)); | 53 rolling_rssi = std::min(50, std::max(-100, rolling_rssi)); |
54 | 54 |
55 UMA_HISTOGRAM_SPARSE_SLOWLY("EasyUnlock.AuthProximity.RollingRssi", | 55 UMA_HISTOGRAM_SPARSE_SLOWLY("EasyUnlock.AuthProximity.RollingRssi", |
56 rolling_rssi); | 56 rolling_rssi); |
57 } | 57 } |
58 | 58 |
59 void RecordAuthProximityTransmitPowerDelta(int transmit_power_delta) { | 59 void RecordAuthProximityTransmitPowerDelta(int transmit_power_delta) { |
60 if (transmit_power_delta != kUnknownProximityValue) | 60 if (transmit_power_delta != device::BluetoothDevice::kUnknownTxPower) |
61 transmit_power_delta = std::min(50, std::max(-100, transmit_power_delta)); | 61 transmit_power_delta = std::min(50, std::max(-100, transmit_power_delta)); |
62 | 62 |
63 UMA_HISTOGRAM_SPARSE_SLOWLY("EasyUnlock.AuthProximity.TransmitPowerDelta", | 63 UMA_HISTOGRAM_SPARSE_SLOWLY("EasyUnlock.AuthProximity.TransmitPowerDelta", |
64 transmit_power_delta); | 64 transmit_power_delta); |
65 } | 65 } |
66 | 66 |
67 void RecordAuthProximityTimeSinceLastZeroRssi( | 67 void RecordAuthProximityTimeSinceLastZeroRssi( |
68 base::TimeDelta time_since_last_zero_rssi) { | 68 base::TimeDelta time_since_last_zero_rssi) { |
69 UMA_HISTOGRAM_TIMES("EasyUnlock.AuthProximity.TimeSinceLastZeroRssi", | 69 UMA_HISTOGRAM_TIMES("EasyUnlock.AuthProximity.TimeSinceLastZeroRssi", |
70 time_since_last_zero_rssi); | 70 time_since_last_zero_rssi); |
71 } | 71 } |
72 | 72 |
73 void RecordAuthProximityRemoteDeviceModelHash(const std::string& device_model) { | 73 void RecordAuthProximityRemoteDeviceModelHash(const std::string& device_model) { |
74 UMA_HISTOGRAM_SPARSE_SLOWLY("EasyUnlock.AuthProximity.RemoteDeviceModelHash", | 74 UMA_HISTOGRAM_SPARSE_SLOWLY("EasyUnlock.AuthProximity.RemoteDeviceModelHash", |
75 HashDeviceModelName(device_model)); | 75 HashDeviceModelName(device_model)); |
76 } | 76 } |
77 | 77 |
78 void RecordRemoteSecuritySettingsState(RemoteSecuritySettingsState state) { | 78 void RecordRemoteSecuritySettingsState(RemoteSecuritySettingsState state) { |
79 DCHECK(state < RemoteSecuritySettingsState::COUNT); | 79 DCHECK(state < RemoteSecuritySettingsState::COUNT); |
80 UMA_HISTOGRAM_ENUMERATION( | 80 UMA_HISTOGRAM_ENUMERATION( |
81 "EasyUnlock.RemoteLockScreenState", static_cast<int>(state), | 81 "EasyUnlock.RemoteLockScreenState", static_cast<int>(state), |
82 static_cast<int>(RemoteSecuritySettingsState::COUNT)); | 82 static_cast<int>(RemoteSecuritySettingsState::COUNT)); |
83 } | 83 } |
84 | 84 |
85 } // namespace metrics | 85 } // namespace metrics |
86 } // namespace proximity_auth | 86 } // namespace proximity_auth |
OLD | NEW |