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

Side by Side Diff: components/sync/driver/glue/sync_backend_host_impl.cc

Issue 2545973003: [Sync] Remove !frontend_ checks in SBHI. (Closed)
Patch Set: 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 "components/sync/driver/glue/sync_backend_host_impl.h" 5 #include "components/sync/driver/glue/sync_backend_host_impl.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/command_line.h" 10 #include "base/command_line.h"
(...skipping 510 matching lines...) Expand 10 before | Expand all | Expand 10 after
521 FROM_HERE, 521 FROM_HERE,
522 base::Bind(&SyncBackendHostCore::DoConfigureSyncer, core_, reason, 522 base::Bind(&SyncBackendHostCore::DoConfigureSyncer, core_, reason,
523 config_types, routing_info, ready_task, retry_callback)); 523 config_types, routing_info, ready_task, retry_callback));
524 } 524 }
525 525
526 void SyncBackendHostImpl::FinishConfigureDataTypesOnFrontendLoop( 526 void SyncBackendHostImpl::FinishConfigureDataTypesOnFrontendLoop(
527 const ModelTypeSet enabled_types, 527 const ModelTypeSet enabled_types,
528 const ModelTypeSet succeeded_configuration_types, 528 const ModelTypeSet succeeded_configuration_types,
529 const ModelTypeSet failed_configuration_types, 529 const ModelTypeSet failed_configuration_types,
530 const base::Callback<void(ModelTypeSet, ModelTypeSet)>& ready_task) { 530 const base::Callback<void(ModelTypeSet, ModelTypeSet)>& ready_task) {
531 if (!frontend_)
532 return;
533
534 if (invalidator_) { 531 if (invalidator_) {
535 CHECK(invalidator_->UpdateRegisteredInvalidationIds( 532 CHECK(invalidator_->UpdateRegisteredInvalidationIds(
536 this, ModelTypeSetToObjectIdSet(enabled_types))); 533 this, ModelTypeSetToObjectIdSet(enabled_types)));
537 } 534 }
538 535
539 if (!ready_task.is_null()) 536 if (!ready_task.is_null())
540 ready_task.Run(succeeded_configuration_types, failed_configuration_types); 537 ready_task.Run(succeeded_configuration_types, failed_configuration_types);
541 } 538 }
542 539
543 void SyncBackendHostImpl::AddExperimentalTypes() { 540 void SyncBackendHostImpl::AddExperimentalTypes() {
544 CHECK(initialized()); 541 CHECK(initialized());
545 Experiments experiments; 542 Experiments experiments;
546 if (core_->sync_manager()->ReceivedExperiment(&experiments)) 543 if (core_->sync_manager()->ReceivedExperiment(&experiments))
547 frontend_->OnExperimentsChanged(experiments); 544 frontend_->OnExperimentsChanged(experiments);
548 } 545 }
549 546
550 void SyncBackendHostImpl::HandleInitializationSuccessOnFrontendLoop( 547 void SyncBackendHostImpl::HandleInitializationSuccessOnFrontendLoop(
551 const WeakHandle<JsBackend> js_backend, 548 const WeakHandle<JsBackend> js_backend,
552 const WeakHandle<DataTypeDebugInfoListener> debug_info_listener, 549 const WeakHandle<DataTypeDebugInfoListener> debug_info_listener,
553 std::unique_ptr<ModelTypeConnector> model_type_connector, 550 std::unique_ptr<ModelTypeConnector> model_type_connector,
554 const std::string& cache_guid) { 551 const std::string& cache_guid) {
555 DCHECK(thread_checker_.CalledOnValidThread()); 552 DCHECK(thread_checker_.CalledOnValidThread());
556 553
557 model_type_connector_ = std::move(model_type_connector); 554 model_type_connector_ = std::move(model_type_connector);
558 555
559 if (!frontend_)
560 return;
561
562 initialized_ = true; 556 initialized_ = true;
563 557
564 if (invalidator_) { 558 if (invalidator_) {
565 invalidator_->RegisterInvalidationHandler(this); 559 invalidator_->RegisterInvalidationHandler(this);
566 invalidation_handler_registered_ = true; 560 invalidation_handler_registered_ = true;
567 561
568 // Fake a state change to initialize the SyncManager's cached invalidator 562 // Fake a state change to initialize the SyncManager's cached invalidator
569 // state. 563 // state.
570 OnInvalidatorStateChange(invalidator_->GetInvalidatorState()); 564 OnInvalidatorStateChange(invalidator_->GetInvalidatorState());
571 } 565 }
572 566
573 // Now that we've downloaded the control types, we can see if there are any 567 // Now that we've downloaded the control types, we can see if there are any
574 // experimental types to enable. This should be done before we inform 568 // experimental types to enable. This should be done before we inform
575 // the frontend to ensure they're visible in the customize screen. 569 // the frontend to ensure they're visible in the customize screen.
576 AddExperimentalTypes(); 570 AddExperimentalTypes();
577 frontend_->OnBackendInitialized(js_backend, debug_info_listener, cache_guid, 571 frontend_->OnBackendInitialized(js_backend, debug_info_listener, cache_guid,
578 true); 572 true);
579 } 573 }
580 574
581 void SyncBackendHostImpl::HandleInitializationFailureOnFrontendLoop() { 575 void SyncBackendHostImpl::HandleInitializationFailureOnFrontendLoop() {
582 DCHECK(thread_checker_.CalledOnValidThread()); 576 DCHECK(thread_checker_.CalledOnValidThread());
583 if (!frontend_)
584 return;
585
586 frontend_->OnBackendInitialized(WeakHandle<JsBackend>(), 577 frontend_->OnBackendInitialized(WeakHandle<JsBackend>(),
587 WeakHandle<DataTypeDebugInfoListener>(), "", 578 WeakHandle<DataTypeDebugInfoListener>(), "",
588 false); 579 false);
589 } 580 }
590 581
591 void SyncBackendHostImpl::HandleSyncCycleCompletedOnFrontendLoop( 582 void SyncBackendHostImpl::HandleSyncCycleCompletedOnFrontendLoop(
592 const SyncCycleSnapshot& snapshot) { 583 const SyncCycleSnapshot& snapshot) {
593 if (!frontend_)
594 return;
595 DCHECK(thread_checker_.CalledOnValidThread()); 584 DCHECK(thread_checker_.CalledOnValidThread());
596 585
597 last_snapshot_ = snapshot; 586 last_snapshot_ = snapshot;
598 587
599 SDVLOG(1) << "Got snapshot " << snapshot.ToString(); 588 SDVLOG(1) << "Got snapshot " << snapshot.ToString();
600 589
601 if (!snapshot.poll_finish_time().is_null()) 590 if (!snapshot.poll_finish_time().is_null())
602 sync_prefs_->SetLastPollTime(snapshot.poll_finish_time()); 591 sync_prefs_->SetLastPollTime(snapshot.poll_finish_time());
603 592
604 // Process any changes to the datatypes we're syncing. 593 // Process any changes to the datatypes we're syncing.
(...skipping 16 matching lines...) Expand all
621 BootstrapTokenType token_type) { 610 BootstrapTokenType token_type) {
622 CHECK(sync_prefs_.get()); 611 CHECK(sync_prefs_.get());
623 if (token_type == PASSPHRASE_BOOTSTRAP_TOKEN) 612 if (token_type == PASSPHRASE_BOOTSTRAP_TOKEN)
624 sync_prefs_->SetEncryptionBootstrapToken(token); 613 sync_prefs_->SetEncryptionBootstrapToken(token);
625 else 614 else
626 sync_prefs_->SetKeystoreEncryptionBootstrapToken(token); 615 sync_prefs_->SetKeystoreEncryptionBootstrapToken(token);
627 } 616 }
628 617
629 void SyncBackendHostImpl::HandleActionableErrorEventOnFrontendLoop( 618 void SyncBackendHostImpl::HandleActionableErrorEventOnFrontendLoop(
630 const SyncProtocolError& sync_error) { 619 const SyncProtocolError& sync_error) {
631 if (!frontend_)
632 return;
633 DCHECK(thread_checker_.CalledOnValidThread()); 620 DCHECK(thread_checker_.CalledOnValidThread());
634 frontend_->OnActionableError(sync_error); 621 frontend_->OnActionableError(sync_error);
635 } 622 }
636 623
637 void SyncBackendHostImpl::HandleMigrationRequestedOnFrontendLoop( 624 void SyncBackendHostImpl::HandleMigrationRequestedOnFrontendLoop(
638 ModelTypeSet types) { 625 ModelTypeSet types) {
639 if (!frontend_)
640 return;
641 DCHECK(thread_checker_.CalledOnValidThread()); 626 DCHECK(thread_checker_.CalledOnValidThread());
642 frontend_->OnMigrationNeededForTypes(types); 627 frontend_->OnMigrationNeededForTypes(types);
643 } 628 }
644 629
645 void SyncBackendHostImpl::OnInvalidatorStateChange(InvalidatorState state) { 630 void SyncBackendHostImpl::OnInvalidatorStateChange(InvalidatorState state) {
646 sync_task_runner_->PostTask( 631 sync_task_runner_->PostTask(
647 FROM_HERE, base::Bind(&SyncBackendHostCore::DoOnInvalidatorStateChange, 632 FROM_HERE, base::Bind(&SyncBackendHostCore::DoOnInvalidatorStateChange,
648 core_, state)); 633 core_, state));
649 } 634 }
650 635
(...skipping 16 matching lines...) Expand all
667 nigori.InitByDerivation("localhost", "dummy", passphrase); 652 nigori.InitByDerivation("localhost", "dummy", passphrase);
668 std::string plaintext; 653 std::string plaintext;
669 bool result = nigori.Decrypt(cached_pending_keys_.blob(), &plaintext); 654 bool result = nigori.Decrypt(cached_pending_keys_.blob(), &plaintext);
670 DVLOG_IF(1, result) << "Passphrase failed to decrypt pending keys."; 655 DVLOG_IF(1, result) << "Passphrase failed to decrypt pending keys.";
671 return result; 656 return result;
672 } 657 }
673 658
674 void SyncBackendHostImpl::NotifyPassphraseRequired( 659 void SyncBackendHostImpl::NotifyPassphraseRequired(
675 PassphraseRequiredReason reason, 660 PassphraseRequiredReason reason,
676 sync_pb::EncryptedData pending_keys) { 661 sync_pb::EncryptedData pending_keys) {
677 if (!frontend_)
678 return;
679
680 DCHECK(thread_checker_.CalledOnValidThread()); 662 DCHECK(thread_checker_.CalledOnValidThread());
681 663
682 // Update our cache of the cryptographer's pending keys. 664 // Update our cache of the cryptographer's pending keys.
683 cached_pending_keys_ = pending_keys; 665 cached_pending_keys_ = pending_keys;
684 666
685 frontend_->OnPassphraseRequired(reason, pending_keys); 667 frontend_->OnPassphraseRequired(reason, pending_keys);
686 } 668 }
687 669
688 void SyncBackendHostImpl::NotifyPassphraseAccepted() { 670 void SyncBackendHostImpl::NotifyPassphraseAccepted() {
689 if (!frontend_)
690 return;
691
692 DCHECK(thread_checker_.CalledOnValidThread()); 671 DCHECK(thread_checker_.CalledOnValidThread());
693
694 // Clear our cache of the cryptographer's pending keys. 672 // Clear our cache of the cryptographer's pending keys.
695 cached_pending_keys_.clear_blob(); 673 cached_pending_keys_.clear_blob();
696 frontend_->OnPassphraseAccepted(); 674 frontend_->OnPassphraseAccepted();
697 } 675 }
698 676
699 void SyncBackendHostImpl::NotifyEncryptedTypesChanged( 677 void SyncBackendHostImpl::NotifyEncryptedTypesChanged(
700 ModelTypeSet encrypted_types, 678 ModelTypeSet encrypted_types,
701 bool encrypt_everything) { 679 bool encrypt_everything) {
702 if (!frontend_)
703 return;
704
705 DCHECK(thread_checker_.CalledOnValidThread()); 680 DCHECK(thread_checker_.CalledOnValidThread());
706 frontend_->OnEncryptedTypesChanged(encrypted_types, encrypt_everything); 681 frontend_->OnEncryptedTypesChanged(encrypted_types, encrypt_everything);
707 } 682 }
708 683
709 void SyncBackendHostImpl::NotifyEncryptionComplete() { 684 void SyncBackendHostImpl::NotifyEncryptionComplete() {
710 if (!frontend_)
711 return;
712
713 DCHECK(thread_checker_.CalledOnValidThread()); 685 DCHECK(thread_checker_.CalledOnValidThread());
714 frontend_->OnEncryptionComplete(); 686 frontend_->OnEncryptionComplete();
715 } 687 }
716 688
717 void SyncBackendHostImpl::HandlePassphraseTypeChangedOnFrontendLoop( 689 void SyncBackendHostImpl::HandlePassphraseTypeChangedOnFrontendLoop(
718 PassphraseType type, 690 PassphraseType type,
719 base::Time explicit_passphrase_time) { 691 base::Time explicit_passphrase_time) {
720 DCHECK(thread_checker_.CalledOnValidThread()); 692 DCHECK(thread_checker_.CalledOnValidThread());
721 DVLOG(1) << "Passphrase type changed to " << PassphraseTypeToString(type); 693 DVLOG(1) << "Passphrase type changed to " << PassphraseTypeToString(type);
722 cached_passphrase_type_ = type; 694 cached_passphrase_type_ = type;
723 cached_explicit_passphrase_time_ = explicit_passphrase_time; 695 cached_explicit_passphrase_time_ = explicit_passphrase_time;
724 } 696 }
725 697
726 void SyncBackendHostImpl::HandleLocalSetPassphraseEncryptionOnFrontendLoop( 698 void SyncBackendHostImpl::HandleLocalSetPassphraseEncryptionOnFrontendLoop(
727 const SyncEncryptionHandler::NigoriState& nigori_state) { 699 const SyncEncryptionHandler::NigoriState& nigori_state) {
728 DCHECK(thread_checker_.CalledOnValidThread()); 700 DCHECK(thread_checker_.CalledOnValidThread());
729 frontend_->OnLocalSetPassphraseEncryption(nigori_state); 701 frontend_->OnLocalSetPassphraseEncryption(nigori_state);
730 } 702 }
731 703
732 void SyncBackendHostImpl::HandleConnectionStatusChangeOnFrontendLoop( 704 void SyncBackendHostImpl::HandleConnectionStatusChangeOnFrontendLoop(
733 ConnectionStatus status) { 705 ConnectionStatus status) {
734 if (!frontend_)
735 return;
736
737 DCHECK(thread_checker_.CalledOnValidThread()); 706 DCHECK(thread_checker_.CalledOnValidThread());
738 707
739 DVLOG(1) << "Connection status changed: " << ConnectionStatusToString(status); 708 DVLOG(1) << "Connection status changed: " << ConnectionStatusToString(status);
740 frontend_->OnConnectionStatusChange(status); 709 frontend_->OnConnectionStatusChange(status);
741 } 710 }
742 711
743 void SyncBackendHostImpl::HandleProtocolEventOnFrontendLoop( 712 void SyncBackendHostImpl::HandleProtocolEventOnFrontendLoop(
744 std::unique_ptr<ProtocolEvent> event) { 713 std::unique_ptr<ProtocolEvent> event) {
745 if (!frontend_)
746 return;
747 frontend_->OnProtocolEvent(*event); 714 frontend_->OnProtocolEvent(*event);
748 } 715 }
749 716
750 void SyncBackendHostImpl::HandleDirectoryCommitCountersUpdatedOnFrontendLoop( 717 void SyncBackendHostImpl::HandleDirectoryCommitCountersUpdatedOnFrontendLoop(
751 ModelType type, 718 ModelType type,
752 const CommitCounters& counters) { 719 const CommitCounters& counters) {
753 if (!frontend_)
754 return;
755 frontend_->OnDirectoryTypeCommitCounterUpdated(type, counters); 720 frontend_->OnDirectoryTypeCommitCounterUpdated(type, counters);
756 } 721 }
757 722
758 void SyncBackendHostImpl::HandleDirectoryUpdateCountersUpdatedOnFrontendLoop( 723 void SyncBackendHostImpl::HandleDirectoryUpdateCountersUpdatedOnFrontendLoop(
759 ModelType type, 724 ModelType type,
760 const UpdateCounters& counters) { 725 const UpdateCounters& counters) {
761 if (!frontend_)
762 return;
763 frontend_->OnDirectoryTypeUpdateCounterUpdated(type, counters); 726 frontend_->OnDirectoryTypeUpdateCounterUpdated(type, counters);
764 } 727 }
765 728
766 void SyncBackendHostImpl::HandleDirectoryStatusCountersUpdatedOnFrontendLoop( 729 void SyncBackendHostImpl::HandleDirectoryStatusCountersUpdatedOnFrontendLoop(
767 ModelType type, 730 ModelType type,
768 const StatusCounters& counters) { 731 const StatusCounters& counters) {
769 if (!frontend_)
770 return;
771 frontend_->OnDatatypeStatusCounterUpdated(type, counters); 732 frontend_->OnDatatypeStatusCounterUpdated(type, counters);
772 } 733 }
773 734
774 void SyncBackendHostImpl::UpdateInvalidationVersions( 735 void SyncBackendHostImpl::UpdateInvalidationVersions(
775 const std::map<ModelType, int64_t>& invalidation_versions) { 736 const std::map<ModelType, int64_t>& invalidation_versions) {
776 sync_prefs_->UpdateInvalidationVersions(invalidation_versions); 737 sync_prefs_->UpdateInvalidationVersions(invalidation_versions);
777 } 738 }
778 739
779 void SyncBackendHostImpl::RefreshTypesForTest(ModelTypeSet types) { 740 void SyncBackendHostImpl::RefreshTypesForTest(ModelTypeSet types) {
780 DCHECK(thread_checker_.CalledOnValidThread()); 741 DCHECK(thread_checker_.CalledOnValidThread());
(...skipping 22 matching lines...) Expand all
803 const SyncManager::ClearServerDataCallback& frontend_callback) { 764 const SyncManager::ClearServerDataCallback& frontend_callback) {
804 DCHECK(thread_checker_.CalledOnValidThread()); 765 DCHECK(thread_checker_.CalledOnValidThread());
805 frontend_callback.Run(); 766 frontend_callback.Run();
806 } 767 }
807 768
808 } // namespace syncer 769 } // namespace syncer
809 770
810 #undef SDVLOG 771 #undef SDVLOG
811 772
812 #undef SLOG 773 #undef SLOG
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698