Chromium Code Reviews| 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 #endif | |
| 766 } | 784 } |
| 767 } | 785 } |
| 768 | 786 |
| 769 configuring_sync_ = false; | 787 configuring_sync_ = false; |
| 770 signin_tracker_.reset(); | 788 signin_tracker_.reset(); |
| 771 } | 789 } |
| 772 | 790 |
| 773 void SyncSetupHandler::OpenSyncSetup(bool force_login) { | 791 void SyncSetupHandler::OpenSyncSetup(bool force_login) { |
| 774 ProfileSyncService* service = GetSyncService(); | 792 ProfileSyncService* service = GetSyncService(); |
| 775 if (!service) { | 793 if (!service) { |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 808 // TODO(kochi): Handle ChromeOS re-enable sync case (http://crosbug/27956). | 826 // TODO(kochi): Handle ChromeOS re-enable sync case (http://crosbug/27956). |
| 809 if (force_login || | 827 if (force_login || |
| 810 !service->AreCredentialsAvailable() || | 828 !service->AreCredentialsAvailable() || |
| 811 service->GetAuthError().state() != GoogleServiceAuthError::NONE) { | 829 service->GetAuthError().state() != GoogleServiceAuthError::NONE) { |
| 812 // User is not logged in, or login has been specially requested - need to | 830 // User is not logged in, or login has been specially requested - need to |
| 813 // display login UI (cases 1-4). | 831 // display login UI (cases 1-4). |
| 814 DisplayGaiaLogin(false); | 832 DisplayGaiaLogin(false); |
| 815 } else { | 833 } else { |
| 816 // User is already logged in. They must have brought up the config wizard | 834 // 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). | 835 // via the "Advanced..." button or through One-Click signin (cases 5/6). |
| 836 #if !defined(OS_CHROMEOS) | |
| 818 DisplayConfigureSync(true, false); | 837 DisplayConfigureSync(true, false); |
|
Andrew T Wilson (Slow)
2012/04/04 17:55:30
I think this is wrong now. You should be #if-ing o
kochi
2012/04/04 18:07:09
Done.
| |
| 838 #else | |
| 839 PrepareConfigDialog(); | |
| 840 #endif | |
| 819 } | 841 } |
| 820 | 842 |
| 821 ShowSetupUI(); | 843 ShowSetupUI(); |
| 822 } | 844 } |
| 823 | 845 |
| 846 void SyncSetupHandler::PrepareConfigDialog() { | |
| 847 // On Chrome OS user is always logged in. Instead of showing login dialog, | |
| 848 // show spinner until the backend gets ready to configure sync. | |
| 849 ProfileSyncService* service = GetSyncService(); | |
| 850 if (!service->sync_initialized()) { | |
| 851 // To listen to the token available notifications, start SigninTracker. | |
| 852 signin_tracker_.reset( | |
| 853 new SigninTracker(GetProfile(), this, | |
| 854 SigninTracker::SERVICES_INITIALIZING)); | |
| 855 service->set_setup_in_progress(true); | |
| 856 service->UnsuppressAndStart(); | |
| 857 DisplaySpinner(); | |
| 858 } else { | |
| 859 DisplayConfigureSync(true, false); | |
| 860 } | |
| 861 } | |
| 862 | |
| 824 // Private member functions. | 863 // Private member functions. |
| 825 | 864 |
| 826 bool SyncSetupHandler::FocusExistingWizardIfPresent() { | 865 bool SyncSetupHandler::FocusExistingWizardIfPresent() { |
| 827 LoginUIService* service = GetLoginUIService(); | 866 LoginUIService* service = GetLoginUIService(); |
| 828 if (!service->current_login_ui()) | 867 if (!service->current_login_ui()) |
| 829 return false; | 868 return false; |
| 830 service->FocusLoginUI(); | 869 service->FocusLoginUI(); |
| 831 return true; | 870 return true; |
| 832 } | 871 } |
| 833 | 872 |
| (...skipping 25 matching lines...) Expand all Loading... | |
| 859 if (i != current_profile_index && AreUserNamesEqual( | 898 if (i != current_profile_index && AreUserNamesEqual( |
| 860 cache.GetUserNameOfProfileAtIndex(i), username_utf16)) { | 899 cache.GetUserNameOfProfileAtIndex(i), username_utf16)) { |
| 861 *error_message = l10n_util::GetStringUTF16( | 900 *error_message = l10n_util::GetStringUTF16( |
| 862 IDS_SYNC_USER_NAME_IN_USE_ERROR); | 901 IDS_SYNC_USER_NAME_IN_USE_ERROR); |
| 863 return false; | 902 return false; |
| 864 } | 903 } |
| 865 } | 904 } |
| 866 | 905 |
| 867 return true; | 906 return true; |
| 868 } | 907 } |
| OLD | NEW |