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 |
600 void SyncSetupHandler::SigninSuccess() { | 616 void SyncSetupHandler::SigninSuccess() { |
| 617 LOG(WARNING) << "SigninSuccess()"; |
601 DCHECK(GetSyncService()->sync_initialized()); | 618 DCHECK(GetSyncService()->sync_initialized()); |
602 // If we have signed in while sync is already setup, it must be due to some | 619 // If we have signed in while sync is already setup, it must be due to some |
603 // kind of re-authentication flow. In that case, just close the signin dialog | 620 // kind of re-authentication flow. In that case, just close the signin dialog |
604 // rather than forcing the user to go through sync configuration. | 621 // rather than forcing the user to go through sync configuration. |
605 if (GetSyncService()->HasSyncSetupCompleted()) | 622 if (GetSyncService()->HasSyncSetupCompleted()) |
606 DisplayGaiaSuccessAndClose(); | 623 DisplayGaiaSuccessAndClose(); |
607 else | 624 else |
608 DisplayConfigureSync(false, false); | 625 DisplayConfigureSync(false, false); |
609 } | 626 } |
610 | 627 |
(...skipping 138 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(); |
| 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 |