Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1285)

Side by Side Diff: chrome/browser/ui/webui/sync_setup_handler.cc

Issue 10192005: Refactor LoginUIService to not rely on WebUI. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Review feedback. Created 8 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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
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
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())
761 OpenSyncSetup(false);
760 } 762 }
761 763
762 void SyncSetupHandler::HandleShowSetupUI(const ListValue* args) { 764 void SyncSetupHandler::HandleShowSetupUI(const ListValue* args) {
763 DCHECK(!configuring_sync_); 765 DCHECK(!configuring_sync_);
764 OpenSyncSetup(false); 766 OpenSyncSetup(false);
765 } 767 }
766 768
767 void SyncSetupHandler::HandleStopSyncing(const ListValue* args) { 769 void SyncSetupHandler::HandleStopSyncing(const ListValue* args) {
768 ProfileSyncService* service = GetSyncService(); 770 ProfileSyncService* service = GetSyncService();
769 DCHECK(service); 771 DCHECK(service);
(...skipping 15 matching lines...) Expand all
785 } else if (configuring_sync_) { 787 } else if (configuring_sync_) {
786 ProfileSyncService::SyncEvent( 788 ProfileSyncService::SyncEvent(
787 ProfileSyncService::CANCEL_DURING_CONFIGURE); 789 ProfileSyncService::CANCEL_DURING_CONFIGURE);
788 } else { 790 } else {
789 ProfileSyncService::SyncEvent( 791 ProfileSyncService::SyncEvent(
790 ProfileSyncService::CANCEL_FROM_SIGNON_WITHOUT_AUTH); 792 ProfileSyncService::CANCEL_FROM_SIGNON_WITHOUT_AUTH);
791 } 793 }
792 } 794 }
793 795
794 // Let the various services know that we're no longer active. 796 // Let the various services know that we're no longer active.
795 GetLoginUIService()->LoginUIClosed(web_ui()); 797 GetLoginUIService()->LoginUIClosed(this);
796 if (sync_service) 798 if (sync_service)
797 sync_service->set_setup_in_progress(false); 799 sync_service->set_setup_in_progress(false);
798 800
799 // Make sure user isn't left half-logged-in (signed in, but without sync 801 // 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 802 // started up). If the user hasn't finished setting up sync, then sign out
801 // and shut down sync. 803 // and shut down sync.
802 if (sync_service && !sync_service->HasSyncSetupCompleted()) { 804 if (sync_service && !sync_service->HasSyncSetupCompleted()) {
803 DVLOG(1) << "Signin aborted by user action"; 805 DVLOG(1) << "Signin aborted by user action";
804 sync_service->DisableForUser(); 806 sync_service->DisableForUser();
805 #if !defined(OS_CHROMEOS) 807 #if !defined(OS_CHROMEOS)
(...skipping 22 matching lines...) Expand all
828 } 830 }
829 831
830 // If the wizard is already visible, just focus that one. 832 // If the wizard is already visible, just focus that one.
831 if (FocusExistingWizardIfPresent()) { 833 if (FocusExistingWizardIfPresent()) {
832 if (!IsActiveLogin()) 834 if (!IsActiveLogin())
833 CloseOverlay(); 835 CloseOverlay();
834 return; 836 return;
835 } 837 }
836 838
837 // Notify services that we are now active. 839 // Notify services that we are now active.
838 GetLoginUIService()->SetLoginUI(web_ui()); 840 GetLoginUIService()->SetLoginUI(this);
839 service->set_setup_in_progress(true); 841 service->set_setup_in_progress(true);
840 842
841 // There are several different UI flows that can bring the user here: 843 // There are several different UI flows that can bring the user here:
842 // 1) Signin promo (passes force_login=true) 844 // 1) Signin promo (passes force_login=true)
843 // 2) Normal signin through options page (AreCredentialsAvailable() will 845 // 2) Normal signin through options page (AreCredentialsAvailable() will
844 // return false). 846 // return false).
845 // 3) Previously working credentials have expired 847 // 3) Previously working credentials have expired
846 // (service->GetAuthError() != NONE). 848 // (service->GetAuthError() != NONE).
847 // 4) User is already signed in, but App Notifications needs to force another 849 // 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) 850 // login so it can fetch an oauth token (passes force_login=true)
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
880 new SigninTracker(GetProfile(), this, 882 new SigninTracker(GetProfile(), this,
881 SigninTracker::SERVICES_INITIALIZING)); 883 SigninTracker::SERVICES_INITIALIZING));
882 service->set_setup_in_progress(true); 884 service->set_setup_in_progress(true);
883 service->UnsuppressAndStart(); 885 service->UnsuppressAndStart();
884 DisplaySpinner(); 886 DisplaySpinner();
885 } else { 887 } else {
886 DisplayConfigureSync(true, false); 888 DisplayConfigureSync(true, false);
887 } 889 }
888 } 890 }
889 891
892 void SyncSetupHandler::FocusUI() {
893 DCHECK(IsActiveLogin());
894 web_ui()->GetWebContents()->GetRenderViewHost()->GetDelegate()->Activate();
895 }
896
897 void SyncSetupHandler::CloseUI() {
898 DCHECK(IsActiveLogin());
899 CloseOverlay();
900 }
901
890 // Private member functions. 902 // Private member functions.
891 903
892 bool SyncSetupHandler::FocusExistingWizardIfPresent() { 904 bool SyncSetupHandler::FocusExistingWizardIfPresent() {
893 LoginUIService* service = GetLoginUIService(); 905 LoginUIService* service = GetLoginUIService();
894 if (!service->current_login_ui()) 906 if (!service->current_login_ui())
895 return false; 907 return false;
896 service->FocusLoginUI(); 908 service->current_login_ui()->FocusUI();
897 return true; 909 return true;
898 } 910 }
899 911
900 LoginUIService* SyncSetupHandler::GetLoginUIService() const { 912 LoginUIService* SyncSetupHandler::GetLoginUIService() const {
901 return LoginUIServiceFactory::GetForProfile(GetProfile()); 913 return LoginUIServiceFactory::GetForProfile(GetProfile());
902 } 914 }
903 915
904 void SyncSetupHandler::CloseOverlay() { 916 void SyncSetupHandler::CloseOverlay() {
905 CloseSyncSetup(); 917 CloseSyncSetup();
906 web_ui()->CallJavascriptFunction("OptionsPage.closeOverlay"); 918 web_ui()->CallJavascriptFunction("OptionsPage.closeOverlay");
(...skipping 18 matching lines...) Expand all
925 if (i != current_profile_index && AreUserNamesEqual( 937 if (i != current_profile_index && AreUserNamesEqual(
926 cache.GetUserNameOfProfileAtIndex(i), username_utf16)) { 938 cache.GetUserNameOfProfileAtIndex(i), username_utf16)) {
927 *error_message = l10n_util::GetStringUTF16( 939 *error_message = l10n_util::GetStringUTF16(
928 IDS_SYNC_USER_NAME_IN_USE_ERROR); 940 IDS_SYNC_USER_NAME_IN_USE_ERROR);
929 return false; 941 return false;
930 } 942 }
931 } 943 }
932 944
933 return true; 945 return true;
934 } 946 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/webui/sync_setup_handler.h ('k') | chrome/browser/ui/webui/sync_setup_handler_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698