OLD | NEW |
---|---|
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/sync_manager_impl.h" | 5 #include "sync/internal_api/sync_manager_impl.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 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
170 CHECK(!initialized_); | 170 CHECK(!initialized_); |
171 } | 171 } |
172 | 172 |
173 bool Init(const FilePath& database_location, | 173 bool Init(const FilePath& database_location, |
174 const WeakHandle<JsEventHandler>& event_handler, | 174 const WeakHandle<JsEventHandler>& event_handler, |
175 const std::string& sync_server_and_path, | 175 const std::string& sync_server_and_path, |
176 int port, | 176 int port, |
177 bool use_ssl, | 177 bool use_ssl, |
178 const scoped_refptr<base::TaskRunner>& blocking_task_runner, | 178 const scoped_refptr<base::TaskRunner>& blocking_task_runner, |
179 scoped_ptr<HttpPostProviderFactory> post_factory, | 179 scoped_ptr<HttpPostProviderFactory> post_factory, |
180 const syncer::ModelSafeRoutingInfo& model_safe_routing_info, | |
181 const std::vector<syncer::ModelSafeWorker*>& workers, | 180 const std::vector<syncer::ModelSafeWorker*>& workers, |
182 syncer::ExtensionsActivityMonitor* | 181 syncer::ExtensionsActivityMonitor* |
183 extensions_activity_monitor, | 182 extensions_activity_monitor, |
184 SyncManager::ChangeDelegate* change_delegate, | 183 SyncManager::ChangeDelegate* change_delegate, |
185 const SyncCredentials& credentials, | 184 const SyncCredentials& credentials, |
186 scoped_ptr<syncer::SyncNotifier> sync_notifier, | 185 scoped_ptr<syncer::SyncNotifier> sync_notifier, |
187 const std::string& restored_key_for_bootstrapping, | 186 const std::string& restored_key_for_bootstrapping, |
188 SyncManager::TestingMode testing_mode, | 187 SyncManager::TestingMode testing_mode, |
189 Encryptor* encryptor, | 188 Encryptor* encryptor, |
190 UnrecoverableErrorHandler* unrecoverable_error_handler, | 189 UnrecoverableErrorHandler* unrecoverable_error_handler, |
(...skipping 512 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
703 : data_(new SyncInternal(name)) {} | 702 : data_(new SyncInternal(name)) {} |
704 | 703 |
705 bool SyncManagerImpl::Init( | 704 bool SyncManagerImpl::Init( |
706 const FilePath& database_location, | 705 const FilePath& database_location, |
707 const WeakHandle<JsEventHandler>& event_handler, | 706 const WeakHandle<JsEventHandler>& event_handler, |
708 const std::string& sync_server_and_path, | 707 const std::string& sync_server_and_path, |
709 int sync_server_port, | 708 int sync_server_port, |
710 bool use_ssl, | 709 bool use_ssl, |
711 const scoped_refptr<base::TaskRunner>& blocking_task_runner, | 710 const scoped_refptr<base::TaskRunner>& blocking_task_runner, |
712 scoped_ptr<HttpPostProviderFactory> post_factory, | 711 scoped_ptr<HttpPostProviderFactory> post_factory, |
713 const syncer::ModelSafeRoutingInfo& model_safe_routing_info, | |
714 const std::vector<syncer::ModelSafeWorker*>& workers, | 712 const std::vector<syncer::ModelSafeWorker*>& workers, |
715 syncer::ExtensionsActivityMonitor* extensions_activity_monitor, | 713 syncer::ExtensionsActivityMonitor* extensions_activity_monitor, |
716 SyncManager::ChangeDelegate* change_delegate, | 714 SyncManager::ChangeDelegate* change_delegate, |
717 const SyncCredentials& credentials, | 715 const SyncCredentials& credentials, |
718 scoped_ptr<syncer::SyncNotifier> sync_notifier, | 716 scoped_ptr<syncer::SyncNotifier> sync_notifier, |
719 const std::string& restored_key_for_bootstrapping, | 717 const std::string& restored_key_for_bootstrapping, |
720 SyncManager::TestingMode testing_mode, | 718 SyncManager::TestingMode testing_mode, |
721 Encryptor* encryptor, | 719 Encryptor* encryptor, |
722 UnrecoverableErrorHandler* unrecoverable_error_handler, | 720 UnrecoverableErrorHandler* unrecoverable_error_handler, |
723 ReportUnrecoverableErrorFunction report_unrecoverable_error_function) { | 721 ReportUnrecoverableErrorFunction report_unrecoverable_error_function) { |
724 DCHECK(thread_checker_.CalledOnValidThread()); | 722 DCHECK(thread_checker_.CalledOnValidThread()); |
725 DCHECK(post_factory.get()); | 723 DCHECK(post_factory.get()); |
726 DVLOG(1) << "SyncManager starting Init..."; | 724 DVLOG(1) << "SyncManager starting Init..."; |
727 std::string server_string(sync_server_and_path); | 725 std::string server_string(sync_server_and_path); |
728 return data_->Init(database_location, | 726 return data_->Init(database_location, |
729 event_handler, | 727 event_handler, |
730 server_string, | 728 server_string, |
731 sync_server_port, | 729 sync_server_port, |
732 use_ssl, | 730 use_ssl, |
733 blocking_task_runner, | 731 blocking_task_runner, |
734 post_factory.Pass(), | 732 post_factory.Pass(), |
735 model_safe_routing_info, | |
736 workers, | 733 workers, |
737 extensions_activity_monitor, | 734 extensions_activity_monitor, |
738 change_delegate, | 735 change_delegate, |
739 credentials, | 736 credentials, |
740 sync_notifier.Pass(), | 737 sync_notifier.Pass(), |
741 restored_key_for_bootstrapping, | 738 restored_key_for_bootstrapping, |
742 testing_mode, | 739 testing_mode, |
743 encryptor, | 740 encryptor, |
744 unrecoverable_error_handler, | 741 unrecoverable_error_handler, |
745 report_unrecoverable_error_function); | 742 report_unrecoverable_error_function); |
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
855 } | 852 } |
856 | 853 |
857 bool SyncManagerImpl::SyncInternal::Init( | 854 bool SyncManagerImpl::SyncInternal::Init( |
858 const FilePath& database_location, | 855 const FilePath& database_location, |
859 const WeakHandle<JsEventHandler>& event_handler, | 856 const WeakHandle<JsEventHandler>& event_handler, |
860 const std::string& sync_server_and_path, | 857 const std::string& sync_server_and_path, |
861 int port, | 858 int port, |
862 bool use_ssl, | 859 bool use_ssl, |
863 const scoped_refptr<base::TaskRunner>& blocking_task_runner, | 860 const scoped_refptr<base::TaskRunner>& blocking_task_runner, |
864 scoped_ptr<HttpPostProviderFactory> post_factory, | 861 scoped_ptr<HttpPostProviderFactory> post_factory, |
865 const syncer::ModelSafeRoutingInfo& model_safe_routing_info, | |
866 const std::vector<syncer::ModelSafeWorker*>& workers, | 862 const std::vector<syncer::ModelSafeWorker*>& workers, |
867 syncer::ExtensionsActivityMonitor* extensions_activity_monitor, | 863 syncer::ExtensionsActivityMonitor* extensions_activity_monitor, |
868 SyncManager::ChangeDelegate* change_delegate, | 864 SyncManager::ChangeDelegate* change_delegate, |
869 const SyncCredentials& credentials, | 865 const SyncCredentials& credentials, |
870 scoped_ptr<syncer::SyncNotifier> sync_notifier, | 866 scoped_ptr<syncer::SyncNotifier> sync_notifier, |
871 const std::string& restored_key_for_bootstrapping, | 867 const std::string& restored_key_for_bootstrapping, |
872 SyncManager::TestingMode testing_mode, | 868 SyncManager::TestingMode testing_mode, |
873 Encryptor* encryptor, | 869 Encryptor* encryptor, |
874 UnrecoverableErrorHandler* unrecoverable_error_handler, | 870 UnrecoverableErrorHandler* unrecoverable_error_handler, |
875 ReportUnrecoverableErrorFunction report_unrecoverable_error_function) { | 871 ReportUnrecoverableErrorFunction report_unrecoverable_error_function) { |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
920 backing_store)); | 916 backing_store)); |
921 | 917 |
922 connection_manager_.reset(new SyncAPIServerConnectionManager( | 918 connection_manager_.reset(new SyncAPIServerConnectionManager( |
923 sync_server_and_path, port, use_ssl, post_factory.release())); | 919 sync_server_and_path, port, use_ssl, post_factory.release())); |
924 | 920 |
925 net::NetworkChangeNotifier::AddIPAddressObserver(this); | 921 net::NetworkChangeNotifier::AddIPAddressObserver(this); |
926 observing_ip_address_changes_ = true; | 922 observing_ip_address_changes_ = true; |
927 | 923 |
928 connection_manager()->AddListener(this); | 924 connection_manager()->AddListener(this); |
929 | 925 |
926 bool success = SignIn(credentials); | |
tim (not reviewing)
2012/07/20 21:00:57
It makes me a bit nervous to start doing "real wor
rlarocque
2012/07/20 21:17:59
Good point.
Could we get rid of the SignIn() func
| |
927 | |
930 // Test mode does not use a syncer context or syncer thread. | 928 // Test mode does not use a syncer context or syncer thread. |
931 if (testing_mode_ == NON_TEST) { | 929 if (testing_mode_ == NON_TEST) { |
932 // Build a SyncSessionContext and store the worker in it. | 930 // Build a SyncSessionContext and store the worker in it. |
933 DVLOG(1) << "Sync is bringing up SyncSessionContext."; | 931 DVLOG(1) << "Sync is bringing up SyncSessionContext."; |
934 std::vector<SyncEngineEventListener*> listeners; | 932 std::vector<SyncEngineEventListener*> listeners; |
935 listeners.push_back(&allstatus_); | 933 listeners.push_back(&allstatus_); |
936 listeners.push_back(this); | 934 listeners.push_back(this); |
937 session_context_.reset(new SyncSessionContext( | 935 session_context_.reset(new SyncSessionContext( |
938 connection_manager_.get(), | 936 connection_manager_.get(), |
939 directory(), | 937 directory(), |
940 model_safe_routing_info, | |
Nicolas Zea
2012/07/20 21:35:39
This concerns me a bit. Could you set the routing
rlarocque
2012/07/23 20:50:30
This shouldn't have any practical impact because t
Nicolas Zea
2012/07/23 23:54:56
Hmm, it'll in fact get set by the initial Nigori-c
| |
941 workers, | 938 workers, |
942 extensions_activity_monitor, | 939 extensions_activity_monitor, |
943 &throttled_data_type_tracker_, | 940 &throttled_data_type_tracker_, |
944 listeners, | 941 listeners, |
945 &debug_info_event_listener_, | 942 &debug_info_event_listener_, |
946 &traffic_recorder_)); | 943 &traffic_recorder_)); |
947 session_context()->set_account_name(credentials.email); | 944 session_context()->set_account_name(credentials.email); |
948 scheduler_.reset(new SyncScheduler(name_, session_context(), new Syncer())); | 945 scheduler_.reset(new SyncScheduler(name_, session_context(), new Syncer())); |
949 } | 946 } |
950 | 947 |
951 bool success = SignIn(credentials); | |
952 | |
953 if (success) { | 948 if (success) { |
954 if (scheduler()) { | 949 if (scheduler()) { |
955 scheduler()->Start(syncer::SyncScheduler::CONFIGURATION_MODE); | 950 scheduler()->Start(syncer::SyncScheduler::CONFIGURATION_MODE); |
956 } | 951 } |
957 | 952 |
958 initialized_ = true; | 953 initialized_ = true; |
959 | 954 |
960 // Unapplied datatypes (those that do not have initial sync ended set) get | 955 // Unapplied datatypes (those that do not have initial sync ended set) get |
961 // re-downloaded during any configuration. But, it's possible for a datatype | 956 // re-downloaded during any configuration. But, it's possible for a datatype |
962 // to have a progress marker but not have initial sync ended yet, making | 957 // to have a progress marker but not have initial sync ended yet, making |
(...skipping 18 matching lines...) Expand all Loading... | |
981 } | 976 } |
982 | 977 |
983 // Notify that initialization is complete. Note: This should be the last to | 978 // Notify that initialization is complete. Note: This should be the last to |
984 // execute if |signed_in| is false. Reason being in that case we would | 979 // execute if |signed_in| is false. Reason being in that case we would |
985 // post a task to shutdown sync. But if this function posts any other tasks | 980 // post a task to shutdown sync. But if this function posts any other tasks |
986 // on the UI thread and if shutdown wins then that tasks would execute on | 981 // on the UI thread and if shutdown wins then that tasks would execute on |
987 // a freed pointer. This is because UI thread is not shut down. | 982 // a freed pointer. This is because UI thread is not shut down. |
988 FOR_EACH_OBSERVER(SyncManager::Observer, observers_, | 983 FOR_EACH_OBSERVER(SyncManager::Observer, observers_, |
989 OnInitializationComplete( | 984 OnInitializationComplete( |
990 MakeWeakHandle(weak_ptr_factory_.GetWeakPtr()), | 985 MakeWeakHandle(weak_ptr_factory_.GetWeakPtr()), |
991 success)); | 986 success, success ? InitialSyncEndedTypes() |
987 : syncer::ModelTypeSet())); | |
992 | 988 |
993 if (!success && testing_mode_ == NON_TEST) | 989 if (!success && testing_mode_ == NON_TEST) |
994 return false; | 990 return false; |
995 | 991 |
996 sync_notifier_->AddObserver(this); | 992 sync_notifier_->AddObserver(this); |
997 | 993 |
998 return success; | 994 return success; |
999 } | 995 } |
1000 | 996 |
1001 void SyncManagerImpl::SyncInternal::UpdateCryptographerAndNigori( | 997 void SyncManagerImpl::SyncInternal::UpdateCryptographerAndNigori( |
(...skipping 1491 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2493 int SyncManagerImpl::GetDefaultNudgeDelay() { | 2489 int SyncManagerImpl::GetDefaultNudgeDelay() { |
2494 return kDefaultNudgeDelayMilliseconds; | 2490 return kDefaultNudgeDelayMilliseconds; |
2495 } | 2491 } |
2496 | 2492 |
2497 // static. | 2493 // static. |
2498 int SyncManagerImpl::GetPreferencesNudgeDelay() { | 2494 int SyncManagerImpl::GetPreferencesNudgeDelay() { |
2499 return kPreferencesNudgeDelayMilliseconds; | 2495 return kPreferencesNudgeDelayMilliseconds; |
2500 } | 2496 } |
2501 | 2497 |
2502 } // namespace syncer | 2498 } // namespace syncer |
OLD | NEW |