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

Side by Side Diff: chrome/browser/ui/webui/settings/people_handler.cc

Issue 1984863002: Clean up LoginUIService. Remove Singleton behavior from PeopleHandler (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: sync and add datatype push update notifications Created 4 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
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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/settings/people_handler.h" 5 #include "chrome/browser/ui/webui/settings/people_handler.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/bind_helpers.h" 10 #include "base/bind_helpers.h"
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after
157 157
158 PeopleHandler::~PeopleHandler() { 158 PeopleHandler::~PeopleHandler() {
159 // Early exit if running unit tests (no actual WebUI is attached). 159 // Early exit if running unit tests (no actual WebUI is attached).
160 if (!web_ui()) 160 if (!web_ui())
161 return; 161 return;
162 162
163 // This case is hit when the user performs a back navigation. 163 // This case is hit when the user performs a back navigation.
164 CloseSyncSetup(); 164 CloseSyncSetup();
165 } 165 }
166 166
167 bool PeopleHandler::IsActiveLogin() const {
168 // LoginUIService can be nullptr if page is brought up in incognito mode
169 // (i.e. if the user is running in guest mode in cros and brings up settings).
170 LoginUIService* service = GetLoginUIService();
171 return service && (service->current_login_ui() == this);
172 }
173
174 void PeopleHandler::RegisterMessages() { 167 void PeopleHandler::RegisterMessages() {
175 web_ui()->RegisterMessageCallback( 168 web_ui()->RegisterMessageCallback(
176 "SyncSetupDidClosePage", 169 "SyncSetupDidClosePage",
177 base::Bind(&PeopleHandler::OnDidClosePage, base::Unretained(this))); 170 base::Bind(&PeopleHandler::OnDidClosePage, base::Unretained(this)));
178 web_ui()->RegisterMessageCallback( 171 web_ui()->RegisterMessageCallback(
179 "SyncSetupSetDatatypes", 172 "SyncSetupSetDatatypes",
180 base::Bind(&PeopleHandler::HandleSetDatatypes, base::Unretained(this))); 173 base::Bind(&PeopleHandler::HandleSetDatatypes, base::Unretained(this)));
181 web_ui()->RegisterMessageCallback( 174 web_ui()->RegisterMessageCallback(
182 "SyncSetupSetEncryption", 175 "SyncSetupSetEncryption",
183 base::Bind(&PeopleHandler::HandleSetEncryption, base::Unretained(this))); 176 base::Bind(&PeopleHandler::HandleSetEncryption, base::Unretained(this)));
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
284 access_point, signin_metrics::Reason::REASON_SIGNIN_PRIMARY_ACCOUNT, 277 access_point, signin_metrics::Reason::REASON_SIGNIN_PRIMARY_ACCOUNT,
285 true); 278 true);
286 } 279 }
287 } 280 }
288 281
289 if (url.is_valid()) 282 if (url.is_valid())
290 chrome::ShowSingletonTab(browser, url); 283 chrome::ShowSingletonTab(browser, url);
291 } 284 }
292 #endif 285 #endif
293 286
294 bool PeopleHandler::PrepareSyncSetup() {
295 // If the wizard is already visible, just focus that one.
296 if (FocusExistingWizardIfPresent()) {
297 if (!IsActiveLogin())
298 CloseSyncSetup();
299 return false;
300 }
301
302 // Notify services that login UI is now active.
303 GetLoginUIService()->SetLoginUI(this);
304
305 ProfileSyncService* service = GetSyncService();
306 if (service)
307 service->SetSetupInProgress(true);
308
309 return true;
310 }
311
312 void PeopleHandler::DisplaySpinner() { 287 void PeopleHandler::DisplaySpinner() {
313 configuring_sync_ = true; 288 configuring_sync_ = true;
314 289
315 const int kTimeoutSec = 30; 290 const int kTimeoutSec = 30;
316 DCHECK(!backend_start_timer_); 291 DCHECK(!backend_start_timer_);
317 backend_start_timer_.reset(new base::OneShotTimer()); 292 backend_start_timer_.reset(new base::OneShotTimer());
318 backend_start_timer_->Start(FROM_HERE, 293 backend_start_timer_->Start(FROM_HERE,
319 base::TimeDelta::FromSeconds(kTimeoutSec), this, 294 base::TimeDelta::FromSeconds(kTimeoutSec), this,
320 &PeopleHandler::DisplayTimeout); 295 &PeopleHandler::DisplayTimeout);
321 296
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after
492 // For web-based signin, the signin page is not displayed in an overlay 467 // For web-based signin, the signin page is not displayed in an overlay
493 // on the settings page. So if we get here, it must be due to the user 468 // on the settings page. So if we get here, it must be due to the user
494 // cancelling signin (by reloading the sync settings page during initial 469 // cancelling signin (by reloading the sync settings page during initial
495 // signin) or by directly navigating to settings/syncSetup 470 // signin) or by directly navigating to settings/syncSetup
496 // (http://crbug.com/229836). So just exit and go back to the settings page. 471 // (http://crbug.com/229836). So just exit and go back to the settings page.
497 DLOG(WARNING) << "Cannot display sync setup UI when not signed in"; 472 DLOG(WARNING) << "Cannot display sync setup UI when not signed in";
498 CloseUI(); 473 CloseUI();
499 return; 474 return;
500 } 475 }
501 476
502 // If a setup wizard is already present, but not on this page, close the 477 OpenSyncSetup(false /* creating_supervised_user */);
503 // blank setup overlay on this page by showing the "done" page. This can
504 // happen if the user navigates to chrome://settings/syncSetup in more than
505 // one tab. See crbug.com/261566.
506 // Note: The following block will transfer focus to the existing wizard.
507 if (IsExistingWizardPresent() && !IsActiveLogin())
508 CloseUI();
509
510 // If a setup wizard is present on this page or another, bring it to focus.
511 // Otherwise, display a new one on this page.
512 if (!FocusExistingWizardIfPresent())
513 OpenSyncSetup(false /* creating_supervised_user */);
514 } 478 }
515 479
516 #if defined(OS_CHROMEOS) 480 #if defined(OS_CHROMEOS)
517 // On ChromeOS, we need to sign out the user session to fix an auth error, so 481 // On ChromeOS, we need to sign out the user session to fix an auth error, so
518 // the user goes through the real signin flow to generate a new auth token. 482 // the user goes through the real signin flow to generate a new auth token.
519 void PeopleHandler::HandleDoSignOutOnAuthError(const base::ListValue* args) { 483 void PeopleHandler::HandleDoSignOutOnAuthError(const base::ListValue* args) {
520 DVLOG(1) << "Signing out the user to fix a sync error."; 484 DVLOG(1) << "Signing out the user to fix a sync error.";
521 chrome::AttemptUserExit(); 485 chrome::AttemptUserExit();
522 } 486 }
523 #endif 487 #endif
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
568 } 532 }
569 533
570 void PeopleHandler::CloseSyncSetup() { 534 void PeopleHandler::CloseSyncSetup() {
571 // Stop a timer to handle timeout in waiting for checking network connection. 535 // Stop a timer to handle timeout in waiting for checking network connection.
572 backend_start_timer_.reset(); 536 backend_start_timer_.reset();
573 537
574 // Clear the sync startup tracker, since the setup wizard is being closed. 538 // Clear the sync startup tracker, since the setup wizard is being closed.
575 sync_startup_tracker_.reset(); 539 sync_startup_tracker_.reset();
576 540
577 ProfileSyncService* sync_service = GetSyncService(); 541 ProfileSyncService* sync_service = GetSyncService();
578 if (IsActiveLogin()) { 542
543 // LoginUIService can be nullptr if page is brought up in incognito mode
544 // (i.e. if the user is running in guest mode in cros and brings up settings).
545 LoginUIService* service = GetLoginUIService();
546 if (service && (service->current_login_ui() == this)) {
579 // Don't log a cancel event if the sync setup dialog is being 547 // Don't log a cancel event if the sync setup dialog is being
580 // automatically closed due to an auth error. 548 // automatically closed due to an auth error.
581 if (!sync_service || (!sync_service->IsFirstSetupComplete() && 549 if (!sync_service || (!sync_service->IsFirstSetupComplete() &&
582 sync_service->GetAuthError().state() == 550 sync_service->GetAuthError().state() ==
583 GoogleServiceAuthError::NONE)) { 551 GoogleServiceAuthError::NONE)) {
584 if (configuring_sync_) { 552 if (configuring_sync_) {
585 ProfileSyncService::SyncEvent( 553 ProfileSyncService::SyncEvent(
586 ProfileSyncService::CANCEL_DURING_CONFIGURE); 554 ProfileSyncService::CANCEL_DURING_CONFIGURE);
587 555
588 // If the user clicked "Cancel" while setting up sync, disable sync 556 // If the user clicked "Cancel" while setting up sync, disable sync
(...skipping 25 matching lines...) Expand all
614 // Alert the sync service anytime the sync setup dialog is closed. This can 582 // Alert the sync service anytime the sync setup dialog is closed. This can
615 // happen due to the user clicking the OK or Cancel button, or due to the 583 // happen due to the user clicking the OK or Cancel button, or due to the
616 // dialog being closed by virtue of sync being disabled in the background. 584 // dialog being closed by virtue of sync being disabled in the background.
617 if (sync_service) 585 if (sync_service)
618 sync_service->SetSetupInProgress(false); 586 sync_service->SetSetupInProgress(false);
619 587
620 configuring_sync_ = false; 588 configuring_sync_ = false;
621 } 589 }
622 590
623 void PeopleHandler::OpenSyncSetup(bool creating_supervised_user) { 591 void PeopleHandler::OpenSyncSetup(bool creating_supervised_user) {
624 if (!PrepareSyncSetup()) 592 // Notify services that login UI is now active.
625 return; 593 GetLoginUIService()->SetLoginUI(this);
594
595 ProfileSyncService* service = GetSyncService();
596 if (service)
597 service->SetSetupInProgress(true);
626 598
627 // There are several different UI flows that can bring the user here: 599 // There are several different UI flows that can bring the user here:
628 // 1) Signin promo. 600 // 1) Signin promo.
629 // 2) Normal signin through settings page (IsAuthenticated() is false). 601 // 2) Normal signin through settings page (IsAuthenticated() is false).
630 // 3) Previously working credentials have expired. 602 // 3) Previously working credentials have expired.
631 // 4) User is signed in, but has stopped sync via the google dashboard, and 603 // 4) User is signed in, but has stopped sync via the google dashboard, and
632 // signout is prohibited by policy so we need to force a re-auth. 604 // signout is prohibited by policy so we need to force a re-auth.
633 // 5) User clicks [Advanced Settings] button on options page while already 605 // 5) User clicks [Advanced Settings] button on options page while already
634 // logged in. 606 // logged in.
635 // 6) One-click signin (credentials are already available, so should display 607 // 6) One-click signin (credentials are already available, so should display
636 // sync configure UI, not login UI). 608 // sync configure UI, not login UI).
637 // 7) User re-enables sync after disabling it via advanced settings. 609 // 7) User re-enables sync after disabling it via advanced settings.
638 #if !defined(OS_CHROMEOS) 610 #if !defined(OS_CHROMEOS)
639 SigninManagerBase* signin = SigninManagerFactory::GetForProfile(profile_); 611 SigninManagerBase* signin = SigninManagerFactory::GetForProfile(profile_);
640 if (!signin->IsAuthenticated() || 612 if (!signin->IsAuthenticated() ||
641 SigninErrorControllerFactory::GetForProfile(profile_)->HasError()) { 613 SigninErrorControllerFactory::GetForProfile(profile_)->HasError()) {
642 // User is not logged in (cases 1-2), or login has been specially requested 614 // User is not logged in (cases 1-2), or login has been specially requested
643 // because previously working credentials have expired (case 3). Close sync 615 // because previously working credentials have expired (case 3). Close sync
644 // setup including any visible overlays, and display the gaia auth page. 616 // setup including any visible overlays, and display the gaia auth page.
645 // Control will be returned to the sync settings page once auth is complete. 617 // Control will be returned to the sync settings page once auth is complete.
646 CloseUI(); 618 CloseUI();
647 DisplayGaiaLogin( 619 DisplayGaiaLogin(
648 creating_supervised_user ? 620 creating_supervised_user ?
649 signin_metrics::AccessPoint::ACCESS_POINT_SUPERVISED_USER : 621 signin_metrics::AccessPoint::ACCESS_POINT_SUPERVISED_USER :
650 signin_metrics::AccessPoint::ACCESS_POINT_SETTINGS); 622 signin_metrics::AccessPoint::ACCESS_POINT_SETTINGS);
651 return; 623 return;
652 } 624 }
653 #endif 625 #endif
654 if (!GetSyncService()) { 626 if (!service) {
655 // This can happen if the user directly navigates to /settings/syncSetup. 627 // This can happen if the user directly navigates to /settings/syncSetup.
656 DLOG(WARNING) << "Cannot display sync UI when sync is disabled"; 628 DLOG(WARNING) << "Cannot display sync UI when sync is disabled";
657 CloseUI(); 629 CloseUI();
658 return; 630 return;
659 } 631 }
660 632
661 // User is already logged in. They must have brought up the config wizard 633 // User is already logged in. They must have brought up the config wizard
662 // via the "Advanced..." button or through One-Click signin (cases 4-6), or 634 // via the "Advanced..." button or through One-Click signin (cases 4-6), or
663 // they are re-enabling sync after having disabled it (case 7). 635 // they are re-enabling sync after having disabled it (case 7).
664 PushSyncPrefs(); 636 PushSyncPrefs();
665 FocusUI();
666 } 637 }
667 638
668 void PeopleHandler::FocusUI() { 639 void PeopleHandler::FocusUI() {
669 DCHECK(IsActiveLogin());
670 WebContents* web_contents = web_ui()->GetWebContents(); 640 WebContents* web_contents = web_ui()->GetWebContents();
671 web_contents->GetDelegate()->ActivateContents(web_contents); 641 web_contents->GetDelegate()->ActivateContents(web_contents);
672 } 642 }
673 643
674 void PeopleHandler::CloseUI() { 644 void PeopleHandler::CloseUI() {
675 CloseSyncSetup(); 645 CloseSyncSetup();
676 CallJavascriptFunction("cr.webUIListenerCallback", 646 CallJavascriptFunction("cr.webUIListenerCallback",
677 base::StringValue("page-status-changed"), 647 base::StringValue("page-status-changed"),
678 base::StringValue(kDonePageStatus)); 648 base::StringValue(kDonePageStatus));
679 } 649 }
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
744 sync_status->SetBoolean("hasError", status_has_error); 714 sync_status->SetBoolean("hasError", status_has_error);
745 715
746 sync_status->SetBoolean("managed", service && service->IsManaged()); 716 sync_status->SetBoolean("managed", service && service->IsManaged());
747 sync_status->SetBoolean("signedIn", signin->IsAuthenticated()); 717 sync_status->SetBoolean("signedIn", signin->IsAuthenticated());
748 sync_status->SetBoolean("hasUnrecoverableError", 718 sync_status->SetBoolean("hasUnrecoverableError",
749 service && service->HasUnrecoverableError()); 719 service && service->HasUnrecoverableError());
750 720
751 return sync_status; 721 return sync_status;
752 } 722 }
753 723
754 bool PeopleHandler::IsExistingWizardPresent() {
755 LoginUIService* service = GetLoginUIService();
756 DCHECK(service);
757 return service->current_login_ui() != nullptr;
758 }
759
760 bool PeopleHandler::FocusExistingWizardIfPresent() {
761 if (!IsExistingWizardPresent())
762 return false;
763
764 LoginUIService* service = GetLoginUIService();
765 DCHECK(service);
766 service->current_login_ui()->FocusUI();
767 return true;
768 }
769
770 void PeopleHandler::PushSyncPrefs() { 724 void PeopleHandler::PushSyncPrefs() {
771 #if !defined(OS_CHROMEOS) 725 #if !defined(OS_CHROMEOS)
772 // Early exit if the user has not signed in yet. 726 // Early exit if the user has not signed in yet.
773 if (!SigninManagerFactory::GetForProfile(profile_)->IsAuthenticated() || 727 if (!SigninManagerFactory::GetForProfile(profile_)->IsAuthenticated() ||
774 SigninErrorControllerFactory::GetForProfile(profile_)->HasError()) { 728 SigninErrorControllerFactory::GetForProfile(profile_)->HasError()) {
775 return; 729 return;
776 } 730 }
777 #endif 731 #endif
778 732
779 // Early exit if there is already a preferences push pending sync startup. 733 // Early exit if there is already a preferences push pending sync startup.
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after
912 base::FilePath profile_file_path = profile_->GetPath(); 866 base::FilePath profile_file_path = profile_->GetPath();
913 ProfileMetrics::LogProfileSyncSignIn(profile_file_path); 867 ProfileMetrics::LogProfileSyncSignIn(profile_file_path);
914 868
915 // We're done configuring, so notify ProfileSyncService that it is OK to 869 // We're done configuring, so notify ProfileSyncService that it is OK to
916 // start syncing. 870 // start syncing.
917 service->SetSetupInProgress(false); 871 service->SetSetupInProgress(false);
918 service->SetFirstSetupComplete(); 872 service->SetFirstSetupComplete();
919 } 873 }
920 874
921 } // namespace settings 875 } // namespace settings
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698