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 403 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 414 // We're done configuring, so notify ProfileSyncService that it is OK to | 414 // We're done configuring, so notify ProfileSyncService that it is OK to |
| 415 // start syncing. | 415 // start syncing. |
| 416 service->SetSyncSetupCompleted(); | 416 service->SetSyncSetupCompleted(); |
| 417 } | 417 } |
| 418 } | 418 } |
| 419 | 419 |
| 420 bool SyncSetupHandler::IsActiveLogin() const { | 420 bool SyncSetupHandler::IsActiveLogin() const { |
| 421 // LoginUIService can be NULL if page is brought up in incognito mode | 421 // LoginUIService can be NULL if page is brought up in incognito mode |
| 422 // (i.e. if the user is running in guest mode in cros and brings up settings). | 422 // (i.e. if the user is running in guest mode in cros and brings up settings). |
| 423 LoginUIService* service = GetLoginUIService(); | 423 LoginUIService* service = GetLoginUIService(); |
| 424 return service && (service->current_login_ui() == web_ui()); | 424 return service && (service->current_login_ui() == this); |
| 425 } | 425 } |
| 426 | 426 |
| 427 void SyncSetupHandler::RegisterMessages() { | 427 void SyncSetupHandler::RegisterMessages() { |
| 428 web_ui()->RegisterMessageCallback( | 428 web_ui()->RegisterMessageCallback( |
| 429 "SyncSetupDidClosePage", | 429 "SyncSetupDidClosePage", |
| 430 base::Bind(&SyncSetupHandler::OnDidClosePage, | 430 base::Bind(&SyncSetupHandler::OnDidClosePage, |
| 431 base::Unretained(this))); | 431 base::Unretained(this))); |
| 432 web_ui()->RegisterMessageCallback( | 432 web_ui()->RegisterMessageCallback( |
| 433 "SyncSetupSubmitAuth", | 433 "SyncSetupSubmitAuth", |
| 434 base::Bind(&SyncSetupHandler::HandleSubmitAuth, | 434 base::Bind(&SyncSetupHandler::HandleSubmitAuth, |
| (...skipping 314 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 749 DCHECK(service); | 749 DCHECK(service); |
| 750 | 750 |
| 751 #if defined(OS_CHROMEOS) | 751 #if defined(OS_CHROMEOS) |
| 752 if (service->GetAuthError().state() != GoogleServiceAuthError::NONE) { | 752 if (service->GetAuthError().state() != GoogleServiceAuthError::NONE) { |
| 753 DLOG(INFO) << "Signing out the user to fix a sync error."; | 753 DLOG(INFO) << "Signing out the user to fix a sync error."; |
| 754 BrowserList::GetLastActive()->ExecuteCommand(IDC_EXIT); | 754 BrowserList::GetLastActive()->ExecuteCommand(IDC_EXIT); |
| 755 return; | 755 return; |
| 756 } | 756 } |
| 757 #endif | 757 #endif |
| 758 | 758 |
| 759 LoginUIServiceFactory::GetForProfile(GetProfile())->ShowLoginUI(false); | 759 // Bring up the existing wizard, or just display it on this page. |
| 760 if (!FocusExistingWizardIfPresent()) { | |
|
James Hawkins
2012/04/27 17:19:03
Optional nit: I believe the precedence in this fil
Andrew T Wilson (Slow)
2012/04/28 00:32:28
Done.
| |
| 761 OpenSyncSetup(false); | |
| 762 } | |
| 760 } | 763 } |
| 761 | 764 |
| 762 void SyncSetupHandler::HandleShowSetupUI(const ListValue* args) { | 765 void SyncSetupHandler::HandleShowSetupUI(const ListValue* args) { |
| 763 DCHECK(!configuring_sync_); | 766 DCHECK(!configuring_sync_); |
| 764 OpenSyncSetup(false); | 767 OpenSyncSetup(false); |
| 765 } | 768 } |
| 766 | 769 |
| 767 void SyncSetupHandler::HandleStopSyncing(const ListValue* args) { | 770 void SyncSetupHandler::HandleStopSyncing(const ListValue* args) { |
| 768 ProfileSyncService* service = GetSyncService(); | 771 ProfileSyncService* service = GetSyncService(); |
| 769 DCHECK(service); | 772 DCHECK(service); |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 785 } else if (configuring_sync_) { | 788 } else if (configuring_sync_) { |
| 786 ProfileSyncService::SyncEvent( | 789 ProfileSyncService::SyncEvent( |
| 787 ProfileSyncService::CANCEL_DURING_CONFIGURE); | 790 ProfileSyncService::CANCEL_DURING_CONFIGURE); |
| 788 } else { | 791 } else { |
| 789 ProfileSyncService::SyncEvent( | 792 ProfileSyncService::SyncEvent( |
| 790 ProfileSyncService::CANCEL_FROM_SIGNON_WITHOUT_AUTH); | 793 ProfileSyncService::CANCEL_FROM_SIGNON_WITHOUT_AUTH); |
| 791 } | 794 } |
| 792 } | 795 } |
| 793 | 796 |
| 794 // Let the various services know that we're no longer active. | 797 // Let the various services know that we're no longer active. |
| 795 GetLoginUIService()->LoginUIClosed(web_ui()); | 798 GetLoginUIService()->LoginUIClosed(this); |
| 796 if (sync_service) | 799 if (sync_service) |
| 797 sync_service->set_setup_in_progress(false); | 800 sync_service->set_setup_in_progress(false); |
| 798 | 801 |
| 799 // Make sure user isn't left half-logged-in (signed in, but without sync | 802 // Make sure user isn't left half-logged-in (signed in, but without sync |
| 800 // started up). If the user hasn't finished setting up sync, then sign out | 803 // started up). If the user hasn't finished setting up sync, then sign out |
| 801 // and shut down sync. | 804 // and shut down sync. |
| 802 if (sync_service && !sync_service->HasSyncSetupCompleted()) { | 805 if (sync_service && !sync_service->HasSyncSetupCompleted()) { |
| 803 DVLOG(1) << "Signin aborted by user action"; | 806 DVLOG(1) << "Signin aborted by user action"; |
| 804 sync_service->DisableForUser(); | 807 sync_service->DisableForUser(); |
| 805 #if !defined(OS_CHROMEOS) | 808 #if !defined(OS_CHROMEOS) |
| (...skipping 22 matching lines...) Expand all Loading... | |
| 828 } | 831 } |
| 829 | 832 |
| 830 // If the wizard is already visible, just focus that one. | 833 // If the wizard is already visible, just focus that one. |
| 831 if (FocusExistingWizardIfPresent()) { | 834 if (FocusExistingWizardIfPresent()) { |
| 832 if (!IsActiveLogin()) | 835 if (!IsActiveLogin()) |
| 833 CloseOverlay(); | 836 CloseOverlay(); |
| 834 return; | 837 return; |
| 835 } | 838 } |
| 836 | 839 |
| 837 // Notify services that we are now active. | 840 // Notify services that we are now active. |
| 838 GetLoginUIService()->SetLoginUI(web_ui()); | 841 GetLoginUIService()->SetLoginUI(this); |
| 839 service->set_setup_in_progress(true); | 842 service->set_setup_in_progress(true); |
| 840 | 843 |
| 841 // There are several different UI flows that can bring the user here: | 844 // There are several different UI flows that can bring the user here: |
| 842 // 1) Signin promo (passes force_login=true) | 845 // 1) Signin promo (passes force_login=true) |
| 843 // 2) Normal signin through options page (AreCredentialsAvailable() will | 846 // 2) Normal signin through options page (AreCredentialsAvailable() will |
| 844 // return false). | 847 // return false). |
| 845 // 3) Previously working credentials have expired | 848 // 3) Previously working credentials have expired |
| 846 // (service->GetAuthError() != NONE). | 849 // (service->GetAuthError() != NONE). |
| 847 // 4) User is already signed in, but App Notifications needs to force another | 850 // 4) User is already signed in, but App Notifications needs to force another |
| 848 // login so it can fetch an oauth token (passes force_login=true) | 851 // login so it can fetch an oauth token (passes force_login=true) |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 880 new SigninTracker(GetProfile(), this, | 883 new SigninTracker(GetProfile(), this, |
| 881 SigninTracker::SERVICES_INITIALIZING)); | 884 SigninTracker::SERVICES_INITIALIZING)); |
| 882 service->set_setup_in_progress(true); | 885 service->set_setup_in_progress(true); |
| 883 service->UnsuppressAndStart(); | 886 service->UnsuppressAndStart(); |
| 884 DisplaySpinner(); | 887 DisplaySpinner(); |
| 885 } else { | 888 } else { |
| 886 DisplayConfigureSync(true, false); | 889 DisplayConfigureSync(true, false); |
| 887 } | 890 } |
| 888 } | 891 } |
| 889 | 892 |
| 893 void SyncSetupHandler::FocusUI() { | |
| 894 DCHECK(IsActiveLogin()); | |
| 895 web_ui()->GetWebContents()->GetRenderViewHost()->GetDelegate()->Activate(); | |
| 896 } | |
| 897 | |
| 898 void SyncSetupHandler::CloseUI() { | |
| 899 DCHECK(IsActiveLogin()); | |
| 900 CloseOverlay(); | |
| 901 } | |
| 902 | |
| 890 // Private member functions. | 903 // Private member functions. |
| 891 | 904 |
| 892 bool SyncSetupHandler::FocusExistingWizardIfPresent() { | 905 bool SyncSetupHandler::FocusExistingWizardIfPresent() { |
| 893 LoginUIService* service = GetLoginUIService(); | 906 LoginUIService* service = GetLoginUIService(); |
| 894 if (!service->current_login_ui()) | 907 if (!service->current_login_ui()) |
| 895 return false; | 908 return false; |
| 896 service->FocusLoginUI(); | 909 service->current_login_ui()->FocusUI(); |
| 897 return true; | 910 return true; |
| 898 } | 911 } |
| 899 | 912 |
| 900 LoginUIService* SyncSetupHandler::GetLoginUIService() const { | 913 LoginUIService* SyncSetupHandler::GetLoginUIService() const { |
| 901 return LoginUIServiceFactory::GetForProfile(GetProfile()); | 914 return LoginUIServiceFactory::GetForProfile(GetProfile()); |
| 902 } | 915 } |
| 903 | 916 |
| 904 void SyncSetupHandler::CloseOverlay() { | 917 void SyncSetupHandler::CloseOverlay() { |
| 905 CloseSyncSetup(); | 918 CloseSyncSetup(); |
| 906 web_ui()->CallJavascriptFunction("OptionsPage.closeOverlay"); | 919 web_ui()->CallJavascriptFunction("OptionsPage.closeOverlay"); |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 925 if (i != current_profile_index && AreUserNamesEqual( | 938 if (i != current_profile_index && AreUserNamesEqual( |
| 926 cache.GetUserNameOfProfileAtIndex(i), username_utf16)) { | 939 cache.GetUserNameOfProfileAtIndex(i), username_utf16)) { |
| 927 *error_message = l10n_util::GetStringUTF16( | 940 *error_message = l10n_util::GetStringUTF16( |
| 928 IDS_SYNC_USER_NAME_IN_USE_ERROR); | 941 IDS_SYNC_USER_NAME_IN_USE_ERROR); |
| 929 return false; | 942 return false; |
| 930 } | 943 } |
| 931 } | 944 } |
| 932 | 945 |
| 933 return true; | 946 return true; |
| 934 } | 947 } |
| OLD | NEW |