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

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

Issue 10483015: [Sync] Refactor sync configuration logic. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 6 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 146 matching lines...) Expand 10 before | Expand all | Expand 10 after
157 // 2) Then, from |frontend_loop_|, halt the sync_thread_ (which is 157 // 2) Then, from |frontend_loop_|, halt the sync_thread_ (which is
158 // a blocking call). This causes syncapi thread-exit handlers 158 // a blocking call). This causes syncapi thread-exit handlers
159 // to run and make use of cached pointers to various components 159 // to run and make use of cached pointers to various components
160 // owned implicitly by us. 160 // owned implicitly by us.
161 // 3) Destroy this Core. That will delete syncapi components in a 161 // 3) Destroy this Core. That will delete syncapi components in a
162 // safe order because the thread that was using them has exited 162 // safe order because the thread that was using them has exited
163 // (in step 2). 163 // (in step 2).
164 void DoStopSyncManagerForShutdown(const base::Closure& closure); 164 void DoStopSyncManagerForShutdown(const base::Closure& closure);
165 void DoShutdown(bool stopping_sync); 165 void DoShutdown(bool stopping_sync);
166 166
167 virtual void DoRequestConfig( 167 // Configuration methods that must execute on sync loop.
168 const browser_sync::ModelSafeRoutingInfo& routing_info, 168 virtual void DoConfigureSyncer(
169 sync_api::ConfigureReason reason,
169 syncable::ModelTypeSet types_to_config, 170 syncable::ModelTypeSet types_to_config,
170 sync_api::ConfigureReason reason); 171 const browser_sync::ModelSafeRoutingInfo routing_info,
171 172 const base::Callback<void(syncable::ModelTypeSet)>& ready_task,
172 // Start the configuration mode. |callback| is called on the sync 173 const base::Closure& retry_callback);
173 // thread. 174 virtual void DoFinishConfigureDataTypes(
174 virtual void DoStartConfiguration(const base::Closure& callback); 175 syncable::ModelTypeSet types_to_config,
176 const base::Callback<void(syncable::ModelTypeSet)>& ready_task);
177 virtual void DoRetryConfiguration(
178 const base::Closure& retry_callback);
175 179
176 // Set the base request context to use when making HTTP calls. 180 // Set the base request context to use when making HTTP calls.
177 // This method will add a reference to the context to persist it 181 // This method will add a reference to the context to persist it
178 // on the IO thread. Must be removed from IO thread. 182 // on the IO thread. Must be removed from IO thread.
179 183
180 sync_api::SyncManager* sync_manager() { return sync_manager_.get(); } 184 sync_api::SyncManager* sync_manager() { return sync_manager_.get(); }
181 185
182 // Delete the sync data folder to cleanup backend data. Happens the first 186 // Delete the sync data folder to cleanup backend data. Happens the first
183 // time sync is enabled for a user (to prevent accidentally reusing old 187 // time sync is enabled for a user (to prevent accidentally reusing old
184 // sync databases), as well as shutdown when you're no longer syncing. 188 // sync databases), as well as shutdown when you're no longer syncing.
185 void DeleteSyncDataFolder(); 189 void DeleteSyncDataFolder();
186 190
187 // A callback from the SyncerThread when it is safe to continue config.
188 void FinishConfigureDataTypes();
189
190 private: 191 private:
191 friend class base::RefCountedThreadSafe<SyncBackendHost::Core>; 192 friend class base::RefCountedThreadSafe<SyncBackendHost::Core>;
192 friend class SyncBackendHostForProfileSyncTest; 193 friend class SyncBackendHostForProfileSyncTest;
193 194
194 virtual ~Core(); 195 virtual ~Core();
195 196
196 // Invoked when initialization of syncapi is complete and we can start 197 // Invoked when initialization of syncapi is complete and we can start
197 // our timer. 198 // our timer.
198 // This must be called from the thread on which SaveChanges is intended to 199 // This must be called from the thread on which SaveChanges is intended to
199 // be run on; the host's |sync_thread_|. 200 // be run on; the host's |sync_thread_|.
(...skipping 350 matching lines...) Expand 10 before | Expand all | Expand 10 after
550 stop_thread_start_time; 551 stop_thread_start_time;
551 UMA_HISTOGRAM_TIMES("Sync.Shutdown.StopSyncThreadTime", 552 UMA_HISTOGRAM_TIMES("Sync.Shutdown.StopSyncThreadTime",
552 stop_sync_thread_time); 553 stop_sync_thread_time);
553 554
554 registrar_.reset(); 555 registrar_.reset();
555 frontend_ = NULL; 556 frontend_ = NULL;
556 core_ = NULL; // Releases reference to core_. 557 core_ = NULL; // Releases reference to core_.
557 } 558 }
558 559
559 void SyncBackendHost::ConfigureDataTypes( 560 void SyncBackendHost::ConfigureDataTypes(
560 sync_api::ConfigureReason reason, 561 const sync_api::ConfigureReason& reason,
561 syncable::ModelTypeSet types_to_add, 562 const syncable::ModelTypeSet& desired_types,
562 syncable::ModelTypeSet types_to_remove, 563 const syncable::ModelTypeSet& disabled_types,
563 NigoriState nigori_state, 564 NigoriState nigori_state,
564 base::Callback<void(syncable::ModelTypeSet)> ready_task, 565 const base::Callback<void(syncable::ModelTypeSet)>& ready_task,
565 base::Callback<void()> retry_callback) { 566 const base::Callback<void()>& retry_callback) {
566 syncable::ModelTypeSet types_to_add_with_nigori = types_to_add; 567 syncable::ModelTypeSet desired_types_with_nigori = desired_types;
567 syncable::ModelTypeSet types_to_remove_with_nigori = types_to_remove; 568 syncable::ModelTypeSet disabled_types_with_nigori = disabled_types;
568 if (nigori_state == WITH_NIGORI) { 569 if (nigori_state == WITH_NIGORI) {
569 types_to_add_with_nigori.Put(syncable::NIGORI); 570 desired_types_with_nigori.Put(syncable::NIGORI);
570 types_to_remove_with_nigori.Remove(syncable::NIGORI); 571 disabled_types_with_nigori.Remove(syncable::NIGORI);
571 } else { 572 } else {
572 types_to_add_with_nigori.Remove(syncable::NIGORI); 573 desired_types_with_nigori.Remove(syncable::NIGORI);
573 types_to_remove_with_nigori.Put(syncable::NIGORI); 574 disabled_types_with_nigori.Put(syncable::NIGORI);
574 } 575 }
575 // Only one configure is allowed at a time. 576 // Only one configure is allowed at a time (DataTypeManager handles user
576 DCHECK(!pending_config_mode_state_.get()); 577 // changes that happen while the syncer is reconfiguraing, and will only
577 DCHECK(!pending_download_state_.get()); 578 // trigger another call to ConfigureDataTypes once the current reconfiguration
579 // completes).
578 DCHECK_GT(initialization_state_, NOT_INITIALIZED); 580 DCHECK_GT(initialization_state_, NOT_INITIALIZED);
579 581
580 pending_config_mode_state_.reset(new PendingConfigureDataTypesState()); 582 // enabled_types \setunion disabled_types gives the set of all registered
581 pending_config_mode_state_->ready_task = ready_task; 583 // types (e.g. types with datatype controllers registered).
582 pending_config_mode_state_->types_to_add = types_to_add_with_nigori; 584 ModelSafeRoutingInfo routing_info;
583 pending_config_mode_state_->added_types = 585 registrar_->ConfigureDataTypes(desired_types_with_nigori,
584 registrar_->ConfigureDataTypes(types_to_add_with_nigori, 586 disabled_types_with_nigori);
585 types_to_remove_with_nigori); 587 registrar_->GetModelSafeRoutingInfo(&routing_info);
586 pending_config_mode_state_->reason = reason;
587 pending_config_mode_state_->retry_callback = retry_callback;
588 588
589 // Cleanup disabled types before starting configuration so that 589 // enabled_types_with_nigori is desired_types_with_nigori \setunion types with
590 // callers can assume that the data types are cleaned up once 590 // model safe workers (e.g. the password store may fail to start up in which
591 // configuration is done. 591 // case we have no model safe worker for it and should not enable it).
592 if (!types_to_remove_with_nigori.Empty()) { 592 // TODO(zea): This shouldn't be necessary. We should do whatever filtering
593 ModelSafeRoutingInfo routing_info; 593 // we need beforehand as part of ProfileSyncComponentsFactory's
594 registrar_->GetModelSafeRoutingInfo(&routing_info); 594 // RegisterDataTypes.
595 sync_thread_.message_loop()->PostTask( 595 const syncable::ModelTypeSet enabled_types =
596 FROM_HERE, 596 GetRoutingInfoTypes(routing_info);
597 base::Bind(&SyncBackendHost::Core::DoRequestCleanupDisabledTypes,
598 core_.get(),
599 routing_info));
600 }
601 597
602 StartConfiguration( 598 // Figure out which types need to actually be downloaded. We pass those on
603 base::Bind(&SyncBackendHost::Core::FinishConfigureDataTypes, 599 // to the syncer while it's in configuration mode so that they can be
604 core_.get())); 600 // downloaded before we perform association. Once we switch to normal mode
601 // downloads will get applied normally and hit the datatype's change
602 // processor.
603 // A datatype is in need of downloading if any of the following are true:
604 // 1. it's enabled and initial_sync_ended is false (initial_sync_ended is
605 // set after applying updates, and hence is a more conservative measure
606 // than having a non-empty progress marker, which is set during
607 // StoreTimestamps).
608 // 2. the type is NIGORI, and any other datatype is being configured (nigori
609 // is always included if we do a configuration).
610 syncable::ModelTypeSet initial_sync_ended_types =
611 core_->sync_manager()->InitialSyncEndedTypes();
612 initial_sync_ended_types.RetainAll(enabled_types);
613 syncable::ModelTypeSet types_to_config =
614 Difference(enabled_types, initial_sync_ended_types);
615 if (types_to_config.Size() > 1)
616 types_to_config.Put(syncable::NIGORI);
617
618 SDVLOG(1) << "Types "
619 << syncable::ModelTypeSetToString(types_to_config)
620 << " added; calling DoConfigureSyncer";
621 // TODO(zea): figure out how to bypass this call if no types are being
622 // configured and GetKey/CleanupDisabledTypes are not needed. For now we rely
623 // on determining the need for GetKey/CleanupDisabledTypes as part of the
624 // SyncManager::ConfigureSyncer/SyncScheduler::Configure logic.
625 RequestConfigureSyncer(reason,
626 types_to_config,
627 routing_info,
628 ready_task,
629 retry_callback);
605 } 630 }
606 631
607 void SyncBackendHost::StartConfiguration(const base::Closure& callback) { 632 void SyncBackendHost::RequestConfigureSyncer(
608 // Put syncer in the config mode. DTM will put us in normal mode once it is 633 sync_api::ConfigureReason reason,
609 // done. This is to ensure we dont do a normal sync when we are doing model 634 syncable::ModelTypeSet types_to_config,
610 // association. 635 const browser_sync::ModelSafeRoutingInfo routing_info,
611 sync_thread_.message_loop()->PostTask(FROM_HERE, base::Bind( 636 const base::Callback<void(syncable::ModelTypeSet)>& ready_task,
612 &SyncBackendHost::Core::DoStartConfiguration, core_.get(), callback)); 637 const base::Closure& retry_callback) {
638 sync_thread_.message_loop()->PostTask(FROM_HERE,
639 base::Bind(&SyncBackendHost::Core::DoConfigureSyncer,
640 core_.get(),
641 reason,
642 types_to_config,
643 routing_info,
644 ready_task,
645 retry_callback));
646 }
647
648 void SyncBackendHost::FinishConfigureDataTypesOnFrontendLoop(
649 const syncable::ModelTypeSet& types_to_configure,
650 const syncable::ModelTypeSet& configured_types,
651 const base::Callback<void(syncable::ModelTypeSet)>& ready_task) {
652 const syncable::ModelTypeSet failed_configuration_types =
653 Difference(types_to_configure, configured_types);
654 SDVLOG(1)
655 << "Added types: "
656 << syncable::ModelTypeSetToString(types_to_configure)
657 << ", configured types: "
658 << syncable::ModelTypeSetToString(configured_types)
659 << ", failed configuration types: "
660 << syncable::ModelTypeSetToString(failed_configuration_types);
661
662 // Update |chrome_sync_notification_bridge_|'s enabled types here as it has
663 // to happen on the UI thread.
664 chrome_sync_notification_bridge_.UpdateEnabledTypes(configured_types);
665
666 // Notify SyncManager (especially the notification listener) about new types.
667 sync_thread_.message_loop()->PostTask(FROM_HERE,
668 base::Bind(&SyncBackendHost::Core::DoUpdateEnabledTypes, core_.get(),
669 configured_types));
670
671 if (!ready_task.is_null())
672 ready_task.Run(failed_configuration_types);
673 }
674
675 void SyncBackendHost::RetryConfigurationOnFrontendLoop(
676 const base::Closure& retry_callback) {
677 SDVLOG(1) << "Failed to complete configuration, informing of retry.";
678 retry_callback.Run();
613 } 679 }
614 680
615 void SyncBackendHost::EnableEncryptEverything() { 681 void SyncBackendHost::EnableEncryptEverything() {
616 sync_thread_.message_loop()->PostTask(FROM_HERE, 682 sync_thread_.message_loop()->PostTask(FROM_HERE,
617 base::Bind(&SyncBackendHost::Core::DoEnableEncryptEverything, 683 base::Bind(&SyncBackendHost::Core::DoEnableEncryptEverything,
618 core_.get())); 684 core_.get()));
619 } 685 }
620 686
621 void SyncBackendHost::ActivateDataType( 687 void SyncBackendHost::ActivateDataType(
622 syncable::ModelType type, ModelSafeGroup group, 688 syncable::ModelType type, ModelSafeGroup group,
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
700 const syncable::ModelTypeSet to_migrate = 766 const syncable::ModelTypeSet to_migrate =
701 snapshot.syncer_status().types_needing_local_migration; 767 snapshot.syncer_status().types_needing_local_migration;
702 if (!to_migrate.Empty()) 768 if (!to_migrate.Empty())
703 frontend_->OnMigrationNeededForTypes(to_migrate); 769 frontend_->OnMigrationNeededForTypes(to_migrate);
704 770
705 // Process any changes to the datatypes we're syncing. 771 // Process any changes to the datatypes we're syncing.
706 // TODO(sync): add support for removing types. 772 // TODO(sync): add support for removing types.
707 if (initialized()) 773 if (initialized())
708 AddExperimentalTypes(); 774 AddExperimentalTypes();
709 775
710 // If we are waiting for a configuration change, check here to see
711 // if this sync cycle has initialized all of the types we've been
712 // waiting for.
713 if (pending_download_state_.get()) {
714 const syncable::ModelTypeSet types_to_add =
715 pending_download_state_->types_to_add;
716 const syncable::ModelTypeSet added_types =
717 pending_download_state_->added_types;
718 DCHECK(types_to_add.HasAll(added_types));
719 const syncable::ModelTypeSet initial_sync_ended =
720 snapshot.initial_sync_ended();
721 const syncable::ModelTypeSet failed_configuration_types =
722 Difference(added_types, initial_sync_ended);
723 SDVLOG(1)
724 << "Added types: "
725 << syncable::ModelTypeSetToString(added_types)
726 << ", configured types: "
727 << syncable::ModelTypeSetToString(initial_sync_ended)
728 << ", failed configuration types: "
729 << syncable::ModelTypeSetToString(failed_configuration_types);
730
731 if (!failed_configuration_types.Empty() &&
732 snapshot.retry_scheduled()) {
733 // Inform the caller that download failed but we are retrying.
734 if (!pending_download_state_->retry_in_progress) {
735 pending_download_state_->retry_callback.Run();
736 pending_download_state_->retry_in_progress = true;
737 }
738 // Nothing more to do.
739 return;
740 }
741
742 scoped_ptr<PendingConfigureDataTypesState> state(
743 pending_download_state_.release());
744 state->ready_task.Run(failed_configuration_types);
745
746 // Syncer did not report an error but did not download everything
747 // we requested either. So abort. The caller of the config will cleanup.
748 if (!failed_configuration_types.Empty())
749 return;
750 }
751
752 if (initialized()) 776 if (initialized())
753 frontend_->OnSyncCycleCompleted(); 777 frontend_->OnSyncCycleCompleted();
754 } 778 }
755 779
756 void SyncBackendHost::FinishConfigureDataTypesOnFrontendLoop() {
757 DCHECK_EQ(MessageLoop::current(), frontend_loop_);
758 // Nudge the syncer. This is necessary for both datatype addition/deletion.
759 //
760 // Deletions need a nudge in order to ensure the deletion occurs in a timely
761 // manner (see issue 56416).
762 //
763 // In the case of additions, on the next sync cycle, the syncer should
764 // notice that the routing info has changed and start the process of
765 // downloading updates for newly added data types. Once this is
766 // complete, the configure_state_.ready_task_ is run via an
767 // OnInitializationComplete notification.
768
769 SDVLOG(1) << "Syncer in config mode. SBH executing "
770 << "FinishConfigureDataTypesOnFrontendLoop";
771
772
773 ModelSafeRoutingInfo routing_info;
774 registrar_->GetModelSafeRoutingInfo(&routing_info);
775 const syncable::ModelTypeSet enabled_types =
776 GetRoutingInfoTypes(routing_info);
777
778 // Update |chrome_sync_notification_bridge_|'s enabled types here as it has
779 // to happen on the UI thread.
780 chrome_sync_notification_bridge_.UpdateEnabledTypes(enabled_types);
781
782 if (pending_config_mode_state_->added_types.Empty() &&
783 !core_->sync_manager()->InitialSyncEndedTypes().HasAll(enabled_types)) {
784
785 // TODO(tim): Log / UMA / count this somehow?
786 // Add only the types with empty progress markers. Note: it is possible
787 // that some types have their initial_sync_ended be false but with non
788 // empty progress marker. Which is ok as the rest of the changes would
789 // be downloaded on a regular nudge and initial_sync_ended should be set
790 // to true. However this is a very corner case. So it is not explicitly
791 // handled.
792 pending_config_mode_state_->added_types =
793 sync_api::GetTypesWithEmptyProgressMarkerToken(enabled_types,
794 GetUserShare());
795 }
796
797 // If we've added types, we always want to request a nudge/config (even if
798 // the initial sync is ended), in case we could not decrypt the data.
799 if (pending_config_mode_state_->added_types.Empty()) {
800 SDVLOG(1) << "No new types added; calling ready_task directly";
801 // No new types - just notify the caller that the types are available.
802 const syncable::ModelTypeSet failed_configuration_types;
803 pending_config_mode_state_->ready_task.Run(failed_configuration_types);
804 } else {
805 pending_download_state_.reset(pending_config_mode_state_.release());
806
807 // Always configure nigori if it's enabled.
808 syncable::ModelTypeSet types_to_config =
809 pending_download_state_->added_types;
810 if (IsNigoriEnabled()) {
811 // Note: Nigori is the only type that gets added with a nonempty
812 // progress marker during config. If the server returns a migration
813 // error then we will go into unrecoverable error. We dont handle it
814 // explicitly because server might help us out here by not sending a
815 // migraiton error for nigori during config.
816 types_to_config.Put(syncable::NIGORI);
817 }
818 SDVLOG(1) << "Types "
819 << syncable::ModelTypeSetToString(types_to_config)
820 << " added; calling DoRequestConfig";
821 ModelSafeRoutingInfo routing_info;
822 registrar_->GetModelSafeRoutingInfo(&routing_info);
823 sync_thread_.message_loop()->PostTask(FROM_HERE,
824 base::Bind(&SyncBackendHost::Core::DoRequestConfig,
825 core_.get(),
826 routing_info,
827 types_to_config,
828 pending_download_state_->reason));
829 }
830
831 pending_config_mode_state_.reset();
832
833 // Notify SyncManager (especially the notification listener) about new types.
834 sync_thread_.message_loop()->PostTask(FROM_HERE,
835 base::Bind(&SyncBackendHost::Core::DoUpdateEnabledTypes, core_.get(),
836 enabled_types));
837 }
838
839 bool SyncBackendHost::IsDownloadingNigoriForTest() const { 780 bool SyncBackendHost::IsDownloadingNigoriForTest() const {
840 return initialization_state_ == DOWNLOADING_NIGORI; 781 return initialization_state_ == DOWNLOADING_NIGORI;
841 } 782 }
842 783
843 SyncBackendHost::DoInitializeOptions::DoInitializeOptions( 784 SyncBackendHost::DoInitializeOptions::DoInitializeOptions(
844 MessageLoop* sync_loop, 785 MessageLoop* sync_loop,
845 SyncBackendRegistrar* registrar, 786 SyncBackendRegistrar* registrar,
846 const ModelSafeRoutingInfo& routing_info, 787 const ModelSafeRoutingInfo& routing_info,
847 const std::vector<ModelSafeWorker*>& workers, 788 const std::vector<ModelSafeWorker*>& workers,
848 ExtensionsActivityMonitor* extensions_activity_monitor, 789 ExtensionsActivityMonitor* extensions_activity_monitor,
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
887 sync_loop_(NULL), 828 sync_loop_(NULL),
888 registrar_(NULL) { 829 registrar_(NULL) {
889 DCHECK(backend.get()); 830 DCHECK(backend.get());
890 } 831 }
891 832
892 SyncBackendHost::Core::~Core() { 833 SyncBackendHost::Core::~Core() {
893 DCHECK(!sync_manager_.get()); 834 DCHECK(!sync_manager_.get());
894 DCHECK(!sync_loop_); 835 DCHECK(!sync_loop_);
895 } 836 }
896 837
897 SyncBackendHost::PendingConfigureDataTypesState::
898 PendingConfigureDataTypesState()
899 : reason(sync_api::CONFIGURE_REASON_UNKNOWN),
900 retry_in_progress(false) {}
901
902 SyncBackendHost::PendingConfigureDataTypesState::
903 ~PendingConfigureDataTypesState() {}
904
905 void SyncBackendHost::Core::OnSyncCycleCompleted( 838 void SyncBackendHost::Core::OnSyncCycleCompleted(
906 const SyncSessionSnapshot& snapshot) { 839 const SyncSessionSnapshot& snapshot) {
907 if (!sync_loop_) 840 if (!sync_loop_)
908 return; 841 return;
909 DCHECK_EQ(MessageLoop::current(), sync_loop_); 842 DCHECK_EQ(MessageLoop::current(), sync_loop_);
910 host_.Call( 843 host_.Call(
911 FROM_HERE, 844 FROM_HERE,
912 &SyncBackendHost::HandleSyncCycleCompletedOnFrontendLoop, 845 &SyncBackendHost::HandleSyncCycleCompletedOnFrontendLoop,
913 snapshot); 846 snapshot);
914 } 847 }
(...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after
1146 const ModelSafeRoutingInfo& routing_info) { 1079 const ModelSafeRoutingInfo& routing_info) {
1147 DCHECK_EQ(MessageLoop::current(), sync_loop_); 1080 DCHECK_EQ(MessageLoop::current(), sync_loop_);
1148 sync_manager_->StartSyncingNormally(routing_info); 1081 sync_manager_->StartSyncingNormally(routing_info);
1149 } 1082 }
1150 1083
1151 void SyncBackendHost::Core::DoRequestClearServerData() { 1084 void SyncBackendHost::Core::DoRequestClearServerData() {
1152 DCHECK_EQ(MessageLoop::current(), sync_loop_); 1085 DCHECK_EQ(MessageLoop::current(), sync_loop_);
1153 sync_manager_->RequestClearServerData(); 1086 sync_manager_->RequestClearServerData();
1154 } 1087 }
1155 1088
1156 void SyncBackendHost::Core::DoRequestCleanupDisabledTypes(
1157 const browser_sync::ModelSafeRoutingInfo& routing_info) {
1158 DCHECK_EQ(MessageLoop::current(), sync_loop_);
1159 sync_manager_->RequestCleanupDisabledTypes(routing_info);
1160 }
1161
1162 void SyncBackendHost::Core::DoSetEncryptionPassphrase( 1089 void SyncBackendHost::Core::DoSetEncryptionPassphrase(
1163 const std::string& passphrase, 1090 const std::string& passphrase,
1164 bool is_explicit) { 1091 bool is_explicit) {
1165 DCHECK_EQ(MessageLoop::current(), sync_loop_); 1092 DCHECK_EQ(MessageLoop::current(), sync_loop_);
1166 sync_manager_->SetEncryptionPassphrase(passphrase, is_explicit); 1093 sync_manager_->SetEncryptionPassphrase(passphrase, is_explicit);
1167 } 1094 }
1168 1095
1169 void SyncBackendHost::Core::DoSetDecryptionPassphrase( 1096 void SyncBackendHost::Core::DoSetDecryptionPassphrase(
1170 const std::string& passphrase) { 1097 const std::string& passphrase) {
1171 DCHECK_EQ(MessageLoop::current(), sync_loop_); 1098 DCHECK_EQ(MessageLoop::current(), sync_loop_);
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
1203 registrar_ = NULL; 1130 registrar_ = NULL;
1204 1131
1205 if (sync_disabled) 1132 if (sync_disabled)
1206 DeleteSyncDataFolder(); 1133 DeleteSyncDataFolder();
1207 1134
1208 sync_loop_ = NULL; 1135 sync_loop_ = NULL;
1209 1136
1210 host_.Reset(); 1137 host_.Reset();
1211 } 1138 }
1212 1139
1213 void SyncBackendHost::Core::DoRequestConfig( 1140 void SyncBackendHost::Core::DoConfigureSyncer(
1214 const browser_sync::ModelSafeRoutingInfo& routing_info, 1141 sync_api::ConfigureReason reason,
1215 syncable::ModelTypeSet types_to_config, 1142 syncable::ModelTypeSet types_to_config,
1216 sync_api::ConfigureReason reason) { 1143 const browser_sync::ModelSafeRoutingInfo routing_info,
1144 const base::Callback<void(syncable::ModelTypeSet)>& ready_task,
1145 const base::Closure& retry_callback) {
1217 DCHECK_EQ(MessageLoop::current(), sync_loop_); 1146 DCHECK_EQ(MessageLoop::current(), sync_loop_);
1218 sync_manager_->RequestConfig(routing_info, types_to_config, reason); 1147 sync_manager_->ConfigureSyncer(
1148 reason,
1149 types_to_config,
1150 routing_info,
1151 base::Bind(&SyncBackendHost::Core::DoFinishConfigureDataTypes,
1152 this,
1153 types_to_config,
1154 ready_task),
1155 base::Bind(&SyncBackendHost::Core::DoRetryConfiguration,
1156 this,
1157 retry_callback));
1219 } 1158 }
1220 1159
1221 void SyncBackendHost::Core::DoStartConfiguration( 1160 void SyncBackendHost::Core::DoFinishConfigureDataTypes(
1222 const base::Closure& callback) { 1161 syncable::ModelTypeSet types_to_config,
1162 const base::Callback<void(syncable::ModelTypeSet)>& ready_task) {
1223 DCHECK_EQ(MessageLoop::current(), sync_loop_); 1163 DCHECK_EQ(MessageLoop::current(), sync_loop_);
1224 sync_manager_->StartConfigurationMode(callback); 1164 syncable::ModelTypeSet configured_types =
1165 sync_manager_->InitialSyncEndedTypes();
rlarocque 2012/06/04 23:01:38 The SyncManager is sitting on the stack frame dire
Nicolas Zea 2012/06/07 19:25:42 This is not called by the sync manager, but by the
1166 configured_types.RetainAll(types_to_config);
1167 host_.Call(FROM_HERE,
1168 &SyncBackendHost::FinishConfigureDataTypesOnFrontendLoop,
1169 types_to_config,
1170 configured_types,
1171 ready_task);
1172 }
1173
1174 void SyncBackendHost::Core::DoRetryConfiguration(
1175 const base::Closure& retry_callback) {
1176 DCHECK_EQ(MessageLoop::current(), sync_loop_);
1177 host_.Call(FROM_HERE,
1178 &SyncBackendHost::RetryConfigurationOnFrontendLoop,
1179 retry_callback);
1225 } 1180 }
1226 1181
1227 void SyncBackendHost::Core::DeleteSyncDataFolder() { 1182 void SyncBackendHost::Core::DeleteSyncDataFolder() {
1228 DCHECK_EQ(MessageLoop::current(), sync_loop_); 1183 DCHECK_EQ(MessageLoop::current(), sync_loop_);
1229 if (file_util::DirectoryExists(sync_data_folder_path_)) { 1184 if (file_util::DirectoryExists(sync_data_folder_path_)) {
1230 if (!file_util::Delete(sync_data_folder_path_, true)) 1185 if (!file_util::Delete(sync_data_folder_path_, true))
1231 SLOG(DFATAL) << "Could not delete the Sync Data folder."; 1186 SLOG(DFATAL) << "Could not delete the Sync Data folder.";
1232 } 1187 }
1233 } 1188 }
1234 1189
1235 void SyncBackendHost::Core::FinishConfigureDataTypes() {
1236 DCHECK_EQ(MessageLoop::current(), sync_loop_);
1237 host_.Call(
1238 FROM_HERE,
1239 &SyncBackendHost::FinishConfigureDataTypesOnFrontendLoop);
1240 }
1241
1242 void SyncBackendHost::Core::StartSavingChanges() { 1190 void SyncBackendHost::Core::StartSavingChanges() {
1243 // We may already be shut down. 1191 // We may already be shut down.
1244 if (!sync_loop_) 1192 if (!sync_loop_)
1245 return; 1193 return;
1246 DCHECK_EQ(MessageLoop::current(), sync_loop_); 1194 DCHECK_EQ(MessageLoop::current(), sync_loop_);
1247 DCHECK(!save_changes_timer_.get()); 1195 DCHECK(!save_changes_timer_.get());
1248 save_changes_timer_.reset(new base::RepeatingTimer<Core>()); 1196 save_changes_timer_.reset(new base::RepeatingTimer<Core>());
1249 save_changes_timer_->Start(FROM_HERE, 1197 save_changes_timer_->Start(FROM_HERE,
1250 base::TimeDelta::FromSeconds(kSaveChangesIntervalSeconds), 1198 base::TimeDelta::FromSeconds(kSaveChangesIntervalSeconds),
1251 this, &Core::SaveChanges); 1199 this, &Core::SaveChanges);
(...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after
1470 FROM_HERE, 1418 FROM_HERE,
1471 base::Bind(&SyncBackendHost::Core::DoRefreshNigori, 1419 base::Bind(&SyncBackendHost::Core::DoRefreshNigori,
1472 core_.get(), sync_thread_done_callback)); 1420 core_.get(), sync_thread_done_callback));
1473 } 1421 }
1474 1422
1475 #undef SDVLOG 1423 #undef SDVLOG
1476 1424
1477 #undef SLOG 1425 #undef SLOG
1478 1426
1479 } // namespace browser_sync 1427 } // namespace browser_sync
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698