Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(206)

Side by Side Diff: chrome/browser/prefs/profile_pref_store_manager.h

Issue 2745563005: Pref service: add support for tracked prefs. (Closed)
Patch Set: deflake tests Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef CHROME_BROWSER_PREFS_PROFILE_PREF_STORE_MANAGER_H_ 5 #ifndef CHROME_BROWSER_PREFS_PROFILE_PREF_STORE_MANAGER_H_
6 #define CHROME_BROWSER_PREFS_PROFILE_PREF_STORE_MANAGER_H_ 6 #define CHROME_BROWSER_PREFS_PROFILE_PREF_STORE_MANAGER_H_
7 7
8 #include <stddef.h> 8 #include <stddef.h>
9 9
10 #include <memory> 10 #include <memory>
11 #include <string> 11 #include <string>
12 #include <vector> 12 #include <vector>
13 13
14 #include "base/files/file_path.h" 14 #include "base/files/file_path.h"
15 #include "base/macros.h" 15 #include "base/macros.h"
16 #include "base/memory/ref_counted.h" 16 #include "base/memory/ref_counted.h"
17 #include "services/preferences/public/interfaces/preferences_configuration.mojom .h" 17 #include "services/preferences/public/interfaces/preferences_configuration.mojom .h"
18 #include "services/preferences/public/interfaces/tracked_preference_validation_d elegate.mojom.h"
18 19
19 class HashStoreContents;
20 class PersistentPrefStore; 20 class PersistentPrefStore;
21 class PrefHashStore;
22 class PrefRegistry; 21 class PrefRegistry;
23 class PrefService; 22 class PrefService;
24 23
25 namespace base { 24 namespace base {
26 class DictionaryValue; 25 class DictionaryValue;
27 class SequencedTaskRunner; 26 class SequencedWorkerPool;
28 } // namespace base 27 } // namespace base
29 28
30 namespace prefs {
31 namespace mojom {
32 class TrackedPreferenceValidationDelegate;
33 }
34 }
35
36 namespace service_manager { 29 namespace service_manager {
37 class Connector; 30 class Connector;
38 } 31 }
39 32
40 namespace user_prefs { 33 namespace user_prefs {
41 class PrefRegistrySyncable; 34 class PrefRegistrySyncable;
42 } // namespace user_prefs 35 } // namespace user_prefs
43 36
44 // Provides a facade through which the user preference store may be accessed and 37 // Provides a facade through which the user preference store may be accessed and
45 // managed. 38 // managed.
46 class ProfilePrefStoreManager { 39 class ProfilePrefStoreManager {
47 public: 40 public:
48 // Instantiates a ProfilePrefStoreManager with the configuration required to 41 // Instantiates a ProfilePrefStoreManager with the configuration required to
49 // manage the user preferences of the profile at |profile_path|. 42 // manage the user preferences of the profile at |profile_path|.
50 // |tracking_configuration| is used for preference tracking.
51 // |reporting_ids_count| is the count of all possible tracked preference IDs
52 // (possibly greater than |tracking_configuration.size()|).
53 // |seed| and |legacy_device_id| are used to track preference value changes 43 // |seed| and |legacy_device_id| are used to track preference value changes
54 // and must be the same on each launch in order to verify loaded preference 44 // and must be the same on each launch in order to verify loaded preference
55 // values. 45 // values.
56 ProfilePrefStoreManager( 46 ProfilePrefStoreManager(const base::FilePath& profile_path,
57 const base::FilePath& profile_path, 47 const std::string& seed,
58 std::vector<prefs::mojom::TrackedPreferenceMetadataPtr> 48 const std::string& legacy_device_id);
59 tracking_configuration,
60 size_t reporting_ids_count,
61 const std::string& seed,
62 const std::string& legacy_device_id,
63 PrefService* local_state);
64 49
65 ~ProfilePrefStoreManager(); 50 ~ProfilePrefStoreManager();
66 51
67 static const bool kPlatformSupportsPreferenceTracking; 52 static const bool kPlatformSupportsPreferenceTracking;
68 53
69 // Register user prefs used by the profile preferences system. 54 // Register user prefs used by the profile preferences system.
70 static void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry); 55 static void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry);
71 56
72 // Retrieves the time of the last preference reset event, if any, for 57 // Retrieves the time of the last preference reset event, if any, for
73 // |pref_service|. Assumes that |pref_service| is backed by a PrefStore that 58 // |pref_service|. Assumes that |pref_service| is backed by a PrefStore that
74 // was built by ProfilePrefStoreManager. 59 // was built by ProfilePrefStoreManager.
75 // If no reset has occurred, returns a null |Time|. 60 // If no reset has occurred, returns a null |Time|.
76 static base::Time GetResetTime(PrefService* pref_service); 61 static base::Time GetResetTime(PrefService* pref_service);
77 62
78 // Clears the time of the last preference reset event, if any, for 63 // Clears the time of the last preference reset event, if any, for
79 // |pref_service|. Assumes that |pref_service| is backed by a PrefStore that 64 // |pref_service|. Assumes that |pref_service| is backed by a PrefStore that
80 // was built by ProfilePrefStoreManager. 65 // was built by ProfilePrefStoreManager.
81 static void ClearResetTime(PrefService* pref_service); 66 static void ClearResetTime(PrefService* pref_service);
82 67
83 #if defined(OS_WIN) 68 #if defined(OS_WIN)
84 // Call before startup tasks kick in to use a different registry path for 69 // Call before startup tasks kick in to use a different registry path for
85 // storing and validating tracked preference MACs. Callers are responsible 70 // storing and validating tracked preference MACs. Callers are responsible
86 // for ensuring that the key is deleted on shutdown. For testing only. 71 // for ensuring that the key is deleted on shutdown. For testing only.
87 static void SetPreferenceValidationRegistryPathForTesting( 72 static void SetPreferenceValidationRegistryPathForTesting(
88 const base::string16* path); 73 const base::string16* path);
89 #endif 74 #endif
90 75
91 // Creates a PersistentPrefStore providing access to the user preferences of 76 // Creates a PersistentPrefStore providing access to the user preferences of
92 // the managed profile. If |on_reset| is provided, it will be invoked if a 77 // the managed profile. If |reset_on_load_observer| is provided, it will be
93 // reset occurs as a result of loading the profile's prefs. 78 // notified if a reset occurs as a result of loading the profile's prefs. An
94 // An optional |validation_delegate| will be notified 79 // optional |validation_delegate| will be notified of the status of each
95 // of the status of each tracked preference as they are checked. 80 // tracked preference as they are checked.
81 // |tracking_configuration| is used for preference tracking.
82 // |reporting_ids_count| is the count of all possible tracked preference IDs
83 // (possibly greater than |tracking_configuration.size()|).
96 PersistentPrefStore* CreateProfilePrefStore( 84 PersistentPrefStore* CreateProfilePrefStore(
97 const scoped_refptr<base::SequencedTaskRunner>& io_task_runner, 85 std::vector<prefs::mojom::TrackedPreferenceMetadataPtr>
98 const base::Closure& on_reset_on_load, 86 tracking_configuration,
99 prefs::mojom::TrackedPreferenceValidationDelegate* validation_delegate, 87 size_t reporting_ids_count,
88 base::SequencedWorkerPool* worker_pool,
89 prefs::mojom::ResetOnLoadObserverPtr reset_on_load_observer,
90 prefs::mojom::TrackedPreferenceValidationDelegatePtr validation_delegate,
100 service_manager::Connector* connector, 91 service_manager::Connector* connector,
101 scoped_refptr<PrefRegistry> pref_registry); 92 scoped_refptr<PrefRegistry> pref_registry);
102 93
103 // Initializes the preferences for the managed profile with the preference 94 // Initializes the preferences for the managed profile with the preference
104 // values in |master_prefs|. Acts synchronously, including blocking IO. 95 // values in |master_prefs|. Acts synchronously, including blocking IO.
105 // Returns true on success. 96 // Returns true on success.
106 bool InitializePrefsFromMasterPrefs( 97 bool InitializePrefsFromMasterPrefs(
98 std::vector<prefs::mojom::TrackedPreferenceMetadataPtr>
99 tracking_configuration,
100 size_t reporting_ids_count,
107 std::unique_ptr<base::DictionaryValue> master_prefs); 101 std::unique_ptr<base::DictionaryValue> master_prefs);
108 102
109 // Creates a single-file PrefStore as was used in M34 and earlier. Used only 103 private:
110 // for testing migration. 104 // Connects to the pref service over mojo and configures it.
111 PersistentPrefStore* CreateDeprecatedCombinedProfilePrefStore( 105 void ConfigurePrefService(
112 const scoped_refptr<base::SequencedTaskRunner>& io_task_runner); 106 std::vector<prefs::mojom::TrackedPreferenceMetadataPtr>
107 tracking_configuration,
108 size_t reporting_ids_count,
109 prefs::mojom::ResetOnLoadObserverPtr reset_on_load_observer,
110 prefs::mojom::TrackedPreferenceValidationDelegatePtr validation_delegate,
111 service_manager::Connector* connector);
113 112
114 private: 113 prefs::mojom::TrackedPersistentPrefStoreConfigurationPtr
115 // Returns a PrefHashStore for the managed profile. Should only be called 114 CreateTrackedPrefStoreConfiguration(
116 // if |kPlatformSupportsPreferenceTracking|. |use_super_mac| determines 115 std::vector<prefs::mojom::TrackedPreferenceMetadataPtr>
117 // whether the returned object will calculate, store, and validate super MACs 116 tracking_configuration,
118 // (and, by extension, accept non-null newly protected preferences as 117 size_t reporting_ids_count,
119 // TrustedInitialized). 118 prefs::mojom::ResetOnLoadObserverPtr reset_on_load_observer,
120 std::unique_ptr<PrefHashStore> GetPrefHashStore(bool use_super_mac); 119 prefs::mojom::TrackedPreferenceValidationDelegatePtr validation_delegate);
121
122 // Returns a PrefHashStore and HashStoreContents which can be be used for
123 // extra out-of-band verifications, or nullptrs if not available on this
124 // platform.
125 std::pair<std::unique_ptr<PrefHashStore>, std::unique_ptr<HashStoreContents>>
126 GetExternalVerificationPrefHashStorePair();
127
128 // Connects to the pref service over mojo and configures it.
129 void ConfigurePrefService(const base::Closure& on_reset_on_load,
130 service_manager::Connector* connector);
131 120
132 const base::FilePath profile_path_; 121 const base::FilePath profile_path_;
133 std::vector<prefs::mojom::TrackedPreferenceMetadataPtr>
134 tracking_configuration_;
135 const size_t reporting_ids_count_;
136 const std::string seed_; 122 const std::string seed_;
137 const std::string legacy_device_id_; 123 const std::string legacy_device_id_;
138 PrefService* local_state_;
139 124
140 DISALLOW_COPY_AND_ASSIGN(ProfilePrefStoreManager); 125 DISALLOW_COPY_AND_ASSIGN(ProfilePrefStoreManager);
141 }; 126 };
142 127
143 #endif // CHROME_BROWSER_PREFS_PROFILE_PREF_STORE_MANAGER_H_ 128 #endif // CHROME_BROWSER_PREFS_PROFILE_PREF_STORE_MANAGER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698