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