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 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 155 // static | 155 // static |
| 156 const char PeopleHandler::kSpinnerPageStatus[] = "spinner"; | 156 const char PeopleHandler::kSpinnerPageStatus[] = "spinner"; |
| 157 const char PeopleHandler::kConfigurePageStatus[] = "configure"; | 157 const char PeopleHandler::kConfigurePageStatus[] = "configure"; |
| 158 const char PeopleHandler::kTimeoutPageStatus[] = "timeout"; | 158 const char PeopleHandler::kTimeoutPageStatus[] = "timeout"; |
| 159 const char PeopleHandler::kDonePageStatus[] = "done"; | 159 const char PeopleHandler::kDonePageStatus[] = "done"; |
| 160 const char PeopleHandler::kPassphraseFailedPageStatus[] = "passphraseFailed"; | 160 const char PeopleHandler::kPassphraseFailedPageStatus[] = "passphraseFailed"; |
| 161 | 161 |
| 162 PeopleHandler::PeopleHandler(Profile* profile) | 162 PeopleHandler::PeopleHandler(Profile* profile) |
| 163 : profile_(profile), | 163 : profile_(profile), |
| 164 configuring_sync_(false), | 164 configuring_sync_(false), |
| 165 signin_observer_(this), | |
| 165 sync_service_observer_(this) {} | 166 sync_service_observer_(this) {} |
| 166 | 167 |
| 167 PeopleHandler::~PeopleHandler() { | 168 PeopleHandler::~PeopleHandler() { |
| 168 // Early exit if running unit tests (no actual WebUI is attached). | 169 // Early exit if running unit tests (no actual WebUI is attached). |
| 169 if (!web_ui()) | 170 if (!web_ui()) |
| 170 return; | 171 return; |
| 171 | 172 |
| 172 // This case is hit when the user performs a back navigation. | 173 // This case is hit when the user performs a back navigation. |
| 173 CloseSyncSetup(); | 174 CloseSyncSetup(); |
| 174 } | 175 } |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 218 #endif | 219 #endif |
| 219 } | 220 } |
| 220 | 221 |
| 221 void PeopleHandler::OnJavascriptAllowed() { | 222 void PeopleHandler::OnJavascriptAllowed() { |
| 222 PrefService* prefs = profile_->GetPrefs(); | 223 PrefService* prefs = profile_->GetPrefs(); |
| 223 profile_pref_registrar_.Init(prefs); | 224 profile_pref_registrar_.Init(prefs); |
| 224 profile_pref_registrar_.Add( | 225 profile_pref_registrar_.Add( |
| 225 prefs::kSigninAllowed, | 226 prefs::kSigninAllowed, |
| 226 base::Bind(&PeopleHandler::UpdateSyncStatus, base::Unretained(this))); | 227 base::Bind(&PeopleHandler::UpdateSyncStatus, base::Unretained(this))); |
| 227 | 228 |
| 229 SigninManagerBase* signin_manager( | |
| 230 SigninManagerFactory::GetInstance()->GetForProfile(profile_)); | |
| 231 if (signin_manager) | |
| 232 signin_observer_.Add(signin_manager); | |
| 233 | |
| 228 ProfileSyncService* sync_service( | 234 ProfileSyncService* sync_service( |
| 229 ProfileSyncServiceFactory::GetInstance()->GetForProfile(profile_)); | 235 ProfileSyncServiceFactory::GetInstance()->GetForProfile(profile_)); |
| 230 if (sync_service) | 236 if (sync_service) |
| 231 sync_service_observer_.Add(sync_service); | 237 sync_service_observer_.Add(sync_service); |
| 232 } | 238 } |
| 233 | 239 |
| 234 void PeopleHandler::OnJavascriptDisallowed() { | 240 void PeopleHandler::OnJavascriptDisallowed() { |
| 235 profile_pref_registrar_.RemoveAll(); | 241 profile_pref_registrar_.RemoveAll(); |
| 242 signin_observer_.RemoveAll(); | |
| 236 sync_service_observer_.RemoveAll(); | 243 sync_service_observer_.RemoveAll(); |
| 237 } | 244 } |
| 238 | 245 |
| 239 #if !defined(OS_CHROMEOS) | 246 #if !defined(OS_CHROMEOS) |
| 240 void PeopleHandler::DisplayGaiaLogin(signin_metrics::AccessPoint access_point) { | 247 void PeopleHandler::DisplayGaiaLogin(signin_metrics::AccessPoint access_point) { |
| 241 DCHECK(!sync_startup_tracker_); | 248 DCHECK(!sync_startup_tracker_); |
| 242 // Advanced options are no longer being configured if the login screen is | 249 // Advanced options are no longer being configured if the login screen is |
| 243 // visible. If the user exits the signin wizard after this without | 250 // visible. If the user exits the signin wizard after this without |
| 244 // configuring sync, CloseSyncSetup() will ensure they are logged out. | 251 // configuring sync, CloseSyncSetup() will ensure they are logged out. |
| 245 configuring_sync_ = false; | 252 configuring_sync_ = false; |
| (...skipping 324 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 570 webui::DeleteProfileAtPath(profile_->GetPath(), web_ui()); | 577 webui::DeleteProfileAtPath(profile_->GetPath(), web_ui()); |
| 571 } | 578 } |
| 572 } | 579 } |
| 573 #endif | 580 #endif |
| 574 | 581 |
| 575 void PeopleHandler::HandleCloseTimeout(const base::ListValue* args) { | 582 void PeopleHandler::HandleCloseTimeout(const base::ListValue* args) { |
| 576 CloseSyncSetup(); | 583 CloseSyncSetup(); |
| 577 } | 584 } |
| 578 | 585 |
| 579 void PeopleHandler::HandleGetSyncStatus(const base::ListValue* args) { | 586 void PeopleHandler::HandleGetSyncStatus(const base::ListValue* args) { |
| 587 AllowJavascript(); | |
| 588 | |
| 580 CHECK_EQ(1U, args->GetSize()); | 589 CHECK_EQ(1U, args->GetSize()); |
| 581 const base::Value* callback_id; | 590 const base::Value* callback_id; |
| 582 CHECK(args->Get(0, &callback_id)); | 591 CHECK(args->Get(0, &callback_id)); |
| 583 | 592 |
| 584 ResolveJavascriptCallback(*callback_id, *GetSyncStatusDictionary()); | 593 ResolveJavascriptCallback(*callback_id, *GetSyncStatusDictionary()); |
| 585 } | 594 } |
| 586 | 595 |
| 587 void PeopleHandler::HandleManageOtherPeople(const base::ListValue* /* args */) { | 596 void PeopleHandler::HandleManageOtherPeople(const base::ListValue* /* args */) { |
| 588 UserManager::Show(base::FilePath(), profiles::USER_MANAGER_NO_TUTORIAL, | 597 UserManager::Show(base::FilePath(), profiles::USER_MANAGER_NO_TUTORIAL, |
| 589 profiles::USER_MANAGER_SELECT_PROFILE_NO_ACTION); | 598 profiles::USER_MANAGER_SELECT_PROFILE_NO_ACTION); |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 652 // 3) Previously working credentials have expired. | 661 // 3) Previously working credentials have expired. |
| 653 // 4) User is signed in, but has stopped sync via the google dashboard, and | 662 // 4) User is signed in, but has stopped sync via the google dashboard, and |
| 654 // signout is prohibited by policy so we need to force a re-auth. | 663 // signout is prohibited by policy so we need to force a re-auth. |
| 655 // 5) User clicks [Advanced Settings] button on options page while already | 664 // 5) User clicks [Advanced Settings] button on options page while already |
| 656 // logged in. | 665 // logged in. |
| 657 // 6) One-click signin (credentials are already available, so should display | 666 // 6) One-click signin (credentials are already available, so should display |
| 658 // sync configure UI, not login UI). | 667 // sync configure UI, not login UI). |
| 659 // 7) User re-enables sync after disabling it via advanced settings. | 668 // 7) User re-enables sync after disabling it via advanced settings. |
| 660 #if !defined(OS_CHROMEOS) | 669 #if !defined(OS_CHROMEOS) |
| 661 SigninManagerBase* signin = SigninManagerFactory::GetForProfile(profile_); | 670 SigninManagerBase* signin = SigninManagerFactory::GetForProfile(profile_); |
| 662 | |
| 663 if (!signin->IsAuthenticated() || | 671 if (!signin->IsAuthenticated() || |
| 664 SigninErrorControllerFactory::GetForProfile(profile_)->HasError()) { | 672 SigninErrorControllerFactory::GetForProfile(profile_)->HasError()) { |
| 665 // User is not logged in (cases 1-2), or login has been specially requested | 673 // User is not logged in (cases 1-2), or login has been specially requested |
| 666 // because previously working credentials have expired (case 3). Close sync | 674 // because previously working credentials have expired (case 3). Close sync |
| 667 // setup including any visible overlays, and display the gaia auth page. | 675 // setup including any visible overlays, and display the gaia auth page. |
| 668 // Control will be returned to the sync settings page once auth is complete. | 676 // Control will be returned to the sync settings page once auth is complete. |
| 669 CloseUI(); | 677 CloseUI(); |
| 670 DisplayGaiaLogin( | 678 DisplayGaiaLogin( |
| 671 creating_supervised_user ? | 679 creating_supervised_user ? |
| 672 signin_metrics::AccessPoint::ACCESS_POINT_SUPERVISED_USER : | 680 signin_metrics::AccessPoint::ACCESS_POINT_SUPERVISED_USER : |
| 673 signin_metrics::AccessPoint::ACCESS_POINT_SETTINGS); | 681 signin_metrics::AccessPoint::ACCESS_POINT_SETTINGS); |
| 674 return; | 682 return; |
| 675 } | 683 } |
| 676 #endif | 684 #endif |
| 677 if (!GetSyncService()) { | 685 if (!GetSyncService()) { |
| 678 // This can happen if the user directly navigates to /settings/syncSetup. | 686 // This can happen if the user directly navigates to /settings/syncSetup. |
| 679 DLOG(WARNING) << "Cannot display sync UI when sync is disabled"; | 687 DLOG(WARNING) << "Cannot display sync UI when sync is disabled"; |
| 680 CloseUI(); | 688 CloseUI(); |
| 681 return; | 689 return; |
| 682 } | 690 } |
| 683 | 691 |
| 684 // User is already logged in. They must have brought up the config wizard | 692 // User is already logged in. They must have brought up the config wizard |
| 685 // via the "Advanced..." button or through One-Click signin (cases 4-6), or | 693 // via the "Advanced..." button or through One-Click signin (cases 4-6), or |
| 686 // they are re-enabling sync after having disabled it (case 7). | 694 // they are re-enabling sync after having disabled it (case 7). |
| 687 PushSyncPrefs(); | 695 PushSyncPrefs(); |
| 688 FocusUI(); | 696 FocusUI(); |
| 689 } | 697 } |
| 690 | 698 |
| 691 void PeopleHandler::OpenConfigureSync() { | |
| 692 if (!PrepareSyncSetup()) | |
| 693 return; | |
| 694 | |
| 695 PushSyncPrefs(); | |
| 696 FocusUI(); | |
| 697 } | |
| 698 | |
| 699 void PeopleHandler::FocusUI() { | 699 void PeopleHandler::FocusUI() { |
| 700 DCHECK(IsActiveLogin()); | 700 DCHECK(IsActiveLogin()); |
| 701 WebContents* web_contents = web_ui()->GetWebContents(); | 701 WebContents* web_contents = web_ui()->GetWebContents(); |
| 702 web_contents->GetDelegate()->ActivateContents(web_contents); | 702 web_contents->GetDelegate()->ActivateContents(web_contents); |
| 703 } | 703 } |
| 704 | 704 |
| 705 void PeopleHandler::CloseUI() { | 705 void PeopleHandler::CloseUI() { |
| 706 CloseSyncSetup(); | 706 CloseSyncSetup(); |
| 707 CallJavascriptFunction("cr.webUIListenerCallback", | 707 CallJavascriptFunction("cr.webUIListenerCallback", |
| 708 base::StringValue("page-status-changed"), | 708 base::StringValue("page-status-changed"), |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 791 bool PeopleHandler::FocusExistingWizardIfPresent() { | 791 bool PeopleHandler::FocusExistingWizardIfPresent() { |
| 792 if (!IsExistingWizardPresent()) | 792 if (!IsExistingWizardPresent()) |
| 793 return false; | 793 return false; |
| 794 | 794 |
| 795 LoginUIService* service = GetLoginUIService(); | 795 LoginUIService* service = GetLoginUIService(); |
| 796 DCHECK(service); | 796 DCHECK(service); |
| 797 service->current_login_ui()->FocusUI(); | 797 service->current_login_ui()->FocusUI(); |
| 798 return true; | 798 return true; |
| 799 } | 799 } |
| 800 | 800 |
| 801 void PeopleHandler::PushSyncPrefs() { | 801 void PeopleHandler::PushSyncPrefs() { |
|
tommycli
2016/05/11 19:19:08
This method was previously only called when the di
| |
| 802 // Should never call this when we are not signed in. | 802 #if !defined(OS_CHROMEOS) |
| 803 DCHECK(SigninManagerFactory::GetForProfile(profile_)->IsAuthenticated()); | 803 // Early exit if the user has not signed in yet. |
| 804 if (!SigninManagerFactory::GetForProfile(profile_)->IsAuthenticated() || | |
| 805 SigninErrorControllerFactory::GetForProfile(profile_)->HasError()) { | |
| 806 return; | |
| 807 } | |
| 808 #endif | |
| 809 | |
| 810 // Early exit if there is already a preferences push pending sync startup. | |
| 811 if (sync_startup_tracker_) | |
| 812 return; | |
| 813 | |
| 804 ProfileSyncService* service = GetSyncService(); | 814 ProfileSyncService* service = GetSyncService(); |
| 805 DCHECK(service); | 815 DCHECK(service); |
| 806 if (!service->IsBackendInitialized()) { | 816 if (!service->IsBackendInitialized()) { |
| 807 service->RequestStart(); | 817 service->RequestStart(); |
| 808 | 818 |
| 809 // See if it's even possible to bring up the sync backend - if not | 819 // See if it's even possible to bring up the sync backend - if not |
| 810 // (unrecoverable error?), don't bother displaying a spinner that will be | 820 // (unrecoverable error?), don't bother displaying a spinner that will be |
| 811 // immediately closed because this leads to some ugly infinite UI loop (see | 821 // immediately closed because this leads to some ugly infinite UI loop (see |
| 812 // http://crbug.com/244769). | 822 // http://crbug.com/244769). |
| 813 if (SyncStartupTracker::GetSyncServiceState(profile_) != | 823 if (SyncStartupTracker::GetSyncServiceState(profile_) != |
| (...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 938 base::FilePath profile_file_path = profile_->GetPath(); | 948 base::FilePath profile_file_path = profile_->GetPath(); |
| 939 ProfileMetrics::LogProfileSyncSignIn(profile_file_path); | 949 ProfileMetrics::LogProfileSyncSignIn(profile_file_path); |
| 940 | 950 |
| 941 // We're done configuring, so notify ProfileSyncService that it is OK to | 951 // We're done configuring, so notify ProfileSyncService that it is OK to |
| 942 // start syncing. | 952 // start syncing. |
| 943 service->SetSetupInProgress(false); | 953 service->SetSetupInProgress(false); |
| 944 service->SetFirstSetupComplete(); | 954 service->SetFirstSetupComplete(); |
| 945 } | 955 } |
| 946 | 956 |
| 947 } // namespace settings | 957 } // namespace settings |
| OLD | NEW |