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

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: Fix merge conflict 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
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 this tab.
509 BringTabToFront(web_ui()->GetWebContents());
510 }
492 } 511 }
493 512
494 void SyncSetupHandler::ConfigureSyncDone() { 513 void SyncSetupHandler::ConfigureSyncDone() {
495 StringValue page("done"); 514 StringValue page("done");
496 web_ui()->CallJavascriptFunction( 515 web_ui()->CallJavascriptFunction(
497 "SyncSetupOverlay.showSyncSetupPage", page); 516 "SyncSetupOverlay.showSyncSetupPage", page);
498 517
499 // Suppress the sync promo once the user signs into sync. This way the user 518 // 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. 519 // doesn't see the sync promo even if they sign out of sync later on.
501 SyncPromoUI::SetUserSkippedSyncPromo(GetProfile()); 520 SyncPromoUI::SetUserSkippedSyncPromo(GetProfile());
502 521
503 ProfileSyncService* service = GetSyncService(); 522 ProfileSyncService* service = GetSyncService();
504 if (!service->HasSyncSetupCompleted()) { 523 if (!service->HasSyncSetupCompleted()) {
505 // This is the first time configuring sync, so log it. 524 // This is the first time configuring sync, so log it.
506 FilePath profile_file_path = GetProfile()->GetPath(); 525 FilePath profile_file_path = GetProfile()->GetPath();
507 ProfileMetrics::LogProfileSyncSignIn(profile_file_path); 526 ProfileMetrics::LogProfileSyncSignIn(profile_file_path);
508 527
509 // We're done configuring, so notify ProfileSyncService that it is OK to 528 // We're done configuring, so notify ProfileSyncService that it is OK to
510 // start syncing. 529 // start syncing.
511 service->SetSyncSetupCompleted(); 530 service->SetSyncSetupCompleted();
512 } 531 }
513 } 532 }
514 533
515 bool SyncSetupHandler::IsActiveLogin() const { 534 bool SyncSetupHandler::IsActiveLogin() const {
516 // LoginUIService can be NULL if page is brought up in incognito mode 535 // LoginUIService can be NULL if page is brought up in incognito mode
517 // (i.e. if the user is running in guest mode in cros and brings up settings). 536 // (i.e. if the user is running in guest mode in cros and brings up
537 // settings).
518 LoginUIService* service = GetLoginUIService(); 538 LoginUIService* service = GetLoginUIService();
519 return service && (service->current_login_ui() == this); 539 return service && (service->current_login_ui() == this);
520 } 540 }
521 541
522 void SyncSetupHandler::RegisterMessages() { 542 void SyncSetupHandler::RegisterMessages() {
523 web_ui()->RegisterMessageCallback( 543 web_ui()->RegisterMessageCallback(
524 "SyncSetupDidClosePage", 544 "SyncSetupDidClosePage",
525 base::Bind(&SyncSetupHandler::OnDidClosePage, 545 base::Bind(&SyncSetupHandler::OnDidClosePage,
526 base::Unretained(this))); 546 base::Unretained(this)));
527 web_ui()->RegisterMessageCallback( 547 web_ui()->RegisterMessageCallback(
(...skipping 31 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 // We are no longer configuring sync if the login screen is visible.
592 // If the user exits the signin wizard after this without configuring sync,
593 // 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(
Andrew T Wilson (Slow) 2012/12/03 13:19:02 So, who closes this GAIA tab when signin is comple
Roger Tawa OOO till Jul 10th 2012/12/03 19:08:28 Right its closed by CloseSyncSetup(). It always g
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 // We are no longer configuring sync if the login screen is visible.
585 // If the user exits the signin wizard after this without configuring sync, 617 // If the user exits the signin wizard after this without configuring sync,
(...skipping 69 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 326 matching lines...) Expand 10 before | Expand all | Expand 10 after
1006 ProfileSyncService::SyncEvent( 1036 ProfileSyncService::SyncEvent(
1007 ProfileSyncService::CANCEL_DURING_SIGNON); 1037 ProfileSyncService::CANCEL_DURING_SIGNON);
1008 } else if (configuring_sync_) { 1038 } else if (configuring_sync_) {
1009 ProfileSyncService::SyncEvent( 1039 ProfileSyncService::SyncEvent(
1010 ProfileSyncService::CANCEL_DURING_CONFIGURE); 1040 ProfileSyncService::CANCEL_DURING_CONFIGURE);
1011 } else { 1041 } else {
1012 ProfileSyncService::SyncEvent( 1042 ProfileSyncService::SyncEvent(
1013 ProfileSyncService::CANCEL_FROM_SIGNON_WITHOUT_AUTH); 1043 ProfileSyncService::CANCEL_FROM_SIGNON_WITHOUT_AUTH);
1014 } 1044 }
1015 } 1045 }
1046
1016 // Let the various services know that we're no longer active. 1047 // Let the various services know that we're no longer active.
1048 if (UseWebBasedSigninFlow())
1049 CloseGaiaSigninPage();
1050
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";
1026 sync_service->DisableForUser(); 1060 sync_service->DisableForUser();
(...skipping 56 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 // In the case of the web-based sign in flow, |configuring_sync_| true means
1094 web_contents->GetDelegate()->ActivateContents(web_contents); 1128 // we are focusing to bring the configure popup window to the top, not the
1129 // Gaia sign in page.
1130 if (UseWebBasedSigninFlow() && !configuring_sync_) {
Andrew T Wilson (Slow) 2012/12/03 13:19:02 So previously, configuring_sync_ was just used to
Roger Tawa OOO till Jul 10th 2012/12/03 19:08:28 Done.
1131 BringTabToFront(active_gaia_signin_tab_);
1132 } else {
1133 WebContents* web_contents = web_ui()->GetWebContents();
1134 web_contents->GetDelegate()->ActivateContents(web_contents);
1135 }
1095 } 1136 }
1096 1137
1097 void SyncSetupHandler::CloseUI() { 1138 void SyncSetupHandler::CloseUI() {
1098 DCHECK(IsActiveLogin()); 1139 DCHECK(IsActiveLogin());
1099 CloseOverlay(); 1140 CloseOverlay();
1100 } 1141 }
1101 1142
1143 void SyncSetupHandler::WebContentsDestroyed(
1144 content::WebContents* web_contents) {
1145 DCHECK(active_gaia_signin_tab_);
1146 CloseSyncSetup();
1147 }
1148
1102 // Private member functions. 1149 // Private member functions.
1103 1150
1104 bool SyncSetupHandler::FocusExistingWizardIfPresent() { 1151 bool SyncSetupHandler::FocusExistingWizardIfPresent() {
1105 LoginUIService* service = GetLoginUIService(); 1152 LoginUIService* service = GetLoginUIService();
1106 if (!service->current_login_ui()) 1153 if (!service->current_login_ui())
1107 return false; 1154 return false;
1108 service->current_login_ui()->FocusUI(); 1155 service->current_login_ui()->FocusUI();
1109 return true; 1156 return true;
1110 } 1157 }
1111 1158
1112 LoginUIService* SyncSetupHandler::GetLoginUIService() const { 1159 LoginUIService* SyncSetupHandler::GetLoginUIService() const {
1113 return LoginUIServiceFactory::GetForProfile(GetProfile()); 1160 return LoginUIServiceFactory::GetForProfile(GetProfile());
1114 } 1161 }
1115 1162
1116 void SyncSetupHandler::CloseOverlay() { 1163 void SyncSetupHandler::CloseOverlay() {
1117 // Stop a timer to handle timeout in waiting for sync setup. 1164 // Stop a timer to handle timeout in waiting for sync setup.
1118 backend_start_timer_.reset(); 1165 backend_start_timer_.reset();
1119 1166
1120 CloseSyncSetup(); 1167 CloseSyncSetup();
1121 web_ui()->CallJavascriptFunction("OptionsPage.closeOverlay"); 1168 web_ui()->CallJavascriptFunction("OptionsPage.closeOverlay");
1122 } 1169 }
1123 1170
1171 void SyncSetupHandler::CloseGaiaSigninPage() {
1172 if (active_gaia_signin_tab_) {
1173 content::WebContentsObserver::Observe(NULL);
1174
1175 Browser* browser = chrome::FindBrowserWithWebContents(
1176 active_gaia_signin_tab_);
1177 if (browser) {
1178 TabStripModel* tab_strip_model = browser->tab_strip_model();
1179 if (tab_strip_model) {
1180 int index = tab_strip_model->GetIndexOfWebContents(
1181 active_gaia_signin_tab_);
1182 if (index != TabStripModel::kNoTab) {
1183 tab_strip_model->ExecuteContextMenuCommand(
1184 index, TabStripModel::CommandCloseTab);
1185 }
1186 }
1187 }
1188 }
1189
1190 active_gaia_signin_tab_ = NULL;
1191 }
1192
1124 bool SyncSetupHandler::IsLoginAuthDataValid(const std::string& username, 1193 bool SyncSetupHandler::IsLoginAuthDataValid(const std::string& username,
1125 string16* error_message) { 1194 string16* error_message) {
1126 if (username.empty()) 1195 if (username.empty())
1127 return true; 1196 return true;
1128 1197
1129 // Can be null during some unit tests. 1198 // Can be null during some unit tests.
1130 if (!web_ui()) 1199 if (!web_ui())
1131 return true; 1200 return true;
1132 1201
1133 if (!GetSignin()->IsAllowedUsername(username)) { 1202 if (!GetSignin()->IsAllowedUsername(username)) {
(...skipping 15 matching lines...) Expand all
1149 if (i != current_profile_index && AreUserNamesEqual( 1218 if (i != current_profile_index && AreUserNamesEqual(
1150 cache.GetUserNameOfProfileAtIndex(i), username_utf16)) { 1219 cache.GetUserNameOfProfileAtIndex(i), username_utf16)) {
1151 *error_message = l10n_util::GetStringUTF16( 1220 *error_message = l10n_util::GetStringUTF16(
1152 IDS_SYNC_USER_NAME_IN_USE_ERROR); 1221 IDS_SYNC_USER_NAME_IN_USE_ERROR);
1153 return false; 1222 return false;
1154 } 1223 }
1155 } 1224 }
1156 1225
1157 return true; 1226 return true;
1158 } 1227 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698