| 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 211 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 346 pref_service->ClearPref(prefs::kSyncHasSetupCompleted); | 345 pref_service->ClearPref(prefs::kSyncHasSetupCompleted); |
| 347 pref_service->ClearPref(prefs::kEncryptionBootstrapToken); | 346 pref_service->ClearPref(prefs::kEncryptionBootstrapToken); |
| 348 | 347 |
| 349 // TODO(nick): The current behavior does not clear e.g. prefs::kSyncBookmarks. | 348 // TODO(nick): The current behavior does not clear e.g. prefs::kSyncBookmarks. |
| 350 // Is that really what we want? | 349 // Is that really what we want? |
| 351 pref_service->ScheduleSavePersistentPrefs(); | 350 pref_service->ScheduleSavePersistentPrefs(); |
| 352 } | 351 } |
| 353 | 352 |
| 354 SyncCredentials ProfileSyncService::GetCredentials() { | 353 SyncCredentials ProfileSyncService::GetCredentials() { |
| 355 SyncCredentials credentials; | 354 SyncCredentials credentials; |
| 356 credentials.email = !cros_user_.empty() ? cros_user_ : signin_->GetUsername(); | 355 credentials.email = cros_user_.empty() ? signin_->GetUsername() : cros_user_; |
| 357 DCHECK(!credentials.email.empty()); | 356 DCHECK(!credentials.email.empty()); |
| 358 TokenService* service = profile_->GetTokenService(); | 357 TokenService* service = profile_->GetTokenService(); |
| 359 credentials.sync_token = service->GetTokenForService( | 358 credentials.sync_token = service->GetTokenForService( |
| 360 GaiaConstants::kSyncService); | 359 browser_sync::SyncServiceName()); |
| 361 return credentials; | 360 return credentials; |
| 362 } | 361 } |
| 363 | 362 |
| 364 void ProfileSyncService::InitializeBackend(bool delete_sync_data_folder) { | 363 void ProfileSyncService::InitializeBackend(bool delete_sync_data_folder) { |
| 365 if (!backend_.get()) { | 364 if (!backend_.get()) { |
| 366 NOTREACHED(); | 365 NOTREACHED(); |
| 367 return; | 366 return; |
| 368 } | 367 } |
| 369 | 368 |
| 370 syncable::ModelTypeSet initial_types; | 369 syncable::ModelTypeSet initial_types; |
| (...skipping 966 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1337 break; | 1336 break; |
| 1338 } | 1337 } |
| 1339 case chrome::NOTIFICATION_GOOGLE_SIGNIN_SUCCESSFUL: { | 1338 case chrome::NOTIFICATION_GOOGLE_SIGNIN_SUCCESSFUL: { |
| 1340 const GoogleServiceSigninSuccessDetails* successful = | 1339 const GoogleServiceSigninSuccessDetails* successful = |
| 1341 (Details<const GoogleServiceSigninSuccessDetails>(details).ptr()); | 1340 (Details<const GoogleServiceSigninSuccessDetails>(details).ptr()); |
| 1342 // 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 |
| 1343 // request and shouldn't override an explicit one. Thus, we either | 1342 // request and shouldn't override an explicit one. Thus, we either |
| 1344 // update the implicit passphrase (idempotent if the passphrase didn't | 1343 // update the implicit passphrase (idempotent if the passphrase didn't |
| 1345 // 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 |
| 1346 // becomes a no-op. | 1345 // becomes a no-op. |
| 1347 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 } |
| 1348 break; | 1353 break; |
| 1349 } | 1354 } |
| 1350 case chrome::NOTIFICATION_GOOGLE_SIGNIN_FAILED: { | 1355 case chrome::NOTIFICATION_GOOGLE_SIGNIN_FAILED: { |
| 1351 GoogleServiceAuthError error = | 1356 GoogleServiceAuthError error = |
| 1352 *(Details<const GoogleServiceAuthError>(details).ptr()); | 1357 *(Details<const GoogleServiceAuthError>(details).ptr()); |
| 1353 UpdateAuthErrorState(error); | 1358 UpdateAuthErrorState(error); |
| 1354 break; | 1359 break; |
| 1355 } | 1360 } |
| 1356 case chrome::NOTIFICATION_TOKEN_REQUEST_FAILED: { | 1361 case chrome::NOTIFICATION_TOKEN_REQUEST_FAILED: { |
| 1357 GoogleServiceAuthError error( | 1362 GoogleServiceAuthError error( |
| 1358 GoogleServiceAuthError::INVALID_GAIA_CREDENTIALS); | 1363 GoogleServiceAuthError::INVALID_GAIA_CREDENTIALS); |
| 1359 UpdateAuthErrorState(error); | 1364 UpdateAuthErrorState(error); |
| 1360 break; | 1365 break; |
| 1361 } | 1366 } |
| 1362 case chrome::NOTIFICATION_TOKEN_AVAILABLE: { | 1367 case chrome::NOTIFICATION_TOKEN_AVAILABLE: { |
| 1363 if (AreCredentialsAvailable()) { | 1368 if (AreCredentialsAvailable()) { |
| 1364 if (backend_initialized_) { | 1369 if (backend_initialized_) { |
| 1365 backend_->UpdateCredentials(GetCredentials()); | 1370 backend_->UpdateCredentials(GetCredentials()); |
| 1366 } | 1371 } |
| 1367 | |
| 1368 if (!profile_->GetPrefs()->GetBoolean(prefs::kSyncSuppressStart)) | 1372 if (!profile_->GetPrefs()->GetBoolean(prefs::kSyncSuppressStart)) |
| 1369 StartUp(); | 1373 StartUp(); |
| 1370 } | 1374 } |
| 1371 break; | 1375 break; |
| 1372 } | 1376 } |
| 1373 case chrome::NOTIFICATION_TOKEN_LOADING_FINISHED: { | 1377 case chrome::NOTIFICATION_TOKEN_LOADING_FINISHED: { |
| 1374 // 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, |
| 1375 // the user will need to signin again, so sign out. | 1379 // the user will need to signin again, so sign out. |
| 1376 if (cros_user_.empty() && | 1380 if (cros_user_.empty() && |
| 1377 !signin_->GetUsername().empty() && | 1381 !signin_->GetUsername().empty() && |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1457 *profile_->GetPrefs()->GetList(prefs::kAcknowledgedSyncTypes)); | 1461 *profile_->GetPrefs()->GetList(prefs::kAcknowledgedSyncTypes)); |
| 1458 syncable::ModelTypeSet registered; | 1462 syncable::ModelTypeSet registered; |
| 1459 GetRegisteredDataTypes(®istered); | 1463 GetRegisteredDataTypes(®istered); |
| 1460 syncable::ModelTypeBitSet registered_bit_set = | 1464 syncable::ModelTypeBitSet registered_bit_set = |
| 1461 syncable::ModelTypeBitSetFromSet(registered); | 1465 syncable::ModelTypeBitSetFromSet(registered); |
| 1462 unacknowledged = registered_bit_set & ~acknowledged; | 1466 unacknowledged = registered_bit_set & ~acknowledged; |
| 1463 } | 1467 } |
| 1464 return unacknowledged; | 1468 return unacknowledged; |
| 1465 } | 1469 } |
| 1466 | 1470 |
| OLD | NEW |