| 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/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 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 190 UnrecoverableErrorHandler* unrecoverable_error_handler, | 190 UnrecoverableErrorHandler* unrecoverable_error_handler, |
| 191 ReportUnrecoverableErrorFunction | 191 ReportUnrecoverableErrorFunction |
| 192 report_unrecoverable_error_function); | 192 report_unrecoverable_error_function); |
| 193 | 193 |
| 194 // Sign into sync with given credentials. | 194 // Sign into sync with given credentials. |
| 195 // We do not verify the tokens given. After this call, the tokens are set | 195 // 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 | 196 // and the sync DB is open. True if successful, false if something |
| 197 // went wrong. | 197 // went wrong. |
| 198 bool SignIn(const SyncCredentials& credentials); | 198 bool SignIn(const SyncCredentials& credentials); |
| 199 | 199 |
| 200 // Purge from the directory those types with non-empty progress markers |
| 201 // but without initial synced ended set. |
| 202 // Returns false if an error occurred, true otherwise. |
| 203 bool PurgePartiallySyncedTypes(); |
| 204 |
| 200 // Update tokens that we're using in Sync. Email must stay the same. | 205 // Update tokens that we're using in Sync. Email must stay the same. |
| 201 void UpdateCredentials(const SyncCredentials& credentials); | 206 void UpdateCredentials(const SyncCredentials& credentials); |
| 202 | 207 |
| 203 // Called when the user disables or enables a sync type. | 208 // Called when the user disables or enables a sync type. |
| 204 void UpdateEnabledTypes(const ModelTypeSet& enabled_types); | 209 void UpdateEnabledTypes(const ModelTypeSet& enabled_types); |
| 205 | 210 |
| 206 // Tell the sync engine to start the syncing process. | 211 // Tell the sync engine to start the syncing process. |
| 207 void StartSyncingNormally( | 212 void StartSyncingNormally( |
| 208 const syncer::ModelSafeRoutingInfo& routing_info); | 213 const syncer::ModelSafeRoutingInfo& routing_info); |
| 209 | 214 |
| (...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 350 syncer::ModelType type, | 355 syncer::ModelType type, |
| 351 ChangeReorderBuffer* buffer, | 356 ChangeReorderBuffer* buffer, |
| 352 Cryptographer* cryptographer, | 357 Cryptographer* cryptographer, |
| 353 const syncable::EntryKernel& original, | 358 const syncable::EntryKernel& original, |
| 354 bool existed_before, | 359 bool existed_before, |
| 355 bool exists_now); | 360 bool exists_now); |
| 356 | 361 |
| 357 // Called only by our NetworkChangeNotifier. | 362 // Called only by our NetworkChangeNotifier. |
| 358 virtual void OnIPAddressChanged() OVERRIDE; | 363 virtual void OnIPAddressChanged() OVERRIDE; |
| 359 | 364 |
| 365 ModelTypeSet GetTypesWithEmptyProgressMarkerToken(ModelTypeSet types) { |
| 366 DCHECK(initialized_); |
| 367 syncer::ModelTypeSet result; |
| 368 for (syncer::ModelTypeSet::Iterator i = types.First(); |
| 369 i.Good(); i.Inc()) { |
| 370 sync_pb::DataTypeProgressMarker marker; |
| 371 directory()->GetDownloadProgress(i.Get(), &marker); |
| 372 |
| 373 if (marker.token().empty()) |
| 374 result.Put(i.Get()); |
| 375 |
| 376 } |
| 377 return result; |
| 378 } |
| 379 |
| 360 syncer::ModelTypeSet InitialSyncEndedTypes() { | 380 syncer::ModelTypeSet InitialSyncEndedTypes() { |
| 361 DCHECK(initialized_); | 381 DCHECK(initialized_); |
| 362 return directory()->initial_sync_ended_types(); | 382 return directory()->initial_sync_ended_types(); |
| 363 } | 383 } |
| 364 | 384 |
| 365 // SyncEngineEventListener implementation. | 385 // SyncEngineEventListener implementation. |
| 366 virtual void OnSyncEngineEvent(const SyncEngineEvent& event) OVERRIDE; | 386 virtual void OnSyncEngineEvent(const SyncEngineEvent& event) OVERRIDE; |
| 367 | 387 |
| 368 // ServerConnectionEventListener implementation. | 388 // ServerConnectionEventListener implementation. |
| 369 virtual void OnServerConnectionEvent( | 389 virtual void OnServerConnectionEvent( |
| 370 const ServerConnectionEvent& event) OVERRIDE; | 390 const ServerConnectionEvent& event) OVERRIDE; |
| 371 | 391 |
| 372 // JsBackend implementation. | 392 // JsBackend implementation. |
| 373 virtual void SetJsEventHandler( | 393 virtual void SetJsEventHandler( |
| 374 const WeakHandle<JsEventHandler>& event_handler) OVERRIDE; | 394 const WeakHandle<JsEventHandler>& event_handler) OVERRIDE; |
| 375 virtual void ProcessJsMessage( | 395 virtual void ProcessJsMessage( |
| 376 const std::string& name, const JsArgList& args, | 396 const std::string& name, const JsArgList& args, |
| 377 const WeakHandle<JsReplyHandler>& reply_handler) OVERRIDE; | 397 const WeakHandle<JsReplyHandler>& reply_handler) OVERRIDE; |
| 378 | 398 |
| 399 void SetSyncSchedulerForTest(scoped_ptr<SyncScheduler> scheduler); |
| 400 |
| 379 private: | 401 private: |
| 380 struct NotificationInfo { | 402 struct NotificationInfo { |
| 381 int total_count; | 403 int total_count; |
| 382 std::string payload; | 404 std::string payload; |
| 383 | 405 |
| 384 NotificationInfo() : total_count(0) {} | 406 NotificationInfo() : total_count(0) {} |
| 385 | 407 |
| 386 ~NotificationInfo() {} | 408 ~NotificationInfo() {} |
| 387 | 409 |
| 388 // Returned pointer owned by the caller. | 410 // Returned pointer owned by the caller. |
| (...skipping 353 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 742 DCHECK(thread_checker_.CalledOnValidThread()); | 764 DCHECK(thread_checker_.CalledOnValidThread()); |
| 743 ReadTransaction trans(FROM_HERE, GetUserShare()); | 765 ReadTransaction trans(FROM_HERE, GetUserShare()); |
| 744 trans.GetWrappedTrans()->OnUnrecoverableError( | 766 trans.GetWrappedTrans()->OnUnrecoverableError( |
| 745 FROM_HERE, "Simulating unrecoverable error for testing purposes."); | 767 FROM_HERE, "Simulating unrecoverable error for testing purposes."); |
| 746 } | 768 } |
| 747 | 769 |
| 748 syncer::ModelTypeSet SyncManager::InitialSyncEndedTypes() { | 770 syncer::ModelTypeSet SyncManager::InitialSyncEndedTypes() { |
| 749 return data_->InitialSyncEndedTypes(); | 771 return data_->InitialSyncEndedTypes(); |
| 750 } | 772 } |
| 751 | 773 |
| 774 syncer::ModelTypeSet SyncManager::GetTypesWithEmptyProgressMarkerToken( |
| 775 syncer::ModelTypeSet types) { |
| 776 return data_->GetTypesWithEmptyProgressMarkerToken(types); |
| 777 } |
| 778 |
| 779 bool SyncManager::PurgePartiallySyncedTypes() { |
| 780 return data_->PurgePartiallySyncedTypes(); |
| 781 } |
| 782 |
| 752 void SyncManager::StartSyncingNormally( | 783 void SyncManager::StartSyncingNormally( |
| 753 const syncer::ModelSafeRoutingInfo& routing_info) { | 784 const syncer::ModelSafeRoutingInfo& routing_info) { |
| 754 DCHECK(thread_checker_.CalledOnValidThread()); | 785 DCHECK(thread_checker_.CalledOnValidThread()); |
| 755 data_->StartSyncingNormally(routing_info); | 786 data_->StartSyncingNormally(routing_info); |
| 756 } | 787 } |
| 757 | 788 |
| 758 void SyncManager::SetEncryptionPassphrase(const std::string& passphrase, | 789 void SyncManager::SetEncryptionPassphrase(const std::string& passphrase, |
| 759 bool is_explicit) { | 790 bool is_explicit) { |
| 760 DCHECK(thread_checker_.CalledOnValidThread()); | 791 DCHECK(thread_checker_.CalledOnValidThread()); |
| 761 data_->SetEncryptionPassphrase(passphrase, is_explicit); | 792 data_->SetEncryptionPassphrase(passphrase, is_explicit); |
| (...skipping 24 matching lines...) Expand all Loading... |
| 786 | 817 |
| 787 bool SyncManager::EncryptEverythingEnabledForTest() const { | 818 bool SyncManager::EncryptEverythingEnabledForTest() const { |
| 788 ReadTransaction trans(FROM_HERE, GetUserShare()); | 819 ReadTransaction trans(FROM_HERE, GetUserShare()); |
| 789 return trans.GetCryptographer()->encrypt_everything(); | 820 return trans.GetCryptographer()->encrypt_everything(); |
| 790 } | 821 } |
| 791 | 822 |
| 792 bool SyncManager::IsUsingExplicitPassphrase() { | 823 bool SyncManager::IsUsingExplicitPassphrase() { |
| 793 return data_ && data_->IsUsingExplicitPassphrase(); | 824 return data_ && data_->IsUsingExplicitPassphrase(); |
| 794 } | 825 } |
| 795 | 826 |
| 796 void SyncManager::RequestCleanupDisabledTypes( | 827 void SyncManager::ConfigureSyncer( |
| 797 const syncer::ModelSafeRoutingInfo& routing_info) { | 828 ConfigureReason reason, |
| 829 const syncer::ModelTypeSet& types_to_config, |
| 830 const syncer::ModelSafeRoutingInfo& new_routing_info, |
| 831 const base::Closure& ready_task, |
| 832 const base::Closure& retry_task) { |
| 798 DCHECK(thread_checker_.CalledOnValidThread()); | 833 DCHECK(thread_checker_.CalledOnValidThread()); |
| 799 if (data_->scheduler()) { | 834 DCHECK(!ready_task.is_null()); |
| 800 data_->session_context()->set_routing_info(routing_info); | 835 DCHECK(!retry_task.is_null()); |
| 801 data_->scheduler()->CleanupDisabledTypes(); | |
| 802 } | |
| 803 } | |
| 804 | 836 |
| 805 void SyncManager::RequestConfig( | 837 // TODO(zea): set this based on whether cryptographer has keystore |
| 806 const syncer::ModelSafeRoutingInfo& routing_info, | 838 // encryption key or not (requires opening a transaction). crbug.com/129665. |
| 807 const ModelTypeSet& types, ConfigureReason reason) { | 839 ConfigurationParams::KeystoreKeyStatus keystore_key_status = |
| 808 DCHECK(thread_checker_.CalledOnValidThread()); | 840 ConfigurationParams::KEYSTORE_KEY_UNNECESSARY; |
| 841 |
| 842 ConfigurationParams params(GetSourceFromReason(reason), |
| 843 types_to_config, |
| 844 new_routing_info, |
| 845 keystore_key_status, |
| 846 ready_task); |
| 847 |
| 809 if (!data_->scheduler()) { | 848 if (!data_->scheduler()) { |
| 810 LOG(INFO) | 849 LOG(INFO) |
| 811 << "SyncManager::RequestConfig: bailing out because scheduler is " | 850 << "SyncManager::ConfigureSyncer: could not configure because " |
| 812 << "null"; | 851 << "scheduler is null"; |
| 852 params.ready_task.Run(); |
| 813 return; | 853 return; |
| 814 } | 854 } |
| 815 StartConfigurationMode(base::Closure()); | |
| 816 data_->session_context()->set_routing_info(routing_info); | |
| 817 data_->scheduler()->ScheduleConfiguration(types, GetSourceFromReason(reason)); | |
| 818 } | |
| 819 | 855 |
| 820 void SyncManager::StartConfigurationMode(const base::Closure& callback) { | 856 data_->scheduler()->Start(syncer::SyncScheduler::CONFIGURATION_MODE); |
| 821 DCHECK(thread_checker_.CalledOnValidThread()); | 857 if (!data_->scheduler()->ScheduleConfiguration(params)) |
| 822 if (!data_->scheduler()) { | 858 retry_task.Run(); |
| 823 LOG(INFO) | 859 |
| 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 } | 860 } |
| 831 | 861 |
| 832 bool SyncManager::SyncInternal::Init( | 862 bool SyncManager::SyncInternal::Init( |
| 833 const FilePath& database_location, | 863 const FilePath& database_location, |
| 834 const WeakHandle<JsEventHandler>& event_handler, | 864 const WeakHandle<JsEventHandler>& event_handler, |
| 835 const std::string& sync_server_and_path, | 865 const std::string& sync_server_and_path, |
| 836 int port, | 866 int port, |
| 837 bool use_ssl, | 867 bool use_ssl, |
| 838 const scoped_refptr<base::TaskRunner>& blocking_task_runner, | 868 const scoped_refptr<base::TaskRunner>& blocking_task_runner, |
| 839 HttpPostProviderFactory* post_factory, | 869 HttpPostProviderFactory* post_factory, |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 916 workers, | 946 workers, |
| 917 extensions_activity_monitor, | 947 extensions_activity_monitor, |
| 918 &throttled_data_type_tracker_, | 948 &throttled_data_type_tracker_, |
| 919 listeners, | 949 listeners, |
| 920 &debug_info_event_listener_, | 950 &debug_info_event_listener_, |
| 921 &traffic_recorder_)); | 951 &traffic_recorder_)); |
| 922 session_context()->set_account_name(credentials.email); | 952 session_context()->set_account_name(credentials.email); |
| 923 scheduler_.reset(new SyncScheduler(name_, session_context(), new Syncer())); | 953 scheduler_.reset(new SyncScheduler(name_, session_context(), new Syncer())); |
| 924 } | 954 } |
| 925 | 955 |
| 926 bool signed_in = SignIn(credentials); | 956 bool success = SignIn(credentials); |
| 927 | 957 |
| 928 if (signed_in) { | 958 if (success) { |
| 929 if (scheduler()) { | 959 if (scheduler()) { |
| 930 scheduler()->Start( | 960 scheduler()->Start(syncer::SyncScheduler::CONFIGURATION_MODE); |
| 931 syncer::SyncScheduler::CONFIGURATION_MODE, base::Closure()); | |
| 932 } | 961 } |
| 933 | 962 |
| 934 initialized_ = true; | 963 initialized_ = true; |
| 935 | 964 |
| 965 // Unapplied datatypes (those that do not have initial sync ended set) get |
| 966 // re-downloaded during any configuration. But, it's possible for a datatype |
| 967 // to have a progress marker but not have initial sync ended yet, making |
| 968 // it a candidate for migration. This is a problem, as the DataTypeManager |
| 969 // does not support a migration while it's already in the middle of a |
| 970 // configuration. As a result, any partially synced datatype can stall the |
| 971 // DTM, waiting for the configuration to complete, which it never will due |
| 972 // to the migration error. In addition, a partially synced nigori will |
| 973 // trigger the migration logic before the backend is initialized, resulting |
| 974 // in crashes. We therefore detect and purge any partially synced types as |
| 975 // part of initialization. |
| 976 if (!PurgePartiallySyncedTypes()) |
| 977 success = false; |
| 978 |
| 936 // Cryptographer should only be accessed while holding a | 979 // Cryptographer should only be accessed while holding a |
| 937 // transaction. Grabbing the user share for the transaction | 980 // transaction. Grabbing the user share for the transaction |
| 938 // checks the initialization state, so this must come after | 981 // checks the initialization state, so this must come after |
| 939 // |initialized_| is set to true. | 982 // |initialized_| is set to true. |
| 940 ReadTransaction trans(FROM_HERE, GetUserShare()); | 983 ReadTransaction trans(FROM_HERE, GetUserShare()); |
| 941 trans.GetCryptographer()->Bootstrap(restored_key_for_bootstrapping); | 984 trans.GetCryptographer()->Bootstrap(restored_key_for_bootstrapping); |
| 942 trans.GetCryptographer()->AddObserver(this); | 985 trans.GetCryptographer()->AddObserver(this); |
| 943 } | 986 } |
| 944 | 987 |
| 945 // Notify that initialization is complete. Note: This should be the last to | 988 // Notify that initialization is complete. Note: This should be the last to |
| 946 // execute if |signed_in| is false. Reason being in that case we would | 989 // execute if |signed_in| is false. Reason being in that case we would |
| 947 // post a task to shutdown sync. But if this function posts any other tasks | 990 // post a task to shutdown sync. But if this function posts any other tasks |
| 948 // on the UI thread and if shutdown wins then that tasks would execute on | 991 // on the UI thread and if shutdown wins then that tasks would execute on |
| 949 // a freed pointer. This is because UI thread is not shut down. | 992 // a freed pointer. This is because UI thread is not shut down. |
| 950 FOR_EACH_OBSERVER(SyncManager::Observer, observers_, | 993 FOR_EACH_OBSERVER(SyncManager::Observer, observers_, |
| 951 OnInitializationComplete( | 994 OnInitializationComplete( |
| 952 MakeWeakHandle(weak_ptr_factory_.GetWeakPtr()), | 995 MakeWeakHandle(weak_ptr_factory_.GetWeakPtr()), |
| 953 signed_in)); | 996 success)); |
| 954 | 997 |
| 955 if (!signed_in && testing_mode_ == NON_TEST) | 998 if (!success && testing_mode_ == NON_TEST) |
| 956 return false; | 999 return false; |
| 957 | 1000 |
| 958 sync_notifier_->AddObserver(this); | 1001 sync_notifier_->AddObserver(this); |
| 959 | 1002 |
| 960 return signed_in; | 1003 return success; |
| 961 } | 1004 } |
| 962 | 1005 |
| 963 void SyncManager::SyncInternal::UpdateCryptographerAndNigori( | 1006 void SyncManager::SyncInternal::UpdateCryptographerAndNigori( |
| 964 const std::string& chrome_version, | 1007 const std::string& chrome_version, |
| 965 const base::Closure& done_callback) { | 1008 const base::Closure& done_callback) { |
| 966 DCHECK(initialized_); | 1009 DCHECK(initialized_); |
| 967 syncer::GetSessionName( | 1010 syncer::GetSessionName( |
| 968 blocking_task_runner_, | 1011 blocking_task_runner_, |
| 969 base::Bind( | 1012 base::Bind( |
| 970 &SyncManager::SyncInternal::UpdateCryptographerAndNigoriCallback, | 1013 &SyncManager::SyncInternal::UpdateCryptographerAndNigoriCallback, |
| (...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1095 allstatus_.SetCryptographerReady(cryptographer->is_ready()); | 1138 allstatus_.SetCryptographerReady(cryptographer->is_ready()); |
| 1096 allstatus_.SetCryptoHasPendingKeys(cryptographer->has_pending_keys()); | 1139 allstatus_.SetCryptoHasPendingKeys(cryptographer->has_pending_keys()); |
| 1097 debug_info_event_listener_.SetCryptographerReady(cryptographer->is_ready()); | 1140 debug_info_event_listener_.SetCryptographerReady(cryptographer->is_ready()); |
| 1098 debug_info_event_listener_.SetCrytographerHasPendingKeys( | 1141 debug_info_event_listener_.SetCrytographerHasPendingKeys( |
| 1099 cryptographer->has_pending_keys()); | 1142 cryptographer->has_pending_keys()); |
| 1100 } | 1143 } |
| 1101 | 1144 |
| 1102 void SyncManager::SyncInternal::StartSyncingNormally( | 1145 void SyncManager::SyncInternal::StartSyncingNormally( |
| 1103 const syncer::ModelSafeRoutingInfo& routing_info) { | 1146 const syncer::ModelSafeRoutingInfo& routing_info) { |
| 1104 // Start the sync scheduler. | 1147 // Start the sync scheduler. |
| 1105 if (scheduler()) { // NULL during certain unittests. | 1148 if (scheduler()) { // NULL during certain unittests. |
| 1149 // TODO(sync): We always want the newest set of routes when we switch back |
| 1150 // to normal mode. Figure out how to enforce set_routing_info is always |
| 1151 // appropriately set and that it's only modified when switching to normal |
| 1152 // mode. |
| 1106 session_context()->set_routing_info(routing_info); | 1153 session_context()->set_routing_info(routing_info); |
| 1107 scheduler()->Start(SyncScheduler::NORMAL_MODE, base::Closure()); | 1154 scheduler()->Start(SyncScheduler::NORMAL_MODE); |
| 1108 } | 1155 } |
| 1109 } | 1156 } |
| 1110 | 1157 |
| 1111 bool SyncManager::SyncInternal::OpenDirectory() { | 1158 bool SyncManager::SyncInternal::OpenDirectory() { |
| 1112 DCHECK(!initialized_) << "Should only happen once"; | 1159 DCHECK(!initialized_) << "Should only happen once"; |
| 1113 | 1160 |
| 1114 // Set before Open(). | 1161 // Set before Open(). |
| 1115 change_observer_ = | 1162 change_observer_ = |
| 1116 syncer::MakeWeakHandle(js_mutation_event_observer_.AsWeakPtr()); | 1163 syncer::MakeWeakHandle(js_mutation_event_observer_.AsWeakPtr()); |
| 1117 WeakHandle<syncable::TransactionObserver> transaction_observer( | 1164 WeakHandle<syncable::TransactionObserver> transaction_observer( |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1151 allstatus_.SetUniqueId(unique_id); | 1198 allstatus_.SetUniqueId(unique_id); |
| 1152 sync_notifier_->SetUniqueId(unique_id); | 1199 sync_notifier_->SetUniqueId(unique_id); |
| 1153 // TODO(tim): Remove once invalidation state has been migrated to new | 1200 // TODO(tim): Remove once invalidation state has been migrated to new |
| 1154 // InvalidationStateTracker store. Bug 124140. | 1201 // InvalidationStateTracker store. Bug 124140. |
| 1155 sync_notifier_->SetStateDeprecated(state); | 1202 sync_notifier_->SetStateDeprecated(state); |
| 1156 | 1203 |
| 1157 UpdateCredentials(credentials); | 1204 UpdateCredentials(credentials); |
| 1158 return true; | 1205 return true; |
| 1159 } | 1206 } |
| 1160 | 1207 |
| 1208 bool SyncManager::SyncInternal::PurgePartiallySyncedTypes() { |
| 1209 syncer::ModelTypeSet partially_synced_types = |
| 1210 syncer::ModelTypeSet::All(); |
| 1211 partially_synced_types.RemoveAll(InitialSyncEndedTypes()); |
| 1212 partially_synced_types.RemoveAll(GetTypesWithEmptyProgressMarkerToken( |
| 1213 syncer::ModelTypeSet::All())); |
| 1214 |
| 1215 UMA_HISTOGRAM_COUNTS("Sync.PartiallySyncedTypes", |
| 1216 partially_synced_types.Size()); |
| 1217 if (partially_synced_types.Empty()) |
| 1218 return true; |
| 1219 return directory()->PurgeEntriesWithTypeIn(partially_synced_types); |
| 1220 } |
| 1221 |
| 1161 void SyncManager::SyncInternal::UpdateCredentials( | 1222 void SyncManager::SyncInternal::UpdateCredentials( |
| 1162 const SyncCredentials& credentials) { | 1223 const SyncCredentials& credentials) { |
| 1163 DCHECK(thread_checker_.CalledOnValidThread()); | 1224 DCHECK(thread_checker_.CalledOnValidThread()); |
| 1164 DCHECK_EQ(credentials.email, share_.name); | 1225 DCHECK_EQ(credentials.email, share_.name); |
| 1165 DCHECK(!credentials.email.empty()); | 1226 DCHECK(!credentials.email.empty()); |
| 1166 DCHECK(!credentials.sync_token.empty()); | 1227 DCHECK(!credentials.sync_token.empty()); |
| 1167 | 1228 |
| 1168 observing_ip_address_changes_ = true; | 1229 observing_ip_address_changes_ = true; |
| 1169 if (connection_manager()->set_auth_token(credentials.sync_token)) { | 1230 if (connection_manager()->set_auth_token(credentials.sync_token)) { |
| 1170 sync_notifier_->UpdateCredentials( | 1231 sync_notifier_->UpdateCredentials( |
| (...skipping 1162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2333 void SyncManager::SyncInternal::AddObserver( | 2394 void SyncManager::SyncInternal::AddObserver( |
| 2334 SyncManager::Observer* observer) { | 2395 SyncManager::Observer* observer) { |
| 2335 observers_.AddObserver(observer); | 2396 observers_.AddObserver(observer); |
| 2336 } | 2397 } |
| 2337 | 2398 |
| 2338 void SyncManager::SyncInternal::RemoveObserver( | 2399 void SyncManager::SyncInternal::RemoveObserver( |
| 2339 SyncManager::Observer* observer) { | 2400 SyncManager::Observer* observer) { |
| 2340 observers_.RemoveObserver(observer); | 2401 observers_.RemoveObserver(observer); |
| 2341 } | 2402 } |
| 2342 | 2403 |
| 2404 void SyncManager::SyncInternal::SetSyncSchedulerForTest( |
| 2405 scoped_ptr<SyncScheduler> sync_scheduler) { |
| 2406 scheduler_ = sync_scheduler.Pass(); |
| 2407 } |
| 2408 |
| 2343 SyncStatus SyncManager::GetDetailedStatus() const { | 2409 SyncStatus SyncManager::GetDetailedStatus() const { |
| 2344 return data_->GetStatus(); | 2410 return data_->GetStatus(); |
| 2345 } | 2411 } |
| 2346 | 2412 |
| 2347 void SyncManager::SaveChanges() { | 2413 void SyncManager::SaveChanges() { |
| 2348 DCHECK(thread_checker_.CalledOnValidThread()); | 2414 DCHECK(thread_checker_.CalledOnValidThread()); |
| 2349 data_->SaveChanges(); | 2415 data_->SaveChanges(); |
| 2350 } | 2416 } |
| 2351 | 2417 |
| 2352 void SyncManager::SyncInternal::SaveChanges() { | 2418 void SyncManager::SyncInternal::SaveChanges() { |
| (...skipping 10 matching lines...) Expand all Loading... |
| 2363 data_->UpdateCryptographerAndNigori( | 2429 data_->UpdateCryptographerAndNigori( |
| 2364 chrome_version, | 2430 chrome_version, |
| 2365 done_callback); | 2431 done_callback); |
| 2366 } | 2432 } |
| 2367 | 2433 |
| 2368 TimeDelta SyncManager::GetNudgeDelayTimeDelta( | 2434 TimeDelta SyncManager::GetNudgeDelayTimeDelta( |
| 2369 const ModelType& model_type) { | 2435 const ModelType& model_type) { |
| 2370 return data_->GetNudgeDelayTimeDelta(model_type); | 2436 return data_->GetNudgeDelayTimeDelta(model_type); |
| 2371 } | 2437 } |
| 2372 | 2438 |
| 2439 void SyncManager::SetSyncSchedulerForTest(scoped_ptr<SyncScheduler> scheduler) { |
| 2440 data_->SetSyncSchedulerForTest(scheduler.Pass()); |
| 2441 } |
| 2442 |
| 2373 syncer::ModelTypeSet SyncManager::GetEncryptedDataTypesForTest() const { | 2443 syncer::ModelTypeSet SyncManager::GetEncryptedDataTypesForTest() const { |
| 2374 ReadTransaction trans(FROM_HERE, GetUserShare()); | 2444 ReadTransaction trans(FROM_HERE, GetUserShare()); |
| 2375 return GetEncryptedTypes(&trans); | 2445 return GetEncryptedTypes(&trans); |
| 2376 } | 2446 } |
| 2377 | 2447 |
| 2378 bool SyncManager::ReceivedExperiment(syncer::Experiments* experiments) | 2448 bool SyncManager::ReceivedExperiment(syncer::Experiments* experiments) |
| 2379 const { | 2449 const { |
| 2380 ReadTransaction trans(FROM_HERE, GetUserShare()); | 2450 ReadTransaction trans(FROM_HERE, GetUserShare()); |
| 2381 ReadNode node(&trans); | 2451 ReadNode node(&trans); |
| 2382 if (node.InitByTagLookup(kNigoriTag) != syncer::BaseNode::INIT_OK) { | 2452 if (node.InitByTagLookup(kNigoriTag) != syncer::BaseNode::INIT_OK) { |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2452 bool InitialSyncEndedForTypes(syncer::ModelTypeSet types, | 2522 bool InitialSyncEndedForTypes(syncer::ModelTypeSet types, |
| 2453 syncer::UserShare* share) { | 2523 syncer::UserShare* share) { |
| 2454 for (syncer::ModelTypeSet::Iterator i = types.First(); | 2524 for (syncer::ModelTypeSet::Iterator i = types.First(); |
| 2455 i.Good(); i.Inc()) { | 2525 i.Good(); i.Inc()) { |
| 2456 if (!share->directory->initial_sync_ended_for_type(i.Get())) | 2526 if (!share->directory->initial_sync_ended_for_type(i.Get())) |
| 2457 return false; | 2527 return false; |
| 2458 } | 2528 } |
| 2459 return true; | 2529 return true; |
| 2460 } | 2530 } |
| 2461 | 2531 |
| 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 | 2532 } // namespace syncer |
| OLD | NEW |