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
3 // found in the LICENSE file.
5 #ifndef CHROME_BROWSER_PREFS_PROFILE_PREF_STORE_MANAGER_H_
6 #define CHROME_BROWSER_PREFS_PROFILE_PREF_STORE_MANAGER_H_
11 #include "base/files/file_path.h"
12 #include "base/macros.h"
13 #include "base/memory/ref_counted.h"
14 #include "base/memory/scoped_ptr.h"
15 #include "chrome/browser/prefs/pref_hash_filter.h"
17 class PersistentPrefStore;
18 class PrefHashStoreImpl;
22 class DictionaryValue;
23 class SequencedTaskRunner;
26 namespace user_prefs {
27 class PrefRegistrySyncable;
28 } // namespace user_prefs
30 class PrefRegistrySimple;
32 // Provides a facade through which the user preference store may be accessed and
34 class ProfilePrefStoreManager {
36 // Instantiates a ProfilePrefStoreManager with the configuration required to
37 // manage the user preferences of the profile at |profile_path|.
38 // |tracking_configuration| is used for preference tracking.
39 // |reporting_ids_count| is the count of all possible tracked preference IDs
40 // (possibly greater than |tracking_configuration.size()|).
41 // |seed| and |device_id| are used to track preference value changes and must
42 // be the same on each launch in order to verify loaded preference values.
43 ProfilePrefStoreManager(
44 const base::FilePath& profile_path,
45 const std::vector<PrefHashFilter::TrackedPreferenceMetadata>&
46 tracking_configuration,
47 size_t reporting_ids_count,
48 const std::string& seed,
49 const std::string& device_id,
50 PrefService* local_state);
52 ~ProfilePrefStoreManager();
54 static const bool kPlatformSupportsPreferenceTracking;
56 // Register local state prefs used by the profile preferences system.
57 static void RegisterPrefs(PrefRegistrySimple* registry);
59 // Register user prefs used by the profile preferences system.
60 static void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry);
62 // Determines the user preferences filename for the profile at |profile_path|.
63 static base::FilePath GetPrefFilePathFromProfilePath(
64 const base::FilePath& profile_path);
66 // Deletes stored hashes for all profiles from |local_state|.
67 static void ResetAllPrefHashStores(PrefService* local_state);
69 // Retrieves the time of the last preference reset event, if any, for
70 // |pref_service|. Assumes that |pref_service| is backed by a PrefStore that
71 // was built by ProfilePrefStoreManager.
72 // If no reset has occurred, returns a null |Time|.
73 static base::Time GetResetTime(PrefService* pref_service);
75 // Clears the time of the last preference reset event, if any, for
76 // |pref_service|. Assumes that |pref_service| is backed by a PrefStore that
77 // was built by ProfilePrefStoreManager.
78 static void ClearResetTime(PrefService* pref_service);
80 // Deletes stored hashes for the managed profile.
81 void ResetPrefHashStore();
83 // Creates a PersistentPrefStore providing access to the user preferences of
84 // the managed profile.
85 PersistentPrefStore* CreateProfilePrefStore(
86 const scoped_refptr<base::SequencedTaskRunner>& io_task_runner);
88 // Checks the presence/version of the hash store for the managed profile and
89 // creates or updates it if necessary. Completes asynchronously and is safe if
90 // the preferences/hash store are concurrently loaded/manipulated by another
92 void UpdateProfileHashStoreIfRequired(
93 const scoped_refptr<base::SequencedTaskRunner>& io_task_runner);
95 // Initializes the preferences for the managed profile with the preference
96 // values in |master_prefs|. Acts synchronously, including blocking IO.
97 // Returns true on success.
98 bool InitializePrefsFromMasterPrefs(
99 const base::DictionaryValue& master_prefs);
102 class InitializeHashStoreObserver;
104 // Returns a PrefHashStoreImpl for the managed profile. Should only be called
105 // if |kPlatformSupportsPreferenceTracking|.
106 scoped_ptr<PrefHashStoreImpl> GetPrefHashStoreImpl();
108 const base::FilePath profile_path_;
109 const std::vector<PrefHashFilter::TrackedPreferenceMetadata>
110 tracking_configuration_;
111 const size_t reporting_ids_count_;
112 const std::string seed_;
113 const std::string device_id_;
114 PrefService* local_state_;
116 DISALLOW_COPY_AND_ASSIGN(ProfilePrefStoreManager);
119 #endif // CHROME_BROWSER_PREFS_PROFILE_PREF_STORE_MANAGER_H_