Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(575)

Side by Side Diff: chrome/browser/sync/profile_sync_service.cc

Issue 6905044: Refactor preference syncing. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix the previous fix Created 9 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/sync/profile_sync_service.h" 5 #include "chrome/browser/sync/profile_sync_service.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 #include <map> 8 #include <map>
9 #include <ostream> 9 #include <ostream>
10 #include <set> 10 #include <set>
(...skipping 23 matching lines...) Expand all
34 #include "chrome/browser/sync/js_arg_list.h" 34 #include "chrome/browser/sync/js_arg_list.h"
35 #include "chrome/browser/sync/profile_sync_factory.h" 35 #include "chrome/browser/sync/profile_sync_factory.h"
36 #include "chrome/browser/sync/signin_manager.h" 36 #include "chrome/browser/sync/signin_manager.h"
37 #include "chrome/browser/ui/browser.h" 37 #include "chrome/browser/ui/browser.h"
38 #include "chrome/browser/ui/browser_list.h" 38 #include "chrome/browser/ui/browser_list.h"
39 #include "chrome/common/chrome_switches.h" 39 #include "chrome/common/chrome_switches.h"
40 #include "chrome/common/net/gaia/gaia_constants.h" 40 #include "chrome/common/net/gaia/gaia_constants.h"
41 #include "chrome/common/pref_names.h" 41 #include "chrome/common/pref_names.h"
42 #include "chrome/common/time_format.h" 42 #include "chrome/common/time_format.h"
43 #include "chrome/common/url_constants.h" 43 #include "chrome/common/url_constants.h"
44 #include "content/common/notification_details.h" 44 #include "content/common/notification_service.h"
45 #include "content/common/notification_source.h"
46 #include "content/common/notification_type.h"
47 #include "grit/generated_resources.h" 45 #include "grit/generated_resources.h"
48 #include "ui/base/l10n/l10n_util.h" 46 #include "ui/base/l10n/l10n_util.h"
49 #include "ui/gfx/native_widget_types.h" 47 #include "ui/gfx/native_widget_types.h"
50 48
51 using browser_sync::ChangeProcessor; 49 using browser_sync::ChangeProcessor;
52 using browser_sync::DataTypeController; 50 using browser_sync::DataTypeController;
53 using browser_sync::DataTypeManager; 51 using browser_sync::DataTypeManager;
54 using browser_sync::SyncBackendHost; 52 using browser_sync::SyncBackendHost;
55 using sync_api::SyncCredentials; 53 using sync_api::SyncCredentials;
56 54
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
132 pref_sync_managed_.Init(prefs::kSyncManaged, profile_->GetPrefs(), this); 130 pref_sync_managed_.Init(prefs::kSyncManaged, profile_->GetPrefs(), this);
133 131
134 // For now, the only thing we can do through policy is to turn sync off. 132 // For now, the only thing we can do through policy is to turn sync off.
135 if (IsManaged()) { 133 if (IsManaged()) {
136 DisableForUser(); 134 DisableForUser();
137 return; 135 return;
138 } 136 }
139 137
140 RegisterAuthNotifications(); 138 RegisterAuthNotifications();
141 139
140 // This will synchronously trigger all new model associators to register
141 // themselves. We do this in initialize so that we can ensure all datatype
142 // controllers have been registered and to ensure any services we depend on
143 // have already been initialized.
144 NotificationService::current()->Notify(
145 NotificationType::PROFILE_SYNC_SERVICE_LOADING,
146 Source<ProfileSyncService>(this),
147 NotificationService::NoDetails());
148
142 // In Chrome, we integrate a SigninManager which works with the sync 149 // In Chrome, we integrate a SigninManager which works with the sync
143 // setup wizard to kick off the TokenService. CrOS does its own plumbing 150 // setup wizard to kick off the TokenService. CrOS does its own plumbing
144 // for the TokenService. 151 // for the TokenService.
145 if (cros_user_.empty()) { 152 if (cros_user_.empty()) {
146 // Will load tokens from DB and broadcast Token events after. 153 // Will load tokens from DB and broadcast Token events after.
147 // Note: We rely on signin_ != NULL unless !cros_user_.empty(). 154 // Note: We rely on signin_ != NULL unless !cros_user_.empty().
148 signin_.reset(new SigninManager()); 155 signin_.reset(new SigninManager());
149 signin_->Initialize(profile_); 156 signin_->Initialize(profile_);
150 } 157 }
151 158
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
236 << "is invalid: " << value; 243 << "is invalid: " << value;
237 } 244 }
238 } 245 }
239 } 246 }
240 } 247 }
241 248
242 void ProfileSyncService::RegisterPreferences() { 249 void ProfileSyncService::RegisterPreferences() {
243 PrefService* pref_service = profile_->GetPrefs(); 250 PrefService* pref_service = profile_->GetPrefs();
244 if (pref_service->FindPreference(prefs::kSyncLastSyncedTime)) 251 if (pref_service->FindPreference(prefs::kSyncLastSyncedTime))
245 return; 252 return;
246 pref_service->RegisterInt64Pref(prefs::kSyncLastSyncedTime, 0); 253 pref_service->RegisterInt64Pref(prefs::kSyncLastSyncedTime,
247 pref_service->RegisterBooleanPref(prefs::kSyncHasSetupCompleted, false); 254 0,
248 pref_service->RegisterBooleanPref(prefs::kSyncSuppressStart, false); 255 false /* don't sync pref */);
256 pref_service->RegisterBooleanPref(prefs::kSyncHasSetupCompleted,
257 false,
258 false /* don't sync pref */);
259 pref_service->RegisterBooleanPref(prefs::kSyncSuppressStart,
260 false,
261 false /* don't sync pref */);
249 262
250 // If you've never synced before, or if you're using Chrome OS, all datatypes 263 // If you've never synced before, or if you're using Chrome OS, all datatypes
251 // are on by default. 264 // are on by default.
252 // TODO(nick): Perhaps a better model would be to always default to false, 265 // TODO(nick): Perhaps a better model would be to always default to false,
253 // and explicitly call SetDataTypes() when the user shows the wizard. 266 // and explicitly call SetDataTypes() when the user shows the wizard.
254 #if defined(OS_CHROMEOS) 267 #if defined(OS_CHROMEOS)
255 bool enable_by_default = true; 268 bool enable_by_default = true;
256 #else 269 #else
257 bool enable_by_default = 270 bool enable_by_default =
258 !pref_service->HasPrefPath(prefs::kSyncHasSetupCompleted); 271 !pref_service->HasPrefPath(prefs::kSyncHasSetupCompleted);
259 #endif 272 #endif
260 273
261 pref_service->RegisterBooleanPref(prefs::kSyncBookmarks, true); 274 pref_service->RegisterBooleanPref(prefs::kSyncBookmarks,
262 pref_service->RegisterBooleanPref(prefs::kSyncPasswords, enable_by_default); 275 true,
263 pref_service->RegisterBooleanPref(prefs::kSyncPreferences, enable_by_default); 276 false /* don't sync pref */);
264 pref_service->RegisterBooleanPref(prefs::kSyncAutofill, enable_by_default); 277 pref_service->RegisterBooleanPref(prefs::kSyncPasswords,
265 pref_service->RegisterBooleanPref(prefs::kSyncThemes, enable_by_default); 278 enable_by_default,
266 pref_service->RegisterBooleanPref(prefs::kSyncTypedUrls, enable_by_default); 279 false /* don't sync pref */);
267 pref_service->RegisterBooleanPref(prefs::kSyncExtensions, enable_by_default); 280 pref_service->RegisterBooleanPref(prefs::kSyncPreferences,
268 pref_service->RegisterBooleanPref(prefs::kSyncApps, enable_by_default); 281 enable_by_default,
269 pref_service->RegisterBooleanPref(prefs::kSyncSessions, enable_by_default); 282 false /* don't sync pref */);
283 pref_service->RegisterBooleanPref(prefs::kSyncAutofill,
284 enable_by_default,
285 false /* don't sync pref */);
286 pref_service->RegisterBooleanPref(prefs::kSyncThemes,
287 enable_by_default,
288 false /* don't sync pref */);
289 pref_service->RegisterBooleanPref(prefs::kSyncTypedUrls,
290 enable_by_default,
291 false /* don't sync pref */);
292 pref_service->RegisterBooleanPref(prefs::kSyncExtensions,
293 enable_by_default,
294 false /* don't sync pref */);
295 pref_service->RegisterBooleanPref(prefs::kSyncApps,
296 enable_by_default,
297 false /* don't sync pref */);
298 pref_service->RegisterBooleanPref(prefs::kSyncSessions,
299 enable_by_default,
300 false /* don't sync pref */);
270 pref_service->RegisterBooleanPref(prefs::kKeepEverythingSynced, 301 pref_service->RegisterBooleanPref(prefs::kKeepEverythingSynced,
271 enable_by_default); 302 enable_by_default,
272 pref_service->RegisterBooleanPref(prefs::kSyncManaged, false); 303 false /* don't sync pref */);
273 pref_service->RegisterStringPref(prefs::kEncryptionBootstrapToken, ""); 304 pref_service->RegisterBooleanPref(prefs::kSyncManaged,
305 false,
306 false /* don't sync pref */);
307 pref_service->RegisterStringPref(prefs::kEncryptionBootstrapToken,
308 "",
309 false /* don't sync pref */);
274 310
275 pref_service->RegisterBooleanPref(prefs::kSyncAutofillProfile, 311 pref_service->RegisterBooleanPref(prefs::kSyncAutofillProfile,
276 enable_by_default); 312 enable_by_default,
313 false /* don't sync pref */);
277 } 314 }
278 315
279 void ProfileSyncService::ClearPreferences() { 316 void ProfileSyncService::ClearPreferences() {
280 PrefService* pref_service = profile_->GetPrefs(); 317 PrefService* pref_service = profile_->GetPrefs();
281 pref_service->ClearPref(prefs::kSyncLastSyncedTime); 318 pref_service->ClearPref(prefs::kSyncLastSyncedTime);
282 pref_service->ClearPref(prefs::kSyncHasSetupCompleted); 319 pref_service->ClearPref(prefs::kSyncHasSetupCompleted);
283 pref_service->ClearPref(prefs::kEncryptionBootstrapToken); 320 pref_service->ClearPref(prefs::kEncryptionBootstrapToken);
284 321
285 // TODO(nick): The current behavior does not clear e.g. prefs::kSyncBookmarks. 322 // TODO(nick): The current behavior does not clear e.g. prefs::kSyncBookmarks.
286 // Is that really what we want? 323 // Is that really what we want?
(...skipping 776 matching lines...) Expand 10 before | Expand all | Expand 10 after
1063 void ProfileSyncService::SetAutofillMigrationDebugInfo( 1100 void ProfileSyncService::SetAutofillMigrationDebugInfo(
1064 syncable::AutofillMigrationDebugInfo::PropertyToSet property_to_set, 1101 syncable::AutofillMigrationDebugInfo::PropertyToSet property_to_set,
1065 const syncable::AutofillMigrationDebugInfo& info) { 1102 const syncable::AutofillMigrationDebugInfo& info) {
1066 if (backend_.get() && backend_initialized_) { 1103 if (backend_.get() && backend_initialized_) {
1067 backend_->SetAutofillMigrationDebugInfo(property_to_set, info); 1104 backend_->SetAutofillMigrationDebugInfo(property_to_set, info);
1068 } else { 1105 } else {
1069 NOTREACHED(); 1106 NOTREACHED();
1070 } 1107 }
1071 } 1108 }
1072 1109
1110 void ProfileSyncService::RegisterModelAssociator(
1111 browser_sync::NewAssociatorInterface* associator) {
1112 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
1113 syncable::ModelType model_type = associator->model_type();
1114 if (data_type_controllers_.count(model_type) > 0) {
1115 DCHECK(!data_type_controllers_[model_type]->model_associator());
1116 data_type_controllers_[model_type]->set_model_associator(associator);
1117
1118 // TODO(zea): pass the generic change processor's pointer back to the model
1119 // associator.
1120 }
1121 }
1122
1073 void ProfileSyncService::ActivateDataType( 1123 void ProfileSyncService::ActivateDataType(
1074 DataTypeController* data_type_controller, 1124 DataTypeController* data_type_controller,
1075 ChangeProcessor* change_processor) { 1125 ChangeProcessor* change_processor) {
1076 if (!backend_.get()) { 1126 if (!backend_.get()) {
1077 NOTREACHED(); 1127 NOTREACHED();
1078 return; 1128 return;
1079 } 1129 }
1080 DCHECK(backend_initialized_); 1130 DCHECK(backend_initialized_);
1081 change_processor->Start(profile(), backend_->GetUserShare()); 1131 if (change_processor) {
1082 backend_->ActivateDataType(data_type_controller, change_processor); 1132 backend_->ActivateDataType(data_type_controller, change_processor);
1133 } else {
1134 // New associator interface.
1135 // TODO(zea): Remove change processor argument here once we have a generic
1136 // change processor.
1137 backend_->ActivateDataType(
1138 data_type_controller,
1139 data_type_controller->model_associator()->change_processor());
1140 }
1083 } 1141 }
1084 1142
1085 void ProfileSyncService::DeactivateDataType( 1143 void ProfileSyncService::DeactivateDataType(
1086 DataTypeController* data_type_controller, 1144 DataTypeController* data_type_controller,
1087 ChangeProcessor* change_processor) { 1145 ChangeProcessor* change_processor) {
1088 change_processor->Stop(); 1146 if (!backend_.get())
1089 if (backend_.get()) 1147 return;
1148 if (change_processor) {
1090 backend_->DeactivateDataType(data_type_controller, change_processor); 1149 backend_->DeactivateDataType(data_type_controller, change_processor);
1150 } else {
1151 // New associator interface.
1152 // TODO(zea): Remove change processor argument here once we have a generic
1153 // change processor.
1154 backend_->DeactivateDataType(
1155 data_type_controller,
1156 data_type_controller->model_associator()->change_processor());
1157 }
1091 } 1158 }
1092 1159
1093 void ProfileSyncService::SetPassphrase(const std::string& passphrase, 1160 void ProfileSyncService::SetPassphrase(const std::string& passphrase,
1094 bool is_explicit, 1161 bool is_explicit,
1095 bool is_creation) { 1162 bool is_creation) {
1096 if (ShouldPushChanges() || observed_passphrase_required_) { 1163 if (ShouldPushChanges() || observed_passphrase_required_) {
1097 backend_->SetPassphrase(passphrase, is_explicit); 1164 backend_->SetPassphrase(passphrase, is_explicit);
1098 } else { 1165 } else {
1099 cached_passphrase_.value = passphrase; 1166 cached_passphrase_.value = passphrase;
1100 cached_passphrase_.is_explicit = is_explicit; 1167 cached_passphrase_.is_explicit = is_explicit;
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after
1274 // is initialized, all enabled data types are consistent with one 1341 // is initialized, all enabled data types are consistent with one
1275 // another, and no unrecoverable error has transpired. 1342 // another, and no unrecoverable error has transpired.
1276 if (unrecoverable_error_detected_) 1343 if (unrecoverable_error_detected_)
1277 return false; 1344 return false;
1278 1345
1279 if (!data_type_manager_.get()) 1346 if (!data_type_manager_.get())
1280 return false; 1347 return false;
1281 1348
1282 return data_type_manager_->state() == DataTypeManager::CONFIGURED; 1349 return data_type_manager_->state() == DataTypeManager::CONFIGURED;
1283 } 1350 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698