OLD | NEW |
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. | 43 // |tracking_configuration| is used for preference tracking. |
51 // |reporting_ids_count| is the count of all possible tracked preference IDs | 44 // |reporting_ids_count| is the count of all possible tracked preference IDs |
52 // (possibly greater than |tracking_configuration.size()|). | 45 // (possibly greater than |tracking_configuration.size()|). |
53 // |seed| and |legacy_device_id| are used to track preference value changes | 46 // |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 | 47 // and must be the same on each launch in order to verify loaded preference |
55 // values. | 48 // values. |
56 ProfilePrefStoreManager( | 49 ProfilePrefStoreManager( |
57 const base::FilePath& profile_path, | 50 const base::FilePath& profile_path, |
58 std::vector<prefs::mojom::TrackedPreferenceMetadataPtr> | 51 std::vector<prefs::mojom::TrackedPreferenceMetadataPtr> |
59 tracking_configuration, | 52 tracking_configuration, |
60 size_t reporting_ids_count, | 53 size_t reporting_ids_count, |
61 const std::string& seed, | 54 const std::string& seed, |
62 const std::string& legacy_device_id, | 55 const std::string& legacy_device_id); |
63 PrefService* local_state); | |
64 | 56 |
65 ~ProfilePrefStoreManager(); | 57 ~ProfilePrefStoreManager(); |
66 | 58 |
67 static const bool kPlatformSupportsPreferenceTracking; | 59 static const bool kPlatformSupportsPreferenceTracking; |
68 | 60 |
69 // Register user prefs used by the profile preferences system. | 61 // Register user prefs used by the profile preferences system. |
70 static void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry); | 62 static void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry); |
71 | 63 |
72 // Retrieves the time of the last preference reset event, if any, for | 64 // 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 | 65 // |pref_service|. Assumes that |pref_service| is backed by a PrefStore that |
74 // was built by ProfilePrefStoreManager. | 66 // was built by ProfilePrefStoreManager. |
75 // If no reset has occurred, returns a null |Time|. | 67 // If no reset has occurred, returns a null |Time|. |
76 static base::Time GetResetTime(PrefService* pref_service); | 68 static base::Time GetResetTime(PrefService* pref_service); |
77 | 69 |
78 // Clears the time of the last preference reset event, if any, for | 70 // 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 | 71 // |pref_service|. Assumes that |pref_service| is backed by a PrefStore that |
80 // was built by ProfilePrefStoreManager. | 72 // was built by ProfilePrefStoreManager. |
81 static void ClearResetTime(PrefService* pref_service); | 73 static void ClearResetTime(PrefService* pref_service); |
82 | 74 |
83 #if defined(OS_WIN) | 75 #if defined(OS_WIN) |
84 // Call before startup tasks kick in to use a different registry path for | 76 // Call before startup tasks kick in to use a different registry path for |
85 // storing and validating tracked preference MACs. Callers are responsible | 77 // storing and validating tracked preference MACs. Callers are responsible |
86 // for ensuring that the key is deleted on shutdown. For testing only. | 78 // for ensuring that the key is deleted on shutdown. For testing only. |
87 static void SetPreferenceValidationRegistryPathForTesting( | 79 static void SetPreferenceValidationRegistryPathForTesting( |
88 const base::string16* path); | 80 const base::string16* path); |
89 #endif | 81 #endif |
90 | 82 |
91 // Creates a PersistentPrefStore providing access to the user preferences of | 83 // 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 | 84 // 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. | 85 // notified if a reset occurs as a result of loading the profile's prefs. An |
94 // An optional |validation_delegate| will be notified | 86 // optional |validation_delegate| will be notified of the status of each |
95 // of the status of each tracked preference as they are checked. | 87 // tracked preference as they are checked. |
96 PersistentPrefStore* CreateProfilePrefStore( | 88 PersistentPrefStore* CreateProfilePrefStore( |
97 const scoped_refptr<base::SequencedTaskRunner>& io_task_runner, | 89 base::SequencedWorkerPool* worker_pool, |
98 const base::Closure& on_reset_on_load, | 90 prefs::mojom::ResetOnLoadObserverPtr reset_on_load_observer, |
99 prefs::mojom::TrackedPreferenceValidationDelegate* validation_delegate, | 91 prefs::mojom::TrackedPreferenceValidationDelegatePtr validation_delegate, |
100 service_manager::Connector* connector, | 92 service_manager::Connector* connector, |
101 scoped_refptr<PrefRegistry> pref_registry); | 93 scoped_refptr<PrefRegistry> pref_registry); |
102 | 94 |
103 // Initializes the preferences for the managed profile with the preference | 95 // Initializes the preferences for the managed profile with the preference |
104 // values in |master_prefs|. Acts synchronously, including blocking IO. | 96 // values in |master_prefs|. Acts synchronously, including blocking IO. |
105 // Returns true on success. | 97 // Returns true on success. |
106 bool InitializePrefsFromMasterPrefs( | 98 bool InitializePrefsFromMasterPrefs( |
107 std::unique_ptr<base::DictionaryValue> master_prefs); | 99 std::unique_ptr<base::DictionaryValue> master_prefs); |
108 | 100 |
109 // Creates a single-file PrefStore as was used in M34 and earlier. Used only | 101 private: |
110 // for testing migration. | 102 // Connects to the pref service over mojo and configures it. |
111 PersistentPrefStore* CreateDeprecatedCombinedProfilePrefStore( | 103 void ConfigurePrefService( |
112 const scoped_refptr<base::SequencedTaskRunner>& io_task_runner); | 104 prefs::mojom::ResetOnLoadObserverPtr reset_on_load_observer, |
| 105 prefs::mojom::TrackedPreferenceValidationDelegatePtr validation_delegate, |
| 106 service_manager::Connector* connector); |
113 | 107 |
114 private: | 108 prefs::mojom::TrackedPersistentPrefStoreConfigurationPtr |
115 // Returns a PrefHashStore for the managed profile. Should only be called | 109 CreateTrackedPrefStoreConfiguration( |
116 // if |kPlatformSupportsPreferenceTracking|. |use_super_mac| determines | 110 prefs::mojom::ResetOnLoadObserverPtr reset_on_load_observer, |
117 // whether the returned object will calculate, store, and validate super MACs | 111 prefs::mojom::TrackedPreferenceValidationDelegatePtr validation_delegate); |
118 // (and, by extension, accept non-null newly protected preferences as | |
119 // TrustedInitialized). | |
120 std::unique_ptr<PrefHashStore> GetPrefHashStore(bool use_super_mac); | |
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 | 112 |
132 const base::FilePath profile_path_; | 113 const base::FilePath profile_path_; |
133 std::vector<prefs::mojom::TrackedPreferenceMetadataPtr> | 114 std::vector<prefs::mojom::TrackedPreferenceMetadataPtr> |
134 tracking_configuration_; | 115 tracking_configuration_; |
135 const size_t reporting_ids_count_; | 116 const size_t reporting_ids_count_; |
136 const std::string seed_; | 117 const std::string seed_; |
137 const std::string legacy_device_id_; | 118 const std::string legacy_device_id_; |
138 PrefService* local_state_; | |
139 | 119 |
140 DISALLOW_COPY_AND_ASSIGN(ProfilePrefStoreManager); | 120 DISALLOW_COPY_AND_ASSIGN(ProfilePrefStoreManager); |
141 }; | 121 }; |
142 | 122 |
143 #endif // CHROME_BROWSER_PREFS_PROFILE_PREF_STORE_MANAGER_H_ | 123 #endif // CHROME_BROWSER_PREFS_PROFILE_PREF_STORE_MANAGER_H_ |
OLD | NEW |