OLD | NEW |
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 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
168 | 168 |
169 PeopleHandler::~PeopleHandler() { | 169 PeopleHandler::~PeopleHandler() { |
170 // Early exit if running unit tests (no actual WebUI is attached). | 170 // Early exit if running unit tests (no actual WebUI is attached). |
171 if (!web_ui()) | 171 if (!web_ui()) |
172 return; | 172 return; |
173 | 173 |
174 // This case is hit when the user performs a back navigation. | 174 // This case is hit when the user performs a back navigation. |
175 CloseSyncSetup(); | 175 CloseSyncSetup(); |
176 } | 176 } |
177 | 177 |
178 bool PeopleHandler::IsActiveLogin() const { | |
179 // LoginUIService can be nullptr if page is brought up in incognito mode | |
180 // (i.e. if the user is running in guest mode in cros and brings up settings). | |
181 LoginUIService* service = GetLoginUIService(); | |
182 return service && (service->current_login_ui() == this); | |
183 } | |
184 | |
185 void PeopleHandler::RegisterMessages() { | 178 void PeopleHandler::RegisterMessages() { |
186 web_ui()->RegisterMessageCallback( | 179 web_ui()->RegisterMessageCallback( |
187 "SyncSetupDidClosePage", | 180 "SyncSetupDidClosePage", |
188 base::Bind(&PeopleHandler::OnDidClosePage, base::Unretained(this))); | 181 base::Bind(&PeopleHandler::OnDidClosePage, base::Unretained(this))); |
189 web_ui()->RegisterMessageCallback( | 182 web_ui()->RegisterMessageCallback( |
190 "SyncSetupSetDatatypes", | 183 "SyncSetupSetDatatypes", |
191 base::Bind(&PeopleHandler::HandleSetDatatypes, base::Unretained(this))); | 184 base::Bind(&PeopleHandler::HandleSetDatatypes, base::Unretained(this))); |
192 web_ui()->RegisterMessageCallback( | 185 web_ui()->RegisterMessageCallback( |
193 "SyncSetupSetEncryption", | 186 "SyncSetupSetEncryption", |
194 base::Bind(&PeopleHandler::HandleSetEncryption, base::Unretained(this))); | 187 base::Bind(&PeopleHandler::HandleSetEncryption, base::Unretained(this))); |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
295 access_point, signin_metrics::Reason::REASON_SIGNIN_PRIMARY_ACCOUNT, | 288 access_point, signin_metrics::Reason::REASON_SIGNIN_PRIMARY_ACCOUNT, |
296 true); | 289 true); |
297 } | 290 } |
298 } | 291 } |
299 | 292 |
300 if (url.is_valid()) | 293 if (url.is_valid()) |
301 chrome::ShowSingletonTab(browser, url); | 294 chrome::ShowSingletonTab(browser, url); |
302 } | 295 } |
303 #endif | 296 #endif |
304 | 297 |
305 bool PeopleHandler::PrepareSyncSetup() { | |
306 // If the wizard is already visible, just focus that one. | |
307 if (FocusExistingWizardIfPresent()) { | |
308 if (!IsActiveLogin()) | |
309 CloseSyncSetup(); | |
310 return false; | |
311 } | |
312 | |
313 // Notify services that login UI is now active. | |
314 GetLoginUIService()->SetLoginUI(this); | |
315 | |
316 ProfileSyncService* service = GetSyncService(); | |
317 if (service) | |
318 sync_blocker_ = service->GetSetupInProgressHandle(); | |
319 | |
320 return true; | |
321 } | |
322 | |
323 void PeopleHandler::DisplaySpinner() { | 298 void PeopleHandler::DisplaySpinner() { |
324 configuring_sync_ = true; | 299 configuring_sync_ = true; |
325 | 300 |
326 const int kTimeoutSec = 30; | 301 const int kTimeoutSec = 30; |
327 DCHECK(!backend_start_timer_); | 302 DCHECK(!backend_start_timer_); |
328 backend_start_timer_.reset(new base::OneShotTimer()); | 303 backend_start_timer_.reset(new base::OneShotTimer()); |
329 backend_start_timer_->Start(FROM_HERE, | 304 backend_start_timer_->Start(FROM_HERE, |
330 base::TimeDelta::FromSeconds(kTimeoutSec), this, | 305 base::TimeDelta::FromSeconds(kTimeoutSec), this, |
331 &PeopleHandler::DisplayTimeout); | 306 &PeopleHandler::DisplayTimeout); |
332 | 307 |
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
507 // For web-based signin, the signin page is not displayed in an overlay | 482 // For web-based signin, the signin page is not displayed in an overlay |
508 // on the settings page. So if we get here, it must be due to the user | 483 // on the settings page. So if we get here, it must be due to the user |
509 // cancelling signin (by reloading the sync settings page during initial | 484 // cancelling signin (by reloading the sync settings page during initial |
510 // signin) or by directly navigating to settings/syncSetup | 485 // signin) or by directly navigating to settings/syncSetup |
511 // (http://crbug.com/229836). So just exit and go back to the settings page. | 486 // (http://crbug.com/229836). So just exit and go back to the settings page. |
512 DLOG(WARNING) << "Cannot display sync setup UI when not signed in"; | 487 DLOG(WARNING) << "Cannot display sync setup UI when not signed in"; |
513 CloseUI(); | 488 CloseUI(); |
514 return; | 489 return; |
515 } | 490 } |
516 | 491 |
517 // If a setup wizard is already present, but not on this page, close the | 492 OpenSyncSetup(false /* creating_supervised_user */); |
518 // blank setup overlay on this page by showing the "done" page. This can | |
519 // happen if the user navigates to chrome://settings/syncSetup in more than | |
520 // one tab. See crbug.com/261566. | |
521 // Note: The following block will transfer focus to the existing wizard. | |
522 if (IsExistingWizardPresent() && !IsActiveLogin()) | |
523 CloseUI(); | |
524 | |
525 // If a setup wizard is present on this page or another, bring it to focus. | |
526 // Otherwise, display a new one on this page. | |
527 if (!FocusExistingWizardIfPresent()) | |
528 OpenSyncSetup(false /* creating_supervised_user */); | |
529 } | 493 } |
530 | 494 |
531 #if defined(OS_CHROMEOS) | 495 #if defined(OS_CHROMEOS) |
532 // On ChromeOS, we need to sign out the user session to fix an auth error, so | 496 // On ChromeOS, we need to sign out the user session to fix an auth error, so |
533 // the user goes through the real signin flow to generate a new auth token. | 497 // the user goes through the real signin flow to generate a new auth token. |
534 void PeopleHandler::HandleDoSignOutOnAuthError(const base::ListValue* args) { | 498 void PeopleHandler::HandleDoSignOutOnAuthError(const base::ListValue* args) { |
535 DVLOG(1) << "Signing out the user to fix a sync error."; | 499 DVLOG(1) << "Signing out the user to fix a sync error."; |
536 chrome::AttemptUserExit(); | 500 chrome::AttemptUserExit(); |
537 } | 501 } |
538 #endif | 502 #endif |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
583 } | 547 } |
584 | 548 |
585 void PeopleHandler::CloseSyncSetup() { | 549 void PeopleHandler::CloseSyncSetup() { |
586 // Stop a timer to handle timeout in waiting for checking network connection. | 550 // Stop a timer to handle timeout in waiting for checking network connection. |
587 backend_start_timer_.reset(); | 551 backend_start_timer_.reset(); |
588 | 552 |
589 // Clear the sync startup tracker, since the setup wizard is being closed. | 553 // Clear the sync startup tracker, since the setup wizard is being closed. |
590 sync_startup_tracker_.reset(); | 554 sync_startup_tracker_.reset(); |
591 | 555 |
592 ProfileSyncService* sync_service = GetSyncService(); | 556 ProfileSyncService* sync_service = GetSyncService(); |
593 if (IsActiveLogin()) { | 557 |
| 558 // LoginUIService can be nullptr if page is brought up in incognito mode |
| 559 // (i.e. if the user is running in guest mode in cros and brings up settings). |
| 560 LoginUIService* service = GetLoginUIService(); |
| 561 if (service && (service->current_login_ui() == this)) { |
594 // Don't log a cancel event if the sync setup dialog is being | 562 // Don't log a cancel event if the sync setup dialog is being |
595 // automatically closed due to an auth error. | 563 // automatically closed due to an auth error. |
596 if (!sync_service || (!sync_service->IsFirstSetupComplete() && | 564 if (!sync_service || (!sync_service->IsFirstSetupComplete() && |
597 sync_service->GetAuthError().state() == | 565 sync_service->GetAuthError().state() == |
598 GoogleServiceAuthError::NONE)) { | 566 GoogleServiceAuthError::NONE)) { |
599 if (configuring_sync_) { | 567 if (configuring_sync_) { |
600 ProfileSyncService::SyncEvent( | 568 ProfileSyncService::SyncEvent( |
601 ProfileSyncService::CANCEL_DURING_CONFIGURE); | 569 ProfileSyncService::CANCEL_DURING_CONFIGURE); |
602 | 570 |
603 // If the user clicked "Cancel" while setting up sync, disable sync | 571 // If the user clicked "Cancel" while setting up sync, disable sync |
(...skipping 24 matching lines...) Expand all Loading... |
628 | 596 |
629 // Alert the sync service anytime the sync setup dialog is closed. This can | 597 // Alert the sync service anytime the sync setup dialog is closed. This can |
630 // happen due to the user clicking the OK or Cancel button, or due to the | 598 // happen due to the user clicking the OK or Cancel button, or due to the |
631 // dialog being closed by virtue of sync being disabled in the background. | 599 // dialog being closed by virtue of sync being disabled in the background. |
632 sync_blocker_.reset(); | 600 sync_blocker_.reset(); |
633 | 601 |
634 configuring_sync_ = false; | 602 configuring_sync_ = false; |
635 } | 603 } |
636 | 604 |
637 void PeopleHandler::OpenSyncSetup(bool creating_supervised_user) { | 605 void PeopleHandler::OpenSyncSetup(bool creating_supervised_user) { |
638 if (!PrepareSyncSetup()) | 606 // Notify services that login UI is now active. |
639 return; | 607 GetLoginUIService()->SetLoginUI(this); |
| 608 |
| 609 ProfileSyncService* service = GetSyncService(); |
| 610 if (service) |
| 611 sync_blocker_ = service->GetSetupInProgressHandle(); |
640 | 612 |
641 // There are several different UI flows that can bring the user here: | 613 // There are several different UI flows that can bring the user here: |
642 // 1) Signin promo. | 614 // 1) Signin promo. |
643 // 2) Normal signin through settings page (IsAuthenticated() is false). | 615 // 2) Normal signin through settings page (IsAuthenticated() is false). |
644 // 3) Previously working credentials have expired. | 616 // 3) Previously working credentials have expired. |
645 // 4) User is signed in, but has stopped sync via the google dashboard, and | 617 // 4) User is signed in, but has stopped sync via the google dashboard, and |
646 // signout is prohibited by policy so we need to force a re-auth. | 618 // signout is prohibited by policy so we need to force a re-auth. |
647 // 5) User clicks [Advanced Settings] button on options page while already | 619 // 5) User clicks [Advanced Settings] button on options page while already |
648 // logged in. | 620 // logged in. |
649 // 6) One-click signin (credentials are already available, so should display | 621 // 6) One-click signin (credentials are already available, so should display |
650 // sync configure UI, not login UI). | 622 // sync configure UI, not login UI). |
651 // 7) User re-enables sync after disabling it via advanced settings. | 623 // 7) User re-enables sync after disabling it via advanced settings. |
652 #if !defined(OS_CHROMEOS) | 624 #if !defined(OS_CHROMEOS) |
653 SigninManagerBase* signin = SigninManagerFactory::GetForProfile(profile_); | 625 SigninManagerBase* signin = SigninManagerFactory::GetForProfile(profile_); |
654 if (!signin->IsAuthenticated() || | 626 if (!signin->IsAuthenticated() || |
655 SigninErrorControllerFactory::GetForProfile(profile_)->HasError()) { | 627 SigninErrorControllerFactory::GetForProfile(profile_)->HasError()) { |
656 // User is not logged in (cases 1-2), or login has been specially requested | 628 // User is not logged in (cases 1-2), or login has been specially requested |
657 // because previously working credentials have expired (case 3). Close sync | 629 // because previously working credentials have expired (case 3). Close sync |
658 // setup including any visible overlays, and display the gaia auth page. | 630 // setup including any visible overlays, and display the gaia auth page. |
659 // Control will be returned to the sync settings page once auth is complete. | 631 // Control will be returned to the sync settings page once auth is complete. |
660 CloseUI(); | 632 CloseUI(); |
661 DisplayGaiaLogin( | 633 DisplayGaiaLogin( |
662 creating_supervised_user ? | 634 creating_supervised_user ? |
663 signin_metrics::AccessPoint::ACCESS_POINT_SUPERVISED_USER : | 635 signin_metrics::AccessPoint::ACCESS_POINT_SUPERVISED_USER : |
664 signin_metrics::AccessPoint::ACCESS_POINT_SETTINGS); | 636 signin_metrics::AccessPoint::ACCESS_POINT_SETTINGS); |
665 return; | 637 return; |
666 } | 638 } |
667 #endif | 639 #endif |
668 if (!GetSyncService()) { | 640 if (!service) { |
669 // This can happen if the user directly navigates to /settings/syncSetup. | 641 // This can happen if the user directly navigates to /settings/syncSetup. |
670 DLOG(WARNING) << "Cannot display sync UI when sync is disabled"; | 642 DLOG(WARNING) << "Cannot display sync UI when sync is disabled"; |
671 CloseUI(); | 643 CloseUI(); |
672 return; | 644 return; |
673 } | 645 } |
674 | 646 |
675 // User is already logged in. They must have brought up the config wizard | 647 // User is already logged in. They must have brought up the config wizard |
676 // via the "Advanced..." button or through One-Click signin (cases 4-6), or | 648 // via the "Advanced..." button or through One-Click signin (cases 4-6), or |
677 // they are re-enabling sync after having disabled it (case 7). | 649 // they are re-enabling sync after having disabled it (case 7). |
678 PushSyncPrefs(); | 650 PushSyncPrefs(); |
679 FocusUI(); | |
680 } | 651 } |
681 | 652 |
682 void PeopleHandler::FocusUI() { | 653 void PeopleHandler::FocusUI() { |
683 DCHECK(IsActiveLogin()); | |
684 WebContents* web_contents = web_ui()->GetWebContents(); | 654 WebContents* web_contents = web_ui()->GetWebContents(); |
685 web_contents->GetDelegate()->ActivateContents(web_contents); | 655 web_contents->GetDelegate()->ActivateContents(web_contents); |
686 } | 656 } |
687 | 657 |
688 void PeopleHandler::CloseUI() { | 658 void PeopleHandler::CloseUI() { |
689 CloseSyncSetup(); | 659 CloseSyncSetup(); |
690 CallJavascriptFunction("cr.webUIListenerCallback", | 660 CallJavascriptFunction("cr.webUIListenerCallback", |
691 base::StringValue("page-status-changed"), | 661 base::StringValue("page-status-changed"), |
692 base::StringValue(kDonePageStatus)); | 662 base::StringValue(kDonePageStatus)); |
693 } | 663 } |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
758 sync_status->SetBoolean("hasError", status_has_error); | 728 sync_status->SetBoolean("hasError", status_has_error); |
759 | 729 |
760 sync_status->SetBoolean("managed", service && service->IsManaged()); | 730 sync_status->SetBoolean("managed", service && service->IsManaged()); |
761 sync_status->SetBoolean("signedIn", signin->IsAuthenticated()); | 731 sync_status->SetBoolean("signedIn", signin->IsAuthenticated()); |
762 sync_status->SetBoolean("hasUnrecoverableError", | 732 sync_status->SetBoolean("hasUnrecoverableError", |
763 service && service->HasUnrecoverableError()); | 733 service && service->HasUnrecoverableError()); |
764 | 734 |
765 return sync_status; | 735 return sync_status; |
766 } | 736 } |
767 | 737 |
768 bool PeopleHandler::IsExistingWizardPresent() { | |
769 LoginUIService* service = GetLoginUIService(); | |
770 DCHECK(service); | |
771 return service->current_login_ui() != nullptr; | |
772 } | |
773 | |
774 bool PeopleHandler::FocusExistingWizardIfPresent() { | |
775 if (!IsExistingWizardPresent()) | |
776 return false; | |
777 | |
778 LoginUIService* service = GetLoginUIService(); | |
779 DCHECK(service); | |
780 service->current_login_ui()->FocusUI(); | |
781 return true; | |
782 } | |
783 | |
784 void PeopleHandler::PushSyncPrefs() { | 738 void PeopleHandler::PushSyncPrefs() { |
785 #if !defined(OS_CHROMEOS) | 739 #if !defined(OS_CHROMEOS) |
786 // Early exit if the user has not signed in yet. | 740 // Early exit if the user has not signed in yet. |
787 if (!SigninManagerFactory::GetForProfile(profile_)->IsAuthenticated() || | 741 if (!SigninManagerFactory::GetForProfile(profile_)->IsAuthenticated() || |
788 SigninErrorControllerFactory::GetForProfile(profile_)->HasError()) { | 742 SigninErrorControllerFactory::GetForProfile(profile_)->HasError()) { |
789 return; | 743 return; |
790 } | 744 } |
791 #endif | 745 #endif |
792 | 746 |
793 // Early exit if there is already a preferences push pending sync startup. | 747 // Early exit if there is already a preferences push pending sync startup. |
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
931 base::FilePath profile_file_path = profile_->GetPath(); | 885 base::FilePath profile_file_path = profile_->GetPath(); |
932 ProfileMetrics::LogProfileSyncSignIn(profile_file_path); | 886 ProfileMetrics::LogProfileSyncSignIn(profile_file_path); |
933 | 887 |
934 // We're done configuring, so notify ProfileSyncService that it is OK to | 888 // We're done configuring, so notify ProfileSyncService that it is OK to |
935 // start syncing. | 889 // start syncing. |
936 sync_blocker_.reset(); | 890 sync_blocker_.reset(); |
937 service->SetFirstSetupComplete(); | 891 service->SetFirstSetupComplete(); |
938 } | 892 } |
939 | 893 |
940 } // namespace settings | 894 } // namespace settings |
OLD | NEW |