| 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 "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
| 9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
| 10 #include "base/compiler_specific.h" | 10 #include "base/compiler_specific.h" |
| (...skipping 583 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 594 // blank setup overlay on this page by showing the "done" page. This can | 594 // blank setup overlay on this page by showing the "done" page. This can |
| 595 // happen if the user navigates to chrome://settings/syncSetup in more than | 595 // happen if the user navigates to chrome://settings/syncSetup in more than |
| 596 // one tab. See crbug.com/261566. | 596 // one tab. See crbug.com/261566. |
| 597 // Note: The following block will transfer focus to the existing wizard. | 597 // Note: The following block will transfer focus to the existing wizard. |
| 598 if (IsExistingWizardPresent() && !IsActiveLogin()) | 598 if (IsExistingWizardPresent() && !IsActiveLogin()) |
| 599 CloseUI(); | 599 CloseUI(); |
| 600 | 600 |
| 601 // If a setup wizard is present on this page or another, bring it to focus. | 601 // If a setup wizard is present on this page or another, bring it to focus. |
| 602 // Otherwise, display a new one on this page. | 602 // Otherwise, display a new one on this page. |
| 603 if (!FocusExistingWizardIfPresent()) | 603 if (!FocusExistingWizardIfPresent()) |
| 604 OpenSyncSetup(args); | 604 OpenSyncSetup(false /* creating_supervised_user */); |
| 605 } | 605 } |
| 606 | 606 |
| 607 #if defined(OS_CHROMEOS) | 607 #if defined(OS_CHROMEOS) |
| 608 // On ChromeOS, we need to sign out the user session to fix an auth error, so | 608 // On ChromeOS, we need to sign out the user session to fix an auth error, so |
| 609 // the user goes through the real signin flow to generate a new auth token. | 609 // the user goes through the real signin flow to generate a new auth token. |
| 610 void PeopleHandler::HandleDoSignOutOnAuthError(const base::ListValue* args) { | 610 void PeopleHandler::HandleDoSignOutOnAuthError(const base::ListValue* args) { |
| 611 DVLOG(1) << "Signing out the user to fix a sync error."; | 611 DVLOG(1) << "Signing out the user to fix a sync error."; |
| 612 chrome::AttemptUserExit(); | 612 chrome::AttemptUserExit(); |
| 613 } | 613 } |
| 614 #endif | 614 #endif |
| 615 | 615 |
| 616 #if !defined(OS_CHROMEOS) | 616 #if !defined(OS_CHROMEOS) |
| 617 void PeopleHandler::HandleStartSignin(const base::ListValue* args) { | 617 void PeopleHandler::HandleStartSignin(const base::ListValue* args) { |
| 618 // Should only be called if the user is not already signed in. | 618 // Should only be called if the user is not already signed in. |
| 619 DCHECK(!SigninManagerFactory::GetForProfile(profile_)->IsAuthenticated()); | 619 DCHECK(!SigninManagerFactory::GetForProfile(profile_)->IsAuthenticated()); |
| 620 OpenSyncSetup(args); | 620 std::string access_point; |
| 621 bool creating_supervised_user = |
| 622 args->GetString(0, &access_point) && |
| 623 access_point == "access-point-supervised-user"; |
| 624 OpenSyncSetup(creating_supervised_user); |
| 621 } | 625 } |
| 622 | 626 |
| 623 void PeopleHandler::HandleStopSyncing(const base::ListValue* args) { | 627 void PeopleHandler::HandleStopSyncing(const base::ListValue* args) { |
| 624 if (GetSyncService()) | 628 if (GetSyncService()) |
| 625 ProfileSyncService::SyncEvent(ProfileSyncService::STOP_FROM_OPTIONS); | 629 ProfileSyncService::SyncEvent(ProfileSyncService::STOP_FROM_OPTIONS); |
| 626 SigninManagerFactory::GetForProfile(profile_) | 630 SigninManagerFactory::GetForProfile(profile_) |
| 627 ->SignOut(signin_metrics::USER_CLICKED_SIGNOUT_SETTINGS); | 631 ->SignOut(signin_metrics::USER_CLICKED_SIGNOUT_SETTINGS); |
| 628 | 632 |
| 629 bool delete_profile = false; | 633 bool delete_profile = false; |
| 630 if (args->GetBoolean(0, &delete_profile) && delete_profile) { | 634 if (args->GetBoolean(0, &delete_profile) && delete_profile) { |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 692 | 696 |
| 693 // Alert the sync service anytime the sync setup dialog is closed. This can | 697 // Alert the sync service anytime the sync setup dialog is closed. This can |
| 694 // happen due to the user clicking the OK or Cancel button, or due to the | 698 // happen due to the user clicking the OK or Cancel button, or due to the |
| 695 // dialog being closed by virtue of sync being disabled in the background. | 699 // dialog being closed by virtue of sync being disabled in the background. |
| 696 if (sync_service) | 700 if (sync_service) |
| 697 sync_service->SetSetupInProgress(false); | 701 sync_service->SetSetupInProgress(false); |
| 698 | 702 |
| 699 configuring_sync_ = false; | 703 configuring_sync_ = false; |
| 700 } | 704 } |
| 701 | 705 |
| 702 void PeopleHandler::OpenSyncSetup(const base::ListValue* args) { | 706 void PeopleHandler::OpenSyncSetup(bool creating_supervised_user) { |
| 703 if (!PrepareSyncSetup()) | 707 if (!PrepareSyncSetup()) |
| 704 return; | 708 return; |
| 705 | 709 |
| 706 // There are several different UI flows that can bring the user here: | 710 // There are several different UI flows that can bring the user here: |
| 707 // 1) Signin promo. | 711 // 1) Signin promo. |
| 708 // 2) Normal signin through settings page (IsAuthenticated() is false). | 712 // 2) Normal signin through settings page (IsAuthenticated() is false). |
| 709 // 3) Previously working credentials have expired. | 713 // 3) Previously working credentials have expired. |
| 710 // 4) User is signed in, but has stopped sync via the google dashboard, and | 714 // 4) User is signed in, but has stopped sync via the google dashboard, and |
| 711 // signout is prohibited by policy so we need to force a re-auth. | 715 // signout is prohibited by policy so we need to force a re-auth. |
| 712 // 5) User clicks [Advanced Settings] button on options page while already | 716 // 5) User clicks [Advanced Settings] button on options page while already |
| 713 // logged in. | 717 // logged in. |
| 714 // 6) One-click signin (credentials are already available, so should display | 718 // 6) One-click signin (credentials are already available, so should display |
| 715 // sync configure UI, not login UI). | 719 // sync configure UI, not login UI). |
| 716 // 7) User re-enables sync after disabling it via advanced settings. | 720 // 7) User re-enables sync after disabling it via advanced settings. |
| 717 #if !defined(OS_CHROMEOS) | 721 #if !defined(OS_CHROMEOS) |
| 718 SigninManagerBase* signin = SigninManagerFactory::GetForProfile(profile_); | 722 SigninManagerBase* signin = SigninManagerFactory::GetForProfile(profile_); |
| 719 | 723 |
| 720 if (!signin->IsAuthenticated() || | 724 if (!signin->IsAuthenticated() || |
| 721 SigninErrorControllerFactory::GetForProfile(profile_)->HasError()) { | 725 SigninErrorControllerFactory::GetForProfile(profile_)->HasError()) { |
| 722 // User is not logged in (cases 1-2), or login has been specially requested | 726 // User is not logged in (cases 1-2), or login has been specially requested |
| 723 // because previously working credentials have expired (case 3). Close sync | 727 // because previously working credentials have expired (case 3). Close sync |
| 724 // setup including any visible overlays, and display the gaia auth page. | 728 // setup including any visible overlays, and display the gaia auth page. |
| 725 // Control will be returned to the sync settings page once auth is complete. | 729 // Control will be returned to the sync settings page once auth is complete. |
| 726 CloseUI(); | 730 CloseUI(); |
| 727 if (args) { | 731 DisplayGaiaLogin( |
| 728 std::string access_point = base::UTF16ToUTF8(ExtractStringValue(args)); | 732 creating_supervised_user |
| 729 if (access_point == "access-point-supervised-user") { | 733 ? signin_metrics::AccessPoint::ACCESS_POINT_SUPERVISED_USER |
| 730 DisplayGaiaLogin( | 734 : signin_metrics::AccessPoint::ACCESS_POINT_SETTINGS); |
| 731 signin_metrics::AccessPoint::ACCESS_POINT_SUPERVISED_USER); | |
| 732 return; | |
| 733 } | |
| 734 } | |
| 735 DisplayGaiaLogin(signin_metrics::AccessPoint::ACCESS_POINT_SETTINGS); | |
| 736 return; | 735 return; |
| 737 } | 736 } |
| 738 #endif | 737 #endif |
| 739 if (!GetSyncService()) { | 738 if (!GetSyncService()) { |
| 740 // This can happen if the user directly navigates to /settings/syncSetup. | 739 // This can happen if the user directly navigates to /settings/syncSetup. |
| 741 DLOG(WARNING) << "Cannot display sync UI when sync is disabled"; | 740 DLOG(WARNING) << "Cannot display sync UI when sync is disabled"; |
| 742 CloseUI(); | 741 CloseUI(); |
| 743 return; | 742 return; |
| 744 } | 743 } |
| 745 | 744 |
| (...skipping 246 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 992 void PeopleHandler::UpdateSyncState() { | 991 void PeopleHandler::UpdateSyncState() { |
| 993 web_ui()->CallJavascriptFunction("settings.SyncPrivateApi.sendSyncStatus", | 992 web_ui()->CallJavascriptFunction("settings.SyncPrivateApi.sendSyncStatus", |
| 994 *GetSyncStateDictionary()); | 993 *GetSyncStateDictionary()); |
| 995 } | 994 } |
| 996 | 995 |
| 997 void PeopleHandler::OnSigninAllowedPrefChange() { | 996 void PeopleHandler::OnSigninAllowedPrefChange() { |
| 998 UpdateSyncState(); | 997 UpdateSyncState(); |
| 999 } | 998 } |
| 1000 | 999 |
| 1001 } // namespace settings | 1000 } // namespace settings |
| OLD | NEW |