f75d3d0eef4436daab6b6e1833a12c651827c2d9
[platform/framework/web/crosswalk.git] / src / chrome / browser / prefs / profile_pref_store_manager.h
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.
4
5 #ifndef CHROME_BROWSER_PREFS_PROFILE_PREF_STORE_MANAGER_H_
6 #define CHROME_BROWSER_PREFS_PROFILE_PREF_STORE_MANAGER_H_
7
8 #include <string>
9 #include <vector>
10
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"
16
17 class PersistentPrefStore;
18 class PrefHashStoreImpl;
19 class PrefService;
20
21 namespace base {
22 class DictionaryValue;
23 class SequencedTaskRunner;
24 }  // namespace base
25
26 namespace user_prefs {
27 class PrefRegistrySyncable;
28 }  // namespace user_prefs
29
30 class PrefRegistrySimple;
31
32 // Provides a facade through which the user preference store may be accessed and
33 // managed.
34 class ProfilePrefStoreManager {
35  public:
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);
51
52   ~ProfilePrefStoreManager();
53
54   static const bool kPlatformSupportsPreferenceTracking;
55
56   // Register local state prefs used by the profile preferences system.
57   static void RegisterPrefs(PrefRegistrySimple* registry);
58
59   // Register user prefs used by the profile preferences system.
60   static void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry);
61
62   // Determines the user preferences filename for the profile at |profile_path|.
63   static base::FilePath GetPrefFilePathFromProfilePath(
64       const base::FilePath& profile_path);
65
66   // Deletes stored hashes for all profiles from |local_state|.
67   static void ResetAllPrefHashStores(PrefService* local_state);
68
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);
74
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);
79
80   // Deletes stored hashes for the managed profile.
81   void ResetPrefHashStore();
82
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);
87
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
91   // task.
92   void UpdateProfileHashStoreIfRequired(
93       const scoped_refptr<base::SequencedTaskRunner>& io_task_runner);
94
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);
100
101  private:
102   class InitializeHashStoreObserver;
103
104   // Returns a PrefHashStoreImpl for the managed profile. Should only be called
105   // if |kPlatformSupportsPreferenceTracking|.
106   scoped_ptr<PrefHashStoreImpl> GetPrefHashStoreImpl();
107
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_;
115
116   DISALLOW_COPY_AND_ASSIGN(ProfilePrefStoreManager);
117 };
118
119 #endif  // CHROME_BROWSER_PREFS_PROFILE_PREF_STORE_MANAGER_H_