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

Side by Side Diff: chrome/browser/sync/glue/sync_backend_host.cc

Issue 10791002: Finish commit 146665. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 5 months 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 | Annotate | Revision Log
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 "build/build_config.h" 5 #include "build/build_config.h"
6 6
7 #include "chrome/browser/sync/glue/sync_backend_host.h" 7 #include "chrome/browser/sync/glue/sync_backend_host.h"
8 8
9 #include <algorithm> 9 #include <algorithm>
10 #include <map> 10 #include <map>
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
119 // SyncBackendHost::UpdateCredentials 119 // SyncBackendHost::UpdateCredentials
120 void DoUpdateCredentials(const syncer::SyncCredentials& credentials); 120 void DoUpdateCredentials(const syncer::SyncCredentials& credentials);
121 121
122 // Called when the user disables or enables a sync type. 122 // Called when the user disables or enables a sync type.
123 void DoUpdateEnabledTypes(const syncer::ModelTypeSet& enabled_types); 123 void DoUpdateEnabledTypes(const syncer::ModelTypeSet& enabled_types);
124 124
125 // Called to tell the syncapi to start syncing (generally after 125 // Called to tell the syncapi to start syncing (generally after
126 // initialization and authentication). 126 // initialization and authentication).
127 void DoStartSyncing(const syncer::ModelSafeRoutingInfo& routing_info); 127 void DoStartSyncing(const syncer::ModelSafeRoutingInfo& routing_info);
128 128
129 // Called to cleanup disabled types.
130 void DoRequestCleanupDisabledTypes(
131 const syncer::ModelSafeRoutingInfo& routing_info);
132
133 // Called to set the passphrase for encryption. 129 // Called to set the passphrase for encryption.
134 void DoSetEncryptionPassphrase(const std::string& passphrase, 130 void DoSetEncryptionPassphrase(const std::string& passphrase,
135 bool is_explicit); 131 bool is_explicit);
136 132
137 // Called to decrypt the pending keys. 133 // Called to decrypt the pending keys.
138 void DoSetDecryptionPassphrase(const std::string& passphrase); 134 void DoSetDecryptionPassphrase(const std::string& passphrase);
139 135
140 // Called to turn on encryption of all sync data as well as 136 // Called to turn on encryption of all sync data as well as
141 // reencrypt everything. 137 // reencrypt everything.
142 void DoEnableEncryptEverything(); 138 void DoEnableEncryptEverything();
143 139
144 // Called to refresh encryption with the most recent passphrase 140 // Called to refresh encryption with the most recent passphrase
145 // and set of encrypted types. Also adds device information to the nigori 141 // and set of encrypted types. Also adds device information to the nigori
146 // node. |done_callback| is called on the sync thread. 142 // node. |done_callback| is called on the sync thread.
147 void DoRefreshNigori(const base::Closure& done_callback); 143 void DoRefreshNigori(const base::Closure& done_callback);
148 144
149 // The shutdown order is a bit complicated: 145 // The shutdown order is a bit complicated:
150 // 1) From |sync_thread_|, invoke the syncapi Shutdown call to do 146 // 1) From |sync_thread_|, invoke the syncapi Shutdown call to do
151 // a final SaveChanges, and close sqlite handles. 147 // a final SaveChanges, and close sqlite handles.
152 // 2) Then, from |frontend_loop_|, halt the sync_thread_ (which is 148 // 2) Then, from |frontend_loop_|, halt the sync_thread_ (which is
153 // a blocking call). This causes syncapi thread-exit handlers 149 // a blocking call). This causes syncapi thread-exit handlers
154 // to run and make use of cached pointers to various components 150 // to run and make use of cached pointers to various components
155 // owned implicitly by us. 151 // owned implicitly by us.
156 // 3) Destroy this Core. That will delete syncapi components in a 152 // 3) Destroy this Core. That will delete syncapi components in a
157 // safe order because the thread that was using them has exited 153 // safe order because the thread that was using them has exited
158 // (in step 2). 154 // (in step 2).
159 void DoStopSyncManagerForShutdown(const base::Closure& closure); 155 void DoStopSyncManagerForShutdown(const base::Closure& closure);
160 void DoShutdown(bool stopping_sync); 156 void DoShutdown(bool stopping_sync);
161 157
162 virtual void DoRequestConfig( 158 // Configuration methods that must execute on sync loop.
163 const syncer::ModelSafeRoutingInfo& routing_info, 159 void DoConfigureSyncer(
160 syncer::ConfigureReason reason,
164 syncer::ModelTypeSet types_to_config, 161 syncer::ModelTypeSet types_to_config,
165 syncer::ConfigureReason reason); 162 const syncer::ModelSafeRoutingInfo routing_info,
166 163 const base::Callback<void(syncer::ModelTypeSet)>& ready_task,
167 // Start the configuration mode. |callback| is called on the sync 164 const base::Closure& retry_callback);
168 // thread. 165 void DoFinishConfigureDataTypes(
169 virtual void DoStartConfiguration(const base::Closure& callback); 166 syncer::ModelTypeSet types_to_config,
167 const base::Callback<void(syncer::ModelTypeSet)>& ready_task);
168 void DoRetryConfiguration(
169 const base::Closure& retry_callback);
170 170
171 // Set the base request context to use when making HTTP calls. 171 // Set the base request context to use when making HTTP calls.
172 // This method will add a reference to the context to persist it 172 // This method will add a reference to the context to persist it
173 // on the IO thread. Must be removed from IO thread. 173 // on the IO thread. Must be removed from IO thread.
174 174
175 syncer::SyncManager* sync_manager() { return sync_manager_.get(); } 175 syncer::SyncManager* sync_manager() { return sync_manager_.get(); }
176 176
177 // Delete the sync data folder to cleanup backend data. Happens the first 177 // Delete the sync data folder to cleanup backend data. Happens the first
178 // time sync is enabled for a user (to prevent accidentally reusing old 178 // time sync is enabled for a user (to prevent accidentally reusing old
179 // sync databases), as well as shutdown when you're no longer syncing. 179 // sync databases), as well as shutdown when you're no longer syncing.
180 void DeleteSyncDataFolder(); 180 void DeleteSyncDataFolder();
181 181
182 // A callback from the SyncerThread when it is safe to continue config.
183 void FinishConfigureDataTypes();
184
185 private: 182 private:
186 friend class base::RefCountedThreadSafe<SyncBackendHost::Core>; 183 friend class base::RefCountedThreadSafe<SyncBackendHost::Core>;
187 friend class SyncBackendHostForProfileSyncTest; 184 friend class SyncBackendHostForProfileSyncTest;
188 185
189 virtual ~Core(); 186 virtual ~Core();
190 187
191 // Invoked when initialization of syncapi is complete and we can start 188 // Invoked when initialization of syncapi is complete and we can start
192 // our timer. 189 // our timer.
193 // This must be called from the thread on which SaveChanges is intended to 190 // This must be called from the thread on which SaveChanges is intended to
194 // be run on; the host's |sync_thread_|. 191 // be run on; the host's |sync_thread_|.
(...skipping 387 matching lines...) Expand 10 before | Expand all | Expand 10 after
582 registrar_.reset(); 579 registrar_.reset();
583 frontend_ = NULL; 580 frontend_ = NULL;
584 core_ = NULL; // Releases reference to core_. 581 core_ = NULL; // Releases reference to core_.
585 } 582 }
586 583
587 void SyncBackendHost::ConfigureDataTypes( 584 void SyncBackendHost::ConfigureDataTypes(
588 syncer::ConfigureReason reason, 585 syncer::ConfigureReason reason,
589 syncer::ModelTypeSet types_to_add, 586 syncer::ModelTypeSet types_to_add,
590 syncer::ModelTypeSet types_to_remove, 587 syncer::ModelTypeSet types_to_remove,
591 NigoriState nigori_state, 588 NigoriState nigori_state,
592 base::Callback<void(syncer::ModelTypeSet)> ready_task, 589 const base::Callback<void(syncer::ModelTypeSet)>& ready_task,
593 base::Callback<void()> retry_callback) { 590 const base::Callback<void()>& retry_callback) {
594 syncer::ModelTypeSet types_to_add_with_nigori = types_to_add; 591 syncer::ModelTypeSet types_to_add_with_nigori = types_to_add;
595 syncer::ModelTypeSet types_to_remove_with_nigori = types_to_remove; 592 syncer::ModelTypeSet types_to_remove_with_nigori = types_to_remove;
596 if (nigori_state == WITH_NIGORI) { 593 if (nigori_state == WITH_NIGORI) {
597 types_to_add_with_nigori.Put(syncer::NIGORI); 594 types_to_add_with_nigori.Put(syncer::NIGORI);
598 types_to_remove_with_nigori.Remove(syncer::NIGORI); 595 types_to_remove_with_nigori.Remove(syncer::NIGORI);
599 } else { 596 } else {
600 types_to_add_with_nigori.Remove(syncer::NIGORI); 597 types_to_add_with_nigori.Remove(syncer::NIGORI);
601 types_to_remove_with_nigori.Put(syncer::NIGORI); 598 types_to_remove_with_nigori.Put(syncer::NIGORI);
602 } 599 }
603 // Only one configure is allowed at a time. 600 // Only one configure is allowed at a time (DataTypeManager handles user
604 DCHECK(!pending_config_mode_state_.get()); 601 // changes that happen while the syncer is reconfiguraing, and will only
605 DCHECK(!pending_download_state_.get()); 602 // trigger another call to ConfigureDataTypes once the current reconfiguration
603 // completes).
606 DCHECK_GT(initialization_state_, NOT_INITIALIZED); 604 DCHECK_GT(initialization_state_, NOT_INITIALIZED);
607 605
608 pending_config_mode_state_.reset(new PendingConfigureDataTypesState()); 606 // The new set of enabled types is types_to_add_with_nigori + the
609 pending_config_mode_state_->ready_task = ready_task; 607 // previously enabled types (on restart, the preferred types are already
610 pending_config_mode_state_->types_to_add = types_to_add_with_nigori; 608 // enabled) - types_to_remove_with_nigori. After reconfiguring the registrar,
611 pending_config_mode_state_->added_types = 609 // the new routing info will reflect the set of enabled types.
612 registrar_->ConfigureDataTypes(types_to_add_with_nigori, 610 syncer::ModelSafeRoutingInfo routing_info;
613 types_to_remove_with_nigori); 611 registrar_->ConfigureDataTypes(types_to_add_with_nigori,
614 pending_config_mode_state_->reason = reason; 612 types_to_remove_with_nigori);
615 pending_config_mode_state_->retry_callback = retry_callback; 613 registrar_->GetModelSafeRoutingInfo(&routing_info);
614 const syncer::ModelTypeSet enabled_types =
615 GetRoutingInfoTypes(routing_info);
616 616
617 // Cleanup disabled types before starting configuration so that 617 // Figure out which types need to actually be downloaded. We pass those on
618 // callers can assume that the data types are cleaned up once 618 // to the syncer while it's in configuration mode so that they can be
619 // configuration is done. 619 // downloaded before we perform association. Once we switch to normal mode
620 if (!types_to_remove_with_nigori.Empty()) { 620 // downloads will get applied normally and hit the datatype's change
621 syncer::ModelSafeRoutingInfo routing_info; 621 // processor.
622 registrar_->GetModelSafeRoutingInfo(&routing_info); 622 // A datatype is in need of downloading if any of the following are true:
623 sync_thread_.message_loop()->PostTask( 623 // 1. it's enabled and initial_sync_ended is false (initial_sync_ended is
624 FROM_HERE, 624 // set after applying updates, and hence is a more conservative measure
625 base::Bind(&SyncBackendHost::Core::DoRequestCleanupDisabledTypes, 625 // than having a non-empty progress marker, which is set during
626 core_.get(), 626 // StoreTimestamps).
627 routing_info)); 627 // 2. the type is NIGORI, and any other datatype is being downloaded (nigori
628 } 628 // is always included if we download a datatype).
629 // TODO(sync): consider moving this logic onto the sync thread (perhaps
630 // as part of SyncManager::ConfigureSyncer).
631 syncer::ModelTypeSet initial_sync_ended_types =
632 core_->sync_manager()->InitialSyncEndedTypes();
633 initial_sync_ended_types.RetainAll(enabled_types);
634 syncer::ModelTypeSet types_to_config =
635 Difference(enabled_types, initial_sync_ended_types);
636 if (!types_to_config.Empty() && enabled_types.Has(syncer::NIGORI))
637 types_to_config.Put(syncer::NIGORI);
629 638
630 StartConfiguration( 639 SDVLOG(1) << "Types "
631 base::Bind(&SyncBackendHost::Core::FinishConfigureDataTypes, 640 << syncer::ModelTypeSetToString(types_to_config)
632 core_.get())); 641 << " added; calling DoConfigureSyncer";
633 } 642 // TODO(zea): figure out how to bypass this call if no types are being
634 643 // configured and GetKey is not needed. For now we rely on determining the
635 void SyncBackendHost::StartConfiguration(const base::Closure& callback) { 644 // need for GetKey as part of the SyncManager::ConfigureSyncer logic.
636 // Put syncer in the config mode. DTM will put us in normal mode once it is 645 RequestConfigureSyncer(reason,
637 // done. This is to ensure we dont do a normal sync when we are doing model 646 types_to_config,
638 // association. 647 routing_info,
639 sync_thread_.message_loop()->PostTask(FROM_HERE, base::Bind( 648 ready_task,
640 &SyncBackendHost::Core::DoStartConfiguration, core_.get(), callback)); 649 retry_callback);
641 } 650 }
642 651
643 void SyncBackendHost::EnableEncryptEverything() { 652 void SyncBackendHost::EnableEncryptEverything() {
644 sync_thread_.message_loop()->PostTask(FROM_HERE, 653 sync_thread_.message_loop()->PostTask(FROM_HERE,
645 base::Bind(&SyncBackendHost::Core::DoEnableEncryptEverything, 654 base::Bind(&SyncBackendHost::Core::DoEnableEncryptEverything,
646 core_.get())); 655 core_.get()));
647 } 656 }
648 657
649 void SyncBackendHost::ActivateDataType( 658 void SyncBackendHost::ActivateDataType(
650 syncer::ModelType type, syncer::ModelSafeGroup group, 659 syncer::ModelType type, syncer::ModelSafeGroup group,
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
701 } else { 710 } else {
702 NOTREACHED(); 711 NOTREACHED();
703 } 712 }
704 } 713 }
705 714
706 void SyncBackendHost::InitCore(const DoInitializeOptions& options) { 715 void SyncBackendHost::InitCore(const DoInitializeOptions& options) {
707 sync_thread_.message_loop()->PostTask(FROM_HERE, 716 sync_thread_.message_loop()->PostTask(FROM_HERE,
708 base::Bind(&SyncBackendHost::Core::DoInitialize, core_.get(), options)); 717 base::Bind(&SyncBackendHost::Core::DoInitialize, core_.get(), options));
709 } 718 }
710 719
711 void SyncBackendHost::HandleSyncCycleCompletedOnFrontendLoop( 720 void SyncBackendHost::RequestConfigureSyncer(
712 const SyncSessionSnapshot& snapshot) { 721 syncer::ConfigureReason reason,
713 if (!frontend_) 722 syncer::ModelTypeSet types_to_config,
714 return; 723 const syncer::ModelSafeRoutingInfo& routing_info,
715 DCHECK_EQ(MessageLoop::current(), frontend_loop_); 724 const base::Callback<void(syncer::ModelTypeSet)>& ready_task,
716 725 const base::Closure& retry_callback) {
717 last_snapshot_ = snapshot; 726 sync_thread_.message_loop()->PostTask(FROM_HERE,
718 727 base::Bind(&SyncBackendHost::Core::DoConfigureSyncer,
719 SDVLOG(1) << "Got snapshot " << snapshot.ToString(); 728 core_.get(),
720 729 reason,
721 const syncer::ModelTypeSet to_migrate = 730 types_to_config,
722 snapshot.model_neutral_state().types_needing_local_migration; 731 routing_info,
723 if (!to_migrate.Empty()) 732 ready_task,
724 frontend_->OnMigrationNeededForTypes(to_migrate); 733 retry_callback));
725
726 // Process any changes to the datatypes we're syncing.
727 // TODO(sync): add support for removing types.
728 if (initialized())
729 AddExperimentalTypes();
730
731 // If we are waiting for a configuration change, check here to see
732 // if this sync cycle has initialized all of the types we've been
733 // waiting for.
734 if (pending_download_state_.get()) {
735 const syncer::ModelTypeSet types_to_add =
736 pending_download_state_->types_to_add;
737 const syncer::ModelTypeSet added_types =
738 pending_download_state_->added_types;
739 DCHECK(types_to_add.HasAll(added_types));
740 const syncer::ModelTypeSet initial_sync_ended =
741 snapshot.initial_sync_ended();
742 const syncer::ModelTypeSet failed_configuration_types =
743 Difference(added_types, initial_sync_ended);
744 SDVLOG(1)
745 << "Added types: "
746 << syncer::ModelTypeSetToString(added_types)
747 << ", configured types: "
748 << syncer::ModelTypeSetToString(initial_sync_ended)
749 << ", failed configuration types: "
750 << syncer::ModelTypeSetToString(failed_configuration_types);
751
752 if (!failed_configuration_types.Empty() &&
753 snapshot.retry_scheduled()) {
754 // Inform the caller that download failed but we are retrying.
755 if (!pending_download_state_->retry_in_progress) {
756 pending_download_state_->retry_callback.Run();
757 pending_download_state_->retry_in_progress = true;
758 }
759 // Nothing more to do.
760 return;
761 }
762
763 scoped_ptr<PendingConfigureDataTypesState> state(
764 pending_download_state_.release());
765 state->ready_task.Run(failed_configuration_types);
766
767 // Syncer did not report an error but did not download everything
768 // we requested either. So abort. The caller of the config will cleanup.
769 if (!failed_configuration_types.Empty())
770 return;
771 }
772
773 if (initialized())
774 frontend_->OnSyncCycleCompleted();
775 } 734 }
776 735
777 void SyncBackendHost::FinishConfigureDataTypesOnFrontendLoop() { 736 void SyncBackendHost::FinishConfigureDataTypesOnFrontendLoop(
778 DCHECK_EQ(MessageLoop::current(), frontend_loop_); 737 syncer::ModelTypeSet types_to_configure,
779 // Nudge the syncer. This is necessary for both datatype addition/deletion. 738 syncer::ModelTypeSet configured_types,
780 // 739 const base::Callback<void(syncer::ModelTypeSet)>& ready_task) {
781 // Deletions need a nudge in order to ensure the deletion occurs in a timely 740 const syncer::ModelTypeSet failed_configuration_types =
782 // manner (see issue 56416). 741 Difference(types_to_configure, configured_types);
783 // 742 SDVLOG(1)
784 // In the case of additions, on the next sync cycle, the syncer should 743 << "Added types: "
785 // notice that the routing info has changed and start the process of 744 << syncer::ModelTypeSetToString(types_to_configure)
786 // downloading updates for newly added data types. Once this is 745 << ", configured types: "
787 // complete, the configure_state_.ready_task_ is run via an 746 << syncer::ModelTypeSetToString(configured_types)
788 // OnInitializationComplete notification. 747 << ", failed configuration types: "
789 748 << syncer::ModelTypeSetToString(failed_configuration_types);
790 SDVLOG(1) << "Syncer in config mode. SBH executing "
791 << "FinishConfigureDataTypesOnFrontendLoop";
792
793 syncer::ModelSafeRoutingInfo routing_info;
794 registrar_->GetModelSafeRoutingInfo(&routing_info);
795 const syncer::ModelTypeSet enabled_types = GetRoutingInfoTypes(routing_info);
796 749
797 // Update |chrome_sync_notification_bridge_|'s enabled types here as it has 750 // Update |chrome_sync_notification_bridge_|'s enabled types here as it has
798 // to happen on the UI thread. 751 // to happen on the UI thread.
799 chrome_sync_notification_bridge_.UpdateEnabledTypes(enabled_types); 752 chrome_sync_notification_bridge_.UpdateEnabledTypes(configured_types);
800
801 if (pending_config_mode_state_->added_types.Empty() &&
802 !core_->sync_manager()->InitialSyncEndedTypes().HasAll(enabled_types)) {
803
804 // TODO(tim): Log / UMA / count this somehow?
805 // Add only the types with empty progress markers. Note: it is possible
806 // that some types have their initial_sync_ended be false but with non
807 // empty progress marker. Which is ok as the rest of the changes would
808 // be downloaded on a regular nudge and initial_sync_ended should be set
809 // to true. However this is a very corner case. So it is not explicitly
810 // handled.
811 pending_config_mode_state_->added_types =
812 syncer::GetTypesWithEmptyProgressMarkerToken(enabled_types,
813 GetUserShare());
814 }
815
816 // If we've added types, we always want to request a nudge/config (even if
817 // the initial sync is ended), in case we could not decrypt the data.
818 if (pending_config_mode_state_->added_types.Empty()) {
819 SDVLOG(1) << "No new types added; calling ready_task directly";
820 // No new types - just notify the caller that the types are available.
821 const syncer::ModelTypeSet failed_configuration_types;
822 pending_config_mode_state_->ready_task.Run(failed_configuration_types);
823 } else {
824 pending_download_state_.reset(pending_config_mode_state_.release());
825
826 // Always configure nigori if it's enabled.
827 syncer::ModelTypeSet types_to_config = pending_download_state_->added_types;
828 if (IsNigoriEnabled()) {
829 // Note: Nigori is the only type that gets added with a nonempty
830 // progress marker during config. If the server returns a migration
831 // error then we will go into unrecoverable error. We dont handle it
832 // explicitly because server might help us out here by not sending a
833 // migraiton error for nigori during config.
834 types_to_config.Put(syncer::NIGORI);
835 }
836 SDVLOG(1) << "Types "
837 << syncer::ModelTypeSetToString(types_to_config)
838 << " added; calling DoRequestConfig";
839 syncer::ModelSafeRoutingInfo routing_info;
840 registrar_->GetModelSafeRoutingInfo(&routing_info);
841 sync_thread_.message_loop()->PostTask(FROM_HERE,
842 base::Bind(&SyncBackendHost::Core::DoRequestConfig,
843 core_.get(),
844 routing_info,
845 types_to_config,
846 pending_download_state_->reason));
847 }
848
849 pending_config_mode_state_.reset();
850 753
851 // Notify SyncManager (especially the notification listener) about new types. 754 // Notify SyncManager (especially the notification listener) about new types.
852 sync_thread_.message_loop()->PostTask(FROM_HERE, 755 sync_thread_.message_loop()->PostTask(FROM_HERE,
853 base::Bind(&SyncBackendHost::Core::DoUpdateEnabledTypes, core_.get(), 756 base::Bind(&SyncBackendHost::Core::DoUpdateEnabledTypes, core_.get(),
854 enabled_types)); 757 configured_types));
855 }
856 758
857 bool SyncBackendHost::IsDownloadingNigoriForTest() const { 759 if (!ready_task.is_null())
858 return initialization_state_ == DOWNLOADING_NIGORI; 760 ready_task.Run(failed_configuration_types);
859 } 761 }
860 762
861 SyncBackendHost::DoInitializeOptions::DoInitializeOptions( 763 SyncBackendHost::DoInitializeOptions::DoInitializeOptions(
862 MessageLoop* sync_loop, 764 MessageLoop* sync_loop,
863 SyncBackendRegistrar* registrar, 765 SyncBackendRegistrar* registrar,
864 const syncer::ModelSafeRoutingInfo& routing_info, 766 const syncer::ModelSafeRoutingInfo& routing_info,
865 const std::vector<syncer::ModelSafeWorker*>& workers, 767 const std::vector<syncer::ModelSafeWorker*>& workers,
866 syncer::ExtensionsActivityMonitor* extensions_activity_monitor, 768 syncer::ExtensionsActivityMonitor* extensions_activity_monitor,
867 const syncer::WeakHandle<syncer::JsEventHandler>& event_handler, 769 const syncer::WeakHandle<syncer::JsEventHandler>& event_handler,
868 const GURL& service_url, 770 const GURL& service_url,
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
906 sync_loop_(NULL), 808 sync_loop_(NULL),
907 registrar_(NULL) { 809 registrar_(NULL) {
908 DCHECK(backend.get()); 810 DCHECK(backend.get());
909 } 811 }
910 812
911 SyncBackendHost::Core::~Core() { 813 SyncBackendHost::Core::~Core() {
912 DCHECK(!sync_manager_.get()); 814 DCHECK(!sync_manager_.get());
913 DCHECK(!sync_loop_); 815 DCHECK(!sync_loop_);
914 } 816 }
915 817
916 SyncBackendHost::PendingConfigureDataTypesState::
917 PendingConfigureDataTypesState()
918 : reason(syncer::CONFIGURE_REASON_UNKNOWN),
919 retry_in_progress(false) {}
920
921 SyncBackendHost::PendingConfigureDataTypesState::
922 ~PendingConfigureDataTypesState() {}
923
924 void SyncBackendHost::Core::OnSyncCycleCompleted( 818 void SyncBackendHost::Core::OnSyncCycleCompleted(
925 const SyncSessionSnapshot& snapshot) { 819 const SyncSessionSnapshot& snapshot) {
926 if (!sync_loop_) 820 if (!sync_loop_)
927 return; 821 return;
928 DCHECK_EQ(MessageLoop::current(), sync_loop_); 822 DCHECK_EQ(MessageLoop::current(), sync_loop_);
929 host_.Call( 823 host_.Call(
930 FROM_HERE, 824 FROM_HERE,
931 &SyncBackendHost::HandleSyncCycleCompletedOnFrontendLoop, 825 &SyncBackendHost::HandleSyncCycleCompletedOnFrontendLoop,
932 snapshot); 826 snapshot);
933 } 827 }
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after
1109 DCHECK_EQ(MessageLoop::current(), sync_loop_); 1003 DCHECK_EQ(MessageLoop::current(), sync_loop_);
1110 sync_manager_->UpdateEnabledTypes(enabled_types); 1004 sync_manager_->UpdateEnabledTypes(enabled_types);
1111 } 1005 }
1112 1006
1113 void SyncBackendHost::Core::DoStartSyncing( 1007 void SyncBackendHost::Core::DoStartSyncing(
1114 const syncer::ModelSafeRoutingInfo& routing_info) { 1008 const syncer::ModelSafeRoutingInfo& routing_info) {
1115 DCHECK_EQ(MessageLoop::current(), sync_loop_); 1009 DCHECK_EQ(MessageLoop::current(), sync_loop_);
1116 sync_manager_->StartSyncingNormally(routing_info); 1010 sync_manager_->StartSyncingNormally(routing_info);
1117 } 1011 }
1118 1012
1119 void SyncBackendHost::Core::DoRequestCleanupDisabledTypes(
1120 const syncer::ModelSafeRoutingInfo& routing_info) {
1121 DCHECK_EQ(MessageLoop::current(), sync_loop_);
1122 sync_manager_->RequestCleanupDisabledTypes(routing_info);
1123 }
1124
1125 void SyncBackendHost::Core::DoSetEncryptionPassphrase( 1013 void SyncBackendHost::Core::DoSetEncryptionPassphrase(
1126 const std::string& passphrase, 1014 const std::string& passphrase,
1127 bool is_explicit) { 1015 bool is_explicit) {
1128 DCHECK_EQ(MessageLoop::current(), sync_loop_); 1016 DCHECK_EQ(MessageLoop::current(), sync_loop_);
1129 sync_manager_->SetEncryptionPassphrase(passphrase, is_explicit); 1017 sync_manager_->SetEncryptionPassphrase(passphrase, is_explicit);
1130 } 1018 }
1131 1019
1132 void SyncBackendHost::Core::DoSetDecryptionPassphrase( 1020 void SyncBackendHost::Core::DoSetDecryptionPassphrase(
1133 const std::string& passphrase) { 1021 const std::string& passphrase) {
1134 DCHECK_EQ(MessageLoop::current(), sync_loop_); 1022 DCHECK_EQ(MessageLoop::current(), sync_loop_);
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
1166 registrar_ = NULL; 1054 registrar_ = NULL;
1167 1055
1168 if (sync_disabled) 1056 if (sync_disabled)
1169 DeleteSyncDataFolder(); 1057 DeleteSyncDataFolder();
1170 1058
1171 sync_loop_ = NULL; 1059 sync_loop_ = NULL;
1172 1060
1173 host_.Reset(); 1061 host_.Reset();
1174 } 1062 }
1175 1063
1176 void SyncBackendHost::Core::DoRequestConfig( 1064 void SyncBackendHost::Core::DoConfigureSyncer(
1177 const syncer::ModelSafeRoutingInfo& routing_info, 1065 syncer::ConfigureReason reason,
1178 syncer::ModelTypeSet types_to_config, 1066 syncer::ModelTypeSet types_to_config,
1179 syncer::ConfigureReason reason) { 1067 const syncer::ModelSafeRoutingInfo routing_info,
1068 const base::Callback<void(syncer::ModelTypeSet)>& ready_task,
1069 const base::Closure& retry_callback) {
1180 DCHECK_EQ(MessageLoop::current(), sync_loop_); 1070 DCHECK_EQ(MessageLoop::current(), sync_loop_);
1181 sync_manager_->RequestConfig(routing_info, types_to_config, reason); 1071 sync_manager_->ConfigureSyncer(
1072 reason,
1073 types_to_config,
1074 routing_info,
1075 base::Bind(&SyncBackendHost::Core::DoFinishConfigureDataTypes,
1076 this,
1077 types_to_config,
1078 ready_task),
1079 base::Bind(&SyncBackendHost::Core::DoRetryConfiguration,
1080 this,
1081 retry_callback));
1182 } 1082 }
1183 1083
1184 void SyncBackendHost::Core::DoStartConfiguration( 1084 void SyncBackendHost::Core::DoFinishConfigureDataTypes(
1185 const base::Closure& callback) { 1085 syncer::ModelTypeSet types_to_config,
1086 const base::Callback<void(syncer::ModelTypeSet)>& ready_task) {
1186 DCHECK_EQ(MessageLoop::current(), sync_loop_); 1087 DCHECK_EQ(MessageLoop::current(), sync_loop_);
1187 sync_manager_->StartConfigurationMode(callback); 1088 syncer::ModelTypeSet configured_types =
1089 sync_manager_->InitialSyncEndedTypes();
1090 configured_types.RetainAll(types_to_config);
1091 host_.Call(FROM_HERE,
1092 &SyncBackendHost::FinishConfigureDataTypesOnFrontendLoop,
1093 types_to_config,
1094 configured_types,
1095 ready_task);
1096 }
1097
1098 void SyncBackendHost::Core::DoRetryConfiguration(
1099 const base::Closure& retry_callback) {
1100 DCHECK_EQ(MessageLoop::current(), sync_loop_);
1101 host_.Call(FROM_HERE,
1102 &SyncBackendHost::RetryConfigurationOnFrontendLoop,
1103 retry_callback);
1188 } 1104 }
1189 1105
1190 void SyncBackendHost::Core::DeleteSyncDataFolder() { 1106 void SyncBackendHost::Core::DeleteSyncDataFolder() {
1191 DCHECK_EQ(MessageLoop::current(), sync_loop_); 1107 DCHECK_EQ(MessageLoop::current(), sync_loop_);
1192 if (file_util::DirectoryExists(sync_data_folder_path_)) { 1108 if (file_util::DirectoryExists(sync_data_folder_path_)) {
1193 if (!file_util::Delete(sync_data_folder_path_, true)) 1109 if (!file_util::Delete(sync_data_folder_path_, true))
1194 SLOG(DFATAL) << "Could not delete the Sync Data folder."; 1110 SLOG(DFATAL) << "Could not delete the Sync Data folder.";
1195 } 1111 }
1196 } 1112 }
1197 1113
1198 void SyncBackendHost::Core::FinishConfigureDataTypes() {
1199 DCHECK_EQ(MessageLoop::current(), sync_loop_);
1200 host_.Call(
1201 FROM_HERE,
1202 &SyncBackendHost::FinishConfigureDataTypesOnFrontendLoop);
1203 }
1204
1205 void SyncBackendHost::Core::StartSavingChanges() { 1114 void SyncBackendHost::Core::StartSavingChanges() {
1206 // We may already be shut down. 1115 // We may already be shut down.
1207 if (!sync_loop_) 1116 if (!sync_loop_)
1208 return; 1117 return;
1209 DCHECK_EQ(MessageLoop::current(), sync_loop_); 1118 DCHECK_EQ(MessageLoop::current(), sync_loop_);
1210 DCHECK(!save_changes_timer_.get()); 1119 DCHECK(!save_changes_timer_.get());
1211 save_changes_timer_.reset(new base::RepeatingTimer<Core>()); 1120 save_changes_timer_.reset(new base::RepeatingTimer<Core>());
1212 save_changes_timer_->Start(FROM_HERE, 1121 save_changes_timer_->Start(FROM_HERE,
1213 base::TimeDelta::FromSeconds(kSaveChangesIntervalSeconds), 1122 base::TimeDelta::FromSeconds(kSaveChangesIntervalSeconds),
1214 this, &Core::SaveChanges); 1123 this, &Core::SaveChanges);
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
1254 } 1163 }
1255 1164
1256 // If setup has completed, start off in DOWNLOADING_NIGORI so that 1165 // If setup has completed, start off in DOWNLOADING_NIGORI so that
1257 // we start off by refreshing nigori. 1166 // we start off by refreshing nigori.
1258 CHECK(sync_prefs_.get()); 1167 CHECK(sync_prefs_.get());
1259 if (sync_prefs_->HasSyncSetupCompleted() && 1168 if (sync_prefs_->HasSyncSetupCompleted() &&
1260 initialization_state_ < DOWNLOADING_NIGORI) { 1169 initialization_state_ < DOWNLOADING_NIGORI) {
1261 initialization_state_ = DOWNLOADING_NIGORI; 1170 initialization_state_ = DOWNLOADING_NIGORI;
1262 } 1171 }
1263 1172
1264 if (sync_prefs_->HasSyncSetupCompleted() &&
1265 initialization_state_ < DOWNLOADING_NIGORI) {
1266 initialization_state_ = DOWNLOADING_NIGORI;
1267 }
1268
1269 // Run initialization state machine. 1173 // Run initialization state machine.
1270 switch (initialization_state_) { 1174 switch (initialization_state_) {
1271 case NOT_INITIALIZED: 1175 case NOT_INITIALIZED:
1272 initialization_state_ = DOWNLOADING_NIGORI; 1176 initialization_state_ = DOWNLOADING_NIGORI;
1273 ConfigureDataTypes( 1177 ConfigureDataTypes(
1274 syncer::CONFIGURE_REASON_NEW_CLIENT, 1178 syncer::CONFIGURE_REASON_NEW_CLIENT,
1275 syncer::ModelTypeSet(), 1179 syncer::ModelTypeSet(),
1276 syncer::ModelTypeSet(), 1180 syncer::ModelTypeSet(),
1277 WITH_NIGORI, 1181 WITH_NIGORI,
1278 // Calls back into this function. 1182 // Calls back into this function.
(...skipping 20 matching lines...) Expand all
1299 // experimental types to enable. This should be done before we inform 1203 // experimental types to enable. This should be done before we inform
1300 // the frontend to ensure they're visible in the customize screen. 1204 // the frontend to ensure they're visible in the customize screen.
1301 AddExperimentalTypes(); 1205 AddExperimentalTypes();
1302 frontend_->OnBackendInitialized(js_backend, true); 1206 frontend_->OnBackendInitialized(js_backend, true);
1303 break; 1207 break;
1304 default: 1208 default:
1305 NOTREACHED(); 1209 NOTREACHED();
1306 } 1210 }
1307 } 1211 }
1308 1212
1213 void SyncBackendHost::HandleSyncCycleCompletedOnFrontendLoop(
1214 const SyncSessionSnapshot& snapshot) {
1215 if (!frontend_)
1216 return;
1217 DCHECK_EQ(MessageLoop::current(), frontend_loop_);
1218
1219 last_snapshot_ = snapshot;
1220
1221 SDVLOG(1) << "Got snapshot " << snapshot.ToString();
1222
1223 const syncer::ModelTypeSet to_migrate =
1224 snapshot.model_neutral_state().types_needing_local_migration;
1225 if (!to_migrate.Empty())
1226 frontend_->OnMigrationNeededForTypes(to_migrate);
1227
1228 // Process any changes to the datatypes we're syncing.
1229 // TODO(sync): add support for removing types.
1230 if (initialized())
1231 AddExperimentalTypes();
1232
1233 if (initialized())
1234 frontend_->OnSyncCycleCompleted();
1235 }
1236
1237 void SyncBackendHost::RetryConfigurationOnFrontendLoop(
1238 const base::Closure& retry_callback) {
1239 SDVLOG(1) << "Failed to complete configuration, informing of retry.";
1240 retry_callback.Run();
1241 }
1242
1309 void SyncBackendHost::PersistEncryptionBootstrapToken( 1243 void SyncBackendHost::PersistEncryptionBootstrapToken(
1310 const std::string& token) { 1244 const std::string& token) {
1311 CHECK(sync_prefs_.get()); 1245 CHECK(sync_prefs_.get());
1312 sync_prefs_->SetEncryptionBootstrapToken(token); 1246 sync_prefs_->SetEncryptionBootstrapToken(token);
1313 } 1247 }
1314 1248
1315 void SyncBackendHost::HandleActionableErrorEventOnFrontendLoop( 1249 void SyncBackendHost::HandleActionableErrorEventOnFrontendLoop(
1316 const syncer::SyncProtocolError& sync_error) { 1250 const syncer::SyncProtocolError& sync_error) {
1317 if (!frontend_) 1251 if (!frontend_)
1318 return; 1252 return;
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
1427 FROM_HERE, 1361 FROM_HERE,
1428 base::Bind(&SyncBackendHost::Core::DoRefreshNigori, 1362 base::Bind(&SyncBackendHost::Core::DoRefreshNigori,
1429 core_.get(), sync_thread_done_callback)); 1363 core_.get(), sync_thread_done_callback));
1430 } 1364 }
1431 1365
1432 #undef SDVLOG 1366 #undef SDVLOG
1433 1367
1434 #undef SLOG 1368 #undef SLOG
1435 1369
1436 } // namespace browser_sync 1370 } // namespace browser_sync
OLDNEW
« no previous file with comments | « chrome/browser/sync/glue/sync_backend_host.h ('k') | chrome/browser/sync/test_profile_sync_service.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698