OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/ui/webui/sync_setup_handler.h" | 5 #include "chrome/browser/ui/webui/sync_setup_handler.h" |
6 | 6 |
7 #include "base/basictypes.h" | 7 #include "base/basictypes.h" |
8 #include "base/bind.h" | 8 #include "base/bind.h" |
9 #include "base/bind_helpers.h" | 9 #include "base/bind_helpers.h" |
10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
(...skipping 267 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
278 localized_strings->SetString("createAccountLinkHTML", | 278 localized_strings->SetString("createAccountLinkHTML", |
279 GetStringFUTF16(IDS_SYNC_CREATE_ACCOUNT_PREFIX, create_account)); | 279 GetStringFUTF16(IDS_SYNC_CREATE_ACCOUNT_PREFIX, create_account)); |
280 | 280 |
281 string16 sync_benefits_url( | 281 string16 sync_benefits_url( |
282 UTF8ToUTF16(google_util::StringAppendGoogleLocaleParam( | 282 UTF8ToUTF16(google_util::StringAppendGoogleLocaleParam( |
283 chrome::kSyncLearnMoreURL))); | 283 chrome::kSyncLearnMoreURL))); |
284 localized_strings->SetString("promoLearnMoreURL", sync_benefits_url); | 284 localized_strings->SetString("promoLearnMoreURL", sync_benefits_url); |
285 | 285 |
286 static OptionsStringResource resources[] = { | 286 static OptionsStringResource resources[] = { |
287 { "syncSetupConfigureTitle", IDS_SYNC_SETUP_CONFIGURE_TITLE }, | 287 { "syncSetupConfigureTitle", IDS_SYNC_SETUP_CONFIGURE_TITLE }, |
| 288 { "syncSetupTimeoutTitle", IDS_SYNC_SETUP_TIME_OUT_TITLE }, |
| 289 { "syncSetupTimeoutContent", IDS_SYNC_SETUP_TIME_OUT_CONTENT }, |
288 { "cannotBeBlank", IDS_SYNC_CANNOT_BE_BLANK }, | 290 { "cannotBeBlank", IDS_SYNC_CANNOT_BE_BLANK }, |
289 { "emailLabel", IDS_SYNC_LOGIN_EMAIL_NEW_LINE }, | 291 { "emailLabel", IDS_SYNC_LOGIN_EMAIL_NEW_LINE }, |
290 { "passwordLabel", IDS_SYNC_LOGIN_PASSWORD_NEW_LINE }, | 292 { "passwordLabel", IDS_SYNC_LOGIN_PASSWORD_NEW_LINE }, |
291 { "invalidCredentials", IDS_SYNC_INVALID_USER_CREDENTIALS }, | 293 { "invalidCredentials", IDS_SYNC_INVALID_USER_CREDENTIALS }, |
292 { "signin", IDS_SYNC_SIGNIN }, | 294 { "signin", IDS_SYNC_SIGNIN }, |
293 { "couldNotConnect", IDS_SYNC_LOGIN_COULD_NOT_CONNECT }, | 295 { "couldNotConnect", IDS_SYNC_LOGIN_COULD_NOT_CONNECT }, |
294 { "unrecoverableError", IDS_SYNC_UNRECOVERABLE_ERROR }, | 296 { "unrecoverableError", IDS_SYNC_UNRECOVERABLE_ERROR }, |
295 { "errorLearnMore", IDS_LEARN_MORE }, | 297 { "errorLearnMore", IDS_LEARN_MORE }, |
296 { "unrecoverableErrorHelpURL", IDS_SYNC_UNRECOVERABLE_ERROR_HELP_URL }, | 298 { "unrecoverableErrorHelpURL", IDS_SYNC_UNRECOVERABLE_ERROR_HELP_URL }, |
297 { "cannotAccessAccount", IDS_SYNC_CANNOT_ACCESS_ACCOUNT }, | 299 { "cannotAccessAccount", IDS_SYNC_CANNOT_ACCESS_ACCOUNT }, |
(...skipping 286 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
584 | 586 |
585 return true; | 587 return true; |
586 } | 588 } |
587 | 589 |
588 // TODO(kochi): Handle error conditions (timeout, other failures). | 590 // TODO(kochi): Handle error conditions (timeout, other failures). |
589 // http://crbug.com/128692 | 591 // http://crbug.com/128692 |
590 void SyncSetupHandler::DisplaySpinner() { | 592 void SyncSetupHandler::DisplaySpinner() { |
591 configuring_sync_ = true; | 593 configuring_sync_ = true; |
592 StringValue page("spinner"); | 594 StringValue page("spinner"); |
593 DictionaryValue args; | 595 DictionaryValue args; |
| 596 |
| 597 const int kTimeoutSec = 30; |
| 598 DCHECK(!backend_start_timer_.get()); |
| 599 backend_start_timer_.reset(new base::OneShotTimer<SyncSetupHandler>()); |
| 600 backend_start_timer_->Start(FROM_HERE, |
| 601 base::TimeDelta::FromSeconds(kTimeoutSec), |
| 602 this, &SyncSetupHandler::DisplayTimeout); |
| 603 |
| 604 web_ui()->CallJavascriptFunction( |
| 605 "SyncSetupOverlay.showSyncSetupPage", page, args); |
| 606 } |
| 607 |
| 608 // TODO(kochi): Handle error conditions other than timeout. |
| 609 // http://crbug.com/128692 |
| 610 void SyncSetupHandler::DisplayTimeout() { |
| 611 // Stop setting up sync service |
| 612 CloseSyncSetup(); |
| 613 |
| 614 StringValue page("timeout"); |
| 615 DictionaryValue args; |
594 web_ui()->CallJavascriptFunction( | 616 web_ui()->CallJavascriptFunction( |
595 "SyncSetupOverlay.showSyncSetupPage", page, args); | 617 "SyncSetupOverlay.showSyncSetupPage", page, args); |
596 } | 618 } |
597 | 619 |
598 void SyncSetupHandler::RecordSignin() { | 620 void SyncSetupHandler::RecordSignin() { |
599 // By default, do nothing - subclasses can override. | 621 // By default, do nothing - subclasses can override. |
600 } | 622 } |
601 | 623 |
602 void SyncSetupHandler::DisplayGaiaSuccessAndClose() { | 624 void SyncSetupHandler::DisplayGaiaSuccessAndClose() { |
603 RecordSignin(); | 625 RecordSignin(); |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
702 } | 724 } |
703 | 725 |
704 void SyncSetupHandler::GaiaCredentialsValid() { | 726 void SyncSetupHandler::GaiaCredentialsValid() { |
705 DCHECK(IsActiveLogin()); | 727 DCHECK(IsActiveLogin()); |
706 | 728 |
707 // Gaia credentials are valid - update the UI. | 729 // Gaia credentials are valid - update the UI. |
708 DisplayGaiaSuccessAndSettingUp(); | 730 DisplayGaiaSuccessAndSettingUp(); |
709 } | 731 } |
710 | 732 |
711 void SyncSetupHandler::SigninFailed(const GoogleServiceAuthError& error) { | 733 void SyncSetupHandler::SigninFailed(const GoogleServiceAuthError& error) { |
| 734 // Stop a timer to handle timeout in waiting for checking network connection. |
| 735 backend_start_timer_.reset(); |
| 736 |
712 last_signin_error_ = error; | 737 last_signin_error_ = error; |
713 // Got a failed signin - this is either just a typical auth error, or a | 738 // Got a failed signin - this is either just a typical auth error, or a |
714 // sync error (treat sync errors as "fatal errors" - i.e. non-auth errors). | 739 // sync error (treat sync errors as "fatal errors" - i.e. non-auth errors). |
715 // On ChromeOS, this condition can happen when auth token is invalid and | 740 // On ChromeOS, this condition can happen when auth token is invalid and |
716 // cannot start sync backend. | 741 // cannot start sync backend. |
717 if (retry_on_signin_failure_) { | 742 if (retry_on_signin_failure_) { |
718 DisplayGaiaLogin(GetSyncService()->HasUnrecoverableError()); | 743 DisplayGaiaLogin(GetSyncService()->HasUnrecoverableError()); |
719 } else { | 744 } else { |
720 // TODO(peria): Show error dialog for prompting sign in and out on | 745 // TODO(peria): Show error dialog for prompting sign in and out on |
721 // Chrome OS. http://crbug.com/128692 | 746 // Chrome OS. http://crbug.com/128692 |
722 CloseOverlay(); | 747 CloseOverlay(); |
723 } | 748 } |
724 } | 749 } |
725 | 750 |
726 Profile* SyncSetupHandler::GetProfile() const { | 751 Profile* SyncSetupHandler::GetProfile() const { |
727 return Profile::FromWebUI(web_ui()); | 752 return Profile::FromWebUI(web_ui()); |
728 } | 753 } |
729 | 754 |
730 ProfileSyncService* SyncSetupHandler::GetSyncService() const { | 755 ProfileSyncService* SyncSetupHandler::GetSyncService() const { |
731 return ProfileSyncServiceFactory::GetForProfile(GetProfile()); | 756 return ProfileSyncServiceFactory::GetForProfile(GetProfile()); |
732 } | 757 } |
733 | 758 |
734 void SyncSetupHandler::SigninSuccess() { | 759 void SyncSetupHandler::SigninSuccess() { |
735 DCHECK(GetSyncService()->sync_initialized()); | 760 DCHECK(GetSyncService()->sync_initialized()); |
| 761 // Stop a timer to handle timeout in waiting for checking network connection. |
| 762 backend_start_timer_.reset(); |
| 763 |
736 // If we have signed in while sync is already setup, it must be due to some | 764 // If we have signed in while sync is already setup, it must be due to some |
737 // kind of re-authentication flow. In that case, just close the signin dialog | 765 // kind of re-authentication flow. In that case, just close the signin dialog |
738 // rather than forcing the user to go through sync configuration. | 766 // rather than forcing the user to go through sync configuration. |
739 if (GetSyncService()->HasSyncSetupCompleted()) | 767 if (GetSyncService()->HasSyncSetupCompleted()) |
740 DisplayGaiaSuccessAndClose(); | 768 DisplayGaiaSuccessAndClose(); |
741 else | 769 else |
742 DisplayConfigureSync(false, false); | 770 DisplayConfigureSync(false, false); |
743 } | 771 } |
744 | 772 |
745 void SyncSetupHandler::HandleConfigure(const ListValue* args) { | 773 void SyncSetupHandler::HandleConfigure(const ListValue* args) { |
(...skipping 251 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
997 return false; | 1025 return false; |
998 service->current_login_ui()->FocusUI(); | 1026 service->current_login_ui()->FocusUI(); |
999 return true; | 1027 return true; |
1000 } | 1028 } |
1001 | 1029 |
1002 LoginUIService* SyncSetupHandler::GetLoginUIService() const { | 1030 LoginUIService* SyncSetupHandler::GetLoginUIService() const { |
1003 return LoginUIServiceFactory::GetForProfile(GetProfile()); | 1031 return LoginUIServiceFactory::GetForProfile(GetProfile()); |
1004 } | 1032 } |
1005 | 1033 |
1006 void SyncSetupHandler::CloseOverlay() { | 1034 void SyncSetupHandler::CloseOverlay() { |
| 1035 // Stop a timer to handle timeout in waiting for sync setup. |
| 1036 backend_start_timer_.reset(); |
| 1037 |
1007 CloseSyncSetup(); | 1038 CloseSyncSetup(); |
1008 web_ui()->CallJavascriptFunction("OptionsPage.closeOverlay"); | 1039 web_ui()->CallJavascriptFunction("OptionsPage.closeOverlay"); |
1009 } | 1040 } |
1010 | 1041 |
1011 bool SyncSetupHandler::IsLoginAuthDataValid(const std::string& username, | 1042 bool SyncSetupHandler::IsLoginAuthDataValid(const std::string& username, |
1012 string16* error_message) { | 1043 string16* error_message) { |
1013 if (username.empty()) | 1044 if (username.empty()) |
1014 return true; | 1045 return true; |
1015 | 1046 |
1016 // Can be null during some unit tests. | 1047 // Can be null during some unit tests. |
(...skipping 19 matching lines...) Expand all Loading... |
1036 if (i != current_profile_index && AreUserNamesEqual( | 1067 if (i != current_profile_index && AreUserNamesEqual( |
1037 cache.GetUserNameOfProfileAtIndex(i), username_utf16)) { | 1068 cache.GetUserNameOfProfileAtIndex(i), username_utf16)) { |
1038 *error_message = l10n_util::GetStringUTF16( | 1069 *error_message = l10n_util::GetStringUTF16( |
1039 IDS_SYNC_USER_NAME_IN_USE_ERROR); | 1070 IDS_SYNC_USER_NAME_IN_USE_ERROR); |
1040 return false; | 1071 return false; |
1041 } | 1072 } |
1042 } | 1073 } |
1043 | 1074 |
1044 return true; | 1075 return true; |
1045 } | 1076 } |
OLD | NEW |