| 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 sync_driver { | |
| 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 syncer::ModelTypeSet GetPreferredDataTypes( | |
| 101 syncer::ModelTypeSet registered_types) const; | |
| 102 // |preferred_types| should be a subset of |registered_types|. All | |
| 103 // types in |preferred_types| are marked preferred, and all types in | |
| 104 // |registered_types| \ |preferred_types| are marked not preferred. | |
| 105 // Changes are still made to the prefs even if | |
| 106 // HasKeepEverythingSynced() is true, but won't be visible until | |
| 107 // SetKeepEverythingSynced(false) is called. | |
| 108 void SetPreferredDataTypes(syncer::ModelTypeSet registered_types, | |
| 109 syncer::ModelTypeSet preferred_types); | |
| 110 | |
| 111 // This pref is set outside of sync. | |
| 112 bool IsManaged() const; | |
| 113 | |
| 114 // Use this encryption bootstrap token if we're using an explicit passphrase. | |
| 115 std::string GetEncryptionBootstrapToken() const; | |
| 116 void SetEncryptionBootstrapToken(const std::string& token); | |
| 117 | |
| 118 // Use this keystore bootstrap token if we're not using an explicit | |
| 119 // passphrase. | |
| 120 std::string GetKeystoreEncryptionBootstrapToken() const; | |
| 121 void SetKeystoreEncryptionBootstrapToken(const std::string& token); | |
| 122 | |
| 123 // Use this for the unique machine tag used for session sync. | |
| 124 std::string GetSyncSessionsGUID() const; | |
| 125 void SetSyncSessionsGUID(const std::string& guid); | |
| 126 | |
| 127 // Maps |data_type| to its corresponding preference name. | |
| 128 static const char* GetPrefNameForDataType(syncer::ModelType data_type); | |
| 129 | |
| 130 #if defined(OS_CHROMEOS) | |
| 131 // Use this spare bootstrap token only when setting up sync for the first | |
| 132 // time. | |
| 133 std::string GetSpareBootstrapToken() const; | |
| 134 void SetSpareBootstrapToken(const std::string& token); | |
| 135 #endif | |
| 136 | |
| 137 // Get/set/clear first sync time of current user. Used to roll back browsing | |
| 138 // data later when user signs out. | |
| 139 base::Time GetFirstSyncTime() const; | |
| 140 void SetFirstSyncTime(base::Time time); | |
| 141 void ClearFirstSyncTime(); | |
| 142 | |
| 143 // Out of band sync passphrase prompt getter/setter. | |
| 144 bool IsPassphrasePrompted() const; | |
| 145 void SetPassphrasePrompted(bool value); | |
| 146 | |
| 147 // For testing. | |
| 148 void SetManagedForTest(bool is_managed); | |
| 149 | |
| 150 // Get/Set number of memory warnings received. | |
| 151 int GetMemoryPressureWarningCount() const; | |
| 152 void SetMemoryPressureWarningCount(int value); | |
| 153 | |
| 154 // Check if the previous shutdown was clean. | |
| 155 bool DidSyncShutdownCleanly() const; | |
| 156 | |
| 157 // Set whether the last shutdown was clean. | |
| 158 void SetCleanShutdown(bool value); | |
| 159 | |
| 160 // Get/set for the last known sync invalidation versions. | |
| 161 void GetInvalidationVersions( | |
| 162 std::map<syncer::ModelType, int64_t>* invalidation_versions) const; | |
| 163 void UpdateInvalidationVersions( | |
| 164 const std::map<syncer::ModelType, int64_t>& invalidation_versions); | |
| 165 | |
| 166 // Will return the contents of the LastRunVersion preference. This may be an | |
| 167 // empty string if no version info was present, and is only valid at | |
| 168 // Sync startup time (after which the LastRunVersion preference will have been | |
| 169 // updated to the current version). | |
| 170 std::string GetLastRunVersion() const; | |
| 171 void SetLastRunVersion(const std::string& current_version); | |
| 172 | |
| 173 // Get/set for flag indicating that passphrase encryption transition is in | |
| 174 // progress. | |
| 175 void SetPassphraseEncryptionTransitionInProgress(bool value); | |
| 176 bool GetPassphraseEncryptionTransitionInProgress() const; | |
| 177 | |
| 178 // Get/set for saved Nigori state that needs to be passed to backend | |
| 179 // initialization after transition. | |
| 180 void SetSavedNigoriStateForPassphraseEncryptionTransition( | |
| 181 const syncer::SyncEncryptionHandler::NigoriState& nigori_state); | |
| 182 std::unique_ptr<syncer::SyncEncryptionHandler::NigoriState> | |
| 183 GetSavedNigoriStateForPassphraseEncryptionTransition() const; | |
| 184 | |
| 185 private: | |
| 186 void RegisterPrefGroups(); | |
| 187 | |
| 188 static void RegisterDataTypePreferredPref( | |
| 189 user_prefs::PrefRegistrySyncable* prefs, | |
| 190 syncer::ModelType type, | |
| 191 bool is_preferred); | |
| 192 bool GetDataTypePreferred(syncer::ModelType type) const; | |
| 193 void SetDataTypePreferred(syncer::ModelType type, bool is_preferred); | |
| 194 | |
| 195 // Returns a ModelTypeSet based on |types| expanded to include pref groups | |
| 196 // (see |pref_groups_|), but as a subset of |registered_types|. | |
| 197 syncer::ModelTypeSet ResolvePrefGroups(syncer::ModelTypeSet registered_types, | |
| 198 syncer::ModelTypeSet types) const; | |
| 199 | |
| 200 void OnSyncManagedPrefChanged(); | |
| 201 | |
| 202 // May be NULL. | |
| 203 PrefService* const pref_service_; | |
| 204 | |
| 205 base::ObserverList<SyncPrefObserver> sync_pref_observers_; | |
| 206 | |
| 207 // The preference that controls whether sync is under control by | |
| 208 // configuration management. | |
| 209 BooleanPrefMember pref_sync_managed_; | |
| 210 | |
| 211 // Groups of prefs that always have the same value as a "master" pref. | |
| 212 // For example, the APPS group has {APP_NOTIFICATIONS, APP_SETTINGS} | |
| 213 // (as well as APPS, but that is implied), so | |
| 214 // pref_groups_[syncer::APPS] = { syncer::APP_NOTIFICATIONS, | |
| 215 // syncer::APP_SETTINGS } | |
| 216 // pref_groups_[syncer::EXTENSIONS] = { syncer::EXTENSION_SETTINGS } | |
| 217 // etc. | |
| 218 typedef std::map<syncer::ModelType, syncer::ModelTypeSet> PrefGroupsMap; | |
| 219 PrefGroupsMap pref_groups_; | |
| 220 | |
| 221 DISALLOW_COPY_AND_ASSIGN(SyncPrefs); | |
| 222 }; | |
| 223 | |
| 224 } // namespace sync_driver | |
| 225 | |
| 226 #endif // COMPONENTS_SYNC_DRIVER_SYNC_PREFS_H_ | |
| OLD | NEW |