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

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

Issue 4980005: Allow sync with 2-factor StrongAuth accounts in ChromeOS. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Refactored 2-factor error passing Created 10 years, 1 month 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) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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 <map> 7 #include <map>
8 #include <set> 8 #include <set>
9 9
10 #include "app/l10n_util.h" 10 #include "app/l10n_util.h"
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
116 ProfileSyncService::~ProfileSyncService() { 116 ProfileSyncService::~ProfileSyncService() {
117 Shutdown(false); 117 Shutdown(false);
118 } 118 }
119 119
120 bool ProfileSyncService::AreCredentialsAvailable() { 120 bool ProfileSyncService::AreCredentialsAvailable() {
121 if (IsManaged()) { 121 if (IsManaged()) {
122 return false; 122 return false;
123 } 123 }
124 124
125 // CrOS user is always logged in. Chrome uses signin_ to check logged in. 125 // CrOS user is always logged in. Chrome uses signin_ to check logged in.
126 if (!cros_user_.empty() || !signin_.GetUsername().empty()) { 126 if (!cros_user_.empty() || !signin_->GetUsername().empty()) {
127 // TODO(chron): Verify CrOS unit test behavior. 127 // TODO(chron): Verify CrOS unit test behavior.
128 if (profile()->GetTokenService() && 128 if (profile()->GetTokenService() &&
129 profile()->GetTokenService()->HasTokenForService( 129 profile()->GetTokenService()->HasTokenForService(
130 GaiaConstants::kSyncService)) { 130 GaiaConstants::kSyncService)) {
131 return true; 131 return true;
132 } 132 }
133 } 133 }
134 return false; 134 return false;
135 } 135 }
136 136
137 void ProfileSyncService::LoadMigratedCredentials(const std::string& username, 137 void ProfileSyncService::LoadMigratedCredentials(const std::string& username,
138 const std::string& token) { 138 const std::string& token) {
139 signin_.SetUsername(username); 139 signin_->SetUsername(username);
140 profile()->GetPrefs()->SetString(prefs::kGoogleServicesUsername, username); 140 profile()->GetPrefs()->SetString(prefs::kGoogleServicesUsername, username);
141 profile()->GetTokenService()->OnIssueAuthTokenSuccess( 141 profile()->GetTokenService()->OnIssueAuthTokenSuccess(
142 GaiaConstants::kSyncService, token); 142 GaiaConstants::kSyncService, token);
143 profile()->GetPrefs()->SetBoolean(prefs::kSyncCredentialsMigrated, true); 143 profile()->GetPrefs()->SetBoolean(prefs::kSyncCredentialsMigrated, true);
144 token_migrator_.reset(); 144 token_migrator_.reset();
145 } 145 }
146 146
147 void ProfileSyncService::Initialize() { 147 void ProfileSyncService::Initialize() {
148 InitSettings(); 148 InitSettings();
149 RegisterPreferences(); 149 RegisterPreferences();
150 150
151 // Watch the preference that indicates sync is managed so we can take 151 // Watch the preference that indicates sync is managed so we can take
152 // appropriate action. 152 // appropriate action.
153 pref_sync_managed_.Init(prefs::kSyncManaged, profile_->GetPrefs(), this); 153 pref_sync_managed_.Init(prefs::kSyncManaged, profile_->GetPrefs(), this);
154 154
155 // For now, the only thing we can do through policy is to turn sync off. 155 // For now, the only thing we can do through policy is to turn sync off.
156 if (IsManaged()) { 156 if (IsManaged()) {
157 DisableForUser(); 157 DisableForUser();
158 return; 158 return;
159 } 159 }
160 160
161 RegisterAuthNotifications(); 161 RegisterAuthNotifications();
162 162
163 // In Chrome, we integrate a SigninManager which works with the sync 163 // In Chrome, we integrate a SigninManager which works with the sync
164 // setup wizard to kick off the TokenService. CrOS does its own plumbing 164 // setup wizard to kick off the TokenService. CrOS does its own plumbing
165 // for the TokenService. 165 // for the TokenService.
166 if (cros_user_.empty()) { 166 if (cros_user_.empty()) {
167 // Will load tokens from DB and broadcast Token events after. 167 // Will load tokens from DB and broadcast Token events after.
168 signin_.Initialize(profile_); 168 // Note: We rely on signin_ != NULL unless !cros_user_.empty().
169 signin_.reset(new SigninManager());
170 signin_->Initialize(profile_);
169 } 171 }
170 172
171 if (!HasSyncSetupCompleted()) { 173 if (!HasSyncSetupCompleted()) {
172 DisableForUser(); // Clean up in case of previous crash / setup abort. 174 DisableForUser(); // Clean up in case of previous crash / setup abort.
173 175
174 // Under ChromeOS, just autostart it anyway if creds are here and start 176 // Under ChromeOS, just autostart it anyway if creds are here and start
175 // is not being suppressed by preferences. 177 // is not being suppressed by preferences.
176 if (!cros_user_.empty() && 178 if (!cros_user_.empty() &&
177 !profile_->GetPrefs()->GetBoolean(prefs::kSyncSuppressStart) && 179 !profile_->GetPrefs()->GetBoolean(prefs::kSyncSuppressStart) &&
178 AreCredentialsAvailable()) { 180 AreCredentialsAvailable()) {
(...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after
374 pref_service->ClearPref(prefs::kSyncHasSetupCompleted); 376 pref_service->ClearPref(prefs::kSyncHasSetupCompleted);
375 pref_service->ClearPref(prefs::kEncryptionBootstrapToken); 377 pref_service->ClearPref(prefs::kEncryptionBootstrapToken);
376 378
377 // TODO(nick): The current behavior does not clear e.g. prefs::kSyncBookmarks. 379 // TODO(nick): The current behavior does not clear e.g. prefs::kSyncBookmarks.
378 // Is that really what we want? 380 // Is that really what we want?
379 pref_service->ScheduleSavePersistentPrefs(); 381 pref_service->ScheduleSavePersistentPrefs();
380 } 382 }
381 383
382 SyncCredentials ProfileSyncService::GetCredentials() { 384 SyncCredentials ProfileSyncService::GetCredentials() {
383 SyncCredentials credentials; 385 SyncCredentials credentials;
384 credentials.email = !cros_user_.empty() ? cros_user_ : signin_.GetUsername(); 386 credentials.email = !cros_user_.empty() ? cros_user_ : signin_->GetUsername();
385 DCHECK(!credentials.email.empty()); 387 DCHECK(!credentials.email.empty());
386 TokenService* service = profile_->GetTokenService(); 388 TokenService* service = profile_->GetTokenService();
387 credentials.sync_token = service->GetTokenForService( 389 credentials.sync_token = service->GetTokenForService(
388 GaiaConstants::kSyncService); 390 GaiaConstants::kSyncService);
389 return credentials; 391 return credentials;
390 } 392 }
391 393
392 void ProfileSyncService::InitializeBackend(bool delete_sync_data_folder) { 394 void ProfileSyncService::InitializeBackend(bool delete_sync_data_folder) {
393 if (!backend_.get()) { 395 if (!backend_.get()) {
394 NOTREACHED(); 396 NOTREACHED();
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
499 &ProfileSyncService::OnClearServerDataTimeout); 501 &ProfileSyncService::OnClearServerDataTimeout);
500 backend_->RequestClearServerData(); 502 backend_->RequestClearServerData();
501 } 503 }
502 504
503 void ProfileSyncService::DisableForUser() { 505 void ProfileSyncService::DisableForUser() {
504 // Clear prefs (including SyncSetupHasCompleted) before shutting down so 506 // Clear prefs (including SyncSetupHasCompleted) before shutting down so
505 // PSS clients don't think we're set up while we're shutting down. 507 // PSS clients don't think we're set up while we're shutting down.
506 ClearPreferences(); 508 ClearPreferences();
507 Shutdown(true); 509 Shutdown(true);
508 510
509 if (cros_user_.empty()) { 511 if (signin_.get()) {
510 signin_.SignOut(); 512 signin_->SignOut();
511 } 513 }
512 514
513 FOR_EACH_OBSERVER(Observer, observers_, OnStateChanged()); 515 FOR_EACH_OBSERVER(Observer, observers_, OnStateChanged());
514 } 516 }
515 517
516 bool ProfileSyncService::HasSyncSetupCompleted() const { 518 bool ProfileSyncService::HasSyncSetupCompleted() const {
517 return profile_->GetPrefs()->GetBoolean(prefs::kSyncHasSetupCompleted); 519 return profile_->GetPrefs()->GetBoolean(prefs::kSyncHasSetupCompleted);
518 } 520 }
519 521
520 void ProfileSyncService::SetSyncSetupCompleted() { 522 void ProfileSyncService::SetSyncSetupCompleted() {
(...skipping 269 matching lines...) Expand 10 before | Expand all | Expand 10 after
790 792
791 void ProfileSyncService::OnUserSubmittedAuth( 793 void ProfileSyncService::OnUserSubmittedAuth(
792 const std::string& username, const std::string& password, 794 const std::string& username, const std::string& password,
793 const std::string& captcha, const std::string& access_code) { 795 const std::string& captcha, const std::string& access_code) {
794 last_attempted_user_email_ = username; 796 last_attempted_user_email_ = username;
795 is_auth_in_progress_ = true; 797 is_auth_in_progress_ = true;
796 FOR_EACH_OBSERVER(Observer, observers_, OnStateChanged()); 798 FOR_EACH_OBSERVER(Observer, observers_, OnStateChanged());
797 799
798 auth_start_time_ = base::TimeTicks::Now(); 800 auth_start_time_ = base::TimeTicks::Now();
799 801
800 // TODO(chron): Mechanism for ChromeOS auth renewal? 802 if (!signin_.get()) {
801 // (maybe just run the dialog anyway?) 803 // In ChromeOS we sign in during login, so we do not instantiate signin_.
802 // or send it to the CrOS login somehow? 804 // If this function gets called, we need to re-authenticate (e.g. for
803 if (!cros_user_.empty()) { 805 // two factor signin), so instantiante signin_ here.
804 LOG(WARNING) << "No mechanism on ChromeOS yet. See http://crbug.com/50292"; 806 signin_.reset(new SigninManager());
807 signin_->Initialize(profile_);
805 } 808 }
806 809
807 if (!access_code.empty()) { 810 if (!access_code.empty()) {
808 signin_.ProvideSecondFactorAccessCode(access_code); 811 signin_->ProvideSecondFactorAccessCode(access_code);
809 return; 812 return;
810 } 813 }
811 814
812 if (!signin_.GetUsername().empty()) { 815 if (!signin_->GetUsername().empty()) {
813 signin_.SignOut(); 816 signin_->SignOut();
814 } 817 }
815 818
816 // The user has submitted credentials, which indicates they don't 819 // The user has submitted credentials, which indicates they don't
817 // want to suppress start up anymore. 820 // want to suppress start up anymore.
818 PrefService* prefs = profile_->GetPrefs(); 821 PrefService* prefs = profile_->GetPrefs();
819 prefs->SetBoolean(prefs::kSyncSuppressStart, false); 822 prefs->SetBoolean(prefs::kSyncSuppressStart, false);
820 prefs->ScheduleSavePersistentPrefs(); 823 prefs->ScheduleSavePersistentPrefs();
821 824
822 signin_.StartSignIn(username, 825 signin_->StartSignIn(username,
823 password, 826 password,
824 last_auth_error_.captcha().token, 827 last_auth_error_.captcha().token,
825 captcha); 828 captcha);
826 } 829 }
827 830
828 void ProfileSyncService::OnUserChoseDatatypes(bool sync_everything, 831 void ProfileSyncService::OnUserChoseDatatypes(bool sync_everything,
829 const syncable::ModelTypeSet& chosen_types) { 832 const syncable::ModelTypeSet& chosen_types) {
830 if (!backend_.get()) { 833 if (!backend_.get()) {
831 NOTREACHED(); 834 NOTREACHED();
832 return; 835 return;
833 } 836 }
834 profile_->GetPrefs()->SetBoolean(prefs::kKeepEverythingSynced, 837 profile_->GetPrefs()->SetBoolean(prefs::kKeepEverythingSynced,
835 sync_everything); 838 sync_everything);
(...skipping 256 matching lines...) Expand 10 before | Expand all | Expand 10 after
1092 1095
1093 if (!profile_->GetPrefs()->GetBoolean(prefs::kSyncSuppressStart)) 1096 if (!profile_->GetPrefs()->GetBoolean(prefs::kSyncSuppressStart))
1094 StartUp(); 1097 StartUp();
1095 } 1098 }
1096 break; 1099 break;
1097 } 1100 }
1098 case NotificationType::TOKEN_LOADING_FINISHED: { 1101 case NotificationType::TOKEN_LOADING_FINISHED: {
1099 // If not in Chrome OS, and we have a username without tokens, 1102 // If not in Chrome OS, and we have a username without tokens,
1100 // the user will need to signin again, so sign out. 1103 // the user will need to signin again, so sign out.
1101 if (cros_user_.empty() && 1104 if (cros_user_.empty() &&
1102 !signin_.GetUsername().empty() && 1105 !signin_->GetUsername().empty() &&
1103 !AreCredentialsAvailable()) { 1106 !AreCredentialsAvailable()) {
1104 DisableForUser(); 1107 DisableForUser();
1105 } 1108 }
1106 break; 1109 break;
1107 } 1110 }
1108 default: { 1111 default: {
1109 NOTREACHED(); 1112 NOTREACHED();
1110 } 1113 }
1111 } 1114 }
1112 } 1115 }
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
1144 // is initialized, all enabled data types are consistent with one 1147 // is initialized, all enabled data types are consistent with one
1145 // another, and no unrecoverable error has transpired. 1148 // another, and no unrecoverable error has transpired.
1146 if (unrecoverable_error_detected_) 1149 if (unrecoverable_error_detected_)
1147 return false; 1150 return false;
1148 1151
1149 if (!data_type_manager_.get()) 1152 if (!data_type_manager_.get())
1150 return false; 1153 return false;
1151 1154
1152 return data_type_manager_->state() == DataTypeManager::CONFIGURED; 1155 return data_type_manager_->state() == DataTypeManager::CONFIGURED;
1153 } 1156 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698