| 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 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 357 CloseUI(); | 364 CloseUI(); |
| 358 } | 365 } |
| 359 | 366 |
| 360 void PeopleHandler::SyncStartupCompleted() { | 367 void PeopleHandler::SyncStartupCompleted() { |
| 361 ProfileSyncService* service = GetSyncService(); | 368 ProfileSyncService* service = GetSyncService(); |
| 362 DCHECK(service->IsBackendInitialized()); | 369 DCHECK(service->IsBackendInitialized()); |
| 363 | 370 |
| 364 // Stop a timer to handle timeout in waiting for checking network connection. | 371 // Stop a timer to handle timeout in waiting for checking network connection. |
| 365 backend_start_timer_.reset(); | 372 backend_start_timer_.reset(); |
| 366 | 373 |
| 374 sync_startup_tracker_.reset(); |
| 375 |
| 367 PushSyncPrefs(); | 376 PushSyncPrefs(); |
| 368 } | 377 } |
| 369 | 378 |
| 370 ProfileSyncService* PeopleHandler::GetSyncService() const { | 379 ProfileSyncService* PeopleHandler::GetSyncService() const { |
| 371 return profile_->IsSyncAllowed() | 380 return profile_->IsSyncAllowed() |
| 372 ? ProfileSyncServiceFactory::GetForProfile(profile_) | 381 ? ProfileSyncServiceFactory::GetForProfile(profile_) |
| 373 : nullptr; | 382 : nullptr; |
| 374 } | 383 } |
| 375 | 384 |
| 376 void PeopleHandler::HandleSetDatatypes(const base::ListValue* args) { | 385 void PeopleHandler::HandleSetDatatypes(const base::ListValue* args) { |
| (...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 570 webui::DeleteProfileAtPath(profile_->GetPath(), web_ui()); | 579 webui::DeleteProfileAtPath(profile_->GetPath(), web_ui()); |
| 571 } | 580 } |
| 572 } | 581 } |
| 573 #endif | 582 #endif |
| 574 | 583 |
| 575 void PeopleHandler::HandleCloseTimeout(const base::ListValue* args) { | 584 void PeopleHandler::HandleCloseTimeout(const base::ListValue* args) { |
| 576 CloseSyncSetup(); | 585 CloseSyncSetup(); |
| 577 } | 586 } |
| 578 | 587 |
| 579 void PeopleHandler::HandleGetSyncStatus(const base::ListValue* args) { | 588 void PeopleHandler::HandleGetSyncStatus(const base::ListValue* args) { |
| 589 AllowJavascript(); |
| 590 |
| 580 CHECK_EQ(1U, args->GetSize()); | 591 CHECK_EQ(1U, args->GetSize()); |
| 581 const base::Value* callback_id; | 592 const base::Value* callback_id; |
| 582 CHECK(args->Get(0, &callback_id)); | 593 CHECK(args->Get(0, &callback_id)); |
| 583 | 594 |
| 584 ResolveJavascriptCallback(*callback_id, *GetSyncStatusDictionary()); | 595 ResolveJavascriptCallback(*callback_id, *GetSyncStatusDictionary()); |
| 585 } | 596 } |
| 586 | 597 |
| 587 void PeopleHandler::HandleManageOtherPeople(const base::ListValue* /* args */) { | 598 void PeopleHandler::HandleManageOtherPeople(const base::ListValue* /* args */) { |
| 588 UserManager::Show(base::FilePath(), profiles::USER_MANAGER_NO_TUTORIAL, | 599 UserManager::Show(base::FilePath(), profiles::USER_MANAGER_NO_TUTORIAL, |
| 589 profiles::USER_MANAGER_SELECT_PROFILE_NO_ACTION); | 600 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. | 663 // 3) Previously working credentials have expired. |
| 653 // 4) User is signed in, but has stopped sync via the google dashboard, and | 664 // 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. | 665 // 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 | 666 // 5) User clicks [Advanced Settings] button on options page while already |
| 656 // logged in. | 667 // logged in. |
| 657 // 6) One-click signin (credentials are already available, so should display | 668 // 6) One-click signin (credentials are already available, so should display |
| 658 // sync configure UI, not login UI). | 669 // sync configure UI, not login UI). |
| 659 // 7) User re-enables sync after disabling it via advanced settings. | 670 // 7) User re-enables sync after disabling it via advanced settings. |
| 660 #if !defined(OS_CHROMEOS) | 671 #if !defined(OS_CHROMEOS) |
| 661 SigninManagerBase* signin = SigninManagerFactory::GetForProfile(profile_); | 672 SigninManagerBase* signin = SigninManagerFactory::GetForProfile(profile_); |
| 662 | |
| 663 if (!signin->IsAuthenticated() || | 673 if (!signin->IsAuthenticated() || |
| 664 SigninErrorControllerFactory::GetForProfile(profile_)->HasError()) { | 674 SigninErrorControllerFactory::GetForProfile(profile_)->HasError()) { |
| 665 // User is not logged in (cases 1-2), or login has been specially requested | 675 // 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 | 676 // because previously working credentials have expired (case 3). Close sync |
| 667 // setup including any visible overlays, and display the gaia auth page. | 677 // 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. | 678 // Control will be returned to the sync settings page once auth is complete. |
| 669 CloseUI(); | 679 CloseUI(); |
| 670 DisplayGaiaLogin( | 680 DisplayGaiaLogin( |
| 671 creating_supervised_user ? | 681 creating_supervised_user ? |
| 672 signin_metrics::AccessPoint::ACCESS_POINT_SUPERVISED_USER : | 682 signin_metrics::AccessPoint::ACCESS_POINT_SUPERVISED_USER : |
| 673 signin_metrics::AccessPoint::ACCESS_POINT_SETTINGS); | 683 signin_metrics::AccessPoint::ACCESS_POINT_SETTINGS); |
| 674 return; | 684 return; |
| 675 } | 685 } |
| 676 #endif | 686 #endif |
| 677 if (!GetSyncService()) { | 687 if (!GetSyncService()) { |
| 678 // This can happen if the user directly navigates to /settings/syncSetup. | 688 // This can happen if the user directly navigates to /settings/syncSetup. |
| 679 DLOG(WARNING) << "Cannot display sync UI when sync is disabled"; | 689 DLOG(WARNING) << "Cannot display sync UI when sync is disabled"; |
| 680 CloseUI(); | 690 CloseUI(); |
| 681 return; | 691 return; |
| 682 } | 692 } |
| 683 | 693 |
| 684 // User is already logged in. They must have brought up the config wizard | 694 // 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 | 695 // 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). | 696 // they are re-enabling sync after having disabled it (case 7). |
| 687 PushSyncPrefs(); | 697 PushSyncPrefs(); |
| 688 FocusUI(); | 698 FocusUI(); |
| 689 } | 699 } |
| 690 | 700 |
| 691 void PeopleHandler::OpenConfigureSync() { | |
| 692 if (!PrepareSyncSetup()) | |
| 693 return; | |
| 694 | |
| 695 PushSyncPrefs(); | |
| 696 FocusUI(); | |
| 697 } | |
| 698 | |
| 699 void PeopleHandler::FocusUI() { | 701 void PeopleHandler::FocusUI() { |
| 700 DCHECK(IsActiveLogin()); | 702 DCHECK(IsActiveLogin()); |
| 701 WebContents* web_contents = web_ui()->GetWebContents(); | 703 WebContents* web_contents = web_ui()->GetWebContents(); |
| 702 web_contents->GetDelegate()->ActivateContents(web_contents); | 704 web_contents->GetDelegate()->ActivateContents(web_contents); |
| 703 } | 705 } |
| 704 | 706 |
| 705 void PeopleHandler::CloseUI() { | 707 void PeopleHandler::CloseUI() { |
| 706 CloseSyncSetup(); | 708 CloseSyncSetup(); |
| 707 CallJavascriptFunction("cr.webUIListenerCallback", | 709 CallJavascriptFunction("cr.webUIListenerCallback", |
| 708 base::StringValue("page-status-changed"), | 710 base::StringValue("page-status-changed"), |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 792 if (!IsExistingWizardPresent()) | 794 if (!IsExistingWizardPresent()) |
| 793 return false; | 795 return false; |
| 794 | 796 |
| 795 LoginUIService* service = GetLoginUIService(); | 797 LoginUIService* service = GetLoginUIService(); |
| 796 DCHECK(service); | 798 DCHECK(service); |
| 797 service->current_login_ui()->FocusUI(); | 799 service->current_login_ui()->FocusUI(); |
| 798 return true; | 800 return true; |
| 799 } | 801 } |
| 800 | 802 |
| 801 void PeopleHandler::PushSyncPrefs() { | 803 void PeopleHandler::PushSyncPrefs() { |
| 802 // Should never call this when we are not signed in. | 804 #if !defined(OS_CHROMEOS) |
| 803 DCHECK(SigninManagerFactory::GetForProfile(profile_)->IsAuthenticated()); | 805 // Early exit if the user has not signed in yet. |
| 806 if (!SigninManagerFactory::GetForProfile(profile_)->IsAuthenticated() || |
| 807 SigninErrorControllerFactory::GetForProfile(profile_)->HasError()) { |
| 808 return; |
| 809 } |
| 810 #endif |
| 811 |
| 812 // Early exit if there is already a preferences push pending sync startup. |
| 813 if (sync_startup_tracker_) |
| 814 return; |
| 815 |
| 804 ProfileSyncService* service = GetSyncService(); | 816 ProfileSyncService* service = GetSyncService(); |
| 805 DCHECK(service); | 817 DCHECK(service); |
| 806 if (!service->IsBackendInitialized()) { | 818 if (!service->IsBackendInitialized()) { |
| 807 service->RequestStart(); | 819 service->RequestStart(); |
| 808 | 820 |
| 809 // See if it's even possible to bring up the sync backend - if not | 821 // 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 | 822 // (unrecoverable error?), don't bother displaying a spinner that will be |
| 811 // immediately closed because this leads to some ugly infinite UI loop (see | 823 // immediately closed because this leads to some ugly infinite UI loop (see |
| 812 // http://crbug.com/244769). | 824 // http://crbug.com/244769). |
| 813 if (SyncStartupTracker::GetSyncServiceState(profile_) != | 825 if (SyncStartupTracker::GetSyncServiceState(profile_) != |
| 814 SyncStartupTracker::SYNC_STARTUP_ERROR) { | 826 SyncStartupTracker::SYNC_STARTUP_ERROR) { |
| 815 DisplaySpinner(); | 827 DisplaySpinner(); |
| 816 } | 828 } |
| 817 | 829 |
| 818 // Start SyncSetupTracker to wait for sync to initialize. | 830 // Start SyncSetupTracker to wait for sync to initialize. |
| 819 sync_startup_tracker_.reset(new SyncStartupTracker(profile_, this)); | 831 sync_startup_tracker_.reset(new SyncStartupTracker(profile_, this)); |
| 820 return; | 832 return; |
| 821 } | 833 } |
| 822 | 834 |
| 823 // Should only get here if user is signed in and sync is initialized, so no | |
| 824 // longer need a SyncStartupTracker. | |
| 825 sync_startup_tracker_.reset(); | |
| 826 configuring_sync_ = true; | 835 configuring_sync_ = true; |
| 827 DCHECK(service->IsBackendInitialized()) | 836 DCHECK(service->IsBackendInitialized()) |
| 828 << "Cannot configure sync until the sync backend is initialized"; | 837 << "Cannot configure sync until the sync backend is initialized"; |
| 829 | 838 |
| 830 // Setup args for the sync configure screen: | 839 // Setup args for the sync configure screen: |
| 831 // syncAllDataTypes: true if the user wants to sync everything | 840 // syncAllDataTypes: true if the user wants to sync everything |
| 832 // syncNothing: true if the user wants to sync nothing | 841 // syncNothing: true if the user wants to sync nothing |
| 833 // <data_type>Registered: true if the associated data type is supported | 842 // <data_type>Registered: true if the associated data type is supported |
| 834 // <data_type>Synced: true if the user wants to sync that specific data type | 843 // <data_type>Synced: true if the user wants to sync that specific data type |
| 835 // encryptionEnabled: true if sync supports encryption | 844 // encryptionEnabled: true if sync supports encryption |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 938 base::FilePath profile_file_path = profile_->GetPath(); | 947 base::FilePath profile_file_path = profile_->GetPath(); |
| 939 ProfileMetrics::LogProfileSyncSignIn(profile_file_path); | 948 ProfileMetrics::LogProfileSyncSignIn(profile_file_path); |
| 940 | 949 |
| 941 // We're done configuring, so notify ProfileSyncService that it is OK to | 950 // We're done configuring, so notify ProfileSyncService that it is OK to |
| 942 // start syncing. | 951 // start syncing. |
| 943 service->SetSetupInProgress(false); | 952 service->SetSetupInProgress(false); |
| 944 service->SetFirstSetupComplete(); | 953 service->SetFirstSetupComplete(); |
| 945 } | 954 } |
| 946 | 955 |
| 947 } // namespace settings | 956 } // namespace settings |
| OLD | NEW |