File: privacy_metrics_service.h

package info (click to toggle)
chromium 139.0.7258.127-1
  • links: PTS, VCS
  • area: main
  • in suites:
  • size: 6,122,068 kB
  • sloc: cpp: 35,100,771; ansic: 7,163,530; javascript: 4,103,002; python: 1,436,920; asm: 946,517; xml: 746,709; pascal: 187,653; perl: 88,691; sh: 88,436; objc: 79,953; sql: 51,488; cs: 44,583; fortran: 24,137; makefile: 22,147; tcl: 15,277; php: 13,980; yacc: 8,984; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (104 lines) | stat: -rw-r--r-- 4,189 bytes parent folder | download | duplicates (7)
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
// Copyright 2021 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_PRIVACY_PRIVACY_METRICS_SERVICE_H_
#define CHROME_BROWSER_PRIVACY_PRIVACY_METRICS_SERVICE_H_

#include "base/gtest_prod_util.h"
#include "base/memory/raw_ptr.h"
#include "components/keyed_service/core/keyed_service.h"
#include "components/signin/public/identity_manager/identity_manager.h"
#include "components/sync/service/sync_service.h"

class HostContentSettingsMap;
class PrefService;

// Records privacy-related UMA metrics and is created on profile startup. Allows
// consolidation of metrics which do not otherwise have an obvious home, as well
// as recording metrics which span events across multiple disparate locations
// in the browser.
class PrivacyMetricsService : public KeyedService,
                              public syncer::SyncServiceObserver,
                              public signin::IdentityManager::Observer {
 public:
  explicit PrivacyMetricsService(
      PrefService* pref_service,
      HostContentSettingsMap* host_content_settings_map_,
      syncer::SyncService* sync_service,
      signin::IdentityManager* identity_manager);
  ~PrivacyMetricsService() override;

  // KeyedService:
  void Shutdown() override;

  // syncer::SyncServiceObserver:
  void OnStateChanged(syncer::SyncService* sync) override;

  // IdentityManager::Observer:
  void OnPrimaryAccountChanged(
      const signin::PrimaryAccountChangeEvent& event_details) override;

 private:
  friend class PrivacyMetricsServiceTest;
  FRIEND_TEST_ALL_PREFIXES(PrivacyMetricsServiceTest, BasicShutdownMetrics);
  FRIEND_TEST_ALL_PREFIXES(PrivacyMetricsServiceTest,
                           FixSyncPausedThroughReLogin);
  FRIEND_TEST_ALL_PREFIXES(PrivacyMetricsServiceTest,
                           FixSyncPausedThroughLogout);
  FRIEND_TEST_ALL_PREFIXES(PrivacyMetricsServiceTest, NoSyncIssues);
  FRIEND_TEST_ALL_PREFIXES(PrivacyMetricsServiceTest, NoSyncIssues);
  FRIEND_TEST_ALL_PREFIXES(PrivacyMetricsServiceTest,
                           AccountChangeNoSyncIssues);
  FRIEND_TEST_ALL_PREFIXES(PrivacyMetricsServiceTest, StartupNoSync);

  // Contains all recorded events related to sync while the profile has clear
  // on exit enabled. Must be kept in sync with the ClearOnExitSyncEvent enum in
  // histograms/enums.xml.
  enum class ClearOnExitSyncEvent {
    kStartupSyncDisabled = 0,
    kStartupSyncPaused = 1,
    kStartupSyncActive = 2,
    kReloginToPausedAccount = 3,
    kLogoutOfPausedAccount = 4,
    kShutdownSyncActiveStartedPausedConsentChange = 5,
    kShutdownSyncActiveStartedPausedNoConsentChange = 6,
    kShutdownSyncActiveStartedActiveConsentChange = 7,
    kShutdownSyncActiveStartedActiveNoConsentChange = 8,
    kShutdownSyncPaused = 9,
    // Add values above this line with a corresponding label in
    // tools/metrics/histograms/enums.xml
    kMaxValue = kShutdownSyncPaused,
  };

  void RecordStartupMetrics();

  void UnregisterObservers();

  // Whether |pref_service_| represents a state where the cookies clear on exit
  // control has been enabled.
  bool IsClearOnExitEnabled();

  void RecordClearOnExitSyncEvent(ClearOnExitSyncEvent event) const;

  // Whether this service observed the |sync_service_| entering the sync
  // paused state before it entered the active state.
  bool sync_started_paused_ = false;

  // Whether this service observed that the sync consent for primary account
  // changed, indicating that a user enabled or disabled sync.
  bool primary_account_consent_changed_ = false;

  const raw_ptr<const PrefService> pref_service_;
  const raw_ptr<const HostContentSettingsMap> host_content_settings_map_;
  const raw_ptr<syncer::SyncService> sync_service_;
  const raw_ptr<signin::IdentityManager> identity_manager_;

  base::ScopedObservation<syncer::SyncService, syncer::SyncServiceObserver>
      sync_service_observer_{this};
  base::ScopedObservation<signin::IdentityManager,
                          signin::IdentityManager::Observer>
      identity_manager_observer_{this};
};

#endif  // CHROME_BROWSER_PRIVACY_PRIVACY_METRICS_SERVICE_H_