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 227 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
524 if (!error_message.empty()) | 526 if (!error_message.empty()) |
525 args.SetString("errorMessage", error_message); | 527 args.SetString("errorMessage", error_message); |
526 if (fatal_error) | 528 if (fatal_error) |
527 args.SetBoolean("fatalError", true); | 529 args.SetBoolean("fatalError", true); |
528 args.SetString("captchaUrl", captcha); | 530 args.SetString("captchaUrl", captcha); |
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). |
kochi
2012/06/13 09:08:29
Timeout is handled, but still need to handle other
| |
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 login_timer_.reset(new base::OneShotTimer<SyncSetupHandler>()); | |
544 login_timer_->Start(FROM_HERE, base::TimeDelta::FromSeconds(kTimeoutSec), | |
545 this, &SyncSetupHandler::DisplayTimeOut); | |
539 web_ui()->CallJavascriptFunction( | 546 web_ui()->CallJavascriptFunction( |
540 "SyncSetupOverlay.showSyncSetupPage", page, args); | 547 "SyncSetupOverlay.showSyncSetupPage", page, args); |
541 } | 548 } |
549 | |
550 void SyncSetupHandler::DisplayTimeOut() { | |
551 configuring_sync_ = false; | |
kochi
2012/06/13 09:08:29
Timeout is handled, but still need to handle other
peria
2012/06/14 01:55:12
Done.
| |
552 StringValue page("timeout"); | |
553 DictionaryValue args; | |
554 | |
555 web_ui()->CallJavascriptFunction( | |
556 "SyncSetupOverlay.showSyncSetupPage", page, args); | |
557 } | |
542 | 558 |
543 void SyncSetupHandler::RecordSignin() { | 559 void SyncSetupHandler::RecordSignin() { |
544 // By default, do nothing - subclasses can override. | 560 // By default, do nothing - subclasses can override. |
545 } | 561 } |
546 | 562 |
547 void SyncSetupHandler::DisplayGaiaSuccessAndClose() { | 563 void SyncSetupHandler::DisplayGaiaSuccessAndClose() { |
548 RecordSignin(); | 564 RecordSignin(); |
549 web_ui()->CallJavascriptFunction("SyncSetupOverlay.showSuccessAndClose"); | 565 web_ui()->CallJavascriptFunction("SyncSetupOverlay.showSuccessAndClose"); |
550 } | 566 } |
551 | 567 |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
655 } | 671 } |
656 | 672 |
657 void SyncSetupHandler::GaiaCredentialsValid() { | 673 void SyncSetupHandler::GaiaCredentialsValid() { |
658 DCHECK(IsActiveLogin()); | 674 DCHECK(IsActiveLogin()); |
659 | 675 |
660 // Gaia credentials are valid - update the UI. | 676 // Gaia credentials are valid - update the UI. |
661 DisplayGaiaSuccessAndSettingUp(); | 677 DisplayGaiaSuccessAndSettingUp(); |
662 } | 678 } |
663 | 679 |
664 void SyncSetupHandler::SigninFailed(const GoogleServiceAuthError& error) { | 680 void SyncSetupHandler::SigninFailed(const GoogleServiceAuthError& error) { |
681 // Stop a timer to handle timeout in waiting for checking network connection. | |
682 if (login_timer_.get()) | |
683 login_timer_.reset(); | |
684 | |
665 last_signin_error_ = error; | 685 last_signin_error_ = error; |
666 // Got a failed signin - this is either just a typical auth error, or a | 686 // 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). | 687 // 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 | 688 // On ChromeOS, this condition should trigger the orange badge on wrench menu |
669 // and prompt to sign out. | 689 // and prompt to sign out. |
670 #if !defined(OS_CHROMEOS) | 690 #if !defined(OS_CHROMEOS) |
671 DisplayGaiaLogin(GetSyncService()->unrecoverable_error_detected()); | 691 DisplayGaiaLogin(GetSyncService()->unrecoverable_error_detected()); |
672 #else | 692 #else |
673 CloseOverlay(); | 693 CloseOverlay(); |
674 #endif | 694 #endif |
675 } | 695 } |
676 | 696 |
677 Profile* SyncSetupHandler::GetProfile() const { | 697 Profile* SyncSetupHandler::GetProfile() const { |
678 return Profile::FromWebUI(web_ui()); | 698 return Profile::FromWebUI(web_ui()); |
679 } | 699 } |
680 | 700 |
681 ProfileSyncService* SyncSetupHandler::GetSyncService() const { | 701 ProfileSyncService* SyncSetupHandler::GetSyncService() const { |
682 return ProfileSyncServiceFactory::GetForProfile(GetProfile()); | 702 return ProfileSyncServiceFactory::GetForProfile(GetProfile()); |
683 } | 703 } |
684 | 704 |
685 void SyncSetupHandler::SigninSuccess() { | 705 void SyncSetupHandler::SigninSuccess() { |
686 DCHECK(GetSyncService()->sync_initialized()); | 706 DCHECK(GetSyncService()->sync_initialized()); |
707 // Stop a timer to handle timeout in waiting for checking network connection. | |
708 if (login_timer_.get()) | |
709 login_timer_.reset(); | |
710 | |
687 // If we have signed in while sync is already setup, it must be due to some | 711 // 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 | 712 // kind of re-authentication flow. In that case, just close the signin dialog |
689 // rather than forcing the user to go through sync configuration. | 713 // rather than forcing the user to go through sync configuration. |
690 if (GetSyncService()->HasSyncSetupCompleted()) | 714 if (GetSyncService()->HasSyncSetupCompleted()) |
691 DisplayGaiaSuccessAndClose(); | 715 DisplayGaiaSuccessAndClose(); |
692 else | 716 else |
693 DisplayConfigureSync(false, false); | 717 DisplayConfigureSync(false, false); |
694 } | 718 } |
695 | 719 |
696 void SyncSetupHandler::HandleConfigure(const ListValue* args) { | 720 void SyncSetupHandler::HandleConfigure(const ListValue* args) { |
(...skipping 324 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1021 if (i != current_profile_index && AreUserNamesEqual( | 1045 if (i != current_profile_index && AreUserNamesEqual( |
1022 cache.GetUserNameOfProfileAtIndex(i), username_utf16)) { | 1046 cache.GetUserNameOfProfileAtIndex(i), username_utf16)) { |
1023 *error_message = l10n_util::GetStringUTF16( | 1047 *error_message = l10n_util::GetStringUTF16( |
1024 IDS_SYNC_USER_NAME_IN_USE_ERROR); | 1048 IDS_SYNC_USER_NAME_IN_USE_ERROR); |
1025 return false; | 1049 return false; |
1026 } | 1050 } |
1027 } | 1051 } |
1028 | 1052 |
1029 return true; | 1053 return true; |
1030 } | 1054 } |
OLD | NEW |