Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(104)

Side by Side Diff: chrome/browser/ui/webui/options/sync_setup_handler.cc

Issue 2551023006: [Sync] SyncEngine 1.5: Fix all backend references in PSS. (Closed)
Patch Set: Fix Android. Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/options/sync_setup_handler.h" 5 #include "chrome/browser/ui/webui/options/sync_setup_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 413 matching lines...) Expand 10 before | Expand all | Expand 10 after
424 424
425 return true; 425 return true;
426 } 426 }
427 427
428 void SyncSetupHandler::DisplaySpinner() { 428 void SyncSetupHandler::DisplaySpinner() {
429 configuring_sync_ = true; 429 configuring_sync_ = true;
430 base::StringValue page("spinner"); 430 base::StringValue page("spinner");
431 base::DictionaryValue args; 431 base::DictionaryValue args;
432 432
433 const int kTimeoutSec = 30; 433 const int kTimeoutSec = 30;
434 DCHECK(!backend_start_timer_); 434 DCHECK(!engine_start_timer_);
435 backend_start_timer_.reset(new base::OneShotTimer()); 435 engine_start_timer_.reset(new base::OneShotTimer());
436 backend_start_timer_->Start(FROM_HERE, 436 engine_start_timer_->Start(FROM_HERE,
437 base::TimeDelta::FromSeconds(kTimeoutSec), 437 base::TimeDelta::FromSeconds(kTimeoutSec), this,
438 this, &SyncSetupHandler::DisplayTimeout); 438 &SyncSetupHandler::DisplayTimeout);
439 439
440 web_ui()->CallJavascriptFunctionUnsafe("SyncSetupOverlay.showSyncSetupPage", 440 web_ui()->CallJavascriptFunctionUnsafe("SyncSetupOverlay.showSyncSetupPage",
441 page, args); 441 page, args);
442 } 442 }
443 443
444 // TODO(kochi): Handle error conditions other than timeout. 444 // TODO(kochi): Handle error conditions other than timeout.
445 // http://crbug.com/128692 445 // http://crbug.com/128692
446 void SyncSetupHandler::DisplayTimeout() { 446 void SyncSetupHandler::DisplayTimeout() {
447 // Stop a timer to handle timeout in waiting for checking network connection. 447 // Stop a timer to handle timeout in waiting for checking network connection.
448 backend_start_timer_.reset(); 448 engine_start_timer_.reset();
449 449
450 // Do not listen to sync startup events. 450 // Do not listen to sync startup events.
451 sync_startup_tracker_.reset(); 451 sync_startup_tracker_.reset();
452 452
453 base::StringValue page("timeout"); 453 base::StringValue page("timeout");
454 base::DictionaryValue args; 454 base::DictionaryValue args;
455 web_ui()->CallJavascriptFunctionUnsafe("SyncSetupOverlay.showSyncSetupPage", 455 web_ui()->CallJavascriptFunctionUnsafe("SyncSetupOverlay.showSyncSetupPage",
456 page, args); 456 page, args);
457 } 457 }
458 458
459 void SyncSetupHandler::OnDidClosePage(const base::ListValue* args) { 459 void SyncSetupHandler::OnDidClosePage(const base::ListValue* args) {
460 CloseSyncSetup(); 460 CloseSyncSetup();
461 } 461 }
462 462
463 void SyncSetupHandler::SyncStartupFailed() { 463 void SyncSetupHandler::SyncStartupFailed() {
464 // Stop a timer to handle timeout in waiting for checking network connection. 464 // Stop a timer to handle timeout in waiting for checking network connection.
465 backend_start_timer_.reset(); 465 engine_start_timer_.reset();
466 466
467 // Just close the sync overlay (the idea is that the base settings page will 467 // Just close the sync overlay (the idea is that the base settings page will
468 // display the current error.) 468 // display the current error.)
469 CloseUI(); 469 CloseUI();
470 } 470 }
471 471
472 void SyncSetupHandler::SyncStartupCompleted() { 472 void SyncSetupHandler::SyncStartupCompleted() {
473 ProfileSyncService* service = GetSyncService(); 473 ProfileSyncService* service = GetSyncService();
474 DCHECK(service->IsBackendInitialized()); 474 DCHECK(service->IsEngineInitialized());
475 475
476 // Stop a timer to handle timeout in waiting for checking network connection. 476 // Stop a timer to handle timeout in waiting for checking network connection.
477 backend_start_timer_.reset(); 477 engine_start_timer_.reset();
478 478
479 DisplayConfigureSync(false); 479 DisplayConfigureSync(false);
480 } 480 }
481 481
482 Profile* SyncSetupHandler::GetProfile() const { 482 Profile* SyncSetupHandler::GetProfile() const {
483 return Profile::FromWebUI(web_ui()); 483 return Profile::FromWebUI(web_ui());
484 } 484 }
485 485
486 ProfileSyncService* SyncSetupHandler::GetSyncService() const { 486 ProfileSyncService* SyncSetupHandler::GetSyncService() const {
487 Profile* profile = GetProfile(); 487 Profile* profile = GetProfile();
(...skipping 20 matching lines...) Expand all
508 NOTREACHED(); 508 NOTREACHED();
509 return; 509 return;
510 } 510 }
511 511
512 // Start configuring the ProfileSyncService using the configuration passed 512 // Start configuring the ProfileSyncService using the configuration passed
513 // to us from the JS layer. 513 // to us from the JS layer.
514 ProfileSyncService* service = GetSyncService(); 514 ProfileSyncService* service = GetSyncService();
515 515
516 // If the sync engine has shutdown for some reason, just close the sync 516 // If the sync engine has shutdown for some reason, just close the sync
517 // dialog. 517 // dialog.
518 if (!service || !service->IsBackendInitialized()) { 518 if (!service || !service->IsEngineInitialized()) {
519 CloseUI(); 519 CloseUI();
520 return; 520 return;
521 } 521 }
522 522
523 // Don't allow "encrypt all" if the ProfileSyncService doesn't allow it. 523 // Don't allow "encrypt all" if the ProfileSyncService doesn't allow it.
524 // The UI is hidden, but the user may have enabled it e.g. by fiddling with 524 // The UI is hidden, but the user may have enabled it e.g. by fiddling with
525 // the web inspector. 525 // the web inspector.
526 if (!service->IsEncryptEverythingAllowed()) 526 if (!service->IsEncryptEverythingAllowed())
527 configuration.encrypt_all = false; 527 configuration.encrypt_all = false;
528 528
529 // Note: Data encryption will not occur until configuration is complete 529 // Note: Data encryption will not occur until configuration is complete
530 // (when the PSS receives its CONFIGURE_DONE notification from the sync 530 // (when the PSS receives its CONFIGURE_DONE notification from the sync
531 // backend), so the user still has a chance to cancel out of the operation 531 // engine), so the user still has a chance to cancel out of the operation
532 // if (for example) some kind of passphrase error is encountered. 532 // if (for example) some kind of passphrase error is encountered.
533 if (configuration.encrypt_all) 533 if (configuration.encrypt_all)
534 service->EnableEncryptEverything(); 534 service->EnableEncryptEverything();
535 535
536 bool passphrase_failed = false; 536 bool passphrase_failed = false;
537 if (!configuration.passphrase.empty()) { 537 if (!configuration.passphrase.empty()) {
538 // We call IsPassphraseRequired() here (instead of 538 // We call IsPassphraseRequired() here (instead of
539 // IsPassphraseRequiredForDecryption()) because the user may try to enter 539 // IsPassphraseRequiredForDecryption()) because the user may try to enter
540 // a passphrase even though no encrypted data types are enabled. 540 // a passphrase even though no encrypted data types are enabled.
541 if (service->IsPassphraseRequired()) { 541 if (service->IsPassphraseRequired()) {
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after
674 } 674 }
675 } 675 }
676 #endif 676 #endif
677 677
678 void SyncSetupHandler::HandleCloseTimeout(const base::ListValue* args) { 678 void SyncSetupHandler::HandleCloseTimeout(const base::ListValue* args) {
679 CloseSyncSetup(); 679 CloseSyncSetup();
680 } 680 }
681 681
682 void SyncSetupHandler::CloseSyncSetup() { 682 void SyncSetupHandler::CloseSyncSetup() {
683 // Stop a timer to handle timeout in waiting for checking network connection. 683 // Stop a timer to handle timeout in waiting for checking network connection.
684 backend_start_timer_.reset(); 684 engine_start_timer_.reset();
685 685
686 // Clear the sync startup tracker, since the setup wizard is being closed. 686 // Clear the sync startup tracker, since the setup wizard is being closed.
687 sync_startup_tracker_.reset(); 687 sync_startup_tracker_.reset();
688 688
689 ProfileSyncService* sync_service = GetSyncService(); 689 ProfileSyncService* sync_service = GetSyncService();
690 if (IsActiveLogin()) { 690 if (IsActiveLogin()) {
691 // Don't log a cancel event if the sync setup dialog is being 691 // Don't log a cancel event if the sync setup dialog is being
692 // automatically closed due to an auth error. 692 // automatically closed due to an auth error.
693 if (!sync_service || (!sync_service->IsFirstSetupComplete() && 693 if (!sync_service || (!sync_service->IsFirstSetupComplete() &&
694 sync_service->GetAuthError().state() == 694 sync_service->GetAuthError().state() ==
695 GoogleServiceAuthError::NONE)) { 695 GoogleServiceAuthError::NONE)) {
696 if (configuring_sync_) { 696 if (configuring_sync_) {
697 ProfileSyncService::SyncEvent( 697 ProfileSyncService::SyncEvent(
698 ProfileSyncService::CANCEL_DURING_CONFIGURE); 698 ProfileSyncService::CANCEL_DURING_CONFIGURE);
699 699
700 // If the user clicked "Cancel" while setting up sync, disable sync 700 // If the user clicked "Cancel" while setting up sync, disable sync
701 // because we don't want the sync backend to remain in the 701 // because we don't want the sync engine to remain in the
702 // first-setup-incomplete state. 702 // first-setup-incomplete state.
703 // Note: In order to disable sync across restarts on Chrome OS, 703 // Note: In order to disable sync across restarts on Chrome OS,
704 // we must call RequestStop(CLEAR_DATA), which suppresses sync startup 704 // we must call RequestStop(CLEAR_DATA), which suppresses sync startup
705 // in addition to disabling it. 705 // in addition to disabling it.
706 if (sync_service) { 706 if (sync_service) {
707 DVLOG(1) << "Sync setup aborted by user action"; 707 DVLOG(1) << "Sync setup aborted by user action";
708 sync_service->RequestStop(ProfileSyncService::CLEAR_DATA); 708 sync_service->RequestStop(ProfileSyncService::CLEAR_DATA);
709 #if !defined(OS_CHROMEOS) 709 #if !defined(OS_CHROMEOS)
710 // Sign out the user on desktop Chrome if they click cancel during 710 // Sign out the user on desktop Chrome if they click cancel during
711 // initial setup. 711 // initial setup.
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
814 service->current_login_ui()->FocusUI(); 814 service->current_login_ui()->FocusUI();
815 return true; 815 return true;
816 } 816 }
817 817
818 void SyncSetupHandler::DisplayConfigureSync(bool passphrase_failed) { 818 void SyncSetupHandler::DisplayConfigureSync(bool passphrase_failed) {
819 // Should never call this when we are not signed in. 819 // Should never call this when we are not signed in.
820 DCHECK(SigninManagerFactory::GetForProfile( 820 DCHECK(SigninManagerFactory::GetForProfile(
821 GetProfile())->IsAuthenticated()); 821 GetProfile())->IsAuthenticated());
822 ProfileSyncService* service = GetSyncService(); 822 ProfileSyncService* service = GetSyncService();
823 DCHECK(service); 823 DCHECK(service);
824 if (!service->IsBackendInitialized()) { 824 if (!service->IsEngineInitialized()) {
825 service->RequestStart(); 825 service->RequestStart();
826 826
827 // See if it's even possible to bring up the sync backend - if not 827 // See if it's even possible to bring up the sync engine - if not
828 // (unrecoverable error?), don't bother displaying a spinner that will be 828 // (unrecoverable error?), don't bother displaying a spinner that will be
829 // immediately closed because this leads to some ugly infinite UI loop (see 829 // immediately closed because this leads to some ugly infinite UI loop (see
830 // http://crbug.com/244769). 830 // http://crbug.com/244769).
831 if (SyncStartupTracker::GetSyncServiceState(GetProfile()) != 831 if (SyncStartupTracker::GetSyncServiceState(GetProfile()) !=
832 SyncStartupTracker::SYNC_STARTUP_ERROR) { 832 SyncStartupTracker::SYNC_STARTUP_ERROR) {
833 DisplaySpinner(); 833 DisplaySpinner();
834 } 834 }
835 835
836 // Start SyncSetupTracker to wait for sync to initialize. 836 // Start SyncSetupTracker to wait for sync to initialize.
837 sync_startup_tracker_.reset( 837 sync_startup_tracker_.reset(
838 new SyncStartupTracker(GetProfile(), this)); 838 new SyncStartupTracker(GetProfile(), this));
839 return; 839 return;
840 } 840 }
841 841
842 // Should only get here if user is signed in and sync is initialized, so no 842 // Should only get here if user is signed in and sync is initialized, so no
843 // longer need a SyncStartupTracker. 843 // longer need a SyncStartupTracker.
844 sync_startup_tracker_.reset(); 844 sync_startup_tracker_.reset();
845 configuring_sync_ = true; 845 configuring_sync_ = true;
846 DCHECK(service->IsBackendInitialized()) 846 DCHECK(service->IsEngineInitialized())
847 << "Cannot configure sync until the sync backend is initialized"; 847 << "Cannot configure sync until the sync engine is initialized";
848 848
849 // Setup args for the sync configure screen: 849 // Setup args for the sync configure screen:
850 // syncAllDataTypes: true if the user wants to sync everything 850 // syncAllDataTypes: true if the user wants to sync everything
851 // syncNothing: true if the user wants to sync nothing 851 // syncNothing: true if the user wants to sync nothing
852 // <data_type>Registered: true if the associated data type is supported 852 // <data_type>Registered: true if the associated data type is supported
853 // <data_type>Synced: true if the user wants to sync that specific data type 853 // <data_type>Synced: true if the user wants to sync that specific data type
854 // paymentsIntegrationEnabled: true if the user wants Payments integration 854 // paymentsIntegrationEnabled: true if the user wants Payments integration
855 // encryptionEnabled: true if sync supports encryption 855 // encryptionEnabled: true if sync supports encryption
856 // encryptAllData: true if user wants to encrypt all data (not just 856 // encryptAllData: true if user wants to encrypt all data (not just
857 // passwords) 857 // passwords)
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
944 page, args); 944 page, args);
945 945
946 // Make sure the tab used for the Gaia sign in does not cover the settings 946 // Make sure the tab used for the Gaia sign in does not cover the settings
947 // tab. 947 // tab.
948 FocusUI(); 948 FocusUI();
949 } 949 }
950 950
951 LoginUIService* SyncSetupHandler::GetLoginUIService() const { 951 LoginUIService* SyncSetupHandler::GetLoginUIService() const {
952 return LoginUIServiceFactory::GetForProfile(GetProfile()); 952 return LoginUIServiceFactory::GetForProfile(GetProfile());
953 } 953 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/webui/options/sync_setup_handler.h ('k') | chrome/browser/ui/webui/options/sync_setup_handler_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698