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/bind.h" | 7 #include "base/bind.h" |
8 #include "base/basictypes.h" | 8 #include "base/basictypes.h" |
9 #include "base/bind_helpers.h" | 9 #include "base/bind_helpers.h" |
10 #include "base/compiler_specific.h" | 10 #include "base/compiler_specific.h" |
(...skipping 472 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
483 if (!error_message.empty()) | 483 if (!error_message.empty()) |
484 args.SetString("error_message", error_message); | 484 args.SetString("error_message", error_message); |
485 if (fatal_error) | 485 if (fatal_error) |
486 args.SetBoolean("fatalError", true); | 486 args.SetBoolean("fatalError", true); |
487 args.SetString("captchaUrl", captcha); | 487 args.SetString("captchaUrl", captcha); |
488 StringValue page("login"); | 488 StringValue page("login"); |
489 web_ui()->CallJavascriptFunction( | 489 web_ui()->CallJavascriptFunction( |
490 "SyncSetupOverlay.showSyncSetupPage", page, args); | 490 "SyncSetupOverlay.showSyncSetupPage", page, args); |
491 } | 491 } |
492 | 492 |
493 // TODO(kochi): Handle error conditions (timeout, other failures). | |
494 void SyncSetupHandler::DisplaySpinner() { | |
495 configuring_sync_ = true; | |
496 StringValue page("spinner"); | |
497 DictionaryValue args; | |
498 web_ui()->CallJavascriptFunction( | |
499 "SyncSetupOverlay.showSyncSetupPage", page, args); | |
500 } | |
501 | |
493 void SyncSetupHandler::RecordSignin() { | 502 void SyncSetupHandler::RecordSignin() { |
494 // By default, do nothing - subclasses can override. | 503 // By default, do nothing - subclasses can override. |
495 } | 504 } |
496 | 505 |
497 void SyncSetupHandler::DisplayGaiaSuccessAndClose() { | 506 void SyncSetupHandler::DisplayGaiaSuccessAndClose() { |
498 RecordSignin(); | 507 RecordSignin(); |
499 web_ui()->CallJavascriptFunction("SyncSetupOverlay.showSuccessAndClose"); | 508 web_ui()->CallJavascriptFunction("SyncSetupOverlay.showSuccessAndClose"); |
500 } | 509 } |
501 | 510 |
502 void SyncSetupHandler::DisplayGaiaSuccessAndSettingUp() { | 511 void SyncSetupHandler::DisplayGaiaSuccessAndSettingUp() { |
503 RecordSignin(); | 512 RecordSignin(); |
504 web_ui()->CallJavascriptFunction("SyncSetupOverlay.showSuccessAndSettingUp"); | 513 web_ui()->CallJavascriptFunction("SyncSetupOverlay.showSuccessAndSettingUp"); |
505 } | 514 } |
506 | 515 |
507 void SyncSetupHandler::ShowFatalError() { | 516 void SyncSetupHandler::ShowFatalError() { |
508 // For now, just send the user back to the login page. Ultimately may want | 517 // For now, just send the user back to the login page. Ultimately may want |
509 // to give different feedback (especially for chromeos). | 518 // to give different feedback (especially for chromeos). |
519 #if !defined(OS_CHROMEOS) | |
510 DisplayGaiaLogin(true); | 520 DisplayGaiaLogin(true); |
521 #endif | |
511 } | 522 } |
512 | 523 |
513 void SyncSetupHandler::OnDidClosePage(const ListValue* args) { | 524 void SyncSetupHandler::OnDidClosePage(const ListValue* args) { |
514 CloseSyncSetup(); | 525 CloseSyncSetup(); |
515 } | 526 } |
516 | 527 |
517 void SyncSetupHandler::HandleSubmitAuth(const ListValue* args) { | 528 void SyncSetupHandler::HandleSubmitAuth(const ListValue* args) { |
518 std::string json; | 529 std::string json; |
519 if (!args->GetString(0, &json)) { | 530 if (!args->GetString(0, &json)) { |
520 NOTREACHED() << "Could not read JSON argument"; | 531 NOTREACHED() << "Could not read JSON argument"; |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
579 DCHECK(IsActiveLogin()); | 590 DCHECK(IsActiveLogin()); |
580 | 591 |
581 // Gaia credentials are valid - update the UI. | 592 // Gaia credentials are valid - update the UI. |
582 DisplayGaiaSuccessAndSettingUp(); | 593 DisplayGaiaSuccessAndSettingUp(); |
583 } | 594 } |
584 | 595 |
585 void SyncSetupHandler::SigninFailed(const GoogleServiceAuthError& error) { | 596 void SyncSetupHandler::SigninFailed(const GoogleServiceAuthError& error) { |
586 last_signin_error_ = error; | 597 last_signin_error_ = error; |
587 // Got a failed signin - this is either just a typical auth error, or a | 598 // Got a failed signin - this is either just a typical auth error, or a |
588 // sync error (treat sync errors as "fatal errors" - i.e. non-auth errors). | 599 // sync error (treat sync errors as "fatal errors" - i.e. non-auth errors). |
600 // On ChromeOS, this condition should trigger the orange badge on wrench menu | |
601 // and prompt to sign out. | |
602 #if !defined(OS_CHROMEOS) | |
589 DisplayGaiaLogin(GetSyncService()->unrecoverable_error_detected()); | 603 DisplayGaiaLogin(GetSyncService()->unrecoverable_error_detected()); |
604 #else | |
605 CloseOverlay(); | |
606 #endif | |
590 } | 607 } |
591 | 608 |
592 Profile* SyncSetupHandler::GetProfile() const { | 609 Profile* SyncSetupHandler::GetProfile() const { |
593 return Profile::FromWebUI(web_ui()); | 610 return Profile::FromWebUI(web_ui()); |
594 } | 611 } |
595 | 612 |
596 ProfileSyncService* SyncSetupHandler::GetSyncService() const { | 613 ProfileSyncService* SyncSetupHandler::GetSyncService() const { |
597 return ProfileSyncServiceFactory::GetForProfile(GetProfile()); | 614 return ProfileSyncServiceFactory::GetForProfile(GetProfile()); |
598 } | 615 } |
599 | 616 |
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
749 } | 766 } |
750 | 767 |
751 // Let the various services know that we're no longer active. | 768 // Let the various services know that we're no longer active. |
752 GetLoginUIService()->LoginUIClosed(web_ui()); | 769 GetLoginUIService()->LoginUIClosed(web_ui()); |
753 if (sync_service) | 770 if (sync_service) |
754 sync_service->set_setup_in_progress(false); | 771 sync_service->set_setup_in_progress(false); |
755 | 772 |
756 // Make sure user isn't left half-logged-in (signed in, but without sync | 773 // Make sure user isn't left half-logged-in (signed in, but without sync |
757 // started up). If the user hasn't finished setting up sync, then sign out | 774 // started up). If the user hasn't finished setting up sync, then sign out |
758 // and shut down sync. | 775 // and shut down sync. |
759 | |
760 if (sync_service && !sync_service->HasSyncSetupCompleted()) { | 776 if (sync_service && !sync_service->HasSyncSetupCompleted()) { |
761 DVLOG(1) << "Signin aborted by user action"; | 777 DVLOG(1) << "Signin aborted by user action"; |
762 sync_service->DisableForUser(); | 778 sync_service->DisableForUser(); |
779 #if !defined(OS_CHROMEOS) | |
763 GetSignin()->SignOut(); | 780 GetSignin()->SignOut(); |
781 #endif | |
764 } | 782 } |
765 } | 783 } |
766 | 784 |
767 configuring_sync_ = false; | 785 configuring_sync_ = false; |
768 signin_tracker_.reset(); | 786 signin_tracker_.reset(); |
769 } | 787 } |
770 | 788 |
771 void SyncSetupHandler::OpenSyncSetup(bool force_login) { | 789 void SyncSetupHandler::OpenSyncSetup(bool force_login) { |
772 ProfileSyncService* service = GetSyncService(); | 790 ProfileSyncService* service = GetSyncService(); |
773 if (!service) { | 791 if (!service) { |
(...skipping 14 matching lines...) Expand all Loading... | |
788 | 806 |
789 // Notify services that we are now active. | 807 // Notify services that we are now active. |
790 GetLoginUIService()->SetLoginUI(web_ui()); | 808 GetLoginUIService()->SetLoginUI(web_ui()); |
791 service->set_setup_in_progress(true); | 809 service->set_setup_in_progress(true); |
792 | 810 |
793 if (!force_login && service->HasSyncSetupCompleted()) { | 811 if (!force_login && service->HasSyncSetupCompleted()) { |
794 // User is already logged in. They must have brought up the config wizard | 812 // User is already logged in. They must have brought up the config wizard |
795 // via the "Advanced..." button or the wrench menu. | 813 // via the "Advanced..." button or the wrench menu. |
796 DisplayConfigureSync(true, false); | 814 DisplayConfigureSync(true, false); |
797 } else { | 815 } else { |
816 #if !defined(OS_CHROMEOS) | |
798 // User is not logged in - need to display login UI. | 817 // User is not logged in - need to display login UI. |
799 DisplayGaiaLogin(false); | 818 DisplayGaiaLogin(false); |
819 #else | |
820 PrepareConfigDialog(); | |
821 #endif | |
800 } | 822 } |
801 | 823 |
802 ShowSetupUI(); | 824 ShowSetupUI(); |
803 } | 825 } |
804 | 826 |
827 void SyncSetupHandler::PrepareConfigDialog() { | |
828 // On Chrome OS user is always logged in. Instead of showing login dialog, | |
829 // show spinner until the backend gets ready to configure sync. | |
830 ProfileSyncService* service = GetSyncService(); | |
831 if (!service->sync_initialized()) { | |
832 // To listen to the token available notifications, start SigninTracker. | |
833 signin_tracker_.reset( | |
834 new SigninTracker(GetProfile(), this, | |
835 SigninTracker::SERVICES_INITIALIZING)); | |
836 service->set_setup_in_progress(true); | |
837 service->UnsuppressAndStart(); | |
Andrew T Wilson (Slow)
2012/04/04 16:52:11
So, if the user cancels out of the spinner, they'l
kochi
2012/04/04 17:29:46
Let's suppress in PSS::DisableForUser() as discuss
| |
838 DisplaySpinner(); | |
839 } else { | |
840 DisplayConfigureSync(true, false); | |
841 } | |
842 } | |
843 | |
805 // Private member functions. | 844 // Private member functions. |
806 | 845 |
807 bool SyncSetupHandler::FocusExistingWizardIfPresent() { | 846 bool SyncSetupHandler::FocusExistingWizardIfPresent() { |
808 LoginUIService* service = GetLoginUIService(); | 847 LoginUIService* service = GetLoginUIService(); |
809 if (!service->current_login_ui()) | 848 if (!service->current_login_ui()) |
810 return false; | 849 return false; |
811 service->FocusLoginUI(); | 850 service->FocusLoginUI(); |
812 return true; | 851 return true; |
813 } | 852 } |
814 | 853 |
(...skipping 25 matching lines...) Expand all Loading... | |
840 if (i != current_profile_index && AreUserNamesEqual( | 879 if (i != current_profile_index && AreUserNamesEqual( |
841 cache.GetUserNameOfProfileAtIndex(i), username_utf16)) { | 880 cache.GetUserNameOfProfileAtIndex(i), username_utf16)) { |
842 *error_message = l10n_util::GetStringUTF16( | 881 *error_message = l10n_util::GetStringUTF16( |
843 IDS_SYNC_USER_NAME_IN_USE_ERROR); | 882 IDS_SYNC_USER_NAME_IN_USE_ERROR); |
844 return false; | 883 return false; |
845 } | 884 } |
846 } | 885 } |
847 | 886 |
848 return true; | 887 return true; |
849 } | 888 } |
OLD | NEW |