| 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 297 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 308 | 308 |
| 309 if (url.is_valid()) | 309 if (url.is_valid()) |
| 310 chrome::ShowSingletonTab(browser, url); | 310 chrome::ShowSingletonTab(browser, url); |
| 311 } | 311 } |
| 312 #endif | 312 #endif |
| 313 | 313 |
| 314 void PeopleHandler::DisplaySpinner() { | 314 void PeopleHandler::DisplaySpinner() { |
| 315 configuring_sync_ = true; | 315 configuring_sync_ = true; |
| 316 | 316 |
| 317 const int kTimeoutSec = 30; | 317 const int kTimeoutSec = 30; |
| 318 DCHECK(!backend_start_timer_); | 318 DCHECK(!engine_start_timer_); |
| 319 backend_start_timer_.reset(new base::OneShotTimer()); | 319 engine_start_timer_.reset(new base::OneShotTimer()); |
| 320 backend_start_timer_->Start(FROM_HERE, | 320 engine_start_timer_->Start(FROM_HERE, |
| 321 base::TimeDelta::FromSeconds(kTimeoutSec), this, | 321 base::TimeDelta::FromSeconds(kTimeoutSec), this, |
| 322 &PeopleHandler::DisplayTimeout); | 322 &PeopleHandler::DisplayTimeout); |
| 323 | 323 |
| 324 CallJavascriptFunction("cr.webUIListenerCallback", | 324 CallJavascriptFunction("cr.webUIListenerCallback", |
| 325 base::StringValue("page-status-changed"), | 325 base::StringValue("page-status-changed"), |
| 326 base::StringValue(kSpinnerPageStatus)); | 326 base::StringValue(kSpinnerPageStatus)); |
| 327 } | 327 } |
| 328 | 328 |
| 329 // TODO(kochi): Handle error conditions other than timeout. | 329 // TODO(kochi): Handle error conditions other than timeout. |
| 330 // http://crbug.com/128692 | 330 // http://crbug.com/128692 |
| 331 void PeopleHandler::DisplayTimeout() { | 331 void PeopleHandler::DisplayTimeout() { |
| 332 // Stop a timer to handle timeout in waiting for checking network connection. | 332 // Stop a timer to handle timeout in waiting for checking network connection. |
| 333 backend_start_timer_.reset(); | 333 engine_start_timer_.reset(); |
| 334 | 334 |
| 335 // Do not listen to sync startup events. | 335 // Do not listen to sync startup events. |
| 336 sync_startup_tracker_.reset(); | 336 sync_startup_tracker_.reset(); |
| 337 | 337 |
| 338 CallJavascriptFunction("cr.webUIListenerCallback", | 338 CallJavascriptFunction("cr.webUIListenerCallback", |
| 339 base::StringValue("page-status-changed"), | 339 base::StringValue("page-status-changed"), |
| 340 base::StringValue(kTimeoutPageStatus)); | 340 base::StringValue(kTimeoutPageStatus)); |
| 341 } | 341 } |
| 342 | 342 |
| 343 void PeopleHandler::OnDidClosePage(const base::ListValue* args) { | 343 void PeopleHandler::OnDidClosePage(const base::ListValue* args) { |
| 344 MarkFirstSetupComplete(); | 344 MarkFirstSetupComplete(); |
| 345 CloseSyncSetup(); | 345 CloseSyncSetup(); |
| 346 } | 346 } |
| 347 | 347 |
| 348 void PeopleHandler::SyncStartupFailed() { | 348 void PeopleHandler::SyncStartupFailed() { |
| 349 // Stop a timer to handle timeout in waiting for checking network connection. | 349 // Stop a timer to handle timeout in waiting for checking network connection. |
| 350 backend_start_timer_.reset(); | 350 engine_start_timer_.reset(); |
| 351 | 351 |
| 352 // Just close the sync overlay (the idea is that the base settings page will | 352 // Just close the sync overlay (the idea is that the base settings page will |
| 353 // display the current error.) | 353 // display the current error.) |
| 354 CloseUI(); | 354 CloseUI(); |
| 355 } | 355 } |
| 356 | 356 |
| 357 void PeopleHandler::SyncStartupCompleted() { | 357 void PeopleHandler::SyncStartupCompleted() { |
| 358 ProfileSyncService* service = GetSyncService(); | 358 ProfileSyncService* service = GetSyncService(); |
| 359 DCHECK(service->IsBackendInitialized()); | 359 DCHECK(service->IsEngineInitialized()); |
| 360 | 360 |
| 361 // Stop a timer to handle timeout in waiting for checking network connection. | 361 // Stop a timer to handle timeout in waiting for checking network connection. |
| 362 backend_start_timer_.reset(); | 362 engine_start_timer_.reset(); |
| 363 | 363 |
| 364 sync_startup_tracker_.reset(); | 364 sync_startup_tracker_.reset(); |
| 365 | 365 |
| 366 PushSyncPrefs(); | 366 PushSyncPrefs(); |
| 367 } | 367 } |
| 368 | 368 |
| 369 ProfileSyncService* PeopleHandler::GetSyncService() const { | 369 ProfileSyncService* PeopleHandler::GetSyncService() const { |
| 370 return profile_->IsSyncAllowed() | 370 return profile_->IsSyncAllowed() |
| 371 ? ProfileSyncServiceFactory::GetForProfile(profile_) | 371 ? ProfileSyncServiceFactory::GetForProfile(profile_) |
| 372 : nullptr; | 372 : nullptr; |
| 373 } | 373 } |
| 374 | 374 |
| 375 void PeopleHandler::HandleSetDatatypes(const base::ListValue* args) { | 375 void PeopleHandler::HandleSetDatatypes(const base::ListValue* args) { |
| 376 DCHECK(!sync_startup_tracker_); | 376 DCHECK(!sync_startup_tracker_); |
| 377 | 377 |
| 378 SyncConfigInfo configuration; | 378 SyncConfigInfo configuration; |
| 379 const base::Value* callback_id = nullptr; | 379 const base::Value* callback_id = nullptr; |
| 380 ParseConfigurationArguments(args, &configuration, &callback_id); | 380 ParseConfigurationArguments(args, &configuration, &callback_id); |
| 381 | 381 |
| 382 PrefService* pref_service = profile_->GetPrefs(); | 382 PrefService* pref_service = profile_->GetPrefs(); |
| 383 pref_service->SetBoolean(autofill::prefs::kAutofillWalletImportEnabled, | 383 pref_service->SetBoolean(autofill::prefs::kAutofillWalletImportEnabled, |
| 384 configuration.payments_integration_enabled); | 384 configuration.payments_integration_enabled); |
| 385 | 385 |
| 386 // Start configuring the ProfileSyncService using the configuration passed | 386 // Start configuring the ProfileSyncService using the configuration passed |
| 387 // to us from the JS layer. | 387 // to us from the JS layer. |
| 388 ProfileSyncService* service = GetSyncService(); | 388 ProfileSyncService* service = GetSyncService(); |
| 389 | 389 |
| 390 // If the sync engine has shutdown for some reason, just close the sync | 390 // If the sync engine has shutdown for some reason, just close the sync |
| 391 // dialog. | 391 // dialog. |
| 392 if (!service || !service->IsBackendInitialized()) { | 392 if (!service || !service->IsEngineInitialized()) { |
| 393 CloseSyncSetup(); | 393 CloseSyncSetup(); |
| 394 ResolveJavascriptCallback(*callback_id, base::StringValue(kDonePageStatus)); | 394 ResolveJavascriptCallback(*callback_id, base::StringValue(kDonePageStatus)); |
| 395 return; | 395 return; |
| 396 } | 396 } |
| 397 | 397 |
| 398 service->OnUserChoseDatatypes(configuration.sync_everything, | 398 service->OnUserChoseDatatypes(configuration.sync_everything, |
| 399 configuration.data_types); | 399 configuration.data_types); |
| 400 | 400 |
| 401 // Choosing data types to sync never fails. | 401 // Choosing data types to sync never fails. |
| 402 ResolveJavascriptCallback(*callback_id, | 402 ResolveJavascriptCallback(*callback_id, |
| (...skipping 10 matching lines...) Expand all Loading... |
| 413 SyncConfigInfo configuration; | 413 SyncConfigInfo configuration; |
| 414 const base::Value* callback_id = nullptr; | 414 const base::Value* callback_id = nullptr; |
| 415 ParseConfigurationArguments(args, &configuration, &callback_id); | 415 ParseConfigurationArguments(args, &configuration, &callback_id); |
| 416 | 416 |
| 417 // Start configuring the ProfileSyncService using the configuration passed | 417 // Start configuring the ProfileSyncService using the configuration passed |
| 418 // to us from the JS layer. | 418 // to us from the JS layer. |
| 419 ProfileSyncService* service = GetSyncService(); | 419 ProfileSyncService* service = GetSyncService(); |
| 420 | 420 |
| 421 // If the sync engine has shutdown for some reason, just close the sync | 421 // If the sync engine has shutdown for some reason, just close the sync |
| 422 // dialog. | 422 // dialog. |
| 423 if (!service || !service->IsBackendInitialized()) { | 423 if (!service || !service->IsEngineInitialized()) { |
| 424 CloseSyncSetup(); | 424 CloseSyncSetup(); |
| 425 ResolveJavascriptCallback(*callback_id, base::StringValue(kDonePageStatus)); | 425 ResolveJavascriptCallback(*callback_id, base::StringValue(kDonePageStatus)); |
| 426 return; | 426 return; |
| 427 } | 427 } |
| 428 | 428 |
| 429 // Don't allow "encrypt all" if the ProfileSyncService doesn't allow it. | 429 // Don't allow "encrypt all" if the ProfileSyncService doesn't allow it. |
| 430 // The UI is hidden, but the user may have enabled it e.g. by fiddling with | 430 // The UI is hidden, but the user may have enabled it e.g. by fiddling with |
| 431 // the web inspector. | 431 // the web inspector. |
| 432 if (!service->IsEncryptEverythingAllowed()) | 432 if (!service->IsEncryptEverythingAllowed()) |
| 433 configuration.encrypt_all = false; | 433 configuration.encrypt_all = false; |
| 434 | 434 |
| 435 // Note: Data encryption will not occur until configuration is complete | 435 // Note: Data encryption will not occur until configuration is complete |
| 436 // (when the PSS receives its CONFIGURE_DONE notification from the sync | 436 // (when the PSS receives its CONFIGURE_DONE notification from the sync |
| 437 // backend), so the user still has a chance to cancel out of the operation | 437 // engine), so the user still has a chance to cancel out of the operation |
| 438 // if (for example) some kind of passphrase error is encountered. | 438 // if (for example) some kind of passphrase error is encountered. |
| 439 if (configuration.encrypt_all) | 439 if (configuration.encrypt_all) |
| 440 service->EnableEncryptEverything(); | 440 service->EnableEncryptEverything(); |
| 441 | 441 |
| 442 bool passphrase_failed = false; | 442 bool passphrase_failed = false; |
| 443 if (!configuration.passphrase.empty()) { | 443 if (!configuration.passphrase.empty()) { |
| 444 // We call IsPassphraseRequired() here (instead of | 444 // We call IsPassphraseRequired() here (instead of |
| 445 // IsPassphraseRequiredForDecryption()) because the user may try to enter | 445 // IsPassphraseRequiredForDecryption()) because the user may try to enter |
| 446 // a passphrase even though no encrypted data types are enabled. | 446 // a passphrase even though no encrypted data types are enabled. |
| 447 if (service->IsPassphraseRequired()) { | 447 if (service->IsPassphraseRequired()) { |
| (...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 561 ResolveJavascriptCallback(*callback_id, *GetSyncStatusDictionary()); | 561 ResolveJavascriptCallback(*callback_id, *GetSyncStatusDictionary()); |
| 562 } | 562 } |
| 563 | 563 |
| 564 void PeopleHandler::HandleManageOtherPeople(const base::ListValue* /* args */) { | 564 void PeopleHandler::HandleManageOtherPeople(const base::ListValue* /* args */) { |
| 565 UserManager::Show(base::FilePath(), profiles::USER_MANAGER_NO_TUTORIAL, | 565 UserManager::Show(base::FilePath(), profiles::USER_MANAGER_NO_TUTORIAL, |
| 566 profiles::USER_MANAGER_SELECT_PROFILE_NO_ACTION); | 566 profiles::USER_MANAGER_SELECT_PROFILE_NO_ACTION); |
| 567 } | 567 } |
| 568 | 568 |
| 569 void PeopleHandler::CloseSyncSetup() { | 569 void PeopleHandler::CloseSyncSetup() { |
| 570 // Stop a timer to handle timeout in waiting for checking network connection. | 570 // Stop a timer to handle timeout in waiting for checking network connection. |
| 571 backend_start_timer_.reset(); | 571 engine_start_timer_.reset(); |
| 572 | 572 |
| 573 // Clear the sync startup tracker, since the setup wizard is being closed. | 573 // Clear the sync startup tracker, since the setup wizard is being closed. |
| 574 sync_startup_tracker_.reset(); | 574 sync_startup_tracker_.reset(); |
| 575 | 575 |
| 576 ProfileSyncService* sync_service = GetSyncService(); | 576 ProfileSyncService* sync_service = GetSyncService(); |
| 577 | 577 |
| 578 // LoginUIService can be nullptr if page is brought up in incognito mode | 578 // LoginUIService can be nullptr if page is brought up in incognito mode |
| 579 // (i.e. if the user is running in guest mode in cros and brings up settings). | 579 // (i.e. if the user is running in guest mode in cros and brings up settings). |
| 580 LoginUIService* service = GetLoginUIService(); | 580 LoginUIService* service = GetLoginUIService(); |
| 581 if (service) { | 581 if (service) { |
| 582 // Don't log a cancel event if the sync setup dialog is being | 582 // Don't log a cancel event if the sync setup dialog is being |
| 583 // automatically closed due to an auth error. | 583 // automatically closed due to an auth error. |
| 584 if ((service->current_login_ui() == this) && | 584 if ((service->current_login_ui() == this) && |
| 585 (!sync_service || (!sync_service->IsFirstSetupComplete() && | 585 (!sync_service || (!sync_service->IsFirstSetupComplete() && |
| 586 sync_service->GetAuthError().state() == | 586 sync_service->GetAuthError().state() == |
| 587 GoogleServiceAuthError::NONE))) { | 587 GoogleServiceAuthError::NONE))) { |
| 588 if (configuring_sync_) { | 588 if (configuring_sync_) { |
| 589 ProfileSyncService::SyncEvent( | 589 ProfileSyncService::SyncEvent( |
| 590 ProfileSyncService::CANCEL_DURING_CONFIGURE); | 590 ProfileSyncService::CANCEL_DURING_CONFIGURE); |
| 591 | 591 |
| 592 // If the user clicked "Cancel" while setting up sync, disable sync | 592 // If the user clicked "Cancel" while setting up sync, disable sync |
| 593 // because we don't want the sync backend to remain in the | 593 // because we don't want the sync engine to remain in the |
| 594 // first-setup-incomplete state. | 594 // first-setup-incomplete state. |
| 595 // Note: In order to disable sync across restarts on Chrome OS, | 595 // Note: In order to disable sync across restarts on Chrome OS, |
| 596 // we must call RequestStop(CLEAR_DATA), which suppresses sync startup | 596 // we must call RequestStop(CLEAR_DATA), which suppresses sync startup |
| 597 // in addition to disabling it. | 597 // in addition to disabling it. |
| 598 if (sync_service) { | 598 if (sync_service) { |
| 599 DVLOG(1) << "Sync setup aborted by user action"; | 599 DVLOG(1) << "Sync setup aborted by user action"; |
| 600 sync_service->RequestStop(ProfileSyncService::CLEAR_DATA); | 600 sync_service->RequestStop(ProfileSyncService::CLEAR_DATA); |
| 601 #if !defined(OS_CHROMEOS) | 601 #if !defined(OS_CHROMEOS) |
| 602 // Sign out the user on desktop Chrome if they click cancel during | 602 // Sign out the user on desktop Chrome if they click cancel during |
| 603 // initial setup. | 603 // initial setup. |
| (...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 772 return; | 772 return; |
| 773 } | 773 } |
| 774 #endif | 774 #endif |
| 775 | 775 |
| 776 // Early exit if there is already a preferences push pending sync startup. | 776 // Early exit if there is already a preferences push pending sync startup. |
| 777 if (sync_startup_tracker_) | 777 if (sync_startup_tracker_) |
| 778 return; | 778 return; |
| 779 | 779 |
| 780 ProfileSyncService* service = GetSyncService(); | 780 ProfileSyncService* service = GetSyncService(); |
| 781 DCHECK(service); | 781 DCHECK(service); |
| 782 if (!service->IsBackendInitialized()) { | 782 if (!service->IsEngineInitialized()) { |
| 783 service->RequestStart(); | 783 service->RequestStart(); |
| 784 | 784 |
| 785 // See if it's even possible to bring up the sync backend - if not | 785 // See if it's even possible to bring up the sync engine - if not |
| 786 // (unrecoverable error?), don't bother displaying a spinner that will be | 786 // (unrecoverable error?), don't bother displaying a spinner that will be |
| 787 // immediately closed because this leads to some ugly infinite UI loop (see | 787 // immediately closed because this leads to some ugly infinite UI loop (see |
| 788 // http://crbug.com/244769). | 788 // http://crbug.com/244769). |
| 789 if (SyncStartupTracker::GetSyncServiceState(profile_) != | 789 if (SyncStartupTracker::GetSyncServiceState(profile_) != |
| 790 SyncStartupTracker::SYNC_STARTUP_ERROR) { | 790 SyncStartupTracker::SYNC_STARTUP_ERROR) { |
| 791 DisplaySpinner(); | 791 DisplaySpinner(); |
| 792 } | 792 } |
| 793 | 793 |
| 794 // Start SyncSetupTracker to wait for sync to initialize. | 794 // Start SyncSetupTracker to wait for sync to initialize. |
| 795 sync_startup_tracker_.reset(new SyncStartupTracker(profile_, this)); | 795 sync_startup_tracker_.reset(new SyncStartupTracker(profile_, this)); |
| 796 return; | 796 return; |
| 797 } | 797 } |
| 798 | 798 |
| 799 configuring_sync_ = true; | 799 configuring_sync_ = true; |
| 800 DCHECK(service->IsBackendInitialized()) | 800 DCHECK(service->IsEngineInitialized()) |
| 801 << "Cannot configure sync until the sync backend is initialized"; | 801 << "Cannot configure sync until the sync engine is initialized"; |
| 802 | 802 |
| 803 // Setup args for the sync configure screen: | 803 // Setup args for the sync configure screen: |
| 804 // syncAllDataTypes: true if the user wants to sync everything | 804 // syncAllDataTypes: true if the user wants to sync everything |
| 805 // <data_type>Registered: true if the associated data type is supported | 805 // <data_type>Registered: true if the associated data type is supported |
| 806 // <data_type>Synced: true if the user wants to sync that specific data type | 806 // <data_type>Synced: true if the user wants to sync that specific data type |
| 807 // paymentsIntegrationEnabled: true if the user wants Payments integration | 807 // paymentsIntegrationEnabled: true if the user wants Payments integration |
| 808 // encryptionEnabled: true if sync supports encryption | 808 // encryptionEnabled: true if sync supports encryption |
| 809 // encryptAllData: true if user wants to encrypt all data (not just | 809 // encryptAllData: true if user wants to encrypt all data (not just |
| 810 // passwords) | 810 // passwords) |
| 811 // passphraseRequired: true if a passphrase is needed to start sync | 811 // passphraseRequired: true if a passphrase is needed to start sync |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 913 base::FilePath profile_file_path = profile_->GetPath(); | 913 base::FilePath profile_file_path = profile_->GetPath(); |
| 914 ProfileMetrics::LogProfileSyncSignIn(profile_file_path); | 914 ProfileMetrics::LogProfileSyncSignIn(profile_file_path); |
| 915 | 915 |
| 916 // We're done configuring, so notify ProfileSyncService that it is OK to | 916 // We're done configuring, so notify ProfileSyncService that it is OK to |
| 917 // start syncing. | 917 // start syncing. |
| 918 sync_blocker_.reset(); | 918 sync_blocker_.reset(); |
| 919 service->SetFirstSetupComplete(); | 919 service->SetFirstSetupComplete(); |
| 920 } | 920 } |
| 921 | 921 |
| 922 } // namespace settings | 922 } // namespace settings |
| OLD | NEW |