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 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
189 return !CommandLine::ForCurrentProcess()->HasSwitch( | 189 return !CommandLine::ForCurrentProcess()->HasSwitch( |
190 switches::kDisableClientOAuthSignin); | 190 switches::kDisableClientOAuthSignin); |
191 } | 191 } |
192 | 192 |
193 } // namespace | 193 } // namespace |
194 | 194 |
195 SyncSetupHandler::SyncSetupHandler(ProfileManager* profile_manager) | 195 SyncSetupHandler::SyncSetupHandler(ProfileManager* profile_manager) |
196 : configuring_sync_(false), | 196 : configuring_sync_(false), |
197 profile_manager_(profile_manager), | 197 profile_manager_(profile_manager), |
198 last_signin_error_(GoogleServiceAuthError::NONE), | 198 last_signin_error_(GoogleServiceAuthError::NONE), |
199 retry_on_signin_failure_(true) { | 199 retry_on_signin_failure_(true), |
200 visible_timeout_(false) { | |
200 } | 201 } |
201 | 202 |
202 SyncSetupHandler::~SyncSetupHandler() { | 203 SyncSetupHandler::~SyncSetupHandler() { |
203 // Just exit if running unit tests (no actual WebUI is attached). | 204 // Just exit if running unit tests (no actual WebUI is attached). |
204 if (!web_ui()) | 205 if (!web_ui()) |
205 return; | 206 return; |
206 | 207 |
207 // This case is hit when the user performs a back navigation. | 208 // This case is hit when the user performs a back navigation. |
208 CloseSyncSetup(); | 209 CloseSyncSetup(); |
209 } | 210 } |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
278 localized_strings->SetString("createAccountLinkHTML", | 279 localized_strings->SetString("createAccountLinkHTML", |
279 GetStringFUTF16(IDS_SYNC_CREATE_ACCOUNT_PREFIX, create_account)); | 280 GetStringFUTF16(IDS_SYNC_CREATE_ACCOUNT_PREFIX, create_account)); |
280 | 281 |
281 string16 sync_benefits_url( | 282 string16 sync_benefits_url( |
282 UTF8ToUTF16(google_util::StringAppendGoogleLocaleParam( | 283 UTF8ToUTF16(google_util::StringAppendGoogleLocaleParam( |
283 chrome::kSyncLearnMoreURL))); | 284 chrome::kSyncLearnMoreURL))); |
284 localized_strings->SetString("promoLearnMoreURL", sync_benefits_url); | 285 localized_strings->SetString("promoLearnMoreURL", sync_benefits_url); |
285 | 286 |
286 static OptionsStringResource resources[] = { | 287 static OptionsStringResource resources[] = { |
287 { "syncSetupConfigureTitle", IDS_SYNC_SETUP_CONFIGURE_TITLE }, | 288 { "syncSetupConfigureTitle", IDS_SYNC_SETUP_CONFIGURE_TITLE }, |
289 { "syncSetupTimeoutTitle", IDS_SYNC_SETUP_TIME_OUT_TITLE }, | |
290 { "syncSetupTimeoutContent", IDS_SYNC_SETUP_TIME_OUT_CONTENT }, | |
288 { "cannotBeBlank", IDS_SYNC_CANNOT_BE_BLANK }, | 291 { "cannotBeBlank", IDS_SYNC_CANNOT_BE_BLANK }, |
289 { "emailLabel", IDS_SYNC_LOGIN_EMAIL_NEW_LINE }, | 292 { "emailLabel", IDS_SYNC_LOGIN_EMAIL_NEW_LINE }, |
290 { "passwordLabel", IDS_SYNC_LOGIN_PASSWORD_NEW_LINE }, | 293 { "passwordLabel", IDS_SYNC_LOGIN_PASSWORD_NEW_LINE }, |
291 { "invalidCredentials", IDS_SYNC_INVALID_USER_CREDENTIALS }, | 294 { "invalidCredentials", IDS_SYNC_INVALID_USER_CREDENTIALS }, |
292 { "signin", IDS_SYNC_SIGNIN }, | 295 { "signin", IDS_SYNC_SIGNIN }, |
293 { "couldNotConnect", IDS_SYNC_LOGIN_COULD_NOT_CONNECT }, | 296 { "couldNotConnect", IDS_SYNC_LOGIN_COULD_NOT_CONNECT }, |
294 { "unrecoverableError", IDS_SYNC_UNRECOVERABLE_ERROR }, | 297 { "unrecoverableError", IDS_SYNC_UNRECOVERABLE_ERROR }, |
295 { "errorLearnMore", IDS_LEARN_MORE }, | 298 { "errorLearnMore", IDS_LEARN_MORE }, |
296 { "unrecoverableErrorHelpURL", IDS_SYNC_UNRECOVERABLE_ERROR_HELP_URL }, | 299 { "unrecoverableErrorHelpURL", IDS_SYNC_UNRECOVERABLE_ERROR_HELP_URL }, |
297 { "cannotAccessAccount", IDS_SYNC_CANNOT_ACCESS_ACCOUNT }, | 300 { "cannotAccessAccount", IDS_SYNC_CANNOT_ACCESS_ACCOUNT }, |
(...skipping 286 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
584 | 587 |
585 return true; | 588 return true; |
586 } | 589 } |
587 | 590 |
588 // TODO(kochi): Handle error conditions (timeout, other failures). | 591 // TODO(kochi): Handle error conditions (timeout, other failures). |
589 // http://crbug.com/128692 | 592 // http://crbug.com/128692 |
590 void SyncSetupHandler::DisplaySpinner() { | 593 void SyncSetupHandler::DisplaySpinner() { |
591 configuring_sync_ = true; | 594 configuring_sync_ = true; |
592 StringValue page("spinner"); | 595 StringValue page("spinner"); |
593 DictionaryValue args; | 596 DictionaryValue args; |
597 | |
598 const int kTimeoutSec = 30; | |
599 DCHECK(!backend_start_timer_.get()); | |
600 backend_start_timer_.reset(new base::OneShotTimer<SyncSetupHandler>()); | |
601 backend_start_timer_->Start(FROM_HERE, | |
602 base::TimeDelta::FromSeconds(kTimeoutSec), | |
603 this, &SyncSetupHandler::DisplayTimeout); | |
604 | |
605 web_ui()->CallJavascriptFunction( | |
606 "SyncSetupOverlay.showSyncSetupPage", page, args); | |
607 } | |
608 | |
609 // TODO(kochi): Handle error conditions other than timeout. | |
610 // http://crbug.com/128692 | |
611 void SyncSetupHandler::DisplayTimeout() { | |
612 // Stop setting up sync service | |
613 CloseSyncSetup(); | |
614 | |
615 visible_timeout_ = true; | |
616 StringValue page("timeout"); | |
617 DictionaryValue args; | |
594 web_ui()->CallJavascriptFunction( | 618 web_ui()->CallJavascriptFunction( |
595 "SyncSetupOverlay.showSyncSetupPage", page, args); | 619 "SyncSetupOverlay.showSyncSetupPage", page, args); |
596 } | 620 } |
597 | 621 |
598 void SyncSetupHandler::RecordSignin() { | 622 void SyncSetupHandler::RecordSignin() { |
599 // By default, do nothing - subclasses can override. | 623 // By default, do nothing - subclasses can override. |
600 } | 624 } |
601 | 625 |
602 void SyncSetupHandler::DisplayGaiaSuccessAndClose() { | 626 void SyncSetupHandler::DisplayGaiaSuccessAndClose() { |
603 RecordSignin(); | 627 RecordSignin(); |
604 web_ui()->CallJavascriptFunction("SyncSetupOverlay.showSuccessAndClose"); | 628 web_ui()->CallJavascriptFunction("SyncSetupOverlay.showSuccessAndClose"); |
605 } | 629 } |
606 | 630 |
607 void SyncSetupHandler::DisplayGaiaSuccessAndSettingUp() { | 631 void SyncSetupHandler::DisplayGaiaSuccessAndSettingUp() { |
608 RecordSignin(); | 632 RecordSignin(); |
609 web_ui()->CallJavascriptFunction("SyncSetupOverlay.showSuccessAndSettingUp"); | 633 web_ui()->CallJavascriptFunction("SyncSetupOverlay.showSuccessAndSettingUp"); |
610 } | 634 } |
611 | 635 |
612 void SyncSetupHandler::OnDidClosePage(const ListValue* args) { | 636 void SyncSetupHandler::OnDidClosePage(const ListValue* args) { |
637 visible_timeout_ = false; | |
613 CloseSyncSetup(); | 638 CloseSyncSetup(); |
614 } | 639 } |
615 | 640 |
616 void SyncSetupHandler::HandleSubmitAuth(const ListValue* args) { | 641 void SyncSetupHandler::HandleSubmitAuth(const ListValue* args) { |
617 std::string json; | 642 std::string json; |
618 if (!args->GetString(0, &json)) { | 643 if (!args->GetString(0, &json)) { |
619 NOTREACHED() << "Could not read JSON argument"; | 644 NOTREACHED() << "Could not read JSON argument"; |
620 return; | 645 return; |
621 } | 646 } |
622 | 647 |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
702 } | 727 } |
703 | 728 |
704 void SyncSetupHandler::GaiaCredentialsValid() { | 729 void SyncSetupHandler::GaiaCredentialsValid() { |
705 DCHECK(IsActiveLogin()); | 730 DCHECK(IsActiveLogin()); |
706 | 731 |
707 // Gaia credentials are valid - update the UI. | 732 // Gaia credentials are valid - update the UI. |
708 DisplayGaiaSuccessAndSettingUp(); | 733 DisplayGaiaSuccessAndSettingUp(); |
709 } | 734 } |
710 | 735 |
711 void SyncSetupHandler::SigninFailed(const GoogleServiceAuthError& error) { | 736 void SyncSetupHandler::SigninFailed(const GoogleServiceAuthError& error) { |
737 // Stop a timer to handle timeout in waiting for checking network connection. | |
738 backend_start_timer_.reset(); | |
739 | |
712 last_signin_error_ = error; | 740 last_signin_error_ = error; |
713 // Got a failed signin - this is either just a typical auth error, or a | 741 // 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). | 742 // 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 | 743 // On ChromeOS, this condition can happen when auth token is invalid and |
716 // cannot start sync backend. | 744 // cannot start sync backend. |
717 if (retry_on_signin_failure_) { | 745 if (retry_on_signin_failure_) { |
718 DisplayGaiaLogin(GetSyncService()->HasUnrecoverableError()); | 746 DisplayGaiaLogin(GetSyncService()->HasUnrecoverableError()); |
719 } else { | 747 } else { |
720 // TODO(peria): Show error dialog for prompting sign in and out on | 748 // TODO(peria): Show error dialog for prompting sign in and out on |
721 // Chrome OS. http://crbug.com/128692 | 749 // Chrome OS. http://crbug.com/128692 |
722 CloseOverlay(); | 750 CloseOverlay(); |
723 } | 751 } |
724 } | 752 } |
725 | 753 |
726 Profile* SyncSetupHandler::GetProfile() const { | 754 Profile* SyncSetupHandler::GetProfile() const { |
727 return Profile::FromWebUI(web_ui()); | 755 return Profile::FromWebUI(web_ui()); |
728 } | 756 } |
729 | 757 |
730 ProfileSyncService* SyncSetupHandler::GetSyncService() const { | 758 ProfileSyncService* SyncSetupHandler::GetSyncService() const { |
731 return ProfileSyncServiceFactory::GetForProfile(GetProfile()); | 759 return ProfileSyncServiceFactory::GetForProfile(GetProfile()); |
732 } | 760 } |
733 | 761 |
734 void SyncSetupHandler::SigninSuccess() { | 762 void SyncSetupHandler::SigninSuccess() { |
735 DCHECK(GetSyncService()->sync_initialized()); | 763 DCHECK(GetSyncService()->sync_initialized()); |
764 // Stop a timer to handle timeout in waiting for checking network connection. | |
765 backend_start_timer_.reset(); | |
766 | |
736 // If we have signed in while sync is already setup, it must be due to some | 767 // 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 | 768 // kind of re-authentication flow. In that case, just close the signin dialog |
738 // rather than forcing the user to go through sync configuration. | 769 // rather than forcing the user to go through sync configuration. |
739 if (GetSyncService()->HasSyncSetupCompleted()) | 770 if (GetSyncService()->HasSyncSetupCompleted()) |
740 DisplayGaiaSuccessAndClose(); | 771 DisplayGaiaSuccessAndClose(); |
741 else | 772 else |
742 DisplayConfigureSync(false, false); | 773 DisplayConfigureSync(false, false); |
743 } | 774 } |
744 | 775 |
745 void SyncSetupHandler::HandleConfigure(const ListValue* args) { | 776 void SyncSetupHandler::HandleConfigure(const ListValue* args) { |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
840 ProfileMetrics::LogProfileSyncInfo(ProfileMetrics::SYNC_CUSTOMIZE); | 871 ProfileMetrics::LogProfileSyncInfo(ProfileMetrics::SYNC_CUSTOMIZE); |
841 if (configuration.encrypt_all) | 872 if (configuration.encrypt_all) |
842 ProfileMetrics::LogProfileSyncInfo(ProfileMetrics::SYNC_ENCRYPT); | 873 ProfileMetrics::LogProfileSyncInfo(ProfileMetrics::SYNC_ENCRYPT); |
843 if (configuration.passphrase_is_gaia && !configuration.passphrase.empty()) | 874 if (configuration.passphrase_is_gaia && !configuration.passphrase.empty()) |
844 ProfileMetrics::LogProfileSyncInfo(ProfileMetrics::SYNC_PASSPHRASE); | 875 ProfileMetrics::LogProfileSyncInfo(ProfileMetrics::SYNC_PASSPHRASE); |
845 if (!configuration.sync_everything) | 876 if (!configuration.sync_everything) |
846 ProfileMetrics::LogProfileSyncInfo(ProfileMetrics::SYNC_CHOOSE); | 877 ProfileMetrics::LogProfileSyncInfo(ProfileMetrics::SYNC_CHOOSE); |
847 } | 878 } |
848 | 879 |
849 void SyncSetupHandler::HandleAttachHandler(const ListValue* args) { | 880 void SyncSetupHandler::HandleAttachHandler(const ListValue* args) { |
881 // Stop recursive calls if timeout dialog is visible. | |
882 if (visible_timeout_) { | |
Andrew T Wilson (Slow)
2012/07/02 15:31:58
I don't get it - why is HandleAttachHandler gettin
peria
2012/07/03 08:06:46
Yes, this method is called a dialog is shown up in
Andrew T Wilson (Slow)
2012/07/03 16:35:05
Your new code still breaks if you get a timeout wh
peria
2012/07/06 06:37:57
I checked with current code (Patch 10),
- click "
| |
883 return; | |
884 } | |
kochi
2012/07/02 09:34:48
You don't need {} here.
peria
2012/07/03 08:06:46
removed the branch.
| |
885 | |
850 bool force_login = false; | 886 bool force_login = false; |
851 std::string json; | 887 std::string json; |
852 if (args->GetString(0, &json) && !json.empty()) { | 888 if (args->GetString(0, &json) && !json.empty()) { |
853 scoped_ptr<Value> parsed_value(base::JSONReader::Read(json)); | 889 scoped_ptr<Value> parsed_value(base::JSONReader::Read(json)); |
854 DictionaryValue* result = static_cast<DictionaryValue*>(parsed_value.get()); | 890 DictionaryValue* result = static_cast<DictionaryValue*>(parsed_value.get()); |
855 result->GetBoolean("forceLogin", &force_login); | 891 result->GetBoolean("forceLogin", &force_login); |
856 } | 892 } |
857 | 893 |
858 OpenSyncSetup(force_login); | 894 OpenSyncSetup(force_login); |
859 } | 895 } |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
928 } | 964 } |
929 | 965 |
930 // Reset the attempted email address and error, otherwise the sync setup | 966 // Reset the attempted email address and error, otherwise the sync setup |
931 // overlay in the settings page will stay in whatever error state it was last | 967 // overlay in the settings page will stay in whatever error state it was last |
932 // when it is reopened. | 968 // when it is reopened. |
933 last_attempted_user_email_.clear(); | 969 last_attempted_user_email_.clear(); |
934 last_signin_error_ = GoogleServiceAuthError::None(); | 970 last_signin_error_ = GoogleServiceAuthError::None(); |
935 | 971 |
936 configuring_sync_ = false; | 972 configuring_sync_ = false; |
937 signin_tracker_.reset(); | 973 signin_tracker_.reset(); |
974 | |
975 // Stop a timer to handle timeout in waiting for sync setup. | |
976 backend_start_timer_.reset(); | |
938 } | 977 } |
939 | 978 |
940 void SyncSetupHandler::OpenSyncSetup(bool force_login) { | 979 void SyncSetupHandler::OpenSyncSetup(bool force_login) { |
941 if (!PrepareSyncSetup()) | 980 if (!PrepareSyncSetup()) |
942 return; | 981 return; |
943 | 982 |
944 ProfileSyncService* service = GetSyncService(); | 983 ProfileSyncService* service = GetSyncService(); |
945 | 984 |
946 // There are several different UI flows that can bring the user here: | 985 // There are several different UI flows that can bring the user here: |
947 // 1) Signin promo (passes force_login=true) | 986 // 1) Signin promo (passes force_login=true) |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1036 if (i != current_profile_index && AreUserNamesEqual( | 1075 if (i != current_profile_index && AreUserNamesEqual( |
1037 cache.GetUserNameOfProfileAtIndex(i), username_utf16)) { | 1076 cache.GetUserNameOfProfileAtIndex(i), username_utf16)) { |
1038 *error_message = l10n_util::GetStringUTF16( | 1077 *error_message = l10n_util::GetStringUTF16( |
1039 IDS_SYNC_USER_NAME_IN_USE_ERROR); | 1078 IDS_SYNC_USER_NAME_IN_USE_ERROR); |
1040 return false; | 1079 return false; |
1041 } | 1080 } |
1042 } | 1081 } |
1043 | 1082 |
1044 return true; | 1083 return true; |
1045 } | 1084 } |
OLD | NEW |