Chromium Code Reviews| 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 11 matching lines...) Expand all Loading... | |
| 22 #include "chrome/browser/profiles/profile_window.h" | 22 #include "chrome/browser/profiles/profile_window.h" |
| 23 #include "chrome/browser/signin/chrome_signin_helper.h" | 23 #include "chrome/browser/signin/chrome_signin_helper.h" |
| 24 #include "chrome/browser/signin/signin_error_controller_factory.h" | 24 #include "chrome/browser/signin/signin_error_controller_factory.h" |
| 25 #include "chrome/browser/signin/signin_manager_factory.h" | 25 #include "chrome/browser/signin/signin_manager_factory.h" |
| 26 #include "chrome/browser/signin/signin_promo.h" | 26 #include "chrome/browser/signin/signin_promo.h" |
| 27 #include "chrome/browser/signin/signin_ui_util.h" | 27 #include "chrome/browser/signin/signin_ui_util.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/sync/sync_ui_util.h" | 29 #include "chrome/browser/sync/sync_ui_util.h" |
| 30 #include "chrome/browser/ui/browser_finder.h" | 30 #include "chrome/browser/ui/browser_finder.h" |
| 31 #include "chrome/browser/ui/browser_window.h" | 31 #include "chrome/browser/ui/browser_window.h" |
| 32 #include "chrome/browser/ui/chrome_pages.h" | |
| 32 #include "chrome/browser/ui/singleton_tabs.h" | 33 #include "chrome/browser/ui/singleton_tabs.h" |
| 33 #include "chrome/browser/ui/user_manager.h" | 34 #include "chrome/browser/ui/user_manager.h" |
| 34 #include "chrome/browser/ui/webui/profile_helper.h" | 35 #include "chrome/browser/ui/webui/profile_helper.h" |
| 35 #include "chrome/browser/ui/webui/signin/login_ui_service.h" | 36 #include "chrome/browser/ui/webui/signin/login_ui_service.h" |
| 36 #include "chrome/browser/ui/webui/signin/login_ui_service_factory.h" | 37 #include "chrome/browser/ui/webui/signin/login_ui_service_factory.h" |
| 37 #include "chrome/common/chrome_switches.h" | 38 #include "chrome/common/chrome_switches.h" |
| 39 #include "chrome/common/url_constants.h" | |
| 38 #include "chrome/grit/generated_resources.h" | 40 #include "chrome/grit/generated_resources.h" |
| 39 #include "components/autofill/core/common/autofill_constants.h" | 41 #include "components/autofill/core/common/autofill_constants.h" |
| 40 #include "components/autofill/core/common/autofill_pref_names.h" | 42 #include "components/autofill/core/common/autofill_pref_names.h" |
| 41 #include "components/browser_sync/profile_sync_service.h" | 43 #include "components/browser_sync/profile_sync_service.h" |
| 42 #include "components/prefs/pref_service.h" | 44 #include "components/prefs/pref_service.h" |
| 43 #include "components/signin/core/browser/signin_error_controller.h" | 45 #include "components/signin/core/browser/signin_error_controller.h" |
| 44 #include "components/signin/core/browser/signin_header_helper.h" | 46 #include "components/signin/core/browser/signin_header_helper.h" |
| 45 #include "components/signin/core/browser/signin_metrics.h" | 47 #include "components/signin/core/browser/signin_metrics.h" |
| 46 #include "components/signin/core/common/profile_management_switches.h" | 48 #include "components/signin/core/common/profile_management_switches.h" |
| 47 #include "components/signin/core/common/signin_pref_names.h" | 49 #include "components/signin/core/common/signin_pref_names.h" |
| (...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 189 PeopleHandler::~PeopleHandler() { | 191 PeopleHandler::~PeopleHandler() { |
| 190 // Early exit if running unit tests (no actual WebUI is attached). | 192 // Early exit if running unit tests (no actual WebUI is attached). |
| 191 if (!web_ui()) | 193 if (!web_ui()) |
| 192 return; | 194 return; |
| 193 | 195 |
| 194 // This case is hit when the user performs a back navigation. | 196 // This case is hit when the user performs a back navigation. |
| 195 CloseSyncSetup(); | 197 CloseSyncSetup(); |
| 196 } | 198 } |
| 197 | 199 |
| 198 void PeopleHandler::RegisterMessages() { | 200 void PeopleHandler::RegisterMessages() { |
| 201 MaybeAcquireSyncBlocker(); | |
| 199 web_ui()->RegisterMessageCallback( | 202 web_ui()->RegisterMessageCallback( |
| 200 "SyncSetupDidClosePage", | 203 "SyncSetupDidClosePage", |
| 201 base::Bind(&PeopleHandler::OnDidClosePage, base::Unretained(this))); | 204 base::Bind(&PeopleHandler::OnDidClosePage, base::Unretained(this))); |
| 202 web_ui()->RegisterMessageCallback( | 205 web_ui()->RegisterMessageCallback( |
| 203 "SyncSetupSetDatatypes", | 206 "SyncSetupSetDatatypes", |
| 204 base::Bind(&PeopleHandler::HandleSetDatatypes, base::Unretained(this))); | 207 base::Bind(&PeopleHandler::HandleSetDatatypes, base::Unretained(this))); |
| 205 web_ui()->RegisterMessageCallback( | 208 web_ui()->RegisterMessageCallback( |
| 206 "SyncSetupSetEncryption", | 209 "SyncSetupSetEncryption", |
| 207 base::Bind(&PeopleHandler::HandleSetEncryption, base::Unretained(this))); | 210 base::Bind(&PeopleHandler::HandleSetEncryption, base::Unretained(this))); |
| 208 web_ui()->RegisterMessageCallback( | 211 web_ui()->RegisterMessageCallback( |
| (...skipping 409 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 618 sync_blocker_.reset(); | 621 sync_blocker_.reset(); |
| 619 | 622 |
| 620 configuring_sync_ = false; | 623 configuring_sync_ = false; |
| 621 } | 624 } |
| 622 | 625 |
| 623 void PeopleHandler::OpenSyncSetup() { | 626 void PeopleHandler::OpenSyncSetup() { |
| 624 // Notify services that login UI is now active. | 627 // Notify services that login UI is now active. |
| 625 GetLoginUIService()->SetLoginUI(this); | 628 GetLoginUIService()->SetLoginUI(this); |
| 626 | 629 |
| 627 ProfileSyncService* service = GetSyncService(); | 630 ProfileSyncService* service = GetSyncService(); |
| 628 if (service) | 631 if (service && !sync_blocker_) |
| 629 sync_blocker_ = service->GetSetupInProgressHandle(); | 632 sync_blocker_ = service->GetSetupInProgressHandle(); |
| 630 | 633 |
| 631 // There are several different UI flows that can bring the user here: | 634 // There are several different UI flows that can bring the user here: |
| 632 // 1) Signin promo. | 635 // 1) Signin promo. |
| 633 // 2) Normal signin through settings page (IsAuthenticated() is false). | 636 // 2) Normal signin through settings page (IsAuthenticated() is false). |
| 634 // 3) Previously working credentials have expired. | 637 // 3) Previously working credentials have expired. |
| 635 // 4) User is signed in, but has stopped sync via the google dashboard, and | 638 // 4) User is signed in, but has stopped sync via the google dashboard, and |
| 636 // signout is prohibited by policy so we need to force a re-auth. | 639 // signout is prohibited by policy so we need to force a re-auth. |
| 637 // 5) User clicks [Advanced Settings] button on options page while already | 640 // 5) User clicks [Advanced Settings] button on options page while already |
| 638 // logged in. | 641 // logged in. |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 679 } | 682 } |
| 680 return; | 683 return; |
| 681 } | 684 } |
| 682 | 685 |
| 683 // User is already logged in. They must have brought up the config wizard | 686 // User is already logged in. They must have brought up the config wizard |
| 684 // via the "Advanced..." button or through One-Click signin (cases 4-6), or | 687 // via the "Advanced..." button or through One-Click signin (cases 4-6), or |
| 685 // they are re-enabling sync after having disabled it (case 7). | 688 // they are re-enabling sync after having disabled it (case 7). |
| 686 PushSyncPrefs(); | 689 PushSyncPrefs(); |
| 687 } | 690 } |
| 688 | 691 |
| 692 // If we're directly loading the sync setup page, we acquire a | |
| 693 // SetupInProgressHandle early in order to prevent a lapse in | |
| 694 // ProfileSyncService's "SetupInProgress" status. This lapse previously occured | |
| 695 // between when the sync confirmation dialog was closed and when the sync setup | |
| 696 // page hadn't yet fired the SyncSetupShowSetupUI event. | |
| 697 void PeopleHandler::MaybeAcquireSyncBlocker() { | |
|
tommycli
2017/07/17 16:44:22
I've been trained to not use MaybeFoo() generally,
Patrick Noland
2017/07/17 20:39:11
Done.
| |
| 698 if (!web_ui()) | |
| 699 return; | |
| 700 WebContents* web_contents = web_ui()->GetWebContents(); | |
| 701 if (web_contents) { | |
| 702 ProfileSyncService* service = GetSyncService(); | |
| 703 const GURL current_url = web_contents->GetVisibleURL(); | |
| 704 if (service && | |
| 705 current_url == chrome::GetSettingsUrl(chrome::kSyncSetupSubPage)) { | |
| 706 sync_blocker_ = service->GetSetupInProgressHandle(); | |
| 707 } | |
| 708 } | |
| 709 } | |
| 710 | |
| 689 void PeopleHandler::FocusUI() { | 711 void PeopleHandler::FocusUI() { |
| 690 WebContents* web_contents = web_ui()->GetWebContents(); | 712 WebContents* web_contents = web_ui()->GetWebContents(); |
| 691 web_contents->GetDelegate()->ActivateContents(web_contents); | 713 web_contents->GetDelegate()->ActivateContents(web_contents); |
| 692 } | 714 } |
| 693 | 715 |
| 694 void PeopleHandler::CloseUI() { | 716 void PeopleHandler::CloseUI() { |
| 695 CloseSyncSetup(); | 717 CloseSyncSetup(); |
| 696 FireWebUIListener("page-status-changed", base::Value(kDonePageStatus)); | 718 FireWebUIListener("page-status-changed", base::Value(kDonePageStatus)); |
| 697 } | 719 } |
| 698 | 720 |
| (...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 905 base::FilePath profile_file_path = profile_->GetPath(); | 927 base::FilePath profile_file_path = profile_->GetPath(); |
| 906 ProfileMetrics::LogProfileSyncSignIn(profile_file_path); | 928 ProfileMetrics::LogProfileSyncSignIn(profile_file_path); |
| 907 | 929 |
| 908 // We're done configuring, so notify ProfileSyncService that it is OK to | 930 // We're done configuring, so notify ProfileSyncService that it is OK to |
| 909 // start syncing. | 931 // start syncing. |
| 910 sync_blocker_.reset(); | 932 sync_blocker_.reset(); |
| 911 service->SetFirstSetupComplete(); | 933 service->SetFirstSetupComplete(); |
| 912 } | 934 } |
| 913 | 935 |
| 914 } // namespace settings | 936 } // namespace settings |
| OLD | NEW |