OLD | NEW |
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 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
63 static const int kSyncClearDataTimeoutInSeconds = 60; // 1 minute. | 63 static const int kSyncClearDataTimeoutInSeconds = 60; // 1 minute. |
64 | 64 |
65 ProfileSyncService::ProfileSyncService(ProfileSyncFactory* factory, | 65 ProfileSyncService::ProfileSyncService(ProfileSyncFactory* factory, |
66 Profile* profile, | 66 Profile* profile, |
67 const std::string& cros_user) | 67 const std::string& cros_user) |
68 : last_auth_error_(AuthError::None()), | 68 : last_auth_error_(AuthError::None()), |
69 tried_creating_explicit_passphrase_(false), | 69 tried_creating_explicit_passphrase_(false), |
70 tried_setting_explicit_passphrase_(false), | 70 tried_setting_explicit_passphrase_(false), |
71 observed_passphrase_required_(false), | 71 observed_passphrase_required_(false), |
72 passphrase_required_for_decryption_(false), | 72 passphrase_required_for_decryption_(false), |
| 73 passphrase_migration_in_progress_(false), |
73 factory_(factory), | 74 factory_(factory), |
74 profile_(profile), | 75 profile_(profile), |
75 cros_user_(cros_user), | 76 cros_user_(cros_user), |
76 sync_service_url_(kDevServerUrl), | 77 sync_service_url_(kDevServerUrl), |
77 backend_initialized_(false), | 78 backend_initialized_(false), |
78 is_auth_in_progress_(false), | 79 is_auth_in_progress_(false), |
79 ALLOW_THIS_IN_INITIALIZER_LIST(wizard_(this)), | 80 ALLOW_THIS_IN_INITIALIZER_LIST(wizard_(this)), |
80 unrecoverable_error_detected_(false), | 81 unrecoverable_error_detected_(false), |
81 ALLOW_THIS_IN_INITIALIZER_LIST(scoped_runnable_method_factory_(this)), | 82 ALLOW_THIS_IN_INITIALIZER_LIST(scoped_runnable_method_factory_(this)), |
82 token_migrator_(NULL), | 83 token_migrator_(NULL), |
(...skipping 659 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
742 wizard_.Step(SyncSetupWizard::GAIA_LOGIN); | 743 wizard_.Step(SyncSetupWizard::GAIA_LOGIN); |
743 | 744 |
744 NotifyObservers(); | 745 NotifyObservers(); |
745 } | 746 } |
746 | 747 |
747 void ProfileSyncService::ShowErrorUI(gfx::NativeWindow parent_window) { | 748 void ProfileSyncService::ShowErrorUI(gfx::NativeWindow parent_window) { |
748 if (observed_passphrase_required()) { | 749 if (observed_passphrase_required()) { |
749 if (IsUsingSecondaryPassphrase()) | 750 if (IsUsingSecondaryPassphrase()) |
750 PromptForExistingPassphrase(parent_window); | 751 PromptForExistingPassphrase(parent_window); |
751 else | 752 else |
752 ShowLoginDialog(parent_window); | 753 SigninForPassphraseMigration(parent_window); |
753 return; | 754 return; |
754 } | 755 } |
755 const GoogleServiceAuthError& error = GetAuthError(); | 756 const GoogleServiceAuthError& error = GetAuthError(); |
756 if (error.state() == GoogleServiceAuthError::INVALID_GAIA_CREDENTIALS || | 757 if (error.state() == GoogleServiceAuthError::INVALID_GAIA_CREDENTIALS || |
757 error.state() == GoogleServiceAuthError::CAPTCHA_REQUIRED || | 758 error.state() == GoogleServiceAuthError::CAPTCHA_REQUIRED || |
758 error.state() == GoogleServiceAuthError::ACCOUNT_DELETED || | 759 error.state() == GoogleServiceAuthError::ACCOUNT_DELETED || |
759 error.state() == GoogleServiceAuthError::ACCOUNT_DISABLED || | 760 error.state() == GoogleServiceAuthError::ACCOUNT_DISABLED || |
760 error.state() == GoogleServiceAuthError::SERVICE_UNAVAILABLE) { | 761 error.state() == GoogleServiceAuthError::SERVICE_UNAVAILABLE) { |
761 ShowLoginDialog(parent_window); | 762 ShowLoginDialog(parent_window); |
762 } | 763 } |
(...skipping 12 matching lines...) Expand all Loading... |
775 void ProfileSyncService::PromptForExistingPassphrase( | 776 void ProfileSyncService::PromptForExistingPassphrase( |
776 gfx::NativeWindow parent_window) { | 777 gfx::NativeWindow parent_window) { |
777 if (WizardIsVisible()) { | 778 if (WizardIsVisible()) { |
778 wizard_.Focus(); | 779 wizard_.Focus(); |
779 return; | 780 return; |
780 } | 781 } |
781 wizard_.SetParent(parent_window); | 782 wizard_.SetParent(parent_window); |
782 wizard_.Step(SyncSetupWizard::ENTER_PASSPHRASE); | 783 wizard_.Step(SyncSetupWizard::ENTER_PASSPHRASE); |
783 } | 784 } |
784 | 785 |
785 void ProfileSyncService::ShowPassphraseMigration( | 786 void ProfileSyncService::SigninForPassphraseMigration( |
786 gfx::NativeWindow parent_window) { | 787 gfx::NativeWindow parent_window) { |
787 wizard_.SetParent(parent_window); | 788 passphrase_migration_in_progress_ = true; |
788 wizard_.Step(SyncSetupWizard::PASSPHRASE_MIGRATION); | 789 ShowLoginDialog(parent_window); |
789 } | |
790 | |
791 void ProfileSyncService::SigninForPassphrase(TabContents* container) { | |
792 string16 prefilled_username = GetAuthenticatedUsername(); | |
793 string16 login_message = sync_ui_util::GetLoginMessageForEncryption(); | |
794 profile_->GetBrowserSignin()->RequestSignin(container, | |
795 prefilled_username, | |
796 login_message, | |
797 this); | |
798 } | 790 } |
799 | 791 |
800 SyncBackendHost::StatusSummary ProfileSyncService::QuerySyncStatusSummary() { | 792 SyncBackendHost::StatusSummary ProfileSyncService::QuerySyncStatusSummary() { |
801 if (backend_.get() && backend_initialized_) | 793 if (backend_.get() && backend_initialized_) |
802 return backend_->GetStatusSummary(); | 794 return backend_->GetStatusSummary(); |
803 else | 795 else |
804 return SyncBackendHost::Status::OFFLINE_UNUSABLE; | 796 return SyncBackendHost::Status::OFFLINE_UNUSABLE; |
805 } | 797 } |
806 | 798 |
807 SyncBackendHost::Status ProfileSyncService::QueryDetailedSyncStatus() { | 799 SyncBackendHost::Status ProfileSyncService::QueryDetailedSyncStatus() { |
(...skipping 320 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1128 case NotificationType::GOOGLE_SIGNIN_SUCCESSFUL: { | 1120 case NotificationType::GOOGLE_SIGNIN_SUCCESSFUL: { |
1129 const GoogleServiceSigninSuccessDetails* successful = | 1121 const GoogleServiceSigninSuccessDetails* successful = |
1130 (Details<const GoogleServiceSigninSuccessDetails>(details).ptr()); | 1122 (Details<const GoogleServiceSigninSuccessDetails>(details).ptr()); |
1131 // We pass 'false' to SetPassphrase to denote that this is an implicit | 1123 // We pass 'false' to SetPassphrase to denote that this is an implicit |
1132 // request and shouldn't override an explicit one. Thus, we either | 1124 // request and shouldn't override an explicit one. Thus, we either |
1133 // update the implicit passphrase (idempotent if the passphrase didn't | 1125 // update the implicit passphrase (idempotent if the passphrase didn't |
1134 // actually change), or the user has an explicit passphrase set so this | 1126 // actually change), or the user has an explicit passphrase set so this |
1135 // becomes a no-op. | 1127 // becomes a no-op. |
1136 tried_implicit_gaia_remove_when_bug_62103_fixed_ = true; | 1128 tried_implicit_gaia_remove_when_bug_62103_fixed_ = true; |
1137 SetPassphrase(successful->password, false, true); | 1129 SetPassphrase(successful->password, false, true); |
| 1130 |
| 1131 // If this signin was to initiate a passphrase migration (on the |
| 1132 // first computer, thus not for decryption), continue the migration. |
| 1133 if (passphrase_migration_in_progress_ && |
| 1134 !passphrase_required_for_decryption_) { |
| 1135 wizard_.Step(SyncSetupWizard::PASSPHRASE_MIGRATION); |
| 1136 passphrase_migration_in_progress_ = false; |
| 1137 } |
| 1138 |
1138 break; | 1139 break; |
1139 } | 1140 } |
1140 case NotificationType::GOOGLE_SIGNIN_FAILED: { | 1141 case NotificationType::GOOGLE_SIGNIN_FAILED: { |
1141 GoogleServiceAuthError error = | 1142 GoogleServiceAuthError error = |
1142 *(Details<const GoogleServiceAuthError>(details).ptr()); | 1143 *(Details<const GoogleServiceAuthError>(details).ptr()); |
1143 UpdateAuthErrorState(error); | 1144 UpdateAuthErrorState(error); |
1144 break; | 1145 break; |
1145 } | 1146 } |
1146 case NotificationType::TOKEN_AVAILABLE: { | 1147 case NotificationType::TOKEN_AVAILABLE: { |
1147 if (AreCredentialsAvailable()) { | 1148 if (AreCredentialsAvailable()) { |
(...skipping 15 matching lines...) Expand all Loading... |
1163 DisableForUser(); | 1164 DisableForUser(); |
1164 } | 1165 } |
1165 break; | 1166 break; |
1166 } | 1167 } |
1167 default: { | 1168 default: { |
1168 NOTREACHED(); | 1169 NOTREACHED(); |
1169 } | 1170 } |
1170 } | 1171 } |
1171 } | 1172 } |
1172 | 1173 |
1173 // This is the delegate callback from BrowserSigin. | |
1174 void ProfileSyncService::OnLoginSuccess() { | |
1175 // The reason for the browser signin was a non-explicit passphrase | |
1176 // required signal. If this is the first time through the passphrase | |
1177 // process, we want to show the migration UI and offer an explicit | |
1178 // passphrase. Otherwise, we're done because the implicit is enough. | |
1179 | |
1180 if (passphrase_required_for_decryption_) { | |
1181 // NOT first time (decrypting something encrypted elsewhere). | |
1182 // Do nothing. | |
1183 } else { | |
1184 ShowPassphraseMigration(NULL); | |
1185 } | |
1186 } | |
1187 | |
1188 // This is the delegate callback from BrowserSigin. | |
1189 void ProfileSyncService::OnLoginFailure(const GoogleServiceAuthError& error) { | |
1190 // Do nothing. The UI will already reflect the fact that the | |
1191 // user is not signed in. | |
1192 } | |
1193 | |
1194 void ProfileSyncService::AddObserver(Observer* observer) { | 1174 void ProfileSyncService::AddObserver(Observer* observer) { |
1195 observers_.AddObserver(observer); | 1175 observers_.AddObserver(observer); |
1196 } | 1176 } |
1197 | 1177 |
1198 void ProfileSyncService::RemoveObserver(Observer* observer) { | 1178 void ProfileSyncService::RemoveObserver(Observer* observer) { |
1199 observers_.RemoveObserver(observer); | 1179 observers_.RemoveObserver(observer); |
1200 } | 1180 } |
1201 | 1181 |
1202 bool ProfileSyncService::HasObserver(Observer* observer) const { | 1182 bool ProfileSyncService::HasObserver(Observer* observer) const { |
1203 return observers_.HasObserver(observer); | 1183 return observers_.HasObserver(observer); |
(...skipping 20 matching lines...) Expand all Loading... |
1224 // is initialized, all enabled data types are consistent with one | 1204 // is initialized, all enabled data types are consistent with one |
1225 // another, and no unrecoverable error has transpired. | 1205 // another, and no unrecoverable error has transpired. |
1226 if (unrecoverable_error_detected_) | 1206 if (unrecoverable_error_detected_) |
1227 return false; | 1207 return false; |
1228 | 1208 |
1229 if (!data_type_manager_.get()) | 1209 if (!data_type_manager_.get()) |
1230 return false; | 1210 return false; |
1231 | 1211 |
1232 return data_type_manager_->state() == DataTypeManager::CONFIGURED; | 1212 return data_type_manager_->state() == DataTypeManager::CONFIGURED; |
1233 } | 1213 } |
OLD | NEW |