| 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 "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> |
| 11 | 11 |
| 12 #include "base/bind.h" | 12 #include "base/bind.h" |
| 13 #include "base/command_line.h" | 13 #include "base/command_line.h" |
| 14 #include "base/compiler_specific.h" | 14 #include "base/compiler_specific.h" |
| 15 #include "base/file_path.h" | 15 #include "base/file_path.h" |
| 16 #include "base/file_util.h" | 16 #include "base/file_util.h" |
| 17 #include "base/location.h" | 17 #include "base/location.h" |
| 18 #include "base/metrics/histogram.h" | 18 #include "base/metrics/histogram.h" |
| 19 #include "base/threading/sequenced_worker_pool.h" | |
| 20 #include "base/threading/thread_restrictions.h" | 19 #include "base/threading/thread_restrictions.h" |
| 21 #include "base/timer.h" | 20 #include "base/timer.h" |
| 22 #include "base/tracked_objects.h" | 21 #include "base/tracked_objects.h" |
| 23 #include "base/utf_string_conversions.h" | 22 #include "base/utf_string_conversions.h" |
| 24 #include "build/build_config.h" | 23 #include "build/build_config.h" |
| 25 #include "chrome/browser/profiles/profile.h" | 24 #include "chrome/browser/profiles/profile.h" |
| 26 #include "chrome/browser/signin/token_service.h" | 25 #include "chrome/browser/signin/token_service.h" |
| 27 #include "chrome/browser/signin/token_service_factory.h" | 26 #include "chrome/browser/signin/token_service_factory.h" |
| 28 #include "chrome/browser/sync/glue/bridged_invalidator.h" | 27 #include "chrome/browser/sync/glue/bridged_invalidator.h" |
| 29 #include "chrome/browser/sync/glue/change_processor.h" | 28 #include "chrome/browser/sync/glue/change_processor.h" |
| 30 #include "chrome/browser/sync/glue/chrome_encryptor.h" | 29 #include "chrome/browser/sync/glue/chrome_encryptor.h" |
| 31 #include "chrome/browser/sync/glue/chrome_sync_notification_bridge.h" | 30 #include "chrome/browser/sync/glue/chrome_sync_notification_bridge.h" |
| 32 #include "chrome/browser/sync/glue/device_info.h" | 31 #include "chrome/browser/sync/glue/device_info.h" |
| 33 #include "chrome/browser/sync/glue/sync_backend_registrar.h" | 32 #include "chrome/browser/sync/glue/sync_backend_registrar.h" |
| 33 #include "chrome/browser/sync/glue/synced_device_tracker.h" |
| 34 #include "chrome/browser/sync/invalidations/invalidator_storage.h" | 34 #include "chrome/browser/sync/invalidations/invalidator_storage.h" |
| 35 #include "chrome/browser/sync/sync_prefs.h" | 35 #include "chrome/browser/sync/sync_prefs.h" |
| 36 #include "chrome/common/chrome_notification_types.h" | 36 #include "chrome/common/chrome_notification_types.h" |
| 37 #include "chrome/common/chrome_switches.h" | 37 #include "chrome/common/chrome_switches.h" |
| 38 #include "chrome/common/chrome_version_info.h" | 38 #include "chrome/common/chrome_version_info.h" |
| 39 #include "content/public/browser/browser_thread.h" | 39 #include "content/public/browser/browser_thread.h" |
| 40 #include "content/public/browser/notification_service.h" | 40 #include "content/public/browser/notification_service.h" |
| 41 #include "content/public/common/content_client.h" | 41 #include "content/public/common/content_client.h" |
| 42 #include "google_apis/gaia/gaia_constants.h" | 42 #include "google_apis/gaia/gaia_constants.h" |
| 43 #include "jingle/notifier/base/notification_method.h" | 43 #include "jingle/notifier/base/notification_method.h" |
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 159 void DoSetEncryptionPassphrase(const std::string& passphrase, | 159 void DoSetEncryptionPassphrase(const std::string& passphrase, |
| 160 bool is_explicit); | 160 bool is_explicit); |
| 161 | 161 |
| 162 // Called to decrypt the pending keys. | 162 // Called to decrypt the pending keys. |
| 163 void DoSetDecryptionPassphrase(const std::string& passphrase); | 163 void DoSetDecryptionPassphrase(const std::string& passphrase); |
| 164 | 164 |
| 165 // Called to turn on encryption of all sync data as well as | 165 // Called to turn on encryption of all sync data as well as |
| 166 // reencrypt everything. | 166 // reencrypt everything. |
| 167 void DoEnableEncryptEverything(); | 167 void DoEnableEncryptEverything(); |
| 168 | 168 |
| 169 // Called to load sync encryption state and re-encrypt any types | 169 // Called to perform tasks which require the control data to be downloaded. |
| 170 // needing encryption as necessary. | 170 // This includes refreshing encryption, setting up the device info change |
| 171 void DoAssociateNigori(); | 171 // processor, etc. |
| 172 void DoInitialProcessControlTypes(); |
| 173 |
| 174 // Some parts of DoInitialProcessControlTypes() may be executed on a different |
| 175 // thread. This function asynchronously continues the work started in |
| 176 // DoInitialProcessControlTypes() once that other thread gets back to us. |
| 177 void DoFinishInitialProcessControlTypes(); |
| 172 | 178 |
| 173 // The shutdown order is a bit complicated: | 179 // The shutdown order is a bit complicated: |
| 174 // 1) From |sync_thread_|, invoke the syncapi Shutdown call to do | 180 // 1) From |sync_thread_|, invoke the syncapi Shutdown call to do |
| 175 // a final SaveChanges, and close sqlite handles. | 181 // a final SaveChanges, and close sqlite handles. |
| 176 // 2) Then, from |frontend_loop_|, halt the sync_thread_ (which is | 182 // 2) Then, from |frontend_loop_|, halt the sync_thread_ (which is |
| 177 // a blocking call). This causes syncapi thread-exit handlers | 183 // a blocking call). This causes syncapi thread-exit handlers |
| 178 // to run and make use of cached pointers to various components | 184 // to run and make use of cached pointers to various components |
| 179 // owned implicitly by us. | 185 // owned implicitly by us. |
| 180 // 3) Destroy this Core. That will delete syncapi components in a | 186 // 3) Destroy this Core. That will delete syncapi components in a |
| 181 // safe order because the thread that was using them has exited | 187 // safe order because the thread that was using them has exited |
| (...skipping 14 matching lines...) Expand all Loading... |
| 196 const base::Callback<void(syncer::ModelTypeSet)>& ready_task); | 202 const base::Callback<void(syncer::ModelTypeSet)>& ready_task); |
| 197 void DoRetryConfiguration( | 203 void DoRetryConfiguration( |
| 198 const base::Closure& retry_callback); | 204 const base::Closure& retry_callback); |
| 199 | 205 |
| 200 // Set the base request context to use when making HTTP calls. | 206 // Set the base request context to use when making HTTP calls. |
| 201 // This method will add a reference to the context to persist it | 207 // This method will add a reference to the context to persist it |
| 202 // on the IO thread. Must be removed from IO thread. | 208 // on the IO thread. Must be removed from IO thread. |
| 203 | 209 |
| 204 syncer::SyncManager* sync_manager() { return sync_manager_.get(); } | 210 syncer::SyncManager* sync_manager() { return sync_manager_.get(); } |
| 205 | 211 |
| 212 SyncedDeviceTracker* synced_device_tracker() { |
| 213 return synced_device_tracker_.get(); |
| 214 } |
| 215 |
| 206 // Delete the sync data folder to cleanup backend data. Happens the first | 216 // Delete the sync data folder to cleanup backend data. Happens the first |
| 207 // time sync is enabled for a user (to prevent accidentally reusing old | 217 // time sync is enabled for a user (to prevent accidentally reusing old |
| 208 // sync databases), as well as shutdown when you're no longer syncing. | 218 // sync databases), as well as shutdown when you're no longer syncing. |
| 209 void DeleteSyncDataFolder(); | 219 void DeleteSyncDataFolder(); |
| 210 | 220 |
| 211 private: | 221 private: |
| 212 friend class base::RefCountedThreadSafe<SyncBackendHost::Core>; | 222 friend class base::RefCountedThreadSafe<SyncBackendHost::Core>; |
| 213 friend class SyncBackendHostForProfileSyncTest; | 223 friend class SyncBackendHostForProfileSyncTest; |
| 214 | 224 |
| 215 virtual ~Core(); | 225 virtual ~Core(); |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 248 // Our parent's notification bridge (not owned). Non-NULL only | 258 // Our parent's notification bridge (not owned). Non-NULL only |
| 249 // between calls to DoInitialize() and DoShutdown(). | 259 // between calls to DoInitialize() and DoShutdown(). |
| 250 ChromeSyncNotificationBridge* chrome_sync_notification_bridge_; | 260 ChromeSyncNotificationBridge* chrome_sync_notification_bridge_; |
| 251 | 261 |
| 252 // The timer used to periodically call SaveChanges. | 262 // The timer used to periodically call SaveChanges. |
| 253 scoped_ptr<base::RepeatingTimer<Core> > save_changes_timer_; | 263 scoped_ptr<base::RepeatingTimer<Core> > save_changes_timer_; |
| 254 | 264 |
| 255 // Our encryptor, which uses Chrome's encryption functions. | 265 // Our encryptor, which uses Chrome's encryption functions. |
| 256 ChromeEncryptor encryptor_; | 266 ChromeEncryptor encryptor_; |
| 257 | 267 |
| 268 // A special ChangeProcessor that tracks the DEVICE_INFO type for us. |
| 269 scoped_ptr<SyncedDeviceTracker> synced_device_tracker_; |
| 270 |
| 258 // The top-level syncapi entry point. Lives on the sync thread. | 271 // The top-level syncapi entry point. Lives on the sync thread. |
| 259 scoped_ptr<syncer::SyncManager> sync_manager_; | 272 scoped_ptr<syncer::SyncManager> sync_manager_; |
| 260 | 273 |
| 261 // Whether or not we registered with |sync_manager_| as an invalidation | 274 // Whether or not we registered with |sync_manager_| as an invalidation |
| 262 // handler. Necessary since we may end up trying to unregister before we | 275 // handler. Necessary since we may end up trying to unregister before we |
| 263 // register in tests (in synchronous initialization mode). | 276 // register in tests (in synchronous initialization mode). |
| 264 // | 277 // |
| 265 // TODO(akalin): Fix this behavior (see http://crbug.com/140354). | 278 // TODO(akalin): Fix this behavior (see http://crbug.com/140354). |
| 266 bool registered_as_invalidation_handler_; | 279 bool registered_as_invalidation_handler_; |
| 267 | 280 |
| (...skipping 486 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 754 void SyncBackendHost::GetModelSafeRoutingInfo( | 767 void SyncBackendHost::GetModelSafeRoutingInfo( |
| 755 syncer::ModelSafeRoutingInfo* out) const { | 768 syncer::ModelSafeRoutingInfo* out) const { |
| 756 if (initialized()) { | 769 if (initialized()) { |
| 757 CHECK(registrar_.get()); | 770 CHECK(registrar_.get()); |
| 758 registrar_->GetModelSafeRoutingInfo(out); | 771 registrar_->GetModelSafeRoutingInfo(out); |
| 759 } else { | 772 } else { |
| 760 NOTREACHED(); | 773 NOTREACHED(); |
| 761 } | 774 } |
| 762 } | 775 } |
| 763 | 776 |
| 777 SyncedDeviceTracker* SyncBackendHost::GetSyncedDeviceTrackerForTest() { |
| 778 return core_->synced_device_tracker(); |
| 779 } |
| 780 |
| 764 void SyncBackendHost::InitCore(const DoInitializeOptions& options) { | 781 void SyncBackendHost::InitCore(const DoInitializeOptions& options) { |
| 765 sync_thread_.message_loop()->PostTask(FROM_HERE, | 782 sync_thread_.message_loop()->PostTask(FROM_HERE, |
| 766 base::Bind(&SyncBackendHost::Core::DoInitialize, core_.get(), options)); | 783 base::Bind(&SyncBackendHost::Core::DoInitialize, core_.get(), options)); |
| 767 } | 784 } |
| 768 | 785 |
| 769 void SyncBackendHost::RequestConfigureSyncer( | 786 void SyncBackendHost::RequestConfigureSyncer( |
| 770 syncer::ConfigureReason reason, | 787 syncer::ConfigureReason reason, |
| 771 syncer::ModelTypeSet types_to_config, | 788 syncer::ModelTypeSet types_to_config, |
| 772 const syncer::ModelSafeRoutingInfo& routing_info, | 789 const syncer::ModelSafeRoutingInfo& routing_info, |
| 773 const base::Callback<void(syncer::ModelTypeSet)>& ready_task, | 790 const base::Callback<void(syncer::ModelTypeSet)>& ready_task, |
| (...skipping 298 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1072 #endif | 1089 #endif |
| 1073 | 1090 |
| 1074 sync_manager_ = options.sync_manager_factory->CreateSyncManager(name_); | 1091 sync_manager_ = options.sync_manager_factory->CreateSyncManager(name_); |
| 1075 sync_manager_->AddObserver(this); | 1092 sync_manager_->AddObserver(this); |
| 1076 sync_manager_->Init( | 1093 sync_manager_->Init( |
| 1077 sync_data_folder_path_, | 1094 sync_data_folder_path_, |
| 1078 options.event_handler, | 1095 options.event_handler, |
| 1079 options.service_url.host() + options.service_url.path(), | 1096 options.service_url.host() + options.service_url.path(), |
| 1080 options.service_url.EffectiveIntPort(), | 1097 options.service_url.EffectiveIntPort(), |
| 1081 options.service_url.SchemeIsSecure(), | 1098 options.service_url.SchemeIsSecure(), |
| 1082 BrowserThread::GetBlockingPool(), | |
| 1083 options.make_http_bridge_factory_fn.Run().Pass(), | 1099 options.make_http_bridge_factory_fn.Run().Pass(), |
| 1084 options.workers, | 1100 options.workers, |
| 1085 options.extensions_activity_monitor, | 1101 options.extensions_activity_monitor, |
| 1086 options.registrar /* as SyncManager::ChangeDelegate */, | 1102 options.registrar /* as SyncManager::ChangeDelegate */, |
| 1087 options.credentials, | 1103 options.credentials, |
| 1088 scoped_ptr<syncer::Invalidator>(new BridgedInvalidator( | 1104 scoped_ptr<syncer::Invalidator>(new BridgedInvalidator( |
| 1089 options.chrome_sync_notification_bridge, | 1105 options.chrome_sync_notification_bridge, |
| 1090 options.invalidator_factory->CreateInvalidator(), | 1106 options.invalidator_factory->CreateInvalidator(), |
| 1091 kDefaultInvalidatorState)), | 1107 kDefaultInvalidatorState)), |
| 1092 options.restored_key_for_bootstrapping, | 1108 options.restored_key_for_bootstrapping, |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1136 sync_manager_->UpdateRegisteredInvalidationIds(this, ids); | 1152 sync_manager_->UpdateRegisteredInvalidationIds(this, ids); |
| 1137 } | 1153 } |
| 1138 } | 1154 } |
| 1139 | 1155 |
| 1140 void SyncBackendHost::Core::DoStartSyncing( | 1156 void SyncBackendHost::Core::DoStartSyncing( |
| 1141 const syncer::ModelSafeRoutingInfo& routing_info) { | 1157 const syncer::ModelSafeRoutingInfo& routing_info) { |
| 1142 DCHECK_EQ(MessageLoop::current(), sync_loop_); | 1158 DCHECK_EQ(MessageLoop::current(), sync_loop_); |
| 1143 sync_manager_->StartSyncingNormally(routing_info); | 1159 sync_manager_->StartSyncingNormally(routing_info); |
| 1144 } | 1160 } |
| 1145 | 1161 |
| 1146 void SyncBackendHost::Core::DoAssociateNigori() { | |
| 1147 DCHECK_EQ(MessageLoop::current(), sync_loop_); | |
| 1148 sync_manager_->GetEncryptionHandler()->Init(); | |
| 1149 host_.Call(FROM_HERE, | |
| 1150 &SyncBackendHost::HandleInitializationCompletedOnFrontendLoop, | |
| 1151 true); | |
| 1152 } | |
| 1153 | |
| 1154 void SyncBackendHost::Core::DoSetEncryptionPassphrase( | 1162 void SyncBackendHost::Core::DoSetEncryptionPassphrase( |
| 1155 const std::string& passphrase, | 1163 const std::string& passphrase, |
| 1156 bool is_explicit) { | 1164 bool is_explicit) { |
| 1157 DCHECK_EQ(MessageLoop::current(), sync_loop_); | 1165 DCHECK_EQ(MessageLoop::current(), sync_loop_); |
| 1158 sync_manager_->GetEncryptionHandler()->SetEncryptionPassphrase( | 1166 sync_manager_->GetEncryptionHandler()->SetEncryptionPassphrase( |
| 1159 passphrase, is_explicit); | 1167 passphrase, is_explicit); |
| 1160 } | 1168 } |
| 1161 | 1169 |
| 1170 void SyncBackendHost::Core::DoInitialProcessControlTypes() { |
| 1171 DCHECK_EQ(MessageLoop::current(), sync_loop_); |
| 1172 |
| 1173 DVLOG(1) << "Initilalizing Control Types"; |
| 1174 |
| 1175 // Initialize encryption. |
| 1176 sync_manager_->GetEncryptionHandler()->Init(); |
| 1177 |
| 1178 if (sync_manager_->GetUserShare()) { // NULL in some tests. |
| 1179 DVLOG(1) << "Initializing DeviceInfo type"; |
| 1180 |
| 1181 // Initialize device info. |
| 1182 synced_device_tracker_.reset( |
| 1183 new SyncedDeviceTracker( |
| 1184 sync_manager_->GetUserShare(), |
| 1185 sync_manager_->cache_guid())); |
| 1186 |
| 1187 // AssociateModels-equivalent. |
| 1188 synced_device_tracker_->InitLocalDeviceInfo( |
| 1189 base::Bind(&SyncBackendHost::Core::DoFinishInitialProcessControlTypes, |
| 1190 this)); |
| 1191 } else { |
| 1192 DVLOG(1) << "Skipping initialization of DeviceInfo"; |
| 1193 host_.Call( |
| 1194 FROM_HERE, |
| 1195 &SyncBackendHost::HandleInitializationCompletedOnFrontendLoop, |
| 1196 true); |
| 1197 } |
| 1198 } |
| 1199 |
| 1200 void SyncBackendHost::Core::DoFinishInitialProcessControlTypes() { |
| 1201 registrar_->ActivateDataType(syncer::DEVICE_INFO, |
| 1202 syncer::GROUP_PASSIVE, |
| 1203 synced_device_tracker_.get(), |
| 1204 sync_manager_->GetUserShare()); |
| 1205 |
| 1206 host_.Call( |
| 1207 FROM_HERE, |
| 1208 &SyncBackendHost::HandleInitializationCompletedOnFrontendLoop, |
| 1209 true); |
| 1210 } |
| 1211 |
| 1162 void SyncBackendHost::Core::DoSetDecryptionPassphrase( | 1212 void SyncBackendHost::Core::DoSetDecryptionPassphrase( |
| 1163 const std::string& passphrase) { | 1213 const std::string& passphrase) { |
| 1164 DCHECK_EQ(MessageLoop::current(), sync_loop_); | 1214 DCHECK_EQ(MessageLoop::current(), sync_loop_); |
| 1165 sync_manager_->GetEncryptionHandler()->SetDecryptionPassphrase( | 1215 sync_manager_->GetEncryptionHandler()->SetDecryptionPassphrase( |
| 1166 passphrase); | 1216 passphrase); |
| 1167 } | 1217 } |
| 1168 | 1218 |
| 1169 void SyncBackendHost::Core::DoEnableEncryptEverything() { | 1219 void SyncBackendHost::Core::DoEnableEncryptEverything() { |
| 1170 DCHECK_EQ(MessageLoop::current(), sync_loop_); | 1220 DCHECK_EQ(MessageLoop::current(), sync_loop_); |
| 1171 sync_manager_->GetEncryptionHandler()->EnableEncryptEverything(); | 1221 sync_manager_->GetEncryptionHandler()->EnableEncryptEverything(); |
| 1172 } | 1222 } |
| 1173 | 1223 |
| 1174 void SyncBackendHost::Core::DoStopSyncManagerForShutdown( | 1224 void SyncBackendHost::Core::DoStopSyncManagerForShutdown( |
| 1175 const base::Closure& closure) { | 1225 const base::Closure& closure) { |
| 1176 if (sync_manager_.get()) { | 1226 if (sync_manager_.get()) { |
| 1177 sync_manager_->StopSyncingForShutdown(closure); | 1227 sync_manager_->StopSyncingForShutdown(closure); |
| 1178 } else { | 1228 } else { |
| 1179 sync_loop_->PostTask(FROM_HERE, closure); | 1229 sync_loop_->PostTask(FROM_HERE, closure); |
| 1180 } | 1230 } |
| 1181 } | 1231 } |
| 1182 | 1232 |
| 1183 void SyncBackendHost::Core::DoShutdown(bool sync_disabled) { | 1233 void SyncBackendHost::Core::DoShutdown(bool sync_disabled) { |
| 1184 DCHECK_EQ(MessageLoop::current(), sync_loop_); | 1234 DCHECK_EQ(MessageLoop::current(), sync_loop_); |
| 1235 // It's safe to do this even if the type was never activated. |
| 1236 registrar_->DeactivateDataType(syncer::DEVICE_INFO); |
| 1237 synced_device_tracker_.reset(); |
| 1238 |
| 1185 DoDestroySyncManager(); | 1239 DoDestroySyncManager(); |
| 1186 | 1240 |
| 1187 chrome_sync_notification_bridge_ = NULL; | 1241 chrome_sync_notification_bridge_ = NULL; |
| 1188 registrar_ = NULL; | 1242 registrar_ = NULL; |
| 1189 | 1243 |
| 1190 if (sync_disabled) | 1244 if (sync_disabled) |
| 1191 DeleteSyncDataFolder(); | 1245 DeleteSyncDataFolder(); |
| 1192 | 1246 |
| 1193 sync_loop_ = NULL; | 1247 sync_loop_ = NULL; |
| 1194 | 1248 |
| (...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1320 | 1374 |
| 1321 // Run initialization state machine. | 1375 // Run initialization state machine. |
| 1322 switch (initialization_state_) { | 1376 switch (initialization_state_) { |
| 1323 case NOT_INITIALIZED: | 1377 case NOT_INITIALIZED: |
| 1324 // This configuration should result in a download request if the nigori | 1378 // This configuration should result in a download request if the nigori |
| 1325 // type's initial_sync_ended bit is unset. If the download request | 1379 // type's initial_sync_ended bit is unset. If the download request |
| 1326 // contains progress markers, there is a risk that the server will try to | 1380 // contains progress markers, there is a risk that the server will try to |
| 1327 // trigger migration. That would be disastrous, so we must rely on the | 1381 // trigger migration. That would be disastrous, so we must rely on the |
| 1328 // sync manager to ensure that this type never has both progress markers | 1382 // sync manager to ensure that this type never has both progress markers |
| 1329 // and !initial_sync_ended. | 1383 // and !initial_sync_ended. |
| 1330 initialization_state_ = DOWNLOADING_NIGORI; | 1384 initialization_state_ = DOWNLOADING_CONTROL_TYPES; |
| 1331 ConfigureDataTypes( | 1385 ConfigureDataTypes( |
| 1332 syncer::CONFIGURE_REASON_NEW_CLIENT, | 1386 syncer::CONFIGURE_REASON_NEW_CLIENT, |
| 1333 syncer::ModelTypeSet(syncer::ControlTypes()), | 1387 syncer::ModelTypeSet(syncer::ControlTypes()), |
| 1334 syncer::ModelTypeSet(), | 1388 syncer::ModelTypeSet(), |
| 1335 // Calls back into this function. | 1389 // Calls back into this function. |
| 1336 base::Bind( | 1390 base::Bind( |
| 1337 &SyncBackendHost:: | 1391 &SyncBackendHost:: |
| 1338 HandleNigoriConfigurationCompletedOnFrontendLoop, | 1392 HandleNigoriConfigurationCompletedOnFrontendLoop, |
| 1339 weak_ptr_factory_.GetWeakPtr()), | 1393 weak_ptr_factory_.GetWeakPtr()), |
| 1340 base::Bind(&SyncBackendHost::OnNigoriDownloadRetry, | 1394 base::Bind(&SyncBackendHost::OnNigoriDownloadRetry, |
| 1341 weak_ptr_factory_.GetWeakPtr())); | 1395 weak_ptr_factory_.GetWeakPtr())); |
| 1342 break; | 1396 break; |
| 1343 case DOWNLOADING_NIGORI: | 1397 case DOWNLOADING_CONTROL_TYPES: |
| 1344 initialization_state_ = ASSOCIATING_NIGORI; | 1398 initialization_state_ = PROCESSING_CONTROL_TYPES; |
| 1345 // Triggers OnEncryptedTypesChanged() and OnEncryptionComplete() | 1399 // Updates encryption and other metadata. Will call |
| 1346 // if necessary. | 1400 // OnEncryptedTypesChanged() and OnEncryptionComplete() if necessary. |
| 1347 sync_thread_.message_loop()->PostTask( | 1401 InitialProcessControlTypes( |
| 1348 FROM_HERE, | 1402 base::Bind( |
| 1349 base::Bind(&SyncBackendHost::Core::DoAssociateNigori, | 1403 &SyncBackendHost:: |
| 1350 core_.get())); | 1404 HandleInitializationCompletedOnFrontendLoop, |
| 1405 weak_ptr_factory_.GetWeakPtr(), true)); |
| 1351 break; | 1406 break; |
| 1352 case ASSOCIATING_NIGORI: | 1407 case PROCESSING_CONTROL_TYPES: |
| 1353 initialization_state_ = INITIALIZED; | 1408 initialization_state_ = INITIALIZED; |
| 1354 // Now that we've downloaded the nigori node, we can see if there are any | 1409 // Now that we've downloaded the nigori node, we can see if there are any |
| 1355 // experimental types to enable. This should be done before we inform | 1410 // experimental types to enable. This should be done before we inform |
| 1356 // the frontend to ensure they're visible in the customize screen. | 1411 // the frontend to ensure they're visible in the customize screen. |
| 1357 AddExperimentalTypes(); | 1412 AddExperimentalTypes(); |
| 1358 frontend_->OnBackendInitialized(js_backend_, | 1413 frontend_->OnBackendInitialized(js_backend_, |
| 1359 debug_info_listener_, | 1414 debug_info_listener_, |
| 1360 true); | 1415 true); |
| 1361 js_backend_.Reset(); | 1416 js_backend_.Reset(); |
| 1362 break; | 1417 break; |
| (...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1521 | 1576 |
| 1522 frontend_->OnConnectionStatusChange(status); | 1577 frontend_->OnConnectionStatusChange(status); |
| 1523 } | 1578 } |
| 1524 | 1579 |
| 1525 void SyncBackendHost::HandleNigoriConfigurationCompletedOnFrontendLoop( | 1580 void SyncBackendHost::HandleNigoriConfigurationCompletedOnFrontendLoop( |
| 1526 const syncer::ModelTypeSet failed_configuration_types) { | 1581 const syncer::ModelTypeSet failed_configuration_types) { |
| 1527 HandleInitializationCompletedOnFrontendLoop( | 1582 HandleInitializationCompletedOnFrontendLoop( |
| 1528 failed_configuration_types.Empty()); | 1583 failed_configuration_types.Empty()); |
| 1529 } | 1584 } |
| 1530 | 1585 |
| 1586 void SyncBackendHost::InitialProcessControlTypes( |
| 1587 const base::Closure& done_callback) { |
| 1588 DCHECK_EQ(MessageLoop::current(), frontend_loop_); |
| 1589 // Then forward the request to the sync thread. |
| 1590 sync_thread_.message_loop()->PostTask( |
| 1591 FROM_HERE, |
| 1592 base::Bind(&SyncBackendHost::Core::DoInitialProcessControlTypes, |
| 1593 core_.get())); |
| 1594 } |
| 1595 |
| 1531 #undef SDVLOG | 1596 #undef SDVLOG |
| 1532 | 1597 |
| 1533 #undef SLOG | 1598 #undef SLOG |
| 1534 | 1599 |
| 1535 } // namespace browser_sync | 1600 } // namespace browser_sync |
| OLD | NEW |