File: crd_uma_logger.cc

package info (click to toggle)
chromium 138.0.7204.183-1~deb12u1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm-proposed-updates
  • size: 6,080,960 kB
  • sloc: cpp: 34,937,079; ansic: 7,176,967; javascript: 4,110,704; python: 1,419,954; asm: 946,768; xml: 739,971; pascal: 187,324; sh: 89,623; perl: 88,663; objc: 79,944; sql: 50,304; cs: 41,786; fortran: 24,137; makefile: 21,811; php: 13,980; tcl: 13,166; yacc: 8,925; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (84 lines) | stat: -rw-r--r-- 3,068 bytes parent folder | download | duplicates (6)
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
// Copyright 2022 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "chrome/browser/ash/policy/remote_commands/crd/crd_uma_logger.h"

#include "base/metrics/histogram_functions.h"
#include "base/strings/stringprintf.h"
#include "base/time/time.h"
#include "chrome/browser/ash/policy/remote_commands/crd/crd_remote_command_utils.h"
#include "components/policy/core/common/cloud/enterprise_metrics.h"
#include "device_management_backend.pb.h"

namespace {

constexpr base::TimeDelta kMinDuration = base::Minutes(1);
constexpr base::TimeDelta kMaxDuration = base::Hours(8);
constexpr base::TimeDelta kBucketSize = base::Minutes(10);

}  // namespace

namespace policy {

CrdUmaLogger::CrdUmaLogger(CrdSessionType session_type,
                           UserSessionType user_session_type)
    : session_type_(session_type), user_session_type_(user_session_type) {}

void CrdUmaLogger::LogSessionLaunchResult(
    ExtendedStartCrdSessionResultCode result_code) {
  base::UmaHistogramEnumeration(
      base::StringPrintf(kMetricDeviceRemoteCommandCrdResultTemplate,
                         FormatCrdSessionType(), FormatUserSessionType()),
      result_code);
}

void CrdUmaLogger::LogSessionDuration(base::TimeDelta duration) {
  // Warning: changing the number of buckets logged will make it impossible to
  // compare UMA logs recorded before and after the change!
  base::UmaHistogramCustomTimes(
      /*name=*/base::StringPrintf(
          kMetricDeviceRemoteCommandCrdSessionDurationTemplate,
          FormatCrdSessionType(), FormatUserSessionType()),
      /*sample=*/duration,
      /*min=*/kMinDuration,
      /*max=*/kMaxDuration,
      /*buckets=*/kMaxDuration / kBucketSize);
}

// Created a separate method to have fixed values for UMA logs.
// The returned strings should not be changed, as they are logged as part of the
// UMA keys.
const char* CrdUmaLogger::FormatUserSessionType() const {
  switch (user_session_type_) {
    case UserSessionType::USER_SESSION_TYPE_UNKNOWN:
      return "UnknownUserSession";
    case UserSessionType::AUTO_LAUNCHED_KIOSK_SESSION:
      return "AutoLaunchedKioskSession";
    case UserSessionType::MANUALLY_LAUNCHED_KIOSK_SESSION:
      return "ManuallyLaunchedKioskSession";
    case UserSessionType::AFFILIATED_USER_SESSION:
      return "AffiliatedUserSession";
    case UserSessionType::UNAFFILIATED_USER_SESSION:
      return "UnaffiliatedUserSession";
    case UserSessionType::MANAGED_GUEST_SESSION:
      return "ManagedGuestSession";
    case UserSessionType::GUEST_SESSION:
      return "GuestSession";
    case UserSessionType::NO_SESSION:
      return "NoUserSession";
  }
}

const char* CrdUmaLogger::FormatCrdSessionType() const {
  switch (session_type_) {
    case CrdSessionType::CRD_SESSION_TYPE_UNKNOWN:
      return "Unknown";
    case CrdSessionType::REMOTE_ACCESS_SESSION:
      return "RemoteAccess";
    case CrdSessionType::REMOTE_SUPPORT_SESSION:
      return "RemoteSupport";
  }
}

}  // namespace policy