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

Side by Side Diff: sync/internal_api/sync_manager.cc

Issue 10701085: Revert "Revert 142517 - [Sync] Refactor sync configuration logic." (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix deps 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 "sync/internal_api/public/sync_manager.h" 5 #include "sync/internal_api/public/sync_manager.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/base64.h" 9 #include "base/base64.h"
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 14 matching lines...) Expand all
25 #include "sync/engine/throttled_data_type_tracker.h" 25 #include "sync/engine/throttled_data_type_tracker.h"
26 #include "sync/internal_api/change_reorder_buffer.h" 26 #include "sync/internal_api/change_reorder_buffer.h"
27 #include "sync/internal_api/debug_info_event_listener.h" 27 #include "sync/internal_api/debug_info_event_listener.h"
28 #include "sync/internal_api/js_mutation_event_observer.h" 28 #include "sync/internal_api/js_mutation_event_observer.h"
29 #include "sync/internal_api/js_sync_manager_observer.h" 29 #include "sync/internal_api/js_sync_manager_observer.h"
30 #include "sync/internal_api/public/base/model_type.h" 30 #include "sync/internal_api/public/base/model_type.h"
31 #include "sync/internal_api/public/base/model_type_payload_map.h" 31 #include "sync/internal_api/public/base/model_type_payload_map.h"
32 #include "sync/internal_api/public/base_node.h" 32 #include "sync/internal_api/public/base_node.h"
33 #include "sync/internal_api/public/configure_reason.h" 33 #include "sync/internal_api/public/configure_reason.h"
34 #include "sync/internal_api/public/engine/polling_constants.h" 34 #include "sync/internal_api/public/engine/polling_constants.h"
35 #include "sync/internal_api/public/http_post_provider_factory.h"
35 #include "sync/internal_api/public/read_node.h" 36 #include "sync/internal_api/public/read_node.h"
36 #include "sync/internal_api/public/read_transaction.h" 37 #include "sync/internal_api/public/read_transaction.h"
37 #include "sync/internal_api/public/user_share.h" 38 #include "sync/internal_api/public/user_share.h"
38 #include "sync/internal_api/public/util/experiments.h" 39 #include "sync/internal_api/public/util/experiments.h"
39 #include "sync/internal_api/public/write_node.h" 40 #include "sync/internal_api/public/write_node.h"
40 #include "sync/internal_api/public/write_transaction.h" 41 #include "sync/internal_api/public/write_transaction.h"
41 #include "sync/internal_api/syncapi_internal.h" 42 #include "sync/internal_api/syncapi_internal.h"
42 #include "sync/internal_api/syncapi_server_connection_manager.h" 43 #include "sync/internal_api/syncapi_server_connection_manager.h"
43 #include "sync/js/js_arg_list.h" 44 #include "sync/js/js_arg_list.h"
44 #include "sync/js/js_backend.h" 45 #include "sync/js/js_backend.h"
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
169 virtual ~SyncInternal() { 170 virtual ~SyncInternal() {
170 CHECK(!initialized_); 171 CHECK(!initialized_);
171 } 172 }
172 173
173 bool Init(const FilePath& database_location, 174 bool Init(const FilePath& database_location,
174 const WeakHandle<JsEventHandler>& event_handler, 175 const WeakHandle<JsEventHandler>& event_handler,
175 const std::string& sync_server_and_path, 176 const std::string& sync_server_and_path,
176 int port, 177 int port,
177 bool use_ssl, 178 bool use_ssl,
178 const scoped_refptr<base::TaskRunner>& blocking_task_runner, 179 const scoped_refptr<base::TaskRunner>& blocking_task_runner,
179 HttpPostProviderFactory* post_factory, 180 scoped_ptr<HttpPostProviderFactory> post_factory,
180 const syncer::ModelSafeRoutingInfo& model_safe_routing_info, 181 const syncer::ModelSafeRoutingInfo& model_safe_routing_info,
181 const std::vector<syncer::ModelSafeWorker*>& workers, 182 const std::vector<syncer::ModelSafeWorker*>& workers,
182 syncer::ExtensionsActivityMonitor* 183 syncer::ExtensionsActivityMonitor*
183 extensions_activity_monitor, 184 extensions_activity_monitor,
184 ChangeDelegate* change_delegate, 185 ChangeDelegate* change_delegate,
185 const SyncCredentials& credentials, 186 const SyncCredentials& credentials,
186 syncer::SyncNotifier* sync_notifier, 187 scoped_ptr<syncer::SyncNotifier> sync_notifier,
187 const std::string& restored_key_for_bootstrapping, 188 const std::string& restored_key_for_bootstrapping,
188 TestingMode testing_mode, 189 TestingMode testing_mode,
189 Encryptor* encryptor, 190 Encryptor* encryptor,
190 UnrecoverableErrorHandler* unrecoverable_error_handler, 191 UnrecoverableErrorHandler* unrecoverable_error_handler,
191 ReportUnrecoverableErrorFunction 192 ReportUnrecoverableErrorFunction
192 report_unrecoverable_error_function); 193 report_unrecoverable_error_function);
193 194
194 // Sign into sync with given credentials. 195 // Sign into sync with given credentials.
195 // We do not verify the tokens given. After this call, the tokens are set 196 // We do not verify the tokens given. After this call, the tokens are set
196 // and the sync DB is open. True if successful, false if something 197 // and the sync DB is open. True if successful, false if something
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after
369 virtual void OnServerConnectionEvent( 370 virtual void OnServerConnectionEvent(
370 const ServerConnectionEvent& event) OVERRIDE; 371 const ServerConnectionEvent& event) OVERRIDE;
371 372
372 // JsBackend implementation. 373 // JsBackend implementation.
373 virtual void SetJsEventHandler( 374 virtual void SetJsEventHandler(
374 const WeakHandle<JsEventHandler>& event_handler) OVERRIDE; 375 const WeakHandle<JsEventHandler>& event_handler) OVERRIDE;
375 virtual void ProcessJsMessage( 376 virtual void ProcessJsMessage(
376 const std::string& name, const JsArgList& args, 377 const std::string& name, const JsArgList& args,
377 const WeakHandle<JsReplyHandler>& reply_handler) OVERRIDE; 378 const WeakHandle<JsReplyHandler>& reply_handler) OVERRIDE;
378 379
380 void SetSyncSchedulerForTest(scoped_ptr<SyncScheduler> scheduler);
381
379 private: 382 private:
380 struct NotificationInfo { 383 struct NotificationInfo {
381 int total_count; 384 int total_count;
382 std::string payload; 385 std::string payload;
383 386
384 NotificationInfo() : total_count(0) {} 387 NotificationInfo() : total_count(0) {}
385 388
386 ~NotificationInfo() {} 389 ~NotificationInfo() {}
387 390
388 // Returned pointer owned by the caller. 391 // Returned pointer owned by the caller.
(...skipping 296 matching lines...) Expand 10 before | Expand all | Expand 10 after
685 SyncManager::SyncManager(const std::string& name) 688 SyncManager::SyncManager(const std::string& name)
686 : data_(new SyncInternal(name)) {} 689 : data_(new SyncInternal(name)) {}
687 690
688 bool SyncManager::Init( 691 bool SyncManager::Init(
689 const FilePath& database_location, 692 const FilePath& database_location,
690 const WeakHandle<JsEventHandler>& event_handler, 693 const WeakHandle<JsEventHandler>& event_handler,
691 const std::string& sync_server_and_path, 694 const std::string& sync_server_and_path,
692 int sync_server_port, 695 int sync_server_port,
693 bool use_ssl, 696 bool use_ssl,
694 const scoped_refptr<base::TaskRunner>& blocking_task_runner, 697 const scoped_refptr<base::TaskRunner>& blocking_task_runner,
695 HttpPostProviderFactory* post_factory, 698 scoped_ptr<HttpPostProviderFactory> post_factory,
696 const syncer::ModelSafeRoutingInfo& model_safe_routing_info, 699 const syncer::ModelSafeRoutingInfo& model_safe_routing_info,
697 const std::vector<syncer::ModelSafeWorker*>& workers, 700 const std::vector<syncer::ModelSafeWorker*>& workers,
698 syncer::ExtensionsActivityMonitor* extensions_activity_monitor, 701 syncer::ExtensionsActivityMonitor* extensions_activity_monitor,
699 ChangeDelegate* change_delegate, 702 ChangeDelegate* change_delegate,
700 const SyncCredentials& credentials, 703 const SyncCredentials& credentials,
701 syncer::SyncNotifier* sync_notifier, 704 scoped_ptr<syncer::SyncNotifier> sync_notifier,
702 const std::string& restored_key_for_bootstrapping, 705 const std::string& restored_key_for_bootstrapping,
703 TestingMode testing_mode, 706 TestingMode testing_mode,
704 Encryptor* encryptor, 707 Encryptor* encryptor,
705 UnrecoverableErrorHandler* unrecoverable_error_handler, 708 UnrecoverableErrorHandler* unrecoverable_error_handler,
706 ReportUnrecoverableErrorFunction report_unrecoverable_error_function) { 709 ReportUnrecoverableErrorFunction report_unrecoverable_error_function) {
707 DCHECK(thread_checker_.CalledOnValidThread()); 710 DCHECK(thread_checker_.CalledOnValidThread());
708 DCHECK(post_factory); 711 DCHECK(post_factory.get());
709 DVLOG(1) << "SyncManager starting Init..."; 712 DVLOG(1) << "SyncManager starting Init...";
710 std::string server_string(sync_server_and_path); 713 std::string server_string(sync_server_and_path);
711 return data_->Init(database_location, 714 return data_->Init(database_location,
712 event_handler, 715 event_handler,
713 server_string, 716 server_string,
714 sync_server_port, 717 sync_server_port,
715 use_ssl, 718 use_ssl,
716 blocking_task_runner, 719 blocking_task_runner,
717 post_factory, 720 post_factory.Pass(),
718 model_safe_routing_info, 721 model_safe_routing_info,
719 workers, 722 workers,
720 extensions_activity_monitor, 723 extensions_activity_monitor,
721 change_delegate, 724 change_delegate,
722 credentials, 725 credentials,
723 sync_notifier, 726 sync_notifier.Pass(),
724 restored_key_for_bootstrapping, 727 restored_key_for_bootstrapping,
725 testing_mode, 728 testing_mode,
726 encryptor, 729 encryptor,
727 unrecoverable_error_handler, 730 unrecoverable_error_handler,
728 report_unrecoverable_error_function); 731 report_unrecoverable_error_function);
729 } 732 }
730 733
731 void SyncManager::UpdateCredentials(const SyncCredentials& credentials) { 734 void SyncManager::UpdateCredentials(const SyncCredentials& credentials) {
732 DCHECK(thread_checker_.CalledOnValidThread()); 735 DCHECK(thread_checker_.CalledOnValidThread());
733 data_->UpdateCredentials(credentials); 736 data_->UpdateCredentials(credentials);
734 } 737 }
735 738
736 void SyncManager::UpdateEnabledTypes(const ModelTypeSet& enabled_types) { 739 void SyncManager::UpdateEnabledTypes(const ModelTypeSet& enabled_types) {
737 DCHECK(thread_checker_.CalledOnValidThread()); 740 DCHECK(thread_checker_.CalledOnValidThread());
738 data_->UpdateEnabledTypes(enabled_types); 741 data_->UpdateEnabledTypes(enabled_types);
739 } 742 }
740 743
741 void SyncManager::ThrowUnrecoverableError() { 744 void SyncManager::ThrowUnrecoverableError() {
742 DCHECK(thread_checker_.CalledOnValidThread()); 745 DCHECK(thread_checker_.CalledOnValidThread());
743 ReadTransaction trans(FROM_HERE, GetUserShare()); 746 ReadTransaction trans(FROM_HERE, GetUserShare());
744 trans.GetWrappedTrans()->OnUnrecoverableError( 747 trans.GetWrappedTrans()->OnUnrecoverableError(
745 FROM_HERE, "Simulating unrecoverable error for testing purposes."); 748 FROM_HERE, "Simulating unrecoverable error for testing purposes.");
746 } 749 }
747 750
748 syncer::ModelTypeSet SyncManager::InitialSyncEndedTypes() { 751 syncer::ModelTypeSet SyncManager::InitialSyncEndedTypes() {
749 return data_->InitialSyncEndedTypes(); 752 return data_->InitialSyncEndedTypes();
750 } 753 }
751 754
755 syncer::ModelTypeSet SyncManager::GetTypesWithEmptyProgressMarkerToken(
756 syncer::ModelTypeSet types) {
757 syncer::ModelTypeSet result;
758 for (syncer::ModelTypeSet::Iterator i = types.First();
759 i.Good(); i.Inc()) {
760 sync_pb::DataTypeProgressMarker marker;
761 GetUserShare()->directory->GetDownloadProgress(i.Get(), &marker);
762
763 if (marker.token().empty())
764 result.Put(i.Get());
765
766 }
767 return result;
768 }
769
752 void SyncManager::StartSyncingNormally( 770 void SyncManager::StartSyncingNormally(
753 const syncer::ModelSafeRoutingInfo& routing_info) { 771 const syncer::ModelSafeRoutingInfo& routing_info) {
754 DCHECK(thread_checker_.CalledOnValidThread()); 772 DCHECK(thread_checker_.CalledOnValidThread());
755 data_->StartSyncingNormally(routing_info); 773 data_->StartSyncingNormally(routing_info);
756 } 774 }
757 775
758 void SyncManager::SetEncryptionPassphrase(const std::string& passphrase, 776 void SyncManager::SetEncryptionPassphrase(const std::string& passphrase,
759 bool is_explicit) { 777 bool is_explicit) {
760 DCHECK(thread_checker_.CalledOnValidThread()); 778 DCHECK(thread_checker_.CalledOnValidThread());
761 data_->SetEncryptionPassphrase(passphrase, is_explicit); 779 data_->SetEncryptionPassphrase(passphrase, is_explicit);
(...skipping 24 matching lines...) Expand all
786 804
787 bool SyncManager::EncryptEverythingEnabledForTest() const { 805 bool SyncManager::EncryptEverythingEnabledForTest() const {
788 ReadTransaction trans(FROM_HERE, GetUserShare()); 806 ReadTransaction trans(FROM_HERE, GetUserShare());
789 return trans.GetCryptographer()->encrypt_everything(); 807 return trans.GetCryptographer()->encrypt_everything();
790 } 808 }
791 809
792 bool SyncManager::IsUsingExplicitPassphrase() { 810 bool SyncManager::IsUsingExplicitPassphrase() {
793 return data_ && data_->IsUsingExplicitPassphrase(); 811 return data_ && data_->IsUsingExplicitPassphrase();
794 } 812 }
795 813
796 void SyncManager::RequestCleanupDisabledTypes( 814 void SyncManager::ConfigureSyncer(
797 const syncer::ModelSafeRoutingInfo& routing_info) { 815 ConfigureReason reason,
816 const syncer::ModelTypeSet& types_to_config,
817 const syncer::ModelSafeRoutingInfo& new_routing_info,
818 const base::Closure& ready_task,
819 const base::Closure& retry_task) {
798 DCHECK(thread_checker_.CalledOnValidThread()); 820 DCHECK(thread_checker_.CalledOnValidThread());
799 if (data_->scheduler()) { 821 DCHECK(!ready_task.is_null());
800 data_->session_context()->set_routing_info(routing_info); 822 DCHECK(!retry_task.is_null());
801 data_->scheduler()->CleanupDisabledTypes();
802 }
803 }
804 823
805 void SyncManager::RequestConfig( 824 // TODO(zea): set this based on whether cryptographer has keystore
806 const syncer::ModelSafeRoutingInfo& routing_info, 825 // encryption key or not (requires opening a transaction). crbug.com/129665.
807 const ModelTypeSet& types, ConfigureReason reason) { 826 ConfigurationParams::KeystoreKeyStatus keystore_key_status =
808 DCHECK(thread_checker_.CalledOnValidThread()); 827 ConfigurationParams::KEYSTORE_KEY_UNNECESSARY;
828
829 ConfigurationParams params(GetSourceFromReason(reason),
830 types_to_config,
831 new_routing_info,
832 keystore_key_status,
833 ready_task);
834
809 if (!data_->scheduler()) { 835 if (!data_->scheduler()) {
810 LOG(INFO) 836 LOG(INFO)
811 << "SyncManager::RequestConfig: bailing out because scheduler is " 837 << "SyncManager::ConfigureSyncer: could not configure because "
812 << "null"; 838 << "scheduler is null";
839 params.ready_task.Run();
813 return; 840 return;
814 } 841 }
815 StartConfigurationMode(base::Closure());
816 data_->session_context()->set_routing_info(routing_info);
817 data_->scheduler()->ScheduleConfiguration(types, GetSourceFromReason(reason));
818 }
819 842
820 void SyncManager::StartConfigurationMode(const base::Closure& callback) { 843 data_->scheduler()->Start(syncer::SyncScheduler::CONFIGURATION_MODE);
821 DCHECK(thread_checker_.CalledOnValidThread()); 844 if (!data_->scheduler()->ScheduleConfiguration(params))
822 if (!data_->scheduler()) { 845 retry_task.Run();
823 LOG(INFO) 846
824 << "SyncManager::StartConfigurationMode: could not start "
825 << "configuration mode because because scheduler is null";
826 return;
827 }
828 data_->scheduler()->Start(
829 syncer::SyncScheduler::CONFIGURATION_MODE, callback);
830 } 847 }
831 848
832 bool SyncManager::SyncInternal::Init( 849 bool SyncManager::SyncInternal::Init(
833 const FilePath& database_location, 850 const FilePath& database_location,
834 const WeakHandle<JsEventHandler>& event_handler, 851 const WeakHandle<JsEventHandler>& event_handler,
835 const std::string& sync_server_and_path, 852 const std::string& sync_server_and_path,
836 int port, 853 int port,
837 bool use_ssl, 854 bool use_ssl,
838 const scoped_refptr<base::TaskRunner>& blocking_task_runner, 855 const scoped_refptr<base::TaskRunner>& blocking_task_runner,
839 HttpPostProviderFactory* post_factory, 856 scoped_ptr<HttpPostProviderFactory> post_factory,
840 const syncer::ModelSafeRoutingInfo& model_safe_routing_info, 857 const syncer::ModelSafeRoutingInfo& model_safe_routing_info,
841 const std::vector<syncer::ModelSafeWorker*>& workers, 858 const std::vector<syncer::ModelSafeWorker*>& workers,
842 syncer::ExtensionsActivityMonitor* extensions_activity_monitor, 859 syncer::ExtensionsActivityMonitor* extensions_activity_monitor,
843 ChangeDelegate* change_delegate, 860 ChangeDelegate* change_delegate,
844 const SyncCredentials& credentials, 861 const SyncCredentials& credentials,
845 syncer::SyncNotifier* sync_notifier, 862 scoped_ptr<syncer::SyncNotifier> sync_notifier,
846 const std::string& restored_key_for_bootstrapping, 863 const std::string& restored_key_for_bootstrapping,
847 TestingMode testing_mode, 864 TestingMode testing_mode,
848 Encryptor* encryptor, 865 Encryptor* encryptor,
849 UnrecoverableErrorHandler* unrecoverable_error_handler, 866 UnrecoverableErrorHandler* unrecoverable_error_handler,
850 ReportUnrecoverableErrorFunction report_unrecoverable_error_function) { 867 ReportUnrecoverableErrorFunction report_unrecoverable_error_function) {
851 CHECK(!initialized_); 868 CHECK(!initialized_);
852 869
853 DCHECK(thread_checker_.CalledOnValidThread()); 870 DCHECK(thread_checker_.CalledOnValidThread());
854 871
855 DVLOG(1) << "Starting SyncInternal initialization."; 872 DVLOG(1) << "Starting SyncInternal initialization.";
856 873
857 weak_handle_this_ = MakeWeakHandle(weak_ptr_factory_.GetWeakPtr()); 874 weak_handle_this_ = MakeWeakHandle(weak_ptr_factory_.GetWeakPtr());
858 875
859 blocking_task_runner_ = blocking_task_runner; 876 blocking_task_runner_ = blocking_task_runner;
860 877
861 change_delegate_ = change_delegate; 878 change_delegate_ = change_delegate;
862 testing_mode_ = testing_mode; 879 testing_mode_ = testing_mode;
863 880
864 sync_notifier_.reset(sync_notifier); 881 sync_notifier_ = sync_notifier.Pass();
865 882
866 AddObserver(&js_sync_manager_observer_); 883 AddObserver(&js_sync_manager_observer_);
867 SetJsEventHandler(event_handler); 884 SetJsEventHandler(event_handler);
868 885
869 AddObserver(&debug_info_event_listener_); 886 AddObserver(&debug_info_event_listener_);
870 887
871 database_path_ = database_location.Append( 888 database_path_ = database_location.Append(
872 syncable::Directory::kSyncDatabaseFilename); 889 syncable::Directory::kSyncDatabaseFilename);
873 encryptor_ = encryptor; 890 encryptor_ = encryptor;
874 unrecoverable_error_handler_ = unrecoverable_error_handler; 891 unrecoverable_error_handler_ = unrecoverable_error_handler;
(...skipping 13 matching lines...) Expand all
888 } 905 }
889 906
890 DCHECK(backing_store); 907 DCHECK(backing_store);
891 share_.directory.reset( 908 share_.directory.reset(
892 new syncable::Directory(encryptor_, 909 new syncable::Directory(encryptor_,
893 unrecoverable_error_handler_, 910 unrecoverable_error_handler_,
894 report_unrecoverable_error_function_, 911 report_unrecoverable_error_function_,
895 backing_store)); 912 backing_store));
896 913
897 connection_manager_.reset(new SyncAPIServerConnectionManager( 914 connection_manager_.reset(new SyncAPIServerConnectionManager(
898 sync_server_and_path, port, use_ssl, post_factory)); 915 sync_server_and_path, port, use_ssl, post_factory.release()));
899 916
900 net::NetworkChangeNotifier::AddIPAddressObserver(this); 917 net::NetworkChangeNotifier::AddIPAddressObserver(this);
901 observing_ip_address_changes_ = true; 918 observing_ip_address_changes_ = true;
902 919
903 connection_manager()->AddListener(this); 920 connection_manager()->AddListener(this);
904 921
905 // Test mode does not use a syncer context or syncer thread. 922 // Test mode does not use a syncer context or syncer thread.
906 if (testing_mode_ == NON_TEST) { 923 if (testing_mode_ == NON_TEST) {
907 // Build a SyncSessionContext and store the worker in it. 924 // Build a SyncSessionContext and store the worker in it.
908 DVLOG(1) << "Sync is bringing up SyncSessionContext."; 925 DVLOG(1) << "Sync is bringing up SyncSessionContext.";
(...skipping 11 matching lines...) Expand all
920 &debug_info_event_listener_, 937 &debug_info_event_listener_,
921 &traffic_recorder_)); 938 &traffic_recorder_));
922 session_context()->set_account_name(credentials.email); 939 session_context()->set_account_name(credentials.email);
923 scheduler_.reset(new SyncScheduler(name_, session_context(), new Syncer())); 940 scheduler_.reset(new SyncScheduler(name_, session_context(), new Syncer()));
924 } 941 }
925 942
926 bool signed_in = SignIn(credentials); 943 bool signed_in = SignIn(credentials);
927 944
928 if (signed_in) { 945 if (signed_in) {
929 if (scheduler()) { 946 if (scheduler()) {
930 scheduler()->Start( 947 scheduler()->Start(syncer::SyncScheduler::CONFIGURATION_MODE);
931 syncer::SyncScheduler::CONFIGURATION_MODE, base::Closure());
932 } 948 }
933 949
934 initialized_ = true; 950 initialized_ = true;
935 951
936 // Cryptographer should only be accessed while holding a 952 // Cryptographer should only be accessed while holding a
937 // transaction. Grabbing the user share for the transaction 953 // transaction. Grabbing the user share for the transaction
938 // checks the initialization state, so this must come after 954 // checks the initialization state, so this must come after
939 // |initialized_| is set to true. 955 // |initialized_| is set to true.
940 ReadTransaction trans(FROM_HERE, GetUserShare()); 956 ReadTransaction trans(FROM_HERE, GetUserShare());
941 trans.GetCryptographer()->Bootstrap(restored_key_for_bootstrapping); 957 trans.GetCryptographer()->Bootstrap(restored_key_for_bootstrapping);
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after
1095 allstatus_.SetCryptographerReady(cryptographer->is_ready()); 1111 allstatus_.SetCryptographerReady(cryptographer->is_ready());
1096 allstatus_.SetCryptoHasPendingKeys(cryptographer->has_pending_keys()); 1112 allstatus_.SetCryptoHasPendingKeys(cryptographer->has_pending_keys());
1097 debug_info_event_listener_.SetCryptographerReady(cryptographer->is_ready()); 1113 debug_info_event_listener_.SetCryptographerReady(cryptographer->is_ready());
1098 debug_info_event_listener_.SetCrytographerHasPendingKeys( 1114 debug_info_event_listener_.SetCrytographerHasPendingKeys(
1099 cryptographer->has_pending_keys()); 1115 cryptographer->has_pending_keys());
1100 } 1116 }
1101 1117
1102 void SyncManager::SyncInternal::StartSyncingNormally( 1118 void SyncManager::SyncInternal::StartSyncingNormally(
1103 const syncer::ModelSafeRoutingInfo& routing_info) { 1119 const syncer::ModelSafeRoutingInfo& routing_info) {
1104 // Start the sync scheduler. 1120 // Start the sync scheduler.
1105 if (scheduler()) { // NULL during certain unittests. 1121 if (scheduler()) { // NULL during certain unittests.
1122 // TODO(sync): We always want the newest set of routes when we switch back
1123 // to normal mode. Figure out how to enforce set_routing_info is always
1124 // appropriately set and that it's only modified when switching to normal
1125 // mode.
1106 session_context()->set_routing_info(routing_info); 1126 session_context()->set_routing_info(routing_info);
1107 scheduler()->Start(SyncScheduler::NORMAL_MODE, base::Closure()); 1127 scheduler()->Start(SyncScheduler::NORMAL_MODE);
1108 } 1128 }
1109 } 1129 }
1110 1130
1111 bool SyncManager::SyncInternal::OpenDirectory() { 1131 bool SyncManager::SyncInternal::OpenDirectory() {
1112 DCHECK(!initialized_) << "Should only happen once"; 1132 DCHECK(!initialized_) << "Should only happen once";
1113 1133
1114 // Set before Open(). 1134 // Set before Open().
1115 change_observer_ = 1135 change_observer_ =
1116 syncer::MakeWeakHandle(js_mutation_event_observer_.AsWeakPtr()); 1136 syncer::MakeWeakHandle(js_mutation_event_observer_.AsWeakPtr());
1117 WeakHandle<syncable::TransactionObserver> transaction_observer( 1137 WeakHandle<syncable::TransactionObserver> transaction_observer(
(...skipping 1215 matching lines...) Expand 10 before | Expand all | Expand 10 after
2333 void SyncManager::SyncInternal::AddObserver( 2353 void SyncManager::SyncInternal::AddObserver(
2334 SyncManager::Observer* observer) { 2354 SyncManager::Observer* observer) {
2335 observers_.AddObserver(observer); 2355 observers_.AddObserver(observer);
2336 } 2356 }
2337 2357
2338 void SyncManager::SyncInternal::RemoveObserver( 2358 void SyncManager::SyncInternal::RemoveObserver(
2339 SyncManager::Observer* observer) { 2359 SyncManager::Observer* observer) {
2340 observers_.RemoveObserver(observer); 2360 observers_.RemoveObserver(observer);
2341 } 2361 }
2342 2362
2363 void SyncManager::SyncInternal::SetSyncSchedulerForTest(
2364 scoped_ptr<SyncScheduler> sync_scheduler) {
2365 scheduler_ = sync_scheduler.Pass();
2366 }
2367
2343 SyncStatus SyncManager::GetDetailedStatus() const { 2368 SyncStatus SyncManager::GetDetailedStatus() const {
2344 return data_->GetStatus(); 2369 return data_->GetStatus();
2345 } 2370 }
2346 2371
2347 void SyncManager::SaveChanges() { 2372 void SyncManager::SaveChanges() {
2348 DCHECK(thread_checker_.CalledOnValidThread()); 2373 DCHECK(thread_checker_.CalledOnValidThread());
2349 data_->SaveChanges(); 2374 data_->SaveChanges();
2350 } 2375 }
2351 2376
2352 void SyncManager::SyncInternal::SaveChanges() { 2377 void SyncManager::SyncInternal::SaveChanges() {
(...skipping 10 matching lines...) Expand all
2363 data_->UpdateCryptographerAndNigori( 2388 data_->UpdateCryptographerAndNigori(
2364 chrome_version, 2389 chrome_version,
2365 done_callback); 2390 done_callback);
2366 } 2391 }
2367 2392
2368 TimeDelta SyncManager::GetNudgeDelayTimeDelta( 2393 TimeDelta SyncManager::GetNudgeDelayTimeDelta(
2369 const ModelType& model_type) { 2394 const ModelType& model_type) {
2370 return data_->GetNudgeDelayTimeDelta(model_type); 2395 return data_->GetNudgeDelayTimeDelta(model_type);
2371 } 2396 }
2372 2397
2398 void SyncManager::SetSyncSchedulerForTest(scoped_ptr<SyncScheduler> scheduler) {
2399 data_->SetSyncSchedulerForTest(scheduler.Pass());
2400 }
2401
2373 syncer::ModelTypeSet SyncManager::GetEncryptedDataTypesForTest() const { 2402 syncer::ModelTypeSet SyncManager::GetEncryptedDataTypesForTest() const {
2374 ReadTransaction trans(FROM_HERE, GetUserShare()); 2403 ReadTransaction trans(FROM_HERE, GetUserShare());
2375 return GetEncryptedTypes(&trans); 2404 return GetEncryptedTypes(&trans);
2376 } 2405 }
2377 2406
2378 bool SyncManager::ReceivedExperiment(syncer::Experiments* experiments) 2407 bool SyncManager::ReceivedExperiment(syncer::Experiments* experiments)
2379 const { 2408 const {
2380 ReadTransaction trans(FROM_HERE, GetUserShare()); 2409 ReadTransaction trans(FROM_HERE, GetUserShare());
2381 ReadNode node(&trans); 2410 ReadNode node(&trans);
2382 if (node.InitByTagLookup(kNigoriTag) != syncer::BaseNode::INIT_OK) { 2411 if (node.InitByTagLookup(kNigoriTag) != syncer::BaseNode::INIT_OK) {
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
2452 bool InitialSyncEndedForTypes(syncer::ModelTypeSet types, 2481 bool InitialSyncEndedForTypes(syncer::ModelTypeSet types,
2453 syncer::UserShare* share) { 2482 syncer::UserShare* share) {
2454 for (syncer::ModelTypeSet::Iterator i = types.First(); 2483 for (syncer::ModelTypeSet::Iterator i = types.First();
2455 i.Good(); i.Inc()) { 2484 i.Good(); i.Inc()) {
2456 if (!share->directory->initial_sync_ended_for_type(i.Get())) 2485 if (!share->directory->initial_sync_ended_for_type(i.Get()))
2457 return false; 2486 return false;
2458 } 2487 }
2459 return true; 2488 return true;
2460 } 2489 }
2461 2490
2462 syncer::ModelTypeSet GetTypesWithEmptyProgressMarkerToken(
2463 syncer::ModelTypeSet types,
2464 syncer::UserShare* share) {
2465 syncer::ModelTypeSet result;
2466 for (syncer::ModelTypeSet::Iterator i = types.First();
2467 i.Good(); i.Inc()) {
2468 sync_pb::DataTypeProgressMarker marker;
2469 share->directory->GetDownloadProgress(i.Get(), &marker);
2470
2471 if (marker.token().empty())
2472 result.Put(i.Get());
2473
2474 }
2475 return result;
2476 }
2477
2478 } // namespace syncer 2491 } // namespace syncer
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698