OLD | NEW |
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 20 matching lines...) Expand all Loading... |
31 #include "chrome/browser/sync/glue/change_processor.h" | 31 #include "chrome/browser/sync/glue/change_processor.h" |
32 #include "chrome/browser/sync/glue/data_type_controller.h" | 32 #include "chrome/browser/sync/glue/data_type_controller.h" |
33 #include "chrome/browser/sync/glue/data_type_manager.h" | 33 #include "chrome/browser/sync/glue/data_type_manager.h" |
34 #include "chrome/browser/sync/glue/session_data_type_controller.h" | 34 #include "chrome/browser/sync/glue/session_data_type_controller.h" |
35 #include "chrome/browser/sync/js_arg_list.h" | 35 #include "chrome/browser/sync/js_arg_list.h" |
36 #include "chrome/browser/sync/js_event_details.h" | 36 #include "chrome/browser/sync/js_event_details.h" |
37 #include "chrome/browser/sync/profile_sync_factory.h" | 37 #include "chrome/browser/sync/profile_sync_factory.h" |
38 #include "chrome/browser/sync/signin_manager.h" | 38 #include "chrome/browser/sync/signin_manager.h" |
39 #include "chrome/browser/ui/browser.h" | 39 #include "chrome/browser/ui/browser.h" |
40 #include "chrome/browser/ui/browser_list.h" | 40 #include "chrome/browser/ui/browser_list.h" |
| 41 #include "chrome/common/chrome_notification_types.h" |
41 #include "chrome/common/chrome_switches.h" | 42 #include "chrome/common/chrome_switches.h" |
42 #include "chrome/common/chrome_version_info.h" | 43 #include "chrome/common/chrome_version_info.h" |
43 #include "chrome/common/net/gaia/gaia_constants.h" | 44 #include "chrome/common/net/gaia/gaia_constants.h" |
44 #include "chrome/common/pref_names.h" | 45 #include "chrome/common/pref_names.h" |
45 #include "chrome/common/time_format.h" | 46 #include "chrome/common/time_format.h" |
46 #include "chrome/common/url_constants.h" | 47 #include "chrome/common/url_constants.h" |
47 #include "content/common/notification_details.h" | 48 #include "content/common/notification_details.h" |
48 #include "content/common/notification_source.h" | 49 #include "content/common/notification_source.h" |
49 #include "content/common/notification_type.h" | |
50 #include "grit/generated_resources.h" | 50 #include "grit/generated_resources.h" |
51 #include "net/base/cookie_monster.h" | 51 #include "net/base/cookie_monster.h" |
52 #include "ui/base/l10n/l10n_util.h" | 52 #include "ui/base/l10n/l10n_util.h" |
53 | 53 |
54 using browser_sync::ChangeProcessor; | 54 using browser_sync::ChangeProcessor; |
55 using browser_sync::DataTypeController; | 55 using browser_sync::DataTypeController; |
56 using browser_sync::DataTypeManager; | 56 using browser_sync::DataTypeManager; |
57 using browser_sync::SyncBackendHost; | 57 using browser_sync::SyncBackendHost; |
58 using sync_api::SyncCredentials; | 58 using sync_api::SyncCredentials; |
59 | 59 |
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
168 } else if (AreCredentialsAvailable()) { | 168 } else if (AreCredentialsAvailable()) { |
169 // If we have credentials and sync setup finished, autostart the backend. | 169 // If we have credentials and sync setup finished, autostart the backend. |
170 // Note that if we haven't finished setting up sync, backend bring up will | 170 // Note that if we haven't finished setting up sync, backend bring up will |
171 // be done by the wizard. | 171 // be done by the wizard. |
172 StartUp(); | 172 StartUp(); |
173 } | 173 } |
174 } | 174 } |
175 | 175 |
176 void ProfileSyncService::RegisterAuthNotifications() { | 176 void ProfileSyncService::RegisterAuthNotifications() { |
177 registrar_.Add(this, | 177 registrar_.Add(this, |
178 NotificationType::TOKEN_AVAILABLE, | 178 chrome::NOTIFICATION_TOKEN_AVAILABLE, |
179 Source<TokenService>(profile_->GetTokenService())); | 179 Source<TokenService>(profile_->GetTokenService())); |
180 registrar_.Add(this, | 180 registrar_.Add(this, |
181 NotificationType::TOKEN_LOADING_FINISHED, | 181 chrome::NOTIFICATION_TOKEN_LOADING_FINISHED, |
182 Source<TokenService>(profile_->GetTokenService())); | 182 Source<TokenService>(profile_->GetTokenService())); |
183 registrar_.Add(this, | 183 registrar_.Add(this, |
184 NotificationType::GOOGLE_SIGNIN_SUCCESSFUL, | 184 chrome::NOTIFICATION_GOOGLE_SIGNIN_SUCCESSFUL, |
185 Source<Profile>(profile_)); | 185 Source<Profile>(profile_)); |
186 registrar_.Add(this, | 186 registrar_.Add(this, |
187 NotificationType::GOOGLE_SIGNIN_FAILED, | 187 chrome::NOTIFICATION_GOOGLE_SIGNIN_FAILED, |
188 Source<Profile>(profile_)); | 188 Source<Profile>(profile_)); |
189 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kEnableSyncOAuth)) { | 189 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kEnableSyncOAuth)) { |
190 registrar_.Add(this, | 190 registrar_.Add(this, |
191 NotificationType::COOKIE_CHANGED, | 191 chrome::NOTIFICATION_COOKIE_CHANGED, |
192 Source<Profile>(profile_)); | 192 Source<Profile>(profile_)); |
193 } | 193 } |
194 } | 194 } |
195 | 195 |
196 void ProfileSyncService::RegisterDataTypeController( | 196 void ProfileSyncService::RegisterDataTypeController( |
197 DataTypeController* data_type_controller) { | 197 DataTypeController* data_type_controller) { |
198 DCHECK_EQ(data_type_controllers_.count(data_type_controller->type()), 0U); | 198 DCHECK_EQ(data_type_controllers_.count(data_type_controller->type()), 0U); |
199 data_type_controllers_[data_type_controller->type()] = | 199 data_type_controllers_[data_type_controller->type()] = |
200 data_type_controller; | 200 data_type_controller; |
201 } | 201 } |
(...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
402 } | 402 } |
403 | 403 |
404 void ProfileSyncService::Shutdown(bool sync_disabled) { | 404 void ProfileSyncService::Shutdown(bool sync_disabled) { |
405 // Stop all data type controllers, if needed. | 405 // Stop all data type controllers, if needed. |
406 if (data_type_manager_.get()) { | 406 if (data_type_manager_.get()) { |
407 if (data_type_manager_->state() != DataTypeManager::STOPPED) { | 407 if (data_type_manager_->state() != DataTypeManager::STOPPED) { |
408 data_type_manager_->Stop(); | 408 data_type_manager_->Stop(); |
409 } | 409 } |
410 | 410 |
411 registrar_.Remove(this, | 411 registrar_.Remove(this, |
412 NotificationType::SYNC_CONFIGURE_START, | 412 chrome::NOTIFICATION_SYNC_CONFIGURE_START, |
413 Source<DataTypeManager>(data_type_manager_.get())); | 413 Source<DataTypeManager>(data_type_manager_.get())); |
414 registrar_.Remove(this, | 414 registrar_.Remove(this, |
415 NotificationType::SYNC_CONFIGURE_DONE, | 415 chrome::NOTIFICATION_SYNC_CONFIGURE_DONE, |
416 Source<DataTypeManager>(data_type_manager_.get())); | 416 Source<DataTypeManager>(data_type_manager_.get())); |
417 data_type_manager_.reset(); | 417 data_type_manager_.reset(); |
418 } | 418 } |
419 | 419 |
420 // Shutdown the migrator before the backend to ensure it doesn't pull a null | 420 // Shutdown the migrator before the backend to ensure it doesn't pull a null |
421 // snapshot. | 421 // snapshot. |
422 migrator_.reset(); | 422 migrator_.reset(); |
423 js_event_handlers_.RemoveBackend(); | 423 js_event_handlers_.RemoveBackend(); |
424 | 424 |
425 // Move aside the backend so nobody else tries to use it while we are | 425 // Move aside the backend so nobody else tries to use it while we are |
(...skipping 660 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1086 // knows what it's doing. | 1086 // knows what it's doing. |
1087 return backend_.get(); | 1087 return backend_.get(); |
1088 } | 1088 } |
1089 | 1089 |
1090 void ProfileSyncService::ConfigureDataTypeManager() { | 1090 void ProfileSyncService::ConfigureDataTypeManager() { |
1091 if (!data_type_manager_.get()) { | 1091 if (!data_type_manager_.get()) { |
1092 data_type_manager_.reset( | 1092 data_type_manager_.reset( |
1093 factory_->CreateDataTypeManager(backend_.get(), | 1093 factory_->CreateDataTypeManager(backend_.get(), |
1094 data_type_controllers_)); | 1094 data_type_controllers_)); |
1095 registrar_.Add(this, | 1095 registrar_.Add(this, |
1096 NotificationType::SYNC_CONFIGURE_START, | 1096 chrome::NOTIFICATION_SYNC_CONFIGURE_START, |
1097 Source<DataTypeManager>(data_type_manager_.get())); | 1097 Source<DataTypeManager>(data_type_manager_.get())); |
1098 registrar_.Add(this, | 1098 registrar_.Add(this, |
1099 NotificationType::SYNC_CONFIGURE_DONE, | 1099 chrome::NOTIFICATION_SYNC_CONFIGURE_DONE, |
1100 Source<DataTypeManager>(data_type_manager_.get())); | 1100 Source<DataTypeManager>(data_type_manager_.get())); |
1101 | 1101 |
1102 // We create the migrator at the same time. | 1102 // We create the migrator at the same time. |
1103 migrator_.reset( | 1103 migrator_.reset( |
1104 new browser_sync::BackendMigrator(this, data_type_manager_.get())); | 1104 new browser_sync::BackendMigrator(this, data_type_manager_.get())); |
1105 } | 1105 } |
1106 | 1106 |
1107 syncable::ModelTypeSet types; | 1107 syncable::ModelTypeSet types; |
1108 GetPreferredDataTypes(&types); | 1108 GetPreferredDataTypes(&types); |
1109 if (IsPassphraseRequiredForDecryption()) { | 1109 if (IsPassphraseRequiredForDecryption()) { |
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1231 DCHECK(encrypted_types->count(syncable::PASSWORDS)); | 1231 DCHECK(encrypted_types->count(syncable::PASSWORDS)); |
1232 } else { | 1232 } else { |
1233 // Either we are in an unrecoverable error or the sync is not yet done | 1233 // Either we are in an unrecoverable error or the sync is not yet done |
1234 // initializing. In either case just return the password type. During | 1234 // initializing. In either case just return the password type. During |
1235 // sync initialization the UI might need to know what our encrypted | 1235 // sync initialization the UI might need to know what our encrypted |
1236 // types are. | 1236 // types are. |
1237 (*encrypted_types).insert(syncable::PASSWORDS); | 1237 (*encrypted_types).insert(syncable::PASSWORDS); |
1238 } | 1238 } |
1239 } | 1239 } |
1240 | 1240 |
1241 void ProfileSyncService::Observe(NotificationType type, | 1241 void ProfileSyncService::Observe(int type, |
1242 const NotificationSource& source, | 1242 const NotificationSource& source, |
1243 const NotificationDetails& details) { | 1243 const NotificationDetails& details) { |
1244 switch (type.value) { | 1244 switch (type) { |
1245 case NotificationType::SYNC_CONFIGURE_START: { | 1245 case chrome::NOTIFICATION_SYNC_CONFIGURE_START: { |
1246 NotifyObservers(); | 1246 NotifyObservers(); |
1247 // TODO(sync): Maybe toast? | 1247 // TODO(sync): Maybe toast? |
1248 break; | 1248 break; |
1249 } | 1249 } |
1250 case NotificationType::SYNC_CONFIGURE_DONE: { | 1250 case chrome::NOTIFICATION_SYNC_CONFIGURE_DONE: { |
1251 DataTypeManager::ConfigureResultWithErrorLocation* result_with_location = | 1251 DataTypeManager::ConfigureResultWithErrorLocation* result_with_location = |
1252 Details<DataTypeManager::ConfigureResultWithErrorLocation>( | 1252 Details<DataTypeManager::ConfigureResultWithErrorLocation>( |
1253 details).ptr(); | 1253 details).ptr(); |
1254 | 1254 |
1255 DataTypeManager::ConfigureResult result = result_with_location->result; | 1255 DataTypeManager::ConfigureResult result = result_with_location->result; |
1256 VLOG(1) << "PSS SYNC_CONFIGURE_DONE called with result: " << result; | 1256 VLOG(1) << "PSS SYNC_CONFIGURE_DONE called with result: " << result; |
1257 if (result == DataTypeManager::ABORTED && | 1257 if (result == DataTypeManager::ABORTED && |
1258 expect_sync_configuration_aborted_) { | 1258 expect_sync_configuration_aborted_) { |
1259 VLOG(0) << "ProfileSyncService::Observe Sync Configure aborted"; | 1259 VLOG(0) << "ProfileSyncService::Observe Sync Configure aborted"; |
1260 expect_sync_configuration_aborted_ = false; | 1260 expect_sync_configuration_aborted_ = false; |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1293 // this is the point where it is safe to switch from config-mode to | 1293 // this is the point where it is safe to switch from config-mode to |
1294 // normal operation. | 1294 // normal operation. |
1295 backend_->StartSyncingWithServer(); | 1295 backend_->StartSyncingWithServer(); |
1296 | 1296 |
1297 if (!pending_types_for_encryption_.empty()) { | 1297 if (!pending_types_for_encryption_.empty()) { |
1298 EncryptDataTypes(pending_types_for_encryption_); | 1298 EncryptDataTypes(pending_types_for_encryption_); |
1299 pending_types_for_encryption_.clear(); | 1299 pending_types_for_encryption_.clear(); |
1300 } | 1300 } |
1301 break; | 1301 break; |
1302 } | 1302 } |
1303 case NotificationType::PREF_CHANGED: { | 1303 case chrome::NOTIFICATION_PREF_CHANGED: { |
1304 std::string* pref_name = Details<std::string>(details).ptr(); | 1304 std::string* pref_name = Details<std::string>(details).ptr(); |
1305 if (*pref_name == prefs::kSyncManaged) { | 1305 if (*pref_name == prefs::kSyncManaged) { |
1306 NotifyObservers(); | 1306 NotifyObservers(); |
1307 if (*pref_sync_managed_) { | 1307 if (*pref_sync_managed_) { |
1308 DisableForUser(); | 1308 DisableForUser(); |
1309 } else if (HasSyncSetupCompleted() && AreCredentialsAvailable()) { | 1309 } else if (HasSyncSetupCompleted() && AreCredentialsAvailable()) { |
1310 StartUp(); | 1310 StartUp(); |
1311 } | 1311 } |
1312 } | 1312 } |
1313 break; | 1313 break; |
1314 } | 1314 } |
1315 case NotificationType::GOOGLE_SIGNIN_SUCCESSFUL: { | 1315 case chrome::NOTIFICATION_GOOGLE_SIGNIN_SUCCESSFUL: { |
1316 const GoogleServiceSigninSuccessDetails* successful = | 1316 const GoogleServiceSigninSuccessDetails* successful = |
1317 (Details<const GoogleServiceSigninSuccessDetails>(details).ptr()); | 1317 (Details<const GoogleServiceSigninSuccessDetails>(details).ptr()); |
1318 // We pass 'false' to SetPassphrase to denote that this is an implicit | 1318 // We pass 'false' to SetPassphrase to denote that this is an implicit |
1319 // request and shouldn't override an explicit one. Thus, we either | 1319 // request and shouldn't override an explicit one. Thus, we either |
1320 // update the implicit passphrase (idempotent if the passphrase didn't | 1320 // update the implicit passphrase (idempotent if the passphrase didn't |
1321 // actually change), or the user has an explicit passphrase set so this | 1321 // actually change), or the user has an explicit passphrase set so this |
1322 // becomes a no-op. | 1322 // becomes a no-op. |
1323 SetPassphrase(successful->password, false, true); | 1323 SetPassphrase(successful->password, false, true); |
1324 break; | 1324 break; |
1325 } | 1325 } |
1326 case NotificationType::GOOGLE_SIGNIN_FAILED: { | 1326 case chrome::NOTIFICATION_GOOGLE_SIGNIN_FAILED: { |
1327 GoogleServiceAuthError error = | 1327 GoogleServiceAuthError error = |
1328 *(Details<const GoogleServiceAuthError>(details).ptr()); | 1328 *(Details<const GoogleServiceAuthError>(details).ptr()); |
1329 UpdateAuthErrorState(error); | 1329 UpdateAuthErrorState(error); |
1330 break; | 1330 break; |
1331 } | 1331 } |
1332 case NotificationType::TOKEN_AVAILABLE: { | 1332 case chrome::NOTIFICATION_TOKEN_AVAILABLE: { |
1333 if (AreCredentialsAvailable()) { | 1333 if (AreCredentialsAvailable()) { |
1334 if (backend_initialized_) { | 1334 if (backend_initialized_) { |
1335 backend_->UpdateCredentials(GetCredentials()); | 1335 backend_->UpdateCredentials(GetCredentials()); |
1336 } | 1336 } |
1337 | 1337 |
1338 if (!profile_->GetPrefs()->GetBoolean(prefs::kSyncSuppressStart)) | 1338 if (!profile_->GetPrefs()->GetBoolean(prefs::kSyncSuppressStart)) |
1339 StartUp(); | 1339 StartUp(); |
1340 } | 1340 } |
1341 break; | 1341 break; |
1342 } | 1342 } |
1343 case NotificationType::TOKEN_LOADING_FINISHED: { | 1343 case chrome::NOTIFICATION_TOKEN_LOADING_FINISHED: { |
1344 // If not in Chrome OS, and we have a username without tokens, | 1344 // If not in Chrome OS, and we have a username without tokens, |
1345 // the user will need to signin again, so sign out. | 1345 // the user will need to signin again, so sign out. |
1346 if (cros_user_.empty() && | 1346 if (cros_user_.empty() && |
1347 !signin_->GetUsername().empty() && | 1347 !signin_->GetUsername().empty() && |
1348 !AreCredentialsAvailable()) { | 1348 !AreCredentialsAvailable()) { |
1349 DisableForUser(); | 1349 DisableForUser(); |
1350 } | 1350 } |
1351 break; | 1351 break; |
1352 } | 1352 } |
1353 case NotificationType::COOKIE_CHANGED: { | 1353 case chrome::NOTIFICATION_COOKIE_CHANGED: { |
1354 OnCookieChanged(Source<Profile>(source).ptr(), | 1354 OnCookieChanged(Source<Profile>(source).ptr(), |
1355 Details<ChromeCookieDetails>(details).ptr()); | 1355 Details<ChromeCookieDetails>(details).ptr()); |
1356 break; | 1356 break; |
1357 } | 1357 } |
1358 default: { | 1358 default: { |
1359 NOTREACHED(); | 1359 NOTREACHED(); |
1360 } | 1360 } |
1361 } | 1361 } |
1362 } | 1362 } |
1363 | 1363 |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1398 // is initialized, all enabled data types are consistent with one | 1398 // is initialized, all enabled data types are consistent with one |
1399 // another, and no unrecoverable error has transpired. | 1399 // another, and no unrecoverable error has transpired. |
1400 if (unrecoverable_error_detected_) | 1400 if (unrecoverable_error_detected_) |
1401 return false; | 1401 return false; |
1402 | 1402 |
1403 if (!data_type_manager_.get()) | 1403 if (!data_type_manager_.get()) |
1404 return false; | 1404 return false; |
1405 | 1405 |
1406 return data_type_manager_->state() == DataTypeManager::CONFIGURED; | 1406 return data_type_manager_->state() == DataTypeManager::CONFIGURED; |
1407 } | 1407 } |
OLD | NEW |