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 266 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
277 localized_strings->SetString("createAccountLinkHTML", | 277 localized_strings->SetString("createAccountLinkHTML", |
278 GetStringFUTF16(IDS_SYNC_CREATE_ACCOUNT_PREFIX, create_account)); | 278 GetStringFUTF16(IDS_SYNC_CREATE_ACCOUNT_PREFIX, create_account)); |
279 | 279 |
280 string16 sync_benefits_url( | 280 string16 sync_benefits_url( |
281 UTF8ToUTF16(google_util::StringAppendGoogleLocaleParam( | 281 UTF8ToUTF16(google_util::StringAppendGoogleLocaleParam( |
282 chrome::kSyncLearnMoreURL))); | 282 chrome::kSyncLearnMoreURL))); |
283 localized_strings->SetString("promoLearnMoreURL", sync_benefits_url); | 283 localized_strings->SetString("promoLearnMoreURL", sync_benefits_url); |
284 | 284 |
285 static OptionsStringResource resources[] = { | 285 static OptionsStringResource resources[] = { |
286 { "syncSetupConfigureTitle", IDS_SYNC_SETUP_CONFIGURE_TITLE }, | 286 { "syncSetupConfigureTitle", IDS_SYNC_SETUP_CONFIGURE_TITLE }, |
287 { "syncSetupTimeoutTitle", IDS_SYNC_SETUP_TIME_OUT_TITLE }, | |
288 { "syncSetupTimeoutContent", IDS_SYNC_SETUP_TIME_OUT_CONTENT }, | |
287 { "cannotBeBlank", IDS_SYNC_CANNOT_BE_BLANK }, | 289 { "cannotBeBlank", IDS_SYNC_CANNOT_BE_BLANK }, |
288 { "emailLabel", IDS_SYNC_LOGIN_EMAIL_NEW_LINE }, | 290 { "emailLabel", IDS_SYNC_LOGIN_EMAIL_NEW_LINE }, |
289 { "passwordLabel", IDS_SYNC_LOGIN_PASSWORD_NEW_LINE }, | 291 { "passwordLabel", IDS_SYNC_LOGIN_PASSWORD_NEW_LINE }, |
290 { "invalidCredentials", IDS_SYNC_INVALID_USER_CREDENTIALS }, | 292 { "invalidCredentials", IDS_SYNC_INVALID_USER_CREDENTIALS }, |
291 { "signin", IDS_SYNC_SIGNIN }, | 293 { "signin", IDS_SYNC_SIGNIN }, |
292 { "couldNotConnect", IDS_SYNC_LOGIN_COULD_NOT_CONNECT }, | 294 { "couldNotConnect", IDS_SYNC_LOGIN_COULD_NOT_CONNECT }, |
293 { "unrecoverableError", IDS_SYNC_UNRECOVERABLE_ERROR }, | 295 { "unrecoverableError", IDS_SYNC_UNRECOVERABLE_ERROR }, |
294 { "errorLearnMore", IDS_LEARN_MORE }, | 296 { "errorLearnMore", IDS_LEARN_MORE }, |
295 { "unrecoverableErrorHelpURL", IDS_SYNC_UNRECOVERABLE_ERROR_HELP_URL }, | 297 { "unrecoverableErrorHelpURL", IDS_SYNC_UNRECOVERABLE_ERROR_HELP_URL }, |
296 { "cannotAccessAccount", IDS_SYNC_CANNOT_ACCESS_ACCOUNT }, | 298 { "cannotAccessAccount", IDS_SYNC_CANNOT_ACCESS_ACCOUNT }, |
(...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
529 StringValue page("login"); | 531 StringValue page("login"); |
530 web_ui()->CallJavascriptFunction( | 532 web_ui()->CallJavascriptFunction( |
531 "SyncSetupOverlay.showSyncSetupPage", page, args); | 533 "SyncSetupOverlay.showSyncSetupPage", page, args); |
532 } | 534 } |
533 | 535 |
534 // TODO(kochi): Handle error conditions (timeout, other failures). | 536 // TODO(kochi): Handle error conditions (timeout, other failures). |
535 void SyncSetupHandler::DisplaySpinner() { | 537 void SyncSetupHandler::DisplaySpinner() { |
536 configuring_sync_ = true; | 538 configuring_sync_ = true; |
537 StringValue page("spinner"); | 539 StringValue page("spinner"); |
538 DictionaryValue args; | 540 DictionaryValue args; |
541 | |
542 const int kTimeoutSec = 30; | |
543 backend_start_timer_.reset(new base::OneShotTimer<SyncSetupHandler>()); | |
544 backend_start_timer_->Start(FROM_HERE, | |
545 base::TimeDelta::FromSeconds(kTimeoutSec), | |
546 this, &SyncSetupHandler::DisplayTimeout); | |
547 web_ui()->CallJavascriptFunction( | |
548 "SyncSetupOverlay.showSyncSetupPage", page, args); | |
549 } | |
550 | |
551 // TODO(kochi): Handle error conditions other than timeout. | |
552 // http://crbug.com/128692 | |
553 void SyncSetupHandler::DisplayTimeout() { | |
554 configuring_sync_ = false; | |
Andrew T Wilson (Slow)
2012/06/20 05:23:42
I think CloseSyncSetup() clears the configuring_sy
peria
2012/06/20 09:20:17
Done.
| |
555 // Stop setting up sync service | |
556 CloseSyncSetup(); | |
557 | |
558 StringValue page("timeout"); | |
559 DictionaryValue args; | |
539 web_ui()->CallJavascriptFunction( | 560 web_ui()->CallJavascriptFunction( |
540 "SyncSetupOverlay.showSyncSetupPage", page, args); | 561 "SyncSetupOverlay.showSyncSetupPage", page, args); |
541 } | 562 } |
542 | 563 |
543 void SyncSetupHandler::RecordSignin() { | 564 void SyncSetupHandler::RecordSignin() { |
544 // By default, do nothing - subclasses can override. | 565 // By default, do nothing - subclasses can override. |
545 } | 566 } |
546 | 567 |
547 void SyncSetupHandler::DisplayGaiaSuccessAndClose() { | 568 void SyncSetupHandler::DisplayGaiaSuccessAndClose() { |
548 RecordSignin(); | 569 RecordSignin(); |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
655 } | 676 } |
656 | 677 |
657 void SyncSetupHandler::GaiaCredentialsValid() { | 678 void SyncSetupHandler::GaiaCredentialsValid() { |
658 DCHECK(IsActiveLogin()); | 679 DCHECK(IsActiveLogin()); |
659 | 680 |
660 // Gaia credentials are valid - update the UI. | 681 // Gaia credentials are valid - update the UI. |
661 DisplayGaiaSuccessAndSettingUp(); | 682 DisplayGaiaSuccessAndSettingUp(); |
662 } | 683 } |
663 | 684 |
664 void SyncSetupHandler::SigninFailed(const GoogleServiceAuthError& error) { | 685 void SyncSetupHandler::SigninFailed(const GoogleServiceAuthError& error) { |
686 // Stop a timer to handle timeout in waiting for checking network connection. | |
687 backend_start_timer_.reset(); | |
688 | |
665 last_signin_error_ = error; | 689 last_signin_error_ = error; |
666 // Got a failed signin - this is either just a typical auth error, or a | 690 // Got a failed signin - this is either just a typical auth error, or a |
667 // sync error (treat sync errors as "fatal errors" - i.e. non-auth errors). | 691 // sync error (treat sync errors as "fatal errors" - i.e. non-auth errors). |
668 // On ChromeOS, this condition should trigger the orange badge on wrench menu | 692 // On ChromeOS, this condition should trigger the orange badge on wrench menu |
669 // and prompt to sign out. | 693 // and prompt to sign out. |
670 #if !defined(OS_CHROMEOS) | 694 #if !defined(OS_CHROMEOS) |
671 DisplayGaiaLogin(GetSyncService()->unrecoverable_error_detected()); | 695 DisplayGaiaLogin(GetSyncService()->unrecoverable_error_detected()); |
672 #else | 696 #else |
673 CloseOverlay(); | 697 CloseOverlay(); |
674 #endif | 698 #endif |
675 } | 699 } |
676 | 700 |
677 Profile* SyncSetupHandler::GetProfile() const { | 701 Profile* SyncSetupHandler::GetProfile() const { |
678 return Profile::FromWebUI(web_ui()); | 702 return Profile::FromWebUI(web_ui()); |
679 } | 703 } |
680 | 704 |
681 ProfileSyncService* SyncSetupHandler::GetSyncService() const { | 705 ProfileSyncService* SyncSetupHandler::GetSyncService() const { |
682 return ProfileSyncServiceFactory::GetForProfile(GetProfile()); | 706 return ProfileSyncServiceFactory::GetForProfile(GetProfile()); |
683 } | 707 } |
684 | 708 |
685 void SyncSetupHandler::SigninSuccess() { | 709 void SyncSetupHandler::SigninSuccess() { |
686 DCHECK(GetSyncService()->sync_initialized()); | 710 DCHECK(GetSyncService()->sync_initialized()); |
711 // Stop a timer to handle timeout in waiting for checking network connection. | |
712 backend_start_timer_.reset(); | |
713 | |
687 // If we have signed in while sync is already setup, it must be due to some | 714 // If we have signed in while sync is already setup, it must be due to some |
688 // kind of re-authentication flow. In that case, just close the signin dialog | 715 // kind of re-authentication flow. In that case, just close the signin dialog |
689 // rather than forcing the user to go through sync configuration. | 716 // rather than forcing the user to go through sync configuration. |
690 if (GetSyncService()->HasSyncSetupCompleted()) | 717 if (GetSyncService()->HasSyncSetupCompleted()) |
691 DisplayGaiaSuccessAndClose(); | 718 DisplayGaiaSuccessAndClose(); |
692 else | 719 else |
693 DisplayConfigureSync(false, false); | 720 DisplayConfigureSync(false, false); |
694 } | 721 } |
695 | 722 |
696 void SyncSetupHandler::HandleConfigure(const ListValue* args) { | 723 void SyncSetupHandler::HandleConfigure(const ListValue* args) { |
(...skipping 285 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
982 return false; | 1009 return false; |
983 service->current_login_ui()->FocusUI(); | 1010 service->current_login_ui()->FocusUI(); |
984 return true; | 1011 return true; |
985 } | 1012 } |
986 | 1013 |
987 LoginUIService* SyncSetupHandler::GetLoginUIService() const { | 1014 LoginUIService* SyncSetupHandler::GetLoginUIService() const { |
988 return LoginUIServiceFactory::GetForProfile(GetProfile()); | 1015 return LoginUIServiceFactory::GetForProfile(GetProfile()); |
989 } | 1016 } |
990 | 1017 |
991 void SyncSetupHandler::CloseOverlay() { | 1018 void SyncSetupHandler::CloseOverlay() { |
1019 // Stop a timer to handle timeout in waiting for sync setup. | |
1020 backend_start_timer_.reset(); | |
1021 | |
992 CloseSyncSetup(); | 1022 CloseSyncSetup(); |
993 web_ui()->CallJavascriptFunction("OptionsPage.closeOverlay"); | 1023 web_ui()->CallJavascriptFunction("OptionsPage.closeOverlay"); |
994 } | 1024 } |
995 | 1025 |
996 bool SyncSetupHandler::IsLoginAuthDataValid(const std::string& username, | 1026 bool SyncSetupHandler::IsLoginAuthDataValid(const std::string& username, |
997 string16* error_message) { | 1027 string16* error_message) { |
998 if (username.empty()) | 1028 if (username.empty()) |
999 return true; | 1029 return true; |
1000 | 1030 |
1001 // Can be null during some unit tests. | 1031 // Can be null during some unit tests. |
(...skipping 19 matching lines...) Expand all Loading... | |
1021 if (i != current_profile_index && AreUserNamesEqual( | 1051 if (i != current_profile_index && AreUserNamesEqual( |
1022 cache.GetUserNameOfProfileAtIndex(i), username_utf16)) { | 1052 cache.GetUserNameOfProfileAtIndex(i), username_utf16)) { |
1023 *error_message = l10n_util::GetStringUTF16( | 1053 *error_message = l10n_util::GetStringUTF16( |
1024 IDS_SYNC_USER_NAME_IN_USE_ERROR); | 1054 IDS_SYNC_USER_NAME_IN_USE_ERROR); |
1025 return false; | 1055 return false; |
1026 } | 1056 } |
1027 } | 1057 } |
1028 | 1058 |
1029 return true; | 1059 return true; |
1030 } | 1060 } |
OLD | NEW |