File: chromeos_system_profile_provider.h

package info (click to toggle)
chromium 138.0.7204.157-1
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 6,071,864 kB
  • sloc: cpp: 34,936,859; ansic: 7,176,967; javascript: 4,110,704; python: 1,419,953; asm: 946,768; xml: 739,967; pascal: 187,324; sh: 89,623; perl: 88,663; objc: 79,944; sql: 50,304; cs: 41,786; fortran: 24,137; makefile: 21,806; 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 (106 lines) | stat: -rw-r--r-- 4,285 bytes parent folder | download | duplicates (4)
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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
// 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.

#ifndef CHROME_BROWSER_METRICS_CHROMEOS_SYSTEM_PROFILE_PROVIDER_H_
#define CHROME_BROWSER_METRICS_CHROMEOS_SYSTEM_PROFILE_PROVIDER_H_

#include <memory>

#include "base/feature_list.h"
#include "base/memory/weak_ptr.h"
#include "chrome/browser/metrics/cached_metrics_profile.h"
#include "chromeos/ash/experiences/arc/arc_features_parser.h"
#include "chromeos/dbus/tpm_manager/tpm_manager.pb.h"
#include "components/metrics/metrics_provider.h"

// Provides the SystemProfile from ChromeOS to different metrics.
class ChromeOSSystemProfileProvider : public metrics::MetricsProvider {
 public:
  ChromeOSSystemProfileProvider();

  ~ChromeOSSystemProfileProvider() override;

  ChromeOSSystemProfileProvider(const ChromeOSSystemProfileProvider&) = delete;
  ChromeOSSystemProfileProvider& operator=(
      const ChromeOSSystemProfileProvider&) = delete;

  // metrics::MetricsProvider:
  void OnDidCreateMetricsLog() override;
  void AsyncInit(base::OnceClosure callback) override;
  void ProvideSystemProfileMetrics(metrics::SystemProfileProto* proto) override;

 private:
  void WriteLinkedAndroidPhoneProto(
      metrics::SystemProfileProto* system_profile_proto);

  // Update the number of users logged into a multi-profile session.
  // If the number of users change while the log is open, the call invalidates
  // the user count value.
  void UpdateMultiProfileUserCount(
      metrics::SystemProfileProto* system_profile_proto);

  void WriteDemoModeDimensionMetrics(
      metrics::SystemProfileProto* system_profile_proto);

  // Loads hardware class information. When this task is complete, |callback|
  // is run.
  void InitTaskGetFullHardwareClass(base::OnceClosure callback);

  // Retrieves ARC features using ArcFeaturesParser. When this task is complete,
  // |callback| is run.
  void InitTaskGetArcFeatures(base::OnceClosure callback);

  // Retrieves TPM firmware version using TpmManagerClient. When this task is
  // complete, |callback| is run.
  void InitTaskGetTpmFirmwareVersion(base::OnceClosure callback);

  // Loads the cellular device variant. When this task is complete, |callback|
  // is run.
  void InitTaskGetCellularDeviceVariant(base::OnceClosure callback);

  // Invoked when StatisticsProvider finishes loading to read the full hardware
  // class from StatisticsProvider and calls the callback.
  void OnMachineStatisticsLoaded(base::OnceClosure callback);

  // Updates ARC-related system profile fields, then calls the callback.
  void OnArcFeaturesParsed(base::OnceClosure callback,
                           std::optional<arc::ArcFeatures> features);

  // Sets the TPM RW firmware version, then calls the callback.
  void OnTpmManagerGetRwVersionInfo(
      base::OnceClosure callback,
      const tpm_manager::GetVersionInfoReply& reply);

  // Sets the cellular device variant, then calls the callback.
  void SetCellularDeviceVariant(base::OnceClosure callback,
                                std::string cellular_device_variant);

  // Use the first signed-in profile for profile-dependent metrics.
  std::unique_ptr<metrics::CachedMetricsProfile> cached_profile_;

  // Whether the user count was registered at the last log initialization.
  bool registered_user_count_at_log_initialization_ = false;

  // The user count at the time that a log was last initialized. Contains a
  // valid value only if |registered_user_count_at_log_initialization_| is
  // true.
  uint64_t user_count_at_log_initialization_ = 0;

  // Hardware class (e.g., hardware qualification ID). This value identifies
  // the configured system components such as CPU, WiFi adapter, etc.
  std::string full_hardware_class_;

  // Cellular device variant for Chrome OS devices with cellular support.
  std::string cellular_device_variant_;

  // ARC release version obtained from build properties.
  std::optional<std::string> arc_release_;

  // The RW firmware version of the TPM (go/trusted-platform-module).
  std::optional<std::string> tpm_rw_firmware_version_;

  base::WeakPtrFactory<ChromeOSSystemProfileProvider> weak_ptr_factory_;
};

#endif  // CHROME_BROWSER_METRICS_CHROMEOS_SYSTEM_PROFILE_PROVIDER_H_