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 474 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
485 if (!error_message.empty()) | 485 if (!error_message.empty()) |
486 args.SetString("error_message", error_message); | 486 args.SetString("error_message", error_message); |
487 if (fatal_error) | 487 if (fatal_error) |
488 args.SetBoolean("fatalError", true); | 488 args.SetBoolean("fatalError", true); |
489 args.SetString("captchaUrl", captcha); | 489 args.SetString("captchaUrl", captcha); |
490 StringValue page("login"); | 490 StringValue page("login"); |
491 web_ui()->CallJavascriptFunction( | 491 web_ui()->CallJavascriptFunction( |
492 "SyncSetupOverlay.showSyncSetupPage", page, args); | 492 "SyncSetupOverlay.showSyncSetupPage", page, args); |
493 } | 493 } |
494 | 494 |
| 495 // TODO(kochi): Handle error conditions (timeout, other failures). |
| 496 void SyncSetupHandler::DisplaySpinner() { |
| 497 configuring_sync_ = true; |
| 498 StringValue page("spinner"); |
| 499 DictionaryValue args; |
| 500 web_ui()->CallJavascriptFunction( |
| 501 "SyncSetupOverlay.showSyncSetupPage", page, args); |
| 502 } |
| 503 |
495 void SyncSetupHandler::RecordSignin() { | 504 void SyncSetupHandler::RecordSignin() { |
496 // By default, do nothing - subclasses can override. | 505 // By default, do nothing - subclasses can override. |
497 } | 506 } |
498 | 507 |
499 void SyncSetupHandler::DisplayGaiaSuccessAndClose() { | 508 void SyncSetupHandler::DisplayGaiaSuccessAndClose() { |
500 RecordSignin(); | 509 RecordSignin(); |
501 web_ui()->CallJavascriptFunction("SyncSetupOverlay.showSuccessAndClose"); | 510 web_ui()->CallJavascriptFunction("SyncSetupOverlay.showSuccessAndClose"); |
502 } | 511 } |
503 | 512 |
504 void SyncSetupHandler::DisplayGaiaSuccessAndSettingUp() { | 513 void SyncSetupHandler::DisplayGaiaSuccessAndSettingUp() { |
505 RecordSignin(); | 514 RecordSignin(); |
506 web_ui()->CallJavascriptFunction("SyncSetupOverlay.showSuccessAndSettingUp"); | 515 web_ui()->CallJavascriptFunction("SyncSetupOverlay.showSuccessAndSettingUp"); |
507 } | 516 } |
508 | 517 |
509 void SyncSetupHandler::ShowFatalError() { | 518 void SyncSetupHandler::ShowFatalError() { |
510 // For now, just send the user back to the login page. Ultimately may want | 519 // For now, just send the user back to the login page. Ultimately may want |
511 // to give different feedback (especially for chromeos). | 520 // to give different feedback (especially for chromeos). |
| 521 #if !defined(OS_CHROMEOS) |
512 DisplayGaiaLogin(true); | 522 DisplayGaiaLogin(true); |
| 523 #endif |
513 } | 524 } |
514 | 525 |
515 void SyncSetupHandler::OnDidClosePage(const ListValue* args) { | 526 void SyncSetupHandler::OnDidClosePage(const ListValue* args) { |
516 CloseSyncSetup(); | 527 CloseSyncSetup(); |
517 } | 528 } |
518 | 529 |
519 void SyncSetupHandler::HandleSubmitAuth(const ListValue* args) { | 530 void SyncSetupHandler::HandleSubmitAuth(const ListValue* args) { |
520 std::string json; | 531 std::string json; |
521 if (!args->GetString(0, &json)) { | 532 if (!args->GetString(0, &json)) { |
522 NOTREACHED() << "Could not read JSON argument"; | 533 NOTREACHED() << "Could not read JSON argument"; |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
581 DCHECK(IsActiveLogin()); | 592 DCHECK(IsActiveLogin()); |
582 | 593 |
583 // Gaia credentials are valid - update the UI. | 594 // Gaia credentials are valid - update the UI. |
584 DisplayGaiaSuccessAndSettingUp(); | 595 DisplayGaiaSuccessAndSettingUp(); |
585 } | 596 } |
586 | 597 |
587 void SyncSetupHandler::SigninFailed(const GoogleServiceAuthError& error) { | 598 void SyncSetupHandler::SigninFailed(const GoogleServiceAuthError& error) { |
588 last_signin_error_ = error; | 599 last_signin_error_ = error; |
589 // Got a failed signin - this is either just a typical auth error, or a | 600 // Got a failed signin - this is either just a typical auth error, or a |
590 // sync error (treat sync errors as "fatal errors" - i.e. non-auth errors). | 601 // sync error (treat sync errors as "fatal errors" - i.e. non-auth errors). |
| 602 // On ChromeOS, this condition should trigger the orange badge on wrench menu |
| 603 // and prompt to sign out. |
| 604 #if !defined(OS_CHROMEOS) |
591 DisplayGaiaLogin(GetSyncService()->unrecoverable_error_detected()); | 605 DisplayGaiaLogin(GetSyncService()->unrecoverable_error_detected()); |
| 606 #else |
| 607 CloseOverlay(); |
| 608 #endif |
592 } | 609 } |
593 | 610 |
594 Profile* SyncSetupHandler::GetProfile() const { | 611 Profile* SyncSetupHandler::GetProfile() const { |
595 return Profile::FromWebUI(web_ui()); | 612 return Profile::FromWebUI(web_ui()); |
596 } | 613 } |
597 | 614 |
598 ProfileSyncService* SyncSetupHandler::GetSyncService() const { | 615 ProfileSyncService* SyncSetupHandler::GetSyncService() const { |
599 return ProfileSyncServiceFactory::GetForProfile(GetProfile()); | 616 return ProfileSyncServiceFactory::GetForProfile(GetProfile()); |
600 } | 617 } |
601 | 618 |
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
751 } | 768 } |
752 | 769 |
753 // Let the various services know that we're no longer active. | 770 // Let the various services know that we're no longer active. |
754 GetLoginUIService()->LoginUIClosed(web_ui()); | 771 GetLoginUIService()->LoginUIClosed(web_ui()); |
755 if (sync_service) | 772 if (sync_service) |
756 sync_service->set_setup_in_progress(false); | 773 sync_service->set_setup_in_progress(false); |
757 | 774 |
758 // Make sure user isn't left half-logged-in (signed in, but without sync | 775 // Make sure user isn't left half-logged-in (signed in, but without sync |
759 // started up). If the user hasn't finished setting up sync, then sign out | 776 // started up). If the user hasn't finished setting up sync, then sign out |
760 // and shut down sync. | 777 // and shut down sync. |
761 | |
762 if (sync_service && !sync_service->HasSyncSetupCompleted()) { | 778 if (sync_service && !sync_service->HasSyncSetupCompleted()) { |
763 DVLOG(1) << "Signin aborted by user action"; | 779 DVLOG(1) << "Signin aborted by user action"; |
764 sync_service->DisableForUser(); | 780 sync_service->DisableForUser(); |
| 781 #if !defined(OS_CHROMEOS) |
765 GetSignin()->SignOut(); | 782 GetSignin()->SignOut(); |
| 783 #else |
| 784 // TODO(atwilson): Move this suppression to PSS::DisableForUser() |
| 785 browser_sync::SyncPrefs sync_prefs(GetProfile()->GetPrefs()); |
| 786 sync_prefs.SetStartSuppressed(true); |
| 787 #endif |
766 } | 788 } |
767 } | 789 } |
768 | 790 |
769 configuring_sync_ = false; | 791 configuring_sync_ = false; |
770 signin_tracker_.reset(); | 792 signin_tracker_.reset(); |
771 } | 793 } |
772 | 794 |
773 void SyncSetupHandler::OpenSyncSetup(bool force_login) { | 795 void SyncSetupHandler::OpenSyncSetup(bool force_login) { |
774 ProfileSyncService* service = GetSyncService(); | 796 ProfileSyncService* service = GetSyncService(); |
775 if (!service) { | 797 if (!service) { |
(...skipping 22 matching lines...) Expand all Loading... |
798 // return false). | 820 // return false). |
799 // 3) Previously working credentials have expired | 821 // 3) Previously working credentials have expired |
800 // (service->GetAuthError() != NONE). | 822 // (service->GetAuthError() != NONE). |
801 // 4) User is already signed in, but App Notifications needs to force another | 823 // 4) User is already signed in, but App Notifications needs to force another |
802 // login so it can fetch an oauth token (passes force_login=true) | 824 // login so it can fetch an oauth token (passes force_login=true) |
803 // 5) User clicks [Advanced Settings] button on options page while already | 825 // 5) User clicks [Advanced Settings] button on options page while already |
804 // logged in. | 826 // logged in. |
805 // 6) One-click signin (credentials are already available, so should display | 827 // 6) One-click signin (credentials are already available, so should display |
806 // sync configure UI, not login UI). | 828 // sync configure UI, not login UI). |
807 // 7) ChromeOS re-enable after disabling sync. | 829 // 7) ChromeOS re-enable after disabling sync. |
808 // TODO(kochi): Handle ChromeOS re-enable sync case (http://crosbug/27956). | 830 #if !defined(OS_CHROMEOS) |
809 if (force_login || | 831 if (force_login || |
810 !service->AreCredentialsAvailable() || | 832 !service->AreCredentialsAvailable() || |
811 service->GetAuthError().state() != GoogleServiceAuthError::NONE) { | 833 service->GetAuthError().state() != GoogleServiceAuthError::NONE) { |
812 // User is not logged in, or login has been specially requested - need to | 834 // User is not logged in, or login has been specially requested - need to |
813 // display login UI (cases 1-4). | 835 // display login UI (cases 1-4). |
814 DisplayGaiaLogin(false); | 836 DisplayGaiaLogin(false); |
815 } else { | 837 } else { |
816 // User is already logged in. They must have brought up the config wizard | 838 // User is already logged in. They must have brought up the config wizard |
817 // via the "Advanced..." button or through One-Click signin (cases 5/6). | 839 // via the "Advanced..." button or through One-Click signin (cases 5/6). |
818 DisplayConfigureSync(true, false); | 840 DisplayConfigureSync(true, false); |
819 } | 841 } |
| 842 #else |
| 843 PrepareConfigDialog(); |
| 844 #endif |
820 | 845 |
821 ShowSetupUI(); | 846 ShowSetupUI(); |
822 } | 847 } |
823 | 848 |
| 849 void SyncSetupHandler::PrepareConfigDialog() { |
| 850 // On Chrome OS user is always logged in. Instead of showing login dialog, |
| 851 // show spinner until the backend gets ready to configure sync. |
| 852 ProfileSyncService* service = GetSyncService(); |
| 853 if (!service->sync_initialized()) { |
| 854 // To listen to the token available notifications, start SigninTracker. |
| 855 signin_tracker_.reset( |
| 856 new SigninTracker(GetProfile(), this, |
| 857 SigninTracker::SERVICES_INITIALIZING)); |
| 858 service->set_setup_in_progress(true); |
| 859 service->UnsuppressAndStart(); |
| 860 DisplaySpinner(); |
| 861 } else { |
| 862 DisplayConfigureSync(true, false); |
| 863 } |
| 864 } |
| 865 |
824 // Private member functions. | 866 // Private member functions. |
825 | 867 |
826 bool SyncSetupHandler::FocusExistingWizardIfPresent() { | 868 bool SyncSetupHandler::FocusExistingWizardIfPresent() { |
827 LoginUIService* service = GetLoginUIService(); | 869 LoginUIService* service = GetLoginUIService(); |
828 if (!service->current_login_ui()) | 870 if (!service->current_login_ui()) |
829 return false; | 871 return false; |
830 service->FocusLoginUI(); | 872 service->FocusLoginUI(); |
831 return true; | 873 return true; |
832 } | 874 } |
833 | 875 |
(...skipping 25 matching lines...) Expand all Loading... |
859 if (i != current_profile_index && AreUserNamesEqual( | 901 if (i != current_profile_index && AreUserNamesEqual( |
860 cache.GetUserNameOfProfileAtIndex(i), username_utf16)) { | 902 cache.GetUserNameOfProfileAtIndex(i), username_utf16)) { |
861 *error_message = l10n_util::GetStringUTF16( | 903 *error_message = l10n_util::GetStringUTF16( |
862 IDS_SYNC_USER_NAME_IN_USE_ERROR); | 904 IDS_SYNC_USER_NAME_IN_USE_ERROR); |
863 return false; | 905 return false; |
864 } | 906 } |
865 } | 907 } |
866 | 908 |
867 return true; | 909 return true; |
868 } | 910 } |
OLD | NEW |