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

Side by Side Diff: chrome/browser/ui/webui/sync_setup_handler.cc

Issue 10539128: Set timeout in sync setup (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Fix a unittest putting MessageLoop Created 8 years, 4 months 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
OLDNEW
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
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 182 matching lines...) Expand 10 before | Expand all | Expand 10 after
480 base::Bind(&SyncSetupHandler::HandleShowSetupUI, 482 base::Bind(&SyncSetupHandler::HandleShowSetupUI,
481 base::Unretained(this))); 483 base::Unretained(this)));
482 web_ui()->RegisterMessageCallback( 484 web_ui()->RegisterMessageCallback(
483 "SyncSetupShowSetupUIWithoutLogin", 485 "SyncSetupShowSetupUIWithoutLogin",
484 base::Bind(&SyncSetupHandler::HandleShowSetupUIWithoutLogin, 486 base::Bind(&SyncSetupHandler::HandleShowSetupUIWithoutLogin,
485 base::Unretained(this))); 487 base::Unretained(this)));
486 web_ui()->RegisterMessageCallback( 488 web_ui()->RegisterMessageCallback(
487 "SyncSetupDoSignOutOnAuthError", 489 "SyncSetupDoSignOutOnAuthError",
488 base::Bind(&SyncSetupHandler::HandleDoSignOutOnAuthError, 490 base::Bind(&SyncSetupHandler::HandleDoSignOutOnAuthError,
489 base::Unretained(this))); 491 base::Unretained(this)));
492 web_ui()->RegisterMessageCallback("CloseTimeout",
493 base::Bind(&SyncSetupHandler::HandleCloseTimeout,
494 base::Unretained(this)));
490 web_ui()->RegisterMessageCallback("SyncSetupStopSyncing", 495 web_ui()->RegisterMessageCallback("SyncSetupStopSyncing",
491 base::Bind(&SyncSetupHandler::HandleStopSyncing, 496 base::Bind(&SyncSetupHandler::HandleStopSyncing,
492 base::Unretained(this))); 497 base::Unretained(this)));
493 } 498 }
494 499
495 SigninManager* SyncSetupHandler::GetSignin() const { 500 SigninManager* SyncSetupHandler::GetSignin() const {
496 return SigninManagerFactory::GetForProfile(GetProfile()); 501 return SigninManagerFactory::GetForProfile(GetProfile());
497 } 502 }
498 503
499 void SyncSetupHandler::DisplayGaiaLogin(bool fatal_error) { 504 void SyncSetupHandler::DisplayGaiaLogin(bool fatal_error) {
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
584 589
585 return true; 590 return true;
586 } 591 }
587 592
588 // TODO(kochi): Handle error conditions (timeout, other failures). 593 // TODO(kochi): Handle error conditions (timeout, other failures).
589 // http://crbug.com/128692 594 // http://crbug.com/128692
590 void SyncSetupHandler::DisplaySpinner() { 595 void SyncSetupHandler::DisplaySpinner() {
591 configuring_sync_ = true; 596 configuring_sync_ = true;
592 StringValue page("spinner"); 597 StringValue page("spinner");
593 DictionaryValue args; 598 DictionaryValue args;
599
600 const int kTimeoutSec = 30;
601 DCHECK(!backend_start_timer_.get());
602 backend_start_timer_.reset(new base::OneShotTimer<SyncSetupHandler>());
603 backend_start_timer_->Start(FROM_HERE,
604 base::TimeDelta::FromSeconds(kTimeoutSec),
605 this, &SyncSetupHandler::DisplayTimeout);
606
607 web_ui()->CallJavascriptFunction(
608 "SyncSetupOverlay.showSyncSetupPage", page, args);
609 }
610
611 // TODO(kochi): Handle error conditions other than timeout.
612 // http://crbug.com/128692
613 void SyncSetupHandler::DisplayTimeout() {
614 // Stop a timer to handle timeout in waiting for checking network connection.
615 backend_start_timer_.reset();
616
617 // Do not listen to signin events.
618 signin_tracker_.reset();
619
620 StringValue page("timeout");
621 DictionaryValue args;
594 web_ui()->CallJavascriptFunction( 622 web_ui()->CallJavascriptFunction(
595 "SyncSetupOverlay.showSyncSetupPage", page, args); 623 "SyncSetupOverlay.showSyncSetupPage", page, args);
596 } 624 }
597 625
598 void SyncSetupHandler::RecordSignin() { 626 void SyncSetupHandler::RecordSignin() {
599 // By default, do nothing - subclasses can override. 627 // By default, do nothing - subclasses can override.
600 } 628 }
601 629
602 void SyncSetupHandler::DisplayGaiaSuccessAndClose() { 630 void SyncSetupHandler::DisplayGaiaSuccessAndClose() {
603 RecordSignin(); 631 RecordSignin();
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
710 } 738 }
711 739
712 void SyncSetupHandler::GaiaCredentialsValid() { 740 void SyncSetupHandler::GaiaCredentialsValid() {
713 DCHECK(IsActiveLogin()); 741 DCHECK(IsActiveLogin());
714 742
715 // Gaia credentials are valid - update the UI. 743 // Gaia credentials are valid - update the UI.
716 DisplayGaiaSuccessAndSettingUp(); 744 DisplayGaiaSuccessAndSettingUp();
717 } 745 }
718 746
719 void SyncSetupHandler::SigninFailed(const GoogleServiceAuthError& error) { 747 void SyncSetupHandler::SigninFailed(const GoogleServiceAuthError& error) {
748 // Stop a timer to handle timeout in waiting for checking network connection.
749 backend_start_timer_.reset();
750
720 last_signin_error_ = error; 751 last_signin_error_ = error;
721 // Got a failed signin - this is either just a typical auth error, or a 752 // Got a failed signin - this is either just a typical auth error, or a
722 // sync error (treat sync errors as "fatal errors" - i.e. non-auth errors). 753 // sync error (treat sync errors as "fatal errors" - i.e. non-auth errors).
723 // On ChromeOS, this condition can happen when auth token is invalid and 754 // On ChromeOS, this condition can happen when auth token is invalid and
724 // cannot start sync backend. 755 // cannot start sync backend.
725 if (retry_on_signin_failure_) { 756 if (retry_on_signin_failure_) {
726 DisplayGaiaLogin(GetSyncService()->HasUnrecoverableError()); 757 DisplayGaiaLogin(GetSyncService()->HasUnrecoverableError());
727 } else { 758 } else {
728 // TODO(peria): Show error dialog for prompting sign in and out on 759 // TODO(peria): Show error dialog for prompting sign in and out on
729 // Chrome OS. http://crbug.com/128692 760 // Chrome OS. http://crbug.com/128692
730 CloseOverlay(); 761 CloseOverlay();
731 } 762 }
732 } 763 }
733 764
734 Profile* SyncSetupHandler::GetProfile() const { 765 Profile* SyncSetupHandler::GetProfile() const {
735 return Profile::FromWebUI(web_ui()); 766 return Profile::FromWebUI(web_ui());
736 } 767 }
737 768
738 ProfileSyncService* SyncSetupHandler::GetSyncService() const { 769 ProfileSyncService* SyncSetupHandler::GetSyncService() const {
739 return ProfileSyncServiceFactory::GetForProfile(GetProfile()); 770 return ProfileSyncServiceFactory::GetForProfile(GetProfile());
740 } 771 }
741 772
742 void SyncSetupHandler::SigninSuccess() { 773 void SyncSetupHandler::SigninSuccess() {
743 DCHECK(GetSyncService()->sync_initialized()); 774 DCHECK(GetSyncService()->sync_initialized());
775 // Stop a timer to handle timeout in waiting for checking network connection.
776 backend_start_timer_.reset();
777
744 // If we have signed in while sync is already setup, it must be due to some 778 // If we have signed in while sync is already setup, it must be due to some
745 // kind of re-authentication flow. In that case, just close the signin dialog 779 // kind of re-authentication flow. In that case, just close the signin dialog
746 // rather than forcing the user to go through sync configuration. 780 // rather than forcing the user to go through sync configuration.
747 if (GetSyncService()->HasSyncSetupCompleted()) 781 if (GetSyncService()->HasSyncSetupCompleted())
748 DisplayGaiaSuccessAndClose(); 782 DisplayGaiaSuccessAndClose();
749 else 783 else
750 DisplayConfigureSync(false, false); 784 DisplayConfigureSync(false, false);
751 } 785 }
752 786
753 void SyncSetupHandler::HandleConfigure(const ListValue* args) { 787 void SyncSetupHandler::HandleConfigure(const ListValue* args) {
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after
893 void SyncSetupHandler::HandleStopSyncing(const ListValue* args) { 927 void SyncSetupHandler::HandleStopSyncing(const ListValue* args) {
894 ProfileSyncService* service = GetSyncService(); 928 ProfileSyncService* service = GetSyncService();
895 DCHECK(service); 929 DCHECK(service);
896 930
897 if (ProfileSyncService::IsSyncEnabled()) { 931 if (ProfileSyncService::IsSyncEnabled()) {
898 service->DisableForUser(); 932 service->DisableForUser();
899 ProfileSyncService::SyncEvent(ProfileSyncService::STOP_FROM_OPTIONS); 933 ProfileSyncService::SyncEvent(ProfileSyncService::STOP_FROM_OPTIONS);
900 } 934 }
901 } 935 }
902 936
937 void SyncSetupHandler::HandleCloseTimeout(const ListValue* args) {
938 CloseSyncSetup();
939 }
940
903 void SyncSetupHandler::CloseSyncSetup() { 941 void SyncSetupHandler::CloseSyncSetup() {
904 // TODO(atwilson): Move UMA tracking of signin events out of sync module. 942 // TODO(atwilson): Move UMA tracking of signin events out of sync module.
905 ProfileSyncService* sync_service = GetSyncService(); 943 ProfileSyncService* sync_service = GetSyncService();
906 if (IsActiveLogin()) { 944 if (IsActiveLogin()) {
907 if (!sync_service->HasSyncSetupCompleted()) { 945 if (!sync_service->HasSyncSetupCompleted()) {
908 if (signin_tracker_.get()) { 946 if (signin_tracker_.get()) {
909 ProfileSyncService::SyncEvent( 947 ProfileSyncService::SyncEvent(
910 ProfileSyncService::CANCEL_DURING_SIGNON); 948 ProfileSyncService::CANCEL_DURING_SIGNON);
911 } else if (configuring_sync_) { 949 } else if (configuring_sync_) {
912 ProfileSyncService::SyncEvent( 950 ProfileSyncService::SyncEvent(
(...skipping 23 matching lines...) Expand all
936 } 974 }
937 975
938 // Reset the attempted email address and error, otherwise the sync setup 976 // Reset the attempted email address and error, otherwise the sync setup
939 // overlay in the settings page will stay in whatever error state it was last 977 // overlay in the settings page will stay in whatever error state it was last
940 // when it is reopened. 978 // when it is reopened.
941 last_attempted_user_email_.clear(); 979 last_attempted_user_email_.clear();
942 last_signin_error_ = GoogleServiceAuthError::None(); 980 last_signin_error_ = GoogleServiceAuthError::None();
943 981
944 configuring_sync_ = false; 982 configuring_sync_ = false;
945 signin_tracker_.reset(); 983 signin_tracker_.reset();
984
985 // Stop a timer to handle timeout in waiting for checking network connection.
986 backend_start_timer_.reset();
946 } 987 }
947 988
948 void SyncSetupHandler::OpenSyncSetup(bool force_login) { 989 void SyncSetupHandler::OpenSyncSetup(bool force_login) {
949 if (!PrepareSyncSetup()) 990 if (!PrepareSyncSetup())
950 return; 991 return;
951 992
952 ProfileSyncService* service = GetSyncService(); 993 ProfileSyncService* service = GetSyncService();
953 994
954 // There are several different UI flows that can bring the user here: 995 // There are several different UI flows that can bring the user here:
955 // 1) Signin promo (passes force_login=true) 996 // 1) Signin promo (passes force_login=true)
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
1005 return false; 1046 return false;
1006 service->current_login_ui()->FocusUI(); 1047 service->current_login_ui()->FocusUI();
1007 return true; 1048 return true;
1008 } 1049 }
1009 1050
1010 LoginUIService* SyncSetupHandler::GetLoginUIService() const { 1051 LoginUIService* SyncSetupHandler::GetLoginUIService() const {
1011 return LoginUIServiceFactory::GetForProfile(GetProfile()); 1052 return LoginUIServiceFactory::GetForProfile(GetProfile());
1012 } 1053 }
1013 1054
1014 void SyncSetupHandler::CloseOverlay() { 1055 void SyncSetupHandler::CloseOverlay() {
1056 // Stop a timer to handle timeout in waiting for sync setup.
1057 backend_start_timer_.reset();
1058
1015 CloseSyncSetup(); 1059 CloseSyncSetup();
1016 web_ui()->CallJavascriptFunction("OptionsPage.closeOverlay"); 1060 web_ui()->CallJavascriptFunction("OptionsPage.closeOverlay");
1017 } 1061 }
1018 1062
1019 bool SyncSetupHandler::IsLoginAuthDataValid(const std::string& username, 1063 bool SyncSetupHandler::IsLoginAuthDataValid(const std::string& username,
1020 string16* error_message) { 1064 string16* error_message) {
1021 if (username.empty()) 1065 if (username.empty())
1022 return true; 1066 return true;
1023 1067
1024 // Can be null during some unit tests. 1068 // Can be null during some unit tests.
(...skipping 19 matching lines...) Expand all
1044 if (i != current_profile_index && AreUserNamesEqual( 1088 if (i != current_profile_index && AreUserNamesEqual(
1045 cache.GetUserNameOfProfileAtIndex(i), username_utf16)) { 1089 cache.GetUserNameOfProfileAtIndex(i), username_utf16)) {
1046 *error_message = l10n_util::GetStringUTF16( 1090 *error_message = l10n_util::GetStringUTF16(
1047 IDS_SYNC_USER_NAME_IN_USE_ERROR); 1091 IDS_SYNC_USER_NAME_IN_USE_ERROR);
1048 return false; 1092 return false;
1049 } 1093 }
1050 } 1094 }
1051 1095
1052 return true; 1096 return true;
1053 } 1097 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/webui/sync_setup_handler.h ('k') | chrome/browser/ui/webui/sync_setup_handler_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698