File: profile_pref_store_manager.h

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 (129 lines) | stat: -rw-r--r-- 5,323 bytes parent folder | download | duplicates (2)
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
// Copyright 2014 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_PREFS_PROFILE_PREF_STORE_MANAGER_H_
#define CHROME_BROWSER_PREFS_PROFILE_PREF_STORE_MANAGER_H_

#include <stddef.h>

#include <string>
#include <vector>

#include "base/files/file_path.h"
#include "base/memory/scoped_refptr.h"
#include "base/task/sequenced_task_runner.h"
#include "base/time/time.h"
#include "base/values.h"
#include "build/build_config.h"
#include "mojo/public/cpp/bindings/pending_remote.h"
#include "services/preferences/public/mojom/preferences.mojom-forward.h"
#include "services/preferences/public/mojom/tracked_preference_validation_delegate.mojom-forward.h"

class PersistentPrefStore;
class PrefService;

namespace service_manager {
class Connector;
}

namespace user_prefs {
class PrefRegistrySyncable;
}  // namespace user_prefs

// Provides a facade through which the user preference store may be accessed and
// managed.
class ProfilePrefStoreManager {
 public:
  // Instantiates a ProfilePrefStoreManager with the configuration required to
  // manage the user preferences of the profile at |profile_path|.
  // |seed| and |legacy_device_id| are used to track preference value changes
  // and must be the same on each launch in order to verify loaded preference
  // values.
  ProfilePrefStoreManager(const base::FilePath& profile_path,
                          const std::string& seed,
                          const std::string& legacy_device_id);

  ProfilePrefStoreManager(const ProfilePrefStoreManager&) = delete;
  ProfilePrefStoreManager& operator=(const ProfilePrefStoreManager&) = delete;
  ~ProfilePrefStoreManager();

  static const bool kPlatformSupportsPreferenceTracking;

  // Register user prefs used by the profile preferences system.
  static void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry);

  // Retrieves the time of the last preference reset event, if any, for
  // |pref_service|. Assumes that |pref_service| is backed by a PrefStore that
  // was built by ProfilePrefStoreManager.
  // If no reset has occurred, returns a null |Time|.
  static base::Time GetResetTime(PrefService* pref_service);

  // Clears the time of the last preference reset event, if any, for
  // |pref_service|. Assumes that |pref_service| is backed by a PrefStore that
  // was built by ProfilePrefStoreManager.
  static void ClearResetTime(PrefService* pref_service);

#if BUILDFLAG(IS_WIN)
  // Call before startup tasks kick in to use a different registry path for
  // storing and validating tracked preference MACs. Callers are responsible
  // for ensuring that the key is deleted on shutdown. For testing only.
  static void SetPreferenceValidationRegistryPathForTesting(
      const std::wstring* path);
#endif

  // Creates a PersistentPrefStore providing access to the user preferences of
  // the managed profile. If |reset_on_load_observer| is provided, it will be
  // notified if a reset occurs as a result of loading the profile's prefs. An
  // optional |validation_delegate| will be notified of the status of each
  // tracked preference as they are checked.
  // |tracking_configuration| is used for preference tracking.
  // |reporting_ids_count| is the count of all possible tracked preference IDs
  // (possibly greater than |tracking_configuration.size()|).
  PersistentPrefStore* CreateProfilePrefStore(
      std::vector<prefs::mojom::TrackedPreferenceMetadataPtr>
          tracking_configuration,
      size_t reporting_ids_count,
      scoped_refptr<base::SequencedTaskRunner> io_task_runner,
      mojo::PendingRemote<prefs::mojom::ResetOnLoadObserver>
          reset_on_load_observer,
      mojo::PendingRemote<prefs::mojom::TrackedPreferenceValidationDelegate>
          validation_delegate);

  // Initializes the preferences for the managed profile with the preference
  // values in |master_prefs|. Acts synchronously, including blocking IO.
  // Returns true on success.
  bool InitializePrefsFromMasterPrefs(
      std::vector<prefs::mojom::TrackedPreferenceMetadataPtr>
          tracking_configuration,
      size_t reporting_ids_count,
      base::Value::Dict master_prefs);

 private:
  // Connects to the pref service over mojo and configures it.
  void ConfigurePrefService(
      std::vector<prefs::mojom::TrackedPreferenceMetadataPtr>
          tracking_configuration,
      size_t reporting_ids_count,
      mojo::PendingRemote<prefs::mojom::ResetOnLoadObserver>
          reset_on_load_observer,
      mojo::PendingRemote<prefs::mojom::TrackedPreferenceValidationDelegate>
          validation_delegate,
      service_manager::Connector* connector);

  prefs::mojom::TrackedPersistentPrefStoreConfigurationPtr
  CreateTrackedPrefStoreConfiguration(
      std::vector<prefs::mojom::TrackedPreferenceMetadataPtr>
          tracking_configuration,
      size_t reporting_ids_count,
      mojo::PendingRemote<prefs::mojom::ResetOnLoadObserver>
          reset_on_load_observer,
      mojo::PendingRemote<prefs::mojom::TrackedPreferenceValidationDelegate>
          validation_delegate);

  const base::FilePath profile_path_;
  const std::string seed_;
  const std::string legacy_device_id_;
};

#endif  // CHROME_BROWSER_PREFS_PROFILE_PREF_STORE_MANAGER_H_