File: metrics_reporting_state.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 (96 lines) | stat: -rw-r--r-- 4,468 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
// Copyright 2011 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_METRICS_REPORTING_STATE_H_
#define CHROME_BROWSER_METRICS_METRICS_REPORTING_STATE_H_

#include "base/functional/callback_forward.h"

using OnMetricsReportingCallbackType = base::OnceCallback<void(bool)>;

// Specifies from where a change to the metrics reporting state was made. When
// metrics reporting is enabled from a settings page, histogram data that was
// collected while metrics reporting was disabled should be cleared (marked as
// reported) so as to not include them in the next log.
// GENERATED_JAVA_ENUM_PACKAGE: org.chromium.chrome.browser.metrics
enum class ChangeMetricsReportingStateCalledFrom {
  kUiSettings,

  // The user opted out of metrics reporting in the First Run Experience.
  kUiFirstRun,

  // Called from the session crashed dialog window.
  kSessionCrashedDialog,

  // Called from Chrome OS settings change. Chrome OS manages settings
  // externally and metrics service listens for changes.
  kCrosMetricsSettingsChange,

  // Called from Chrome OS on settings creation/initialization. This happens
  // once on each log in.
  kCrosMetricsSettingsCreated,

  // Called on ChromeOS from Lacros on initialization to initialize state.
  kCrosMetricsInitializedFromAsh,

  // Called on ChromeOS pre-consent metrics. This happens once per powerwash.
  kCrosMetricsPreConsent,
};

// Changes metrics reporting state without caring about the success of the
// change. |called_from| should be set to |kUiSettings| when enabling metrics
// from a settings page (to mark histogram data collected while metrics
// reporting was disabled as reported so as to not include them in the next
// log). If |called_from| is set to anything else, then metrics will not be
// cleared when enabling metrics reporting.
void ChangeMetricsReportingState(
    bool enabled,
    ChangeMetricsReportingStateCalledFrom called_from);

// Changes metrics reporting state to the new value of |enabled|. Starts or
// stops the metrics service based on the new state and then runs |callback_fn|
// (which can be null) with the updated state (as the operation may fail). On
// platforms other than CrOS and Android, also updates the underlying pref.
// |called_from| should be set to |kUiSettings| when enabling metrics from a
// settings page (to mark histogram data collected while metrics reporting was
// disabled as reported so as to not include them in the next log). If
// |called_from| is set to anything else, then metrics will not be cleared when
// enabling metrics reporting.
// TODO(crbug.com/40592297): Support setting the pref on all platforms.
void ChangeMetricsReportingStateWithReply(
    bool enabled,
    OnMetricsReportingCallbackType callback_fn,
    ChangeMetricsReportingStateCalledFrom called_from);

// Update metrics prefs on a permission (opt-in/out) change. When opting out,
// this clears various client ids. When opting in, this resets saving crash
// prefs, so as not to trigger upload of various stale data. |called_from|
// should be set to |kUiSettings| when enabling metrics from a settings page (to
// mark histogram data collected while metrics reporting was disabled as
// reported so as to not include them in the next log). If |called_from| is set
// to anything else, then metrics will not be cleared when enabling metrics
// reporting.
void UpdateMetricsPrefsOnPermissionChange(
    bool metrics_enabled,
    ChangeMetricsReportingStateCalledFrom called_from);

// Propagates the state of metrics reporting pref (which may be policy
// managed) to GoogleUpdateSettings.
void ApplyMetricsReportingPolicy();

// Returns whether MetricsReporting can be modified by the user (except
// Android).
//
// For Ash Chrome, metrics reporting may be controlled by an enterprise policy
// and the metrics service pref inherits the value from the policy. Reporting
// policy will be considered managed if an enterprise policy exists.
bool IsMetricsReportingPolicyManaged();

// Clears previously collected metrics data. Used when enabling metrics to
// prevent data collected while metrics reporting was disabled from being
// included in the next log. Note that histogram data is not discarded. Rather,
// they are just marked as being already reported.
void ClearPreviouslyCollectedMetricsData();

#endif  // CHROME_BROWSER_METRICS_METRICS_REPORTING_STATE_H_