File: metrics.cc

package info (click to toggle)
chromium-browser 57.0.2987.98-1~deb8u1
  • links: PTS, VCS
  • area: main
  • in suites: jessie
  • size: 2,637,852 kB
  • ctags: 2,544,394
  • sloc: cpp: 12,815,961; ansic: 3,676,222; python: 1,147,112; asm: 526,608; java: 523,212; xml: 286,794; perl: 92,654; sh: 86,408; objc: 73,271; makefile: 27,698; cs: 18,487; yacc: 13,031; tcl: 12,957; pascal: 4,875; ml: 4,716; lex: 3,904; sql: 3,862; ruby: 1,982; lisp: 1,508; php: 1,368; exp: 404; awk: 325; csh: 117; jsp: 39; sed: 37
file content (86 lines) | stat: -rw-r--r-- 2,916 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "components/proximity_auth/metrics.h"

#include <stdint.h>

#include <algorithm>

#include "base/logging.h"
#include "base/macros.h"
#include "base/md5.h"
#include "base/metrics/histogram_macros.h"
#include "base/metrics/sparse_histogram.h"
#include "base/sys_byteorder.h"

namespace proximity_auth {
namespace metrics {

namespace {

// Converts the 4-byte prefix of an MD5 hash into a int32_t value.
int32_t DigestToInt32(const base::MD5Digest& digest) {
  // First, copy to a uint32_t, since byte swapping and endianness conversions
  // expect unsigned integers.
  uint32_t unsigned_value;
  DCHECK_GE(arraysize(digest.a), sizeof(unsigned_value));
  memcpy(&unsigned_value, digest.a, sizeof(unsigned_value));
  unsigned_value = base::ByteSwap(base::HostToNet32(unsigned_value));

  // Then copy the resulting bit pattern to an int32_t to match the datatype
  // that histograms expect.
  int32_t value;
  memcpy(&value, &unsigned_value, sizeof(value));
  return value;
}

// Returns a hash of the given |name|, encoded as a 32-bit signed integer.
int32_t HashDeviceModelName(const std::string& name) {
  base::MD5Digest digest;
  base::MD5Sum(name.c_str(), name.size(), &digest);
  return DigestToInt32(digest);
}

}  // namespace

const char kUnknownDeviceModel[] = "Unknown";
const int kUnknownProximityValue = 127;

void RecordAuthProximityRollingRssi(int rolling_rssi) {
  if (rolling_rssi != kUnknownProximityValue)
    rolling_rssi = std::min(50, std::max(-100, rolling_rssi));

  UMA_HISTOGRAM_SPARSE_SLOWLY("EasyUnlock.AuthProximity.RollingRssi",
                              rolling_rssi);
}

void RecordAuthProximityTransmitPowerDelta(int transmit_power_delta) {
  if (transmit_power_delta != kUnknownProximityValue)
    transmit_power_delta = std::min(50, std::max(-100, transmit_power_delta));

  UMA_HISTOGRAM_SPARSE_SLOWLY("EasyUnlock.AuthProximity.TransmitPowerDelta",
                              transmit_power_delta);
}

void RecordAuthProximityTimeSinceLastZeroRssi(
    base::TimeDelta time_since_last_zero_rssi) {
  UMA_HISTOGRAM_TIMES("EasyUnlock.AuthProximity.TimeSinceLastZeroRssi",
                      time_since_last_zero_rssi);
}

void RecordAuthProximityRemoteDeviceModelHash(const std::string& device_model) {
  UMA_HISTOGRAM_SPARSE_SLOWLY("EasyUnlock.AuthProximity.RemoteDeviceModelHash",
                              HashDeviceModelName(device_model));
}

void RecordRemoteSecuritySettingsState(RemoteSecuritySettingsState state) {
  DCHECK(state < RemoteSecuritySettingsState::COUNT);
  UMA_HISTOGRAM_ENUMERATION(
      "EasyUnlock.RemoteLockScreenState", static_cast<int>(state),
      static_cast<int>(RemoteSecuritySettingsState::COUNT));
}

}  // namespace metrics
}  // namespace proximity_auth