Refactor WebsiteSettings to operate on a SecurityInfo
[chromium-blink-merge.git] / chrome / browser / prefs / profile_pref_store_manager.h
blob51228008026fe147c1183d06ea94af4cc6985921
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_
8 #include <string>
9 #include <vector>
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 "components/user_prefs/tracked/pref_hash_filter.h"
17 class PersistentPrefStore;
18 class PrefHashStore;
19 class PrefService;
20 class TrackedPreferenceValidationDelegate;
22 namespace base {
23 class DictionaryValue;
24 class SequencedTaskRunner;
25 } // namespace base
27 namespace user_prefs {
28 class PrefRegistrySyncable;
29 } // namespace user_prefs
31 class PrefRegistrySimple;
33 // Provides a facade through which the user preference store may be accessed and
34 // managed.
35 class ProfilePrefStoreManager {
36 public:
37 // Instantiates a ProfilePrefStoreManager with the configuration required to
38 // manage the user preferences of the profile at |profile_path|.
39 // |tracking_configuration| is used for preference tracking.
40 // |reporting_ids_count| is the count of all possible tracked preference IDs
41 // (possibly greater than |tracking_configuration.size()|).
42 // |seed| and |device_id| are used to track preference value changes and must
43 // be the same on each launch in order to verify loaded preference values.
44 ProfilePrefStoreManager(
45 const base::FilePath& profile_path,
46 const std::vector<PrefHashFilter::TrackedPreferenceMetadata>&
47 tracking_configuration,
48 size_t reporting_ids_count,
49 const std::string& seed,
50 const std::string& device_id,
51 PrefService* local_state);
53 ~ProfilePrefStoreManager();
55 static const bool kPlatformSupportsPreferenceTracking;
57 // Register local state prefs used by the profile preferences system.
58 static void RegisterPrefs(PrefRegistrySimple* registry);
60 // Register user prefs used by the profile preferences system.
61 static void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry);
63 // Determines the user preferences filename for the profile at |profile_path|.
64 static base::FilePath GetPrefFilePathFromProfilePath(
65 const base::FilePath& profile_path);
67 // Deletes stored hashes for all profiles from |local_state|.
68 static void ResetAllPrefHashStores(PrefService* local_state);
70 // Retrieves the time of the last preference reset event, if any, for
71 // |pref_service|. Assumes that |pref_service| is backed by a PrefStore that
72 // was built by ProfilePrefStoreManager.
73 // If no reset has occurred, returns a null |Time|.
74 static base::Time GetResetTime(PrefService* pref_service);
76 // Clears the time of the last preference reset event, if any, for
77 // |pref_service|. Assumes that |pref_service| is backed by a PrefStore that
78 // was built by ProfilePrefStoreManager.
79 static void ClearResetTime(PrefService* pref_service);
81 // Creates a PersistentPrefStore providing access to the user preferences of
82 // the managed profile. If |on_reset| is provided, it will be invoked if a
83 // reset occurs as a result of loading the profile's prefs.
84 // An optional |validation_delegate| will be notified
85 // of the status of each tracked preference as they are checked.
86 PersistentPrefStore* CreateProfilePrefStore(
87 const scoped_refptr<base::SequencedTaskRunner>& io_task_runner,
88 const base::Closure& on_reset_on_load,
89 TrackedPreferenceValidationDelegate* validation_delegate);
91 // Initializes the preferences for the managed profile with the preference
92 // values in |master_prefs|. Acts synchronously, including blocking IO.
93 // Returns true on success.
94 bool InitializePrefsFromMasterPrefs(
95 const base::DictionaryValue& master_prefs);
97 // Creates a single-file PrefStore as was used in M34 and earlier. Used only
98 // for testing migration.
99 PersistentPrefStore* CreateDeprecatedCombinedProfilePrefStore(
100 const scoped_refptr<base::SequencedTaskRunner>& io_task_runner);
102 private:
103 // Returns a PrefHashStore for the managed profile. Should only be called
104 // if |kPlatformSupportsPreferenceTracking|. |use_super_mac| determines
105 // whether the returned object will calculate, store, and validate super MACs
106 // (and, by extension, accept non-null newly protected preferences as
107 // TrustedInitialized).
108 scoped_ptr<PrefHashStore> GetPrefHashStore(bool use_super_mac);
110 const base::FilePath profile_path_;
111 const std::vector<PrefHashFilter::TrackedPreferenceMetadata>
112 tracking_configuration_;
113 const size_t reporting_ids_count_;
114 const std::string seed_;
115 const std::string device_id_;
116 PrefService* local_state_;
118 DISALLOW_COPY_AND_ASSIGN(ProfilePrefStoreManager);
121 #endif // CHROME_BROWSER_PREFS_PROFILE_PREF_STORE_MANAGER_H_