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

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

Issue 11418200: Setup from settings should allow configuration first (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Address review comments Created 8 years 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
« no previous file with comments | « chrome/browser/ui/webui/sync_setup_handler.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/basictypes.h" 7 #include "base/basictypes.h"
8 #include "base/bind.h" 8 #include "base/bind.h"
9 #include "base/bind_helpers.h" 9 #include "base/bind_helpers.h"
10 #include "base/command_line.h" 10 #include "base/command_line.h"
(...skipping 10 matching lines...) Expand all
21 #include "chrome/browser/profiles/profile_info_cache.h" 21 #include "chrome/browser/profiles/profile_info_cache.h"
22 #include "chrome/browser/profiles/profile_manager.h" 22 #include "chrome/browser/profiles/profile_manager.h"
23 #include "chrome/browser/profiles/profile_metrics.h" 23 #include "chrome/browser/profiles/profile_metrics.h"
24 #include "chrome/browser/prefs/pref_service.h" 24 #include "chrome/browser/prefs/pref_service.h"
25 #include "chrome/browser/signin/signin_manager.h" 25 #include "chrome/browser/signin/signin_manager.h"
26 #include "chrome/browser/signin/signin_manager_factory.h" 26 #include "chrome/browser/signin/signin_manager_factory.h"
27 #include "chrome/browser/sync/profile_sync_service.h" 27 #include "chrome/browser/sync/profile_sync_service.h"
28 #include "chrome/browser/sync/profile_sync_service_factory.h" 28 #include "chrome/browser/sync/profile_sync_service_factory.h"
29 #include "chrome/browser/ui/browser_finder.h" 29 #include "chrome/browser/ui/browser_finder.h"
30 #include "chrome/browser/ui/browser_navigator.h" 30 #include "chrome/browser/ui/browser_navigator.h"
31 #include "chrome/browser/ui/tabs/tab_strip_model.h"
31 #include "chrome/browser/ui/webui/signin/login_ui_service.h" 32 #include "chrome/browser/ui/webui/signin/login_ui_service.h"
32 #include "chrome/browser/ui/webui/signin/login_ui_service_factory.h" 33 #include "chrome/browser/ui/webui/signin/login_ui_service_factory.h"
33 #include "chrome/browser/ui/webui/sync_promo/sync_promo_ui.h" 34 #include "chrome/browser/ui/webui/sync_promo/sync_promo_ui.h"
34 #include "chrome/common/chrome_switches.h" 35 #include "chrome/common/chrome_switches.h"
35 #include "chrome/common/pref_names.h" 36 #include "chrome/common/pref_names.h"
36 #include "chrome/common/url_constants.h" 37 #include "chrome/common/url_constants.h"
37 #include "content/public/browser/render_view_host.h" 38 #include "content/public/browser/render_view_host.h"
38 #include "content/public/browser/web_contents.h" 39 #include "content/public/browser/web_contents.h"
39 #include "content/public/browser/web_contents_delegate.h" 40 #include "content/public/browser/web_contents_delegate.h"
40 #include "google_apis/gaia/gaia_constants.h" 41 #include "google_apis/gaia/gaia_constants.h"
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after
184 bool IsKeystoreEncryptionEnabled() { 185 bool IsKeystoreEncryptionEnabled() {
185 return CommandLine::ForCurrentProcess()->HasSwitch( 186 return CommandLine::ForCurrentProcess()->HasSwitch(
186 switches::kSyncKeystoreEncryption); 187 switches::kSyncKeystoreEncryption);
187 } 188 }
188 189
189 bool UseWebBasedSigninFlow() { 190 bool UseWebBasedSigninFlow() {
190 return CommandLine::ForCurrentProcess()->HasSwitch( 191 return CommandLine::ForCurrentProcess()->HasSwitch(
191 switches::kUseWebBasedSigninFlow); 192 switches::kUseWebBasedSigninFlow);
192 } 193 }
193 194
195 void BringTabToFront(WebContents* web_contents) {
196 Browser* browser = chrome::FindBrowserWithWebContents(web_contents);
197 if (browser) {
198 TabStripModel* tab_strip_model = browser->tab_strip_model();
199 if (tab_strip_model) {
200 int index = tab_strip_model->GetIndexOfWebContents(web_contents);
201 if (index != TabStripModel::kNoTab)
202 tab_strip_model->ActivateTabAt(index, false);
203 }
204 }
205 }
206
194 } // namespace 207 } // namespace
195 208
196 SyncSetupHandler::SyncSetupHandler(ProfileManager* profile_manager) 209 SyncSetupHandler::SyncSetupHandler(ProfileManager* profile_manager)
197 : configuring_sync_(false), 210 : configuring_sync_(false),
198 profile_manager_(profile_manager), 211 profile_manager_(profile_manager),
199 last_signin_error_(GoogleServiceAuthError::NONE), 212 last_signin_error_(GoogleServiceAuthError::NONE),
200 retry_on_signin_failure_(true) { 213 retry_on_signin_failure_(true),
214 active_gaia_signin_tab_(NULL) {
201 } 215 }
202 216
203 SyncSetupHandler::~SyncSetupHandler() { 217 SyncSetupHandler::~SyncSetupHandler() {
204 // Just exit if running unit tests (no actual WebUI is attached). 218 // Just exit if running unit tests (no actual WebUI is attached).
205 if (!web_ui()) 219 if (!web_ui())
206 return; 220 return;
207 221
208 // This case is hit when the user performs a back navigation. 222 // This case is hit when the user performs a back navigation.
209 CloseSyncSetup(); 223 CloseSyncSetup();
210 } 224 }
(...skipping 271 matching lines...) Expand 10 before | Expand all | Expand 10 after
482 "fullEncryptionBody", 496 "fullEncryptionBody",
483 GetStringUTF16(IDS_SYNC_FULL_ENCRYPTION_DATA)); 497 GetStringUTF16(IDS_SYNC_FULL_ENCRYPTION_DATA));
484 } 498 }
485 } else { 499 } else {
486 args.SetBoolean("usePassphrase", service->IsUsingSecondaryPassphrase()); 500 args.SetBoolean("usePassphrase", service->IsUsingSecondaryPassphrase());
487 } 501 }
488 502
489 StringValue page("configure"); 503 StringValue page("configure");
490 web_ui()->CallJavascriptFunction( 504 web_ui()->CallJavascriptFunction(
491 "SyncSetupOverlay.showSyncSetupPage", page, args); 505 "SyncSetupOverlay.showSyncSetupPage", page, args);
506
507 if (UseWebBasedSigninFlow()) {
508 // Make sure the tab used for the Gaia sign in does not cover the settings
509 // tab.
510 BringTabToFront(web_ui()->GetWebContents());
511 }
492 } 512 }
493 513
494 void SyncSetupHandler::ConfigureSyncDone() { 514 void SyncSetupHandler::ConfigureSyncDone() {
495 StringValue page("done"); 515 StringValue page("done");
496 web_ui()->CallJavascriptFunction( 516 web_ui()->CallJavascriptFunction(
497 "SyncSetupOverlay.showSyncSetupPage", page); 517 "SyncSetupOverlay.showSyncSetupPage", page);
498 518
499 // Suppress the sync promo once the user signs into sync. This way the user 519 // Suppress the sync promo once the user signs into sync. This way the user
500 // doesn't see the sync promo even if they sign out of sync later on. 520 // doesn't see the sync promo even if they sign out of sync later on.
501 SyncPromoUI::SetUserSkippedSyncPromo(GetProfile()); 521 SyncPromoUI::SetUserSkippedSyncPromo(GetProfile());
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
559 base::Bind(&SyncSetupHandler::HandleStopSyncing, 579 base::Bind(&SyncSetupHandler::HandleStopSyncing,
560 base::Unretained(this))); 580 base::Unretained(this)));
561 } 581 }
562 582
563 SigninManager* SyncSetupHandler::GetSignin() const { 583 SigninManager* SyncSetupHandler::GetSignin() const {
564 return SigninManagerFactory::GetForProfile(GetProfile()); 584 return SigninManagerFactory::GetForProfile(GetProfile());
565 } 585 }
566 586
567 void SyncSetupHandler::DisplayGaiaLogin(bool fatal_error) { 587 void SyncSetupHandler::DisplayGaiaLogin(bool fatal_error) {
568 if (UseWebBasedSigninFlow()) { 588 if (UseWebBasedSigninFlow()) {
589 DCHECK(!active_gaia_signin_tab_);
590
591 // Advanced options are no longer being configured if the login screen is
592 // visible. If the user exits the signin wizard after this without
593 // configuring sync, CloseSyncSetup() will ensure they are logged out.
594 configuring_sync_ = false;
595
569 GURL url(SyncPromoUI::GetSyncPromoURL(GURL(), 596 GURL url(SyncPromoUI::GetSyncPromoURL(GURL(),
570 SyncPromoUI::SOURCE_SETTINGS, false)); 597 SyncPromoUI::SOURCE_SETTINGS, false));
571 Browser* browser = chrome::FindBrowserWithWebContents( 598 Browser* browser = chrome::FindBrowserWithWebContents(
572 web_ui()->GetWebContents()); 599 web_ui()->GetWebContents());
573 browser->OpenURL( 600 active_gaia_signin_tab_ = browser->OpenURL(
574 content::OpenURLParams(url, content::Referrer(), SINGLETON_TAB, 601 content::OpenURLParams(url, content::Referrer(), SINGLETON_TAB,
575 content::PAGE_TRANSITION_AUTO_BOOKMARK, false)); 602 content::PAGE_TRANSITION_AUTO_BOOKMARK,
603 false));
604 content::WebContentsObserver::Observe(active_gaia_signin_tab_);
605 signin_tracker_.reset(
606 new SigninTracker(GetProfile(), this,
607 SigninTracker::WAITING_FOR_GAIA_VALIDATION));
576 } else { 608 } else {
577 retry_on_signin_failure_ = true; 609 retry_on_signin_failure_ = true;
578 DisplayGaiaLoginWithErrorMessage(string16(), fatal_error); 610 DisplayGaiaLoginWithErrorMessage(string16(), fatal_error);
579 } 611 }
580 } 612 }
581 613
582 void SyncSetupHandler::DisplayGaiaLoginWithErrorMessage( 614 void SyncSetupHandler::DisplayGaiaLoginWithErrorMessage(
583 const string16& error_message, bool fatal_error) { 615 const string16& error_message, bool fatal_error) {
584 // We are no longer configuring sync if the login screen is visible. 616 // Advanced options are no longer being configured if the login screen is
585 // If the user exits the signin wizard after this without configuring sync, 617 // visible. If the user exits the signin wizard after this without
586 // CloseSyncSetup() will ensure they are logged out. 618 // configuring sync, CloseSyncSetup() will ensure they are logged out.
587 configuring_sync_ = false; 619 configuring_sync_ = false;
588 620
589 string16 local_error_message(error_message); 621 string16 local_error_message(error_message);
590 622
591 // Setup args for the GAIA login screen: 623 // Setup args for the GAIA login screen:
592 // error_message: custom error message to display. 624 // error_message: custom error message to display.
593 // fatalError: fatal error message to display. 625 // fatalError: fatal error message to display.
594 // error: GoogleServiceAuthError from previous login attempt (0 if none). 626 // error: GoogleServiceAuthError from previous login attempt (0 if none).
595 // user: The email the user most recently entered. 627 // user: The email the user most recently entered.
596 // editable_user: Whether the username field should be editable. 628 // editable_user: Whether the username field should be editable.
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
655 return false; 687 return false;
656 } 688 }
657 689
658 // If the wizard is already visible, just focus that one. 690 // If the wizard is already visible, just focus that one.
659 if (FocusExistingWizardIfPresent()) { 691 if (FocusExistingWizardIfPresent()) {
660 if (!IsActiveLogin()) 692 if (!IsActiveLogin())
661 CloseOverlay(); 693 CloseOverlay();
662 return false; 694 return false;
663 } 695 }
664 696
665 if (!UseWebBasedSigninFlow()) { 697 // Notify services that login UI is now active.
666 // Notify services that login UI is now active. 698 GetLoginUIService()->SetLoginUI(this);
667 GetLoginUIService()->SetLoginUI(this); 699 service->SetSetupInProgress(true);
668 service->SetSetupInProgress(true);
669 }
670 700
671 return true; 701 return true;
672 } 702 }
673 703
674 void SyncSetupHandler::DisplaySpinner() { 704 void SyncSetupHandler::DisplaySpinner() {
675 configuring_sync_ = true; 705 configuring_sync_ = true;
676 StringValue page("spinner"); 706 StringValue page("spinner");
677 DictionaryValue args; 707 DictionaryValue args;
678 708
679 const int kTimeoutSec = 30; 709 const int kTimeoutSec = 30;
(...skipping 26 matching lines...) Expand all
706 // By default, do nothing - subclasses can override. 736 // By default, do nothing - subclasses can override.
707 } 737 }
708 738
709 void SyncSetupHandler::DisplayGaiaSuccessAndClose() { 739 void SyncSetupHandler::DisplayGaiaSuccessAndClose() {
710 RecordSignin(); 740 RecordSignin();
711 web_ui()->CallJavascriptFunction("SyncSetupOverlay.showSuccessAndClose"); 741 web_ui()->CallJavascriptFunction("SyncSetupOverlay.showSuccessAndClose");
712 } 742 }
713 743
714 void SyncSetupHandler::DisplayGaiaSuccessAndSettingUp() { 744 void SyncSetupHandler::DisplayGaiaSuccessAndSettingUp() {
715 RecordSignin(); 745 RecordSignin();
746 if (UseWebBasedSigninFlow())
747 CloseGaiaSigninPage();
748
716 web_ui()->CallJavascriptFunction("SyncSetupOverlay.showSuccessAndSettingUp"); 749 web_ui()->CallJavascriptFunction("SyncSetupOverlay.showSuccessAndSettingUp");
717 } 750 }
718 751
719 void SyncSetupHandler::OnDidClosePage(const ListValue* args) { 752 void SyncSetupHandler::OnDidClosePage(const ListValue* args) {
720 CloseSyncSetup(); 753 CloseSyncSetup();
721 } 754 }
722 755
723 void SyncSetupHandler::HandleSubmitAuth(const ListValue* args) { 756 void SyncSetupHandler::HandleSubmitAuth(const ListValue* args) {
724 std::string json; 757 std::string json;
725 if (!args->GetString(0, &json)) { 758 if (!args->GetString(0, &json)) {
(...skipping 280 matching lines...) Expand 10 before | Expand all | Expand 10 after
1006 ProfileSyncService::SyncEvent( 1039 ProfileSyncService::SyncEvent(
1007 ProfileSyncService::CANCEL_DURING_SIGNON); 1040 ProfileSyncService::CANCEL_DURING_SIGNON);
1008 } else if (configuring_sync_) { 1041 } else if (configuring_sync_) {
1009 ProfileSyncService::SyncEvent( 1042 ProfileSyncService::SyncEvent(
1010 ProfileSyncService::CANCEL_DURING_CONFIGURE); 1043 ProfileSyncService::CANCEL_DURING_CONFIGURE);
1011 } else { 1044 } else {
1012 ProfileSyncService::SyncEvent( 1045 ProfileSyncService::SyncEvent(
1013 ProfileSyncService::CANCEL_FROM_SIGNON_WITHOUT_AUTH); 1046 ProfileSyncService::CANCEL_FROM_SIGNON_WITHOUT_AUTH);
1014 } 1047 }
1015 } 1048 }
1049
1016 // Let the various services know that we're no longer active. 1050 // Let the various services know that we're no longer active.
1017 GetLoginUIService()->LoginUIClosed(this); 1051 GetLoginUIService()->LoginUIClosed(this);
1018 } 1052 }
1019 1053
1020 if (sync_service) { 1054 if (sync_service) {
1021 // Make sure user isn't left half-logged-in (signed in, but without sync 1055 // Make sure user isn't left half-logged-in (signed in, but without sync
1022 // started up). If the user hasn't finished setting up sync, then sign out 1056 // started up). If the user hasn't finished setting up sync, then sign out
1023 // and shut down sync. 1057 // and shut down sync.
1024 if (!sync_service->HasSyncSetupCompleted()) { 1058 if (!sync_service->HasSyncSetupCompleted()) {
1025 DVLOG(1) << "Signin aborted by user action"; 1059 DVLOG(1) << "Signin aborted by user action";
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
1083 void SyncSetupHandler::OpenConfigureSync() { 1117 void SyncSetupHandler::OpenConfigureSync() {
1084 if (!PrepareSyncSetup()) 1118 if (!PrepareSyncSetup())
1085 return; 1119 return;
1086 1120
1087 DisplayConfigureSync(true, false); 1121 DisplayConfigureSync(true, false);
1088 ShowSetupUI(); 1122 ShowSetupUI();
1089 } 1123 }
1090 1124
1091 void SyncSetupHandler::FocusUI() { 1125 void SyncSetupHandler::FocusUI() {
1092 DCHECK(IsActiveLogin()); 1126 DCHECK(IsActiveLogin());
1093 WebContents* web_contents = web_ui()->GetWebContents(); 1127 if (UseWebBasedSigninFlow() && signin_tracker_) {
1094 web_contents->GetDelegate()->ActivateContents(web_contents); 1128 BringTabToFront(active_gaia_signin_tab_);
1129 } else {
1130 WebContents* web_contents = web_ui()->GetWebContents();
1131 web_contents->GetDelegate()->ActivateContents(web_contents);
1132 }
1095 } 1133 }
1096 1134
1097 void SyncSetupHandler::CloseUI() { 1135 void SyncSetupHandler::CloseUI() {
1098 DCHECK(IsActiveLogin()); 1136 DCHECK(IsActiveLogin());
1099 CloseOverlay(); 1137 CloseOverlay();
1100 } 1138 }
1101 1139
1140 void SyncSetupHandler::WebContentsDestroyed(
1141 content::WebContents* web_contents) {
1142 DCHECK(active_gaia_signin_tab_);
1143 CloseSyncSetup();
1144 }
1145
1102 // Private member functions. 1146 // Private member functions.
1103 1147
1104 bool SyncSetupHandler::FocusExistingWizardIfPresent() { 1148 bool SyncSetupHandler::FocusExistingWizardIfPresent() {
1105 LoginUIService* service = GetLoginUIService(); 1149 LoginUIService* service = GetLoginUIService();
1106 if (!service->current_login_ui()) 1150 if (!service->current_login_ui())
1107 return false; 1151 return false;
1108 service->current_login_ui()->FocusUI(); 1152 service->current_login_ui()->FocusUI();
1109 return true; 1153 return true;
1110 } 1154 }
1111 1155
1112 LoginUIService* SyncSetupHandler::GetLoginUIService() const { 1156 LoginUIService* SyncSetupHandler::GetLoginUIService() const {
1113 return LoginUIServiceFactory::GetForProfile(GetProfile()); 1157 return LoginUIServiceFactory::GetForProfile(GetProfile());
1114 } 1158 }
1115 1159
1116 void SyncSetupHandler::CloseOverlay() { 1160 void SyncSetupHandler::CloseOverlay() {
1117 // Stop a timer to handle timeout in waiting for sync setup. 1161 // Stop a timer to handle timeout in waiting for sync setup.
1118 backend_start_timer_.reset(); 1162 backend_start_timer_.reset();
1119 1163
1120 CloseSyncSetup(); 1164 CloseSyncSetup();
1121 web_ui()->CallJavascriptFunction("OptionsPage.closeOverlay"); 1165 web_ui()->CallJavascriptFunction("OptionsPage.closeOverlay");
1122 } 1166 }
1123 1167
1168 void SyncSetupHandler::CloseGaiaSigninPage() {
1169 if (active_gaia_signin_tab_) {
1170 content::WebContentsObserver::Observe(NULL);
1171
1172 Browser* browser = chrome::FindBrowserWithWebContents(
1173 active_gaia_signin_tab_);
1174 if (browser) {
1175 TabStripModel* tab_strip_model = browser->tab_strip_model();
1176 if (tab_strip_model) {
1177 int index = tab_strip_model->GetIndexOfWebContents(
1178 active_gaia_signin_tab_);
1179 if (index != TabStripModel::kNoTab) {
1180 tab_strip_model->ExecuteContextMenuCommand(
1181 index, TabStripModel::CommandCloseTab);
1182 }
1183 }
1184 }
1185 }
1186
1187 active_gaia_signin_tab_ = NULL;
1188 }
1189
1124 bool SyncSetupHandler::IsLoginAuthDataValid(const std::string& username, 1190 bool SyncSetupHandler::IsLoginAuthDataValid(const std::string& username,
1125 string16* error_message) { 1191 string16* error_message) {
1126 if (username.empty()) 1192 if (username.empty())
1127 return true; 1193 return true;
1128 1194
1129 // Can be null during some unit tests. 1195 // Can be null during some unit tests.
1130 if (!web_ui()) 1196 if (!web_ui())
1131 return true; 1197 return true;
1132 1198
1133 if (!GetSignin()->IsAllowedUsername(username)) { 1199 if (!GetSignin()->IsAllowedUsername(username)) {
(...skipping 15 matching lines...) Expand all
1149 if (i != current_profile_index && AreUserNamesEqual( 1215 if (i != current_profile_index && AreUserNamesEqual(
1150 cache.GetUserNameOfProfileAtIndex(i), username_utf16)) { 1216 cache.GetUserNameOfProfileAtIndex(i), username_utf16)) {
1151 *error_message = l10n_util::GetStringUTF16( 1217 *error_message = l10n_util::GetStringUTF16(
1152 IDS_SYNC_USER_NAME_IN_USE_ERROR); 1218 IDS_SYNC_USER_NAME_IN_USE_ERROR);
1153 return false; 1219 return false;
1154 } 1220 }
1155 } 1221 }
1156 1222
1157 return true; 1223 return true;
1158 } 1224 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/webui/sync_setup_handler.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698