| 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 18 matching lines...) Expand all Loading... |
| 29 #include "chrome/browser/sync/engine/configure_reason.h" | 29 #include "chrome/browser/sync/engine/configure_reason.h" |
| 30 #include "chrome/browser/sync/engine/syncapi.h" | 30 #include "chrome/browser/sync/engine/syncapi.h" |
| 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/js_arg_list.h" | 35 #include "chrome/browser/sync/js/js_arg_list.h" |
| 36 #include "chrome/browser/sync/js/js_event_details.h" | 36 #include "chrome/browser/sync/js/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/sync/util/oauth.h" |
| 39 #include "chrome/browser/ui/browser.h" | 40 #include "chrome/browser/ui/browser.h" |
| 40 #include "chrome/browser/ui/browser_list.h" | 41 #include "chrome/browser/ui/browser_list.h" |
| 41 #include "chrome/browser/ui/browser_window.h" | 42 #include "chrome/browser/ui/browser_window.h" |
| 42 #include "chrome/common/chrome_notification_types.h" | 43 #include "chrome/common/chrome_notification_types.h" |
| 43 #include "chrome/common/chrome_switches.h" | 44 #include "chrome/common/chrome_switches.h" |
| 44 #include "chrome/common/chrome_version_info.h" | 45 #include "chrome/common/chrome_version_info.h" |
| 45 #include "chrome/common/net/gaia/gaia_constants.h" | 46 #include "chrome/common/net/gaia/gaia_constants.h" |
| 46 #include "chrome/common/pref_names.h" | 47 #include "chrome/common/pref_names.h" |
| 47 #include "chrome/common/time_format.h" | 48 #include "chrome/common/time_format.h" |
| 48 #include "chrome/common/url_constants.h" | 49 #include "chrome/common/url_constants.h" |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 110 } | 111 } |
| 111 | 112 |
| 112 bool ProfileSyncService::AreCredentialsAvailable() { | 113 bool ProfileSyncService::AreCredentialsAvailable() { |
| 113 if (IsManaged()) { | 114 if (IsManaged()) { |
| 114 return false; | 115 return false; |
| 115 } | 116 } |
| 116 | 117 |
| 117 // CrOS user is always logged in. Chrome uses signin_ to check logged in. | 118 // CrOS user is always logged in. Chrome uses signin_ to check logged in. |
| 118 if (!cros_user_.empty() || !signin_->GetUsername().empty()) { | 119 if (!cros_user_.empty() || !signin_->GetUsername().empty()) { |
| 119 // TODO(chron): Verify CrOS unit test behavior. | 120 // TODO(chron): Verify CrOS unit test behavior. |
| 120 if (profile()->GetTokenService() && | 121 return profile()->GetTokenService() && |
| 121 profile()->GetTokenService()->HasTokenForService( | 122 profile()->GetTokenService()->HasTokenForService( |
| 122 GaiaConstants::kSyncService)) { | 123 browser_sync::SyncServiceName()); |
| 123 return true; | |
| 124 } | |
| 125 } | 124 } |
| 126 return false; | 125 return false; |
| 127 } | 126 } |
| 128 | 127 |
| 129 void ProfileSyncService::Initialize() { | 128 void ProfileSyncService::Initialize() { |
| 130 InitSettings(); | 129 InitSettings(); |
| 131 RegisterPreferences(); | 130 RegisterPreferences(); |
| 132 | 131 |
| 133 // We clear this here (vs Shutdown) because we want to remember that an error | 132 // We clear this here (vs Shutdown) because we want to remember that an error |
| 134 // happened on shutdown so we can display details (message, location) about it | 133 // happened on shutdown so we can display details (message, location) about it |
| (...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 258 void ProfileSyncService::RegisterPreferences() { | 257 void ProfileSyncService::RegisterPreferences() { |
| 259 PrefService* pref_service = profile_->GetPrefs(); | 258 PrefService* pref_service = profile_->GetPrefs(); |
| 260 if (pref_service->FindPreference(prefs::kSyncLastSyncedTime)) | 259 if (pref_service->FindPreference(prefs::kSyncLastSyncedTime)) |
| 261 return; | 260 return; |
| 262 pref_service->RegisterInt64Pref(prefs::kSyncLastSyncedTime, | 261 pref_service->RegisterInt64Pref(prefs::kSyncLastSyncedTime, |
| 263 0, | 262 0, |
| 264 PrefService::UNSYNCABLE_PREF); | 263 PrefService::UNSYNCABLE_PREF); |
| 265 pref_service->RegisterBooleanPref(prefs::kSyncHasSetupCompleted, | 264 pref_service->RegisterBooleanPref(prefs::kSyncHasSetupCompleted, |
| 266 false, | 265 false, |
| 267 PrefService::UNSYNCABLE_PREF); | 266 PrefService::UNSYNCABLE_PREF); |
| 267 pref_service->RegisterBooleanPref(prefs::kSyncUsingOAuth, |
| 268 false, |
| 269 PrefService::UNSYNCABLE_PREF); |
| 268 pref_service->RegisterBooleanPref(prefs::kSyncSuppressStart, | 270 pref_service->RegisterBooleanPref(prefs::kSyncSuppressStart, |
| 269 false, | 271 false, |
| 270 PrefService::UNSYNCABLE_PREF); | 272 PrefService::UNSYNCABLE_PREF); |
| 271 | 273 |
| 272 // If you've never synced before, or if you're using Chrome OS, all datatypes | 274 // If you've never synced before, or if you're using Chrome OS, all datatypes |
| 273 // are on by default. | 275 // are on by default. |
| 274 // TODO(nick): Perhaps a better model would be to always default to false, | 276 // TODO(nick): Perhaps a better model would be to always default to false, |
| 275 // and explicitly call SetDataTypes() when the user shows the wizard. | 277 // and explicitly call SetDataTypes() when the user shows the wizard. |
| 276 #if defined(OS_CHROMEOS) | 278 #if defined(OS_CHROMEOS) |
| 277 bool enable_by_default = true; | 279 bool enable_by_default = true; |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 346 pref_service->ClearPref(prefs::kSyncHasSetupCompleted); | 348 pref_service->ClearPref(prefs::kSyncHasSetupCompleted); |
| 347 pref_service->ClearPref(prefs::kEncryptionBootstrapToken); | 349 pref_service->ClearPref(prefs::kEncryptionBootstrapToken); |
| 348 | 350 |
| 349 // TODO(nick): The current behavior does not clear e.g. prefs::kSyncBookmarks. | 351 // TODO(nick): The current behavior does not clear e.g. prefs::kSyncBookmarks. |
| 350 // Is that really what we want? | 352 // Is that really what we want? |
| 351 pref_service->ScheduleSavePersistentPrefs(); | 353 pref_service->ScheduleSavePersistentPrefs(); |
| 352 } | 354 } |
| 353 | 355 |
| 354 SyncCredentials ProfileSyncService::GetCredentials() { | 356 SyncCredentials ProfileSyncService::GetCredentials() { |
| 355 SyncCredentials credentials; | 357 SyncCredentials credentials; |
| 356 credentials.email = !cros_user_.empty() ? cros_user_ : signin_->GetUsername(); | 358 credentials.email = cros_user_.empty() ? signin_->GetUsername() : cros_user_; |
| 357 DCHECK(!credentials.email.empty()); | 359 DCHECK(!credentials.email.empty()); |
| 358 TokenService* service = profile_->GetTokenService(); | 360 TokenService* service = profile_->GetTokenService(); |
| 359 credentials.sync_token = service->GetTokenForService( | 361 credentials.sync_token = service->GetTokenForService( |
| 360 GaiaConstants::kSyncService); | 362 browser_sync::SyncServiceName()); |
| 361 return credentials; | 363 return credentials; |
| 362 } | 364 } |
| 363 | 365 |
| 364 void ProfileSyncService::InitializeBackend(bool delete_sync_data_folder) { | 366 void ProfileSyncService::InitializeBackend(bool delete_sync_data_folder) { |
| 365 if (!backend_.get()) { | 367 if (!backend_.get()) { |
| 366 NOTREACHED(); | 368 NOTREACHED(); |
| 367 return; | 369 return; |
| 368 } | 370 } |
| 369 | 371 |
| 370 syncable::ModelTypeSet initial_types; | 372 syncable::ModelTypeSet initial_types; |
| (...skipping 963 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1334 break; | 1336 break; |
| 1335 } | 1337 } |
| 1336 case chrome::NOTIFICATION_GOOGLE_SIGNIN_SUCCESSFUL: { | 1338 case chrome::NOTIFICATION_GOOGLE_SIGNIN_SUCCESSFUL: { |
| 1337 const GoogleServiceSigninSuccessDetails* successful = | 1339 const GoogleServiceSigninSuccessDetails* successful = |
| 1338 (Details<const GoogleServiceSigninSuccessDetails>(details).ptr()); | 1340 (Details<const GoogleServiceSigninSuccessDetails>(details).ptr()); |
| 1339 // We pass 'false' to SetPassphrase to denote that this is an implicit | 1341 // We pass 'false' to SetPassphrase to denote that this is an implicit |
| 1340 // request and shouldn't override an explicit one. Thus, we either | 1342 // request and shouldn't override an explicit one. Thus, we either |
| 1341 // update the implicit passphrase (idempotent if the passphrase didn't | 1343 // update the implicit passphrase (idempotent if the passphrase didn't |
| 1342 // actually change), or the user has an explicit passphrase set so this | 1344 // actually change), or the user has an explicit passphrase set so this |
| 1343 // becomes a no-op. | 1345 // becomes a no-op. |
| 1344 SetPassphrase(successful->password, false, true); | 1346 if (browser_sync::IsUsingOAuth()) { |
| 1347 // TODO(rickcam): Bug 92323: Fetch password through special Gaia request |
| 1348 DCHECK(successful->password.empty()); |
| 1349 LOG(WARNING) << "Not initializing sync passphrase."; |
| 1350 } else { |
| 1351 SetPassphrase(successful->password, false, true); |
| 1352 } |
| 1345 break; | 1353 break; |
| 1346 } | 1354 } |
| 1347 case chrome::NOTIFICATION_GOOGLE_SIGNIN_FAILED: { | 1355 case chrome::NOTIFICATION_GOOGLE_SIGNIN_FAILED: { |
| 1348 GoogleServiceAuthError error = | 1356 GoogleServiceAuthError error = |
| 1349 *(Details<const GoogleServiceAuthError>(details).ptr()); | 1357 *(Details<const GoogleServiceAuthError>(details).ptr()); |
| 1350 UpdateAuthErrorState(error); | 1358 UpdateAuthErrorState(error); |
| 1351 break; | 1359 break; |
| 1352 } | 1360 } |
| 1353 case chrome::NOTIFICATION_TOKEN_REQUEST_FAILED: { | 1361 case chrome::NOTIFICATION_TOKEN_REQUEST_FAILED: { |
| 1354 GoogleServiceAuthError error( | 1362 GoogleServiceAuthError error( |
| 1355 GoogleServiceAuthError::INVALID_GAIA_CREDENTIALS); | 1363 GoogleServiceAuthError::INVALID_GAIA_CREDENTIALS); |
| 1356 UpdateAuthErrorState(error); | 1364 UpdateAuthErrorState(error); |
| 1357 break; | 1365 break; |
| 1358 } | 1366 } |
| 1359 case chrome::NOTIFICATION_TOKEN_AVAILABLE: { | 1367 case chrome::NOTIFICATION_TOKEN_AVAILABLE: { |
| 1360 if (AreCredentialsAvailable()) { | 1368 if (AreCredentialsAvailable()) { |
| 1361 if (backend_initialized_) { | 1369 if (backend_initialized_) { |
| 1362 backend_->UpdateCredentials(GetCredentials()); | 1370 backend_->UpdateCredentials(GetCredentials()); |
| 1363 } | 1371 } |
| 1364 | |
| 1365 if (!profile_->GetPrefs()->GetBoolean(prefs::kSyncSuppressStart)) | 1372 if (!profile_->GetPrefs()->GetBoolean(prefs::kSyncSuppressStart)) |
| 1366 StartUp(); | 1373 StartUp(); |
| 1367 } | 1374 } |
| 1368 break; | 1375 break; |
| 1369 } | 1376 } |
| 1370 case chrome::NOTIFICATION_TOKEN_LOADING_FINISHED: { | 1377 case chrome::NOTIFICATION_TOKEN_LOADING_FINISHED: { |
| 1371 // If not in Chrome OS, and we have a username without tokens, | 1378 // If not in Chrome OS, and we have a username without tokens, |
| 1372 // the user will need to signin again, so sign out. | 1379 // the user will need to signin again, so sign out. |
| 1373 if (cros_user_.empty() && | 1380 if (cros_user_.empty() && |
| 1374 !signin_->GetUsername().empty() && | 1381 !signin_->GetUsername().empty() && |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1454 *profile_->GetPrefs()->GetList(prefs::kAcknowledgedSyncTypes)); | 1461 *profile_->GetPrefs()->GetList(prefs::kAcknowledgedSyncTypes)); |
| 1455 syncable::ModelTypeSet registered; | 1462 syncable::ModelTypeSet registered; |
| 1456 GetRegisteredDataTypes(®istered); | 1463 GetRegisteredDataTypes(®istered); |
| 1457 syncable::ModelTypeBitSet registered_bit_set = | 1464 syncable::ModelTypeBitSet registered_bit_set = |
| 1458 syncable::ModelTypeBitSetFromSet(registered); | 1465 syncable::ModelTypeBitSetFromSet(registered); |
| 1459 unacknowledged = registered_bit_set & ~acknowledged; | 1466 unacknowledged = registered_bit_set & ~acknowledged; |
| 1460 } | 1467 } |
| 1461 return unacknowledged; | 1468 return unacknowledged; |
| 1462 } | 1469 } |
| 1463 | 1470 |
| OLD | NEW |