File: chrome_browser_main_extra_parts_metrics.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 (135 lines) | stat: -rw-r--r-- 4,616 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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
// Copyright 2013 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_CHROME_BROWSER_MAIN_EXTRA_PARTS_METRICS_H_
#define CHROME_BROWSER_METRICS_CHROME_BROWSER_MAIN_EXTRA_PARTS_METRICS_H_

#include <stdint.h>

#include <memory>
#include <optional>
#include <string>

#include "base/scoped_observation.h"
#include "build/build_config.h"
#include "chrome/browser/chrome_browser_main_extra_parts.h"
#include "components/webui/flags/flags_state.h"
#include "components/webui/flags/flags_storage.h"
#include "ui/display/display_observer.h"

class ChromeBrowserMainParts;
class PrefRegistrySimple;
class PrefService;

#if !BUILDFLAG(IS_ANDROID)
class BatteryDischargeReporter;
class PerformanceInterventionMetricsReporter;
class PowerMetricsReporter;
class ProcessMonitor;
#endif

#if BUILDFLAG(IS_LINUX)
class PressureMetricsReporter;
#endif  // BUILDFLAG(IS_LINUX)

#if BUILDFLAG(IS_ANDROID)
bool IsBundleForMixedDeviceAccordingToVersionCode(
    const std::string& version_code);
#endif

namespace web_app {
class SamplingMetricsProvider;
}  // namespace web_app

namespace chrome {
void AddMetricsExtraParts(ChromeBrowserMainParts* main_parts);
}

class ChromeBrowserMainExtraPartsMetrics : public ChromeBrowserMainExtraParts,
                                           public display::DisplayObserver {
 public:
  ChromeBrowserMainExtraPartsMetrics();

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

  ~ChromeBrowserMainExtraPartsMetrics() override;

  // Overridden from ChromeBrowserMainExtraParts:
  void PreCreateThreads() override;
  void PostCreateMainMessageLoop() override;
  void PreProfileInit() override;
  void PreBrowserStart() override;
  void PostBrowserStart() override;
  void PreMainMessageLoopRun() override;
  void PostDestroyThreads() override;

  // Registers local state prefs used by this class.
  static void RegisterPrefs(PrefRegistrySimple* registry);

 protected:
  // The --enable-benchmarking flag is transient and should go away after 3
  // launches. This method handles both the countdown and the reset. This logic
  // introduces an implicit dependency between the implementation of
  // chrome://flags and the storage layer in flags_ui::PrefServiceFlagsStorage.
  // This was deemed better than exposing one-off logic into the
  // flags_ui::PrefServiceFlagsStorage layer to handle this use case.
  //
  // |pref_service| is used to store the countdown state. |storage| is used to
  // check whether --enable-benchmarking flag has been enabled, and to later
  // reset the flag if necessary. |access| is unused.
  //
  // Protected for testing.
  static void HandleEnableBenchmarkingCountdown(
      PrefService* pref_service,
      std::unique_ptr<flags_ui::FlagsStorage> storage,
      flags_ui::FlagAccess access);

  // This method asynchronously invokes HandleEnableBenchmarkingCountdown with
  // parameters (fetched asynchronously).
  //
  // Protected for testing.
  virtual void HandleEnableBenchmarkingCountdownAsync();

 private:
  // DisplayObserver overrides.
  void OnDisplayAdded(const display::Display& new_display) override;
  void OnDisplaysRemoved(const display::Displays& removed_displays) override;
  void OnDisplayMetricsChanged(const display::Display& display,
                               uint32_t changed_metrics) override;

  // If the number of displays has changed, emit a UMA metric.
  void EmitDisplaysChangedMetric();

  // A cached value for the number of displays.
  int display_count_;

  std::optional<display::ScopedDisplayObserver> display_observer_;

#if !BUILDFLAG(IS_ANDROID)
  // The process monitor instance. Allows collecting metrics about every child
  // process.
  std::unique_ptr<ProcessMonitor> process_monitor_;

  // Reports power metrics.
  std::unique_ptr<PowerMetricsReporter> power_metrics_reporter_;

  std::unique_ptr<BatteryDischargeReporter> battery_discharge_reporter_;

  std::unique_ptr<PerformanceInterventionMetricsReporter>
      performance_intervention_metrics_reporter_;

  // Reports PWA metrics.
  std::unique_ptr<web_app::SamplingMetricsProvider> web_app_metrics_provider_;
#endif  // !BUILDFLAG(IS_ANDROID)

#if BUILDFLAG(IS_LINUX)
  // Reports pressure metrics.
  std::unique_ptr<PressureMetricsReporter> pressure_metrics_reporter_;
#endif  // BUILDFLAG(IS_LINUX)
};

#endif  // CHROME_BROWSER_METRICS_CHROME_BROWSER_MAIN_EXTRA_PARTS_METRICS_H_