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