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