OLD | NEW |
| (Empty) |
1 // Copyright (c) 2012 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 COMPONENTS_SYNC_DRIVER_SYNC_PREFS_H_ | |
6 #define COMPONENTS_SYNC_DRIVER_SYNC_PREFS_H_ | |
7 | |
8 #include <stdint.h> | |
9 | |
10 #include <map> | |
11 #include <memory> | |
12 #include <string> | |
13 | |
14 #include "base/compiler_specific.h" | |
15 #include "base/macros.h" | |
16 #include "base/memory/weak_ptr.h" | |
17 #include "base/observer_list.h" | |
18 #include "base/threading/non_thread_safe.h" | |
19 #include "base/time/time.h" | |
20 #include "build/build_config.h" | |
21 #include "components/prefs/pref_member.h" | |
22 #include "components/sync/base/model_type.h" | |
23 #include "components/sync/core/sync_encryption_handler.h" | |
24 | |
25 class PrefService; | |
26 class ProfileIOData; | |
27 | |
28 namespace user_prefs { | |
29 class PrefRegistrySyncable; | |
30 } | |
31 | |
32 namespace syncer { | |
33 | |
34 class SyncPrefObserver { | |
35 public: | |
36 // Called whenever the pref that controls whether sync is managed | |
37 // changes. | |
38 virtual void OnSyncManagedPrefChange(bool is_sync_managed) = 0; | |
39 | |
40 protected: | |
41 virtual ~SyncPrefObserver(); | |
42 }; | |
43 | |
44 // SyncPrefs is a helper class that manages getting, setting, and | |
45 // persisting global sync preferences. It is not thread-safe, and | |
46 // lives on the UI thread. | |
47 // | |
48 // TODO(akalin): Some classes still read the prefs directly. Consider | |
49 // passing down a pointer to SyncPrefs to them. A list of files: | |
50 // | |
51 // profile_sync_service_startup_unittest.cc | |
52 // profile_sync_service.cc | |
53 // sync_setup_flow.cc | |
54 // sync_setup_wizard.cc | |
55 // sync_setup_wizard_unittest.cc | |
56 // two_client_preferences_sync_test.cc | |
57 class SyncPrefs : NON_EXPORTED_BASE(public base::NonThreadSafe), | |
58 public base::SupportsWeakPtr<SyncPrefs> { | |
59 public: | |
60 // |pref_service| may not be NULL. | |
61 // Does not take ownership of |pref_service|. | |
62 explicit SyncPrefs(PrefService* pref_service); | |
63 | |
64 // For testing. | |
65 SyncPrefs(); | |
66 | |
67 virtual ~SyncPrefs(); | |
68 | |
69 static void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry); | |
70 | |
71 void AddSyncPrefObserver(SyncPrefObserver* sync_pref_observer); | |
72 void RemoveSyncPrefObserver(SyncPrefObserver* sync_pref_observer); | |
73 | |
74 // Clears important sync preferences. | |
75 void ClearPreferences(); | |
76 | |
77 // Getters and setters for global sync prefs. | |
78 | |
79 bool IsFirstSetupComplete() const; | |
80 void SetFirstSetupComplete(); | |
81 | |
82 bool SyncHasAuthError() const; | |
83 void SetSyncAuthError(bool error); | |
84 | |
85 bool IsSyncRequested() const; | |
86 void SetSyncRequested(bool is_requested); | |
87 | |
88 base::Time GetLastSyncedTime() const; | |
89 void SetLastSyncedTime(base::Time time); | |
90 | |
91 base::Time GetLastPollTime() const; | |
92 void SetLastPollTime(base::Time time); | |
93 | |
94 bool HasKeepEverythingSynced() const; | |
95 void SetKeepEverythingSynced(bool keep_everything_synced); | |
96 | |
97 // The returned set is guaranteed to be a subset of | |
98 // |registered_types|. Returns |registered_types| directly if | |
99 // HasKeepEverythingSynced() is true. | |
100 ModelTypeSet GetPreferredDataTypes(ModelTypeSet registered_types) const; | |
101 // |preferred_types| should be a subset of |registered_types|. All | |
102 // types in |preferred_types| are marked preferred, and all types in | |
103 // |registered_types| \ |preferred_types| are marked not preferred. | |
104 // Changes are still made to the prefs even if | |
105 // HasKeepEverythingSynced() is true, but won't be visible until | |
106 // SetKeepEverythingSynced(false) is called. | |
107 void SetPreferredDataTypes(ModelTypeSet registered_types, | |
108 ModelTypeSet preferred_types); | |
109 | |
110 // This pref is set outside of sync. | |
111 bool IsManaged() const; | |
112 | |
113 // Use this encryption bootstrap token if we're using an explicit passphrase. | |
114 std::string GetEncryptionBootstrapToken() const; | |
115 void SetEncryptionBootstrapToken(const std::string& token); | |
116 | |
117 // Use this keystore bootstrap token if we're not using an explicit | |
118 // passphrase. | |
119 std::string GetKeystoreEncryptionBootstrapToken() const; | |
120 void SetKeystoreEncryptionBootstrapToken(const std::string& token); | |
121 | |
122 // Use this for the unique machine tag used for session sync. | |
123 std::string GetSyncSessionsGUID() const; | |
124 void SetSyncSessionsGUID(const std::string& guid); | |
125 | |
126 // Maps |data_type| to its corresponding preference name. | |
127 static const char* GetPrefNameForDataType(ModelType data_type); | |
128 | |
129 #if defined(OS_CHROMEOS) | |
130 // Use this spare bootstrap token only when setting up sync for the first | |
131 // time. | |
132 std::string GetSpareBootstrapToken() const; | |
133 void SetSpareBootstrapToken(const std::string& token); | |
134 #endif | |
135 | |
136 // Get/set/clear first sync time of current user. Used to roll back browsing | |
137 // data later when user signs out. | |
138 base::Time GetFirstSyncTime() const; | |
139 void SetFirstSyncTime(base::Time time); | |
140 void ClearFirstSyncTime(); | |
141 | |
142 // Out of band sync passphrase prompt getter/setter. | |
143 bool IsPassphrasePrompted() const; | |
144 void SetPassphrasePrompted(bool value); | |
145 | |
146 // For testing. | |
147 void SetManagedForTest(bool is_managed); | |
148 | |
149 // Get/Set number of memory warnings received. | |
150 int GetMemoryPressureWarningCount() const; | |
151 void SetMemoryPressureWarningCount(int value); | |
152 | |
153 // Check if the previous shutdown was clean. | |
154 bool DidSyncShutdownCleanly() const; | |
155 | |
156 // Set whether the last shutdown was clean. | |
157 void SetCleanShutdown(bool value); | |
158 | |
159 // Get/set for the last known sync invalidation versions. | |
160 void GetInvalidationVersions( | |
161 std::map<ModelType, int64_t>* invalidation_versions) const; | |
162 void UpdateInvalidationVersions( | |
163 const std::map<ModelType, int64_t>& invalidation_versions); | |
164 | |
165 // Will return the contents of the LastRunVersion preference. This may be an | |
166 // empty string if no version info was present, and is only valid at | |
167 // Sync startup time (after which the LastRunVersion preference will have been | |
168 // updated to the current version). | |
169 std::string GetLastRunVersion() const; | |
170 void SetLastRunVersion(const std::string& current_version); | |
171 | |
172 // Get/set for flag indicating that passphrase encryption transition is in | |
173 // progress. | |
174 void SetPassphraseEncryptionTransitionInProgress(bool value); | |
175 bool GetPassphraseEncryptionTransitionInProgress() const; | |
176 | |
177 // Get/set for saved Nigori state that needs to be passed to backend | |
178 // initialization after transition. | |
179 void SetSavedNigoriStateForPassphraseEncryptionTransition( | |
180 const SyncEncryptionHandler::NigoriState& nigori_state); | |
181 std::unique_ptr<SyncEncryptionHandler::NigoriState> | |
182 GetSavedNigoriStateForPassphraseEncryptionTransition() const; | |
183 | |
184 private: | |
185 void RegisterPrefGroups(); | |
186 | |
187 static void RegisterDataTypePreferredPref( | |
188 user_prefs::PrefRegistrySyncable* prefs, | |
189 ModelType type, | |
190 bool is_preferred); | |
191 bool GetDataTypePreferred(ModelType type) const; | |
192 void SetDataTypePreferred(ModelType type, bool is_preferred); | |
193 | |
194 // Returns a ModelTypeSet based on |types| expanded to include pref groups | |
195 // (see |pref_groups_|), but as a subset of |registered_types|. | |
196 ModelTypeSet ResolvePrefGroups(ModelTypeSet registered_types, | |
197 ModelTypeSet types) const; | |
198 | |
199 void OnSyncManagedPrefChanged(); | |
200 | |
201 // May be NULL. | |
202 PrefService* const pref_service_; | |
203 | |
204 base::ObserverList<SyncPrefObserver> sync_pref_observers_; | |
205 | |
206 // The preference that controls whether sync is under control by | |
207 // configuration management. | |
208 BooleanPrefMember pref_sync_managed_; | |
209 | |
210 // Groups of prefs that always have the same value as a "master" pref. | |
211 // For example, the APPS group has {APP_NOTIFICATIONS, APP_SETTINGS} | |
212 // (as well as APPS, but that is implied), so | |
213 // pref_groups_[APPS] = { APP_NOTIFICATIONS, | |
214 // APP_SETTINGS } | |
215 // pref_groups_[EXTENSIONS] = { EXTENSION_SETTINGS } | |
216 // etc. | |
217 typedef std::map<ModelType, ModelTypeSet> PrefGroupsMap; | |
218 PrefGroupsMap pref_groups_; | |
219 | |
220 DISALLOW_COPY_AND_ASSIGN(SyncPrefs); | |
221 }; | |
222 | |
223 } // namespace syncer | |
224 | |
225 #endif // COMPONENTS_SYNC_DRIVER_SYNC_PREFS_H_ | |
OLD | NEW |