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.h" | 5 #include "sync/internal_api/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 823 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
834 | 834 |
835 bool SyncManager::EncryptEverythingEnabledForTest() const { | 835 bool SyncManager::EncryptEverythingEnabledForTest() const { |
836 ReadTransaction trans(FROM_HERE, GetUserShare()); | 836 ReadTransaction trans(FROM_HERE, GetUserShare()); |
837 return trans.GetCryptographer()->encrypt_everything(); | 837 return trans.GetCryptographer()->encrypt_everything(); |
838 } | 838 } |
839 | 839 |
840 bool SyncManager::IsUsingExplicitPassphrase() { | 840 bool SyncManager::IsUsingExplicitPassphrase() { |
841 return data_ && data_->IsUsingExplicitPassphrase(); | 841 return data_ && data_->IsUsingExplicitPassphrase(); |
842 } | 842 } |
843 | 843 |
844 void SyncManager::RequestCleanupDisabledTypes( | |
845 const browser_sync::ModelSafeRoutingInfo& routing_info) { | |
846 DCHECK(thread_checker_.CalledOnValidThread()); | |
847 if (data_->scheduler()) { | |
848 data_->session_context()->set_routing_info(routing_info); | |
849 data_->scheduler()->ScheduleCleanupDisabledTypes(); | |
850 } | |
851 } | |
852 | |
853 void SyncManager::RequestClearServerData() { | 844 void SyncManager::RequestClearServerData() { |
854 DCHECK(thread_checker_.CalledOnValidThread()); | 845 DCHECK(thread_checker_.CalledOnValidThread()); |
855 if (data_->scheduler()) | 846 if (data_->scheduler()) |
856 data_->scheduler()->ScheduleClearUserData(); | 847 data_->scheduler()->ScheduleClearUserData(); |
857 } | 848 } |
858 | 849 |
859 void SyncManager::RequestConfig( | 850 void SyncManager::ConfigureSyncer( |
860 const browser_sync::ModelSafeRoutingInfo& routing_info, | 851 ConfigureReason reason, |
861 const ModelTypeSet& types, ConfigureReason reason) { | 852 const syncable::ModelTypeSet& types_to_config, |
853 const browser_sync::ModelSafeRoutingInfo& new_routing_info, | |
854 const base::Closure& ready_task, | |
855 const base::Closure& retry_task) { | |
862 DCHECK(thread_checker_.CalledOnValidThread()); | 856 DCHECK(thread_checker_.CalledOnValidThread()); |
863 if (!data_->scheduler()) { | 857 DCHECK(!ready_task.is_null()); |
864 LOG(INFO) | 858 DCHECK(!retry_task.is_null()); |
865 << "SyncManager::RequestConfig: bailing out because scheduler is " | 859 if (data_->scheduler()) { |
866 << "null"; | 860 // TODO(zea): set this based on whether cryptographer has keystore |
867 return; | 861 // encryption key or not (requires opening a transaction). |
862 bool need_encryption_key = false; | |
863 | |
864 // We do a cleanup if this is the first configuration after a restart (to | |
865 // handle the case where we failed to configure a previous type) or if we're | |
866 // disabling a type. | |
867 // Note: it's not necessary to check for empty progress markers. Any type | |
868 // that we attempted to enable would have been in the current routing info. | |
869 // If it failed to download, we'll either disable it, in which case it's | |
870 // removed from the routing info, or we attempt to retry it, in which case | |
871 // it would remain in the routing info (and since it didn't have | |
872 // initial_sync_ended set we'll ensure we attempt to redownload). | |
873 bool need_cleanup = false; | |
874 const browser_sync::ModelSafeRoutingInfo& current_routing_info = | |
875 data_->session_context()->routing_info(); | |
876 if (current_routing_info.empty() || // Restart case. | |
rlarocque
2012/06/04 23:01:38
See CleanupDisabltedTypesCommand::ExecuteImpl().
Nicolas Zea
2012/06/07 19:25:42
See other comment. This is gone now.
| |
877 !GetRoutingInfoTypes(new_routing_info).HasAll( | |
878 GetRoutingInfoTypes(current_routing_info))) // Disabled datatypes. | |
879 need_cleanup = true; | |
880 | |
881 SyncScheduler::ConfigureParams params( | |
882 GetSourceFromReason(reason), | |
883 types_to_config, | |
884 new_routing_info, | |
885 need_cleanup, | |
886 need_encryption_key, | |
887 ready_task); | |
888 data_->scheduler()->Start(SyncScheduler::CONFIGURATION_MODE); | |
889 // Returns false if a retry has been scheduled. Either way, will invoke the | |
890 // ready task when the configure job completes. | |
891 if (!data_->scheduler()->Configure(params)) | |
892 retry_task.Run(); | |
893 } else { | |
894 LOG(INFO) << "SyncManager::ConfigureSyncer: bailing out because scheduler " | |
895 << "is null."; | |
896 ready_task.Run(); | |
868 } | 897 } |
869 StartConfigurationMode(base::Closure()); | |
870 data_->session_context()->set_routing_info(routing_info); | |
871 data_->scheduler()->ScheduleConfig(types, GetSourceFromReason(reason)); | |
872 } | |
873 | |
874 void SyncManager::StartConfigurationMode(const base::Closure& callback) { | |
875 DCHECK(thread_checker_.CalledOnValidThread()); | |
876 if (!data_->scheduler()) { | |
877 LOG(INFO) | |
878 << "SyncManager::StartConfigurationMode: could not start " | |
879 << "configuration mode because because scheduler is null"; | |
880 return; | |
881 } | |
882 data_->scheduler()->Start( | |
883 browser_sync::SyncScheduler::CONFIGURATION_MODE, callback); | |
884 } | 898 } |
885 | 899 |
886 bool SyncManager::SyncInternal::Init( | 900 bool SyncManager::SyncInternal::Init( |
887 const FilePath& database_location, | 901 const FilePath& database_location, |
888 const WeakHandle<JsEventHandler>& event_handler, | 902 const WeakHandle<JsEventHandler>& event_handler, |
889 const std::string& sync_server_and_path, | 903 const std::string& sync_server_and_path, |
890 int port, | 904 int port, |
891 bool use_ssl, | 905 bool use_ssl, |
892 const scoped_refptr<base::TaskRunner>& blocking_task_runner, | 906 const scoped_refptr<base::TaskRunner>& blocking_task_runner, |
893 HttpPostProviderFactory* post_factory, | 907 HttpPostProviderFactory* post_factory, |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
958 &debug_info_event_listener_, | 972 &debug_info_event_listener_, |
959 &traffic_recorder_)); | 973 &traffic_recorder_)); |
960 session_context()->set_account_name(credentials.email); | 974 session_context()->set_account_name(credentials.email); |
961 scheduler_.reset(new SyncScheduler(name_, session_context(), new Syncer())); | 975 scheduler_.reset(new SyncScheduler(name_, session_context(), new Syncer())); |
962 } | 976 } |
963 | 977 |
964 bool signed_in = SignIn(credentials); | 978 bool signed_in = SignIn(credentials); |
965 | 979 |
966 if (signed_in) { | 980 if (signed_in) { |
967 if (scheduler()) { | 981 if (scheduler()) { |
968 scheduler()->Start( | 982 scheduler()->Start(SyncScheduler::CONFIGURATION_MODE); |
969 browser_sync::SyncScheduler::CONFIGURATION_MODE, base::Closure()); | |
970 } | 983 } |
971 | 984 |
972 initialized_ = true; | 985 initialized_ = true; |
973 | 986 |
974 // Cryptographer should only be accessed while holding a | 987 // Cryptographer should only be accessed while holding a |
975 // transaction. Grabbing the user share for the transaction | 988 // transaction. Grabbing the user share for the transaction |
976 // checks the initialization state, so this must come after | 989 // checks the initialization state, so this must come after |
977 // |initialized_| is set to true. | 990 // |initialized_| is set to true. |
978 ReadTransaction trans(FROM_HERE, GetUserShare()); | 991 ReadTransaction trans(FROM_HERE, GetUserShare()); |
979 trans.GetCryptographer()->Bootstrap(restored_key_for_bootstrapping); | 992 trans.GetCryptographer()->Bootstrap(restored_key_for_bootstrapping); |
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1133 allstatus_.SetCryptographerReady(cryptographer->is_ready()); | 1146 allstatus_.SetCryptographerReady(cryptographer->is_ready()); |
1134 allstatus_.SetCryptoHasPendingKeys(cryptographer->has_pending_keys()); | 1147 allstatus_.SetCryptoHasPendingKeys(cryptographer->has_pending_keys()); |
1135 debug_info_event_listener_.SetCryptographerReady(cryptographer->is_ready()); | 1148 debug_info_event_listener_.SetCryptographerReady(cryptographer->is_ready()); |
1136 debug_info_event_listener_.SetCrytographerHasPendingKeys( | 1149 debug_info_event_listener_.SetCrytographerHasPendingKeys( |
1137 cryptographer->has_pending_keys()); | 1150 cryptographer->has_pending_keys()); |
1138 } | 1151 } |
1139 | 1152 |
1140 void SyncManager::SyncInternal::StartSyncingNormally( | 1153 void SyncManager::SyncInternal::StartSyncingNormally( |
1141 const browser_sync::ModelSafeRoutingInfo& routing_info) { | 1154 const browser_sync::ModelSafeRoutingInfo& routing_info) { |
1142 // Start the sync scheduler. | 1155 // Start the sync scheduler. |
1143 if (scheduler()) { // NULL during certain unittests. | 1156 if (scheduler()) // NULL during certain unittests. |
1144 session_context()->set_routing_info(routing_info); | 1157 scheduler()->Start(SyncScheduler::NORMAL_MODE); |
1145 scheduler()->Start(SyncScheduler::NORMAL_MODE, base::Closure()); | |
1146 } | |
1147 } | 1158 } |
1148 | 1159 |
1149 bool SyncManager::SyncInternal::OpenDirectory() { | 1160 bool SyncManager::SyncInternal::OpenDirectory() { |
1150 DCHECK(!initialized_) << "Should only happen once"; | 1161 DCHECK(!initialized_) << "Should only happen once"; |
1151 | 1162 |
1152 // Set before Open(). | 1163 // Set before Open(). |
1153 change_observer_ = | 1164 change_observer_ = |
1154 browser_sync::MakeWeakHandle(js_mutation_event_observer_.AsWeakPtr()); | 1165 browser_sync::MakeWeakHandle(js_mutation_event_observer_.AsWeakPtr()); |
1155 WeakHandle<syncable::TransactionObserver> transaction_observer( | 1166 WeakHandle<syncable::TransactionObserver> transaction_observer( |
1156 browser_sync::MakeWeakHandle(js_mutation_event_observer_.AsWeakPtr())); | 1167 browser_sync::MakeWeakHandle(js_mutation_event_observer_.AsWeakPtr())); |
(...skipping 1344 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2501 share->directory->GetDownloadProgress(i.Get(), &marker); | 2512 share->directory->GetDownloadProgress(i.Get(), &marker); |
2502 | 2513 |
2503 if (marker.token().empty()) | 2514 if (marker.token().empty()) |
2504 result.Put(i.Get()); | 2515 result.Put(i.Get()); |
2505 | 2516 |
2506 } | 2517 } |
2507 return result; | 2518 return result; |
2508 } | 2519 } |
2509 | 2520 |
2510 } // namespace sync_api | 2521 } // namespace sync_api |
OLD | NEW |