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/sync/glue/bridged_invalidator.h" | 26 #include "chrome/browser/sync/glue/bridged_invalidator.h" |
28 #include "chrome/browser/sync/glue/change_processor.h" | 27 #include "chrome/browser/sync/glue/change_processor.h" |
29 #include "chrome/browser/sync/glue/chrome_encryptor.h" | 28 #include "chrome/browser/sync/glue/chrome_encryptor.h" |
30 #include "chrome/browser/sync/glue/chrome_sync_notification_bridge.h" | 29 #include "chrome/browser/sync/glue/chrome_sync_notification_bridge.h" |
31 #include "chrome/browser/sync/glue/sync_backend_registrar.h" | 30 #include "chrome/browser/sync/glue/sync_backend_registrar.h" |
| 31 #include "chrome/browser/sync/glue/synced_device_tracker.h" |
| 32 #include "chrome/browser/sync/glue/device_info.h" |
32 #include "chrome/browser/sync/invalidations/invalidator_storage.h" | 33 #include "chrome/browser/sync/invalidations/invalidator_storage.h" |
33 #include "chrome/browser/sync/sync_prefs.h" | 34 #include "chrome/browser/sync/sync_prefs.h" |
34 #include "chrome/common/chrome_notification_types.h" | 35 #include "chrome/common/chrome_notification_types.h" |
35 #include "chrome/common/chrome_switches.h" | 36 #include "chrome/common/chrome_switches.h" |
36 #include "chrome/common/chrome_version_info.h" | 37 #include "chrome/common/chrome_version_info.h" |
37 #include "content/public/browser/browser_thread.h" | 38 #include "content/public/browser/browser_thread.h" |
38 #include "content/public/browser/notification_service.h" | 39 #include "content/public/browser/notification_service.h" |
39 #include "content/public/common/content_client.h" | 40 #include "content/public/common/content_client.h" |
40 #include "google_apis/gaia/gaia_constants.h" | 41 #include "google_apis/gaia/gaia_constants.h" |
41 #include "jingle/notifier/base/notification_method.h" | 42 #include "jingle/notifier/base/notification_method.h" |
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
154 void DoSetEncryptionPassphrase(const std::string& passphrase, | 155 void DoSetEncryptionPassphrase(const std::string& passphrase, |
155 bool is_explicit); | 156 bool is_explicit); |
156 | 157 |
157 // Called to decrypt the pending keys. | 158 // Called to decrypt the pending keys. |
158 void DoSetDecryptionPassphrase(const std::string& passphrase); | 159 void DoSetDecryptionPassphrase(const std::string& passphrase); |
159 | 160 |
160 // Called to turn on encryption of all sync data as well as | 161 // Called to turn on encryption of all sync data as well as |
161 // reencrypt everything. | 162 // reencrypt everything. |
162 void DoEnableEncryptEverything(); | 163 void DoEnableEncryptEverything(); |
163 | 164 |
164 // Called to load sync encryption state and re-encrypt any types | 165 // Called to perform tasks which require the control data to be downloaded. |
165 // needing encryption as necessary. | 166 // This includes refreshing encryption, setting up the device info change |
166 void DoAssociateNigori(); | 167 // processor, etc. |
| 168 void DoInitialProcessControlTypes(); |
| 169 |
| 170 void FinishInitialProcessControlTypes(); |
167 | 171 |
168 // The shutdown order is a bit complicated: | 172 // The shutdown order is a bit complicated: |
169 // 1) From |sync_thread_|, invoke the syncapi Shutdown call to do | 173 // 1) From |sync_thread_|, invoke the syncapi Shutdown call to do |
170 // a final SaveChanges, and close sqlite handles. | 174 // a final SaveChanges, and close sqlite handles. |
171 // 2) Then, from |frontend_loop_|, halt the sync_thread_ (which is | 175 // 2) Then, from |frontend_loop_|, halt the sync_thread_ (which is |
172 // a blocking call). This causes syncapi thread-exit handlers | 176 // a blocking call). This causes syncapi thread-exit handlers |
173 // to run and make use of cached pointers to various components | 177 // to run and make use of cached pointers to various components |
174 // owned implicitly by us. | 178 // owned implicitly by us. |
175 // 3) Destroy this Core. That will delete syncapi components in a | 179 // 3) Destroy this Core. That will delete syncapi components in a |
176 // safe order because the thread that was using them has exited | 180 // safe order because the thread that was using them has exited |
(...skipping 14 matching lines...) Expand all Loading... |
191 const base::Callback<void(syncer::ModelTypeSet)>& ready_task); | 195 const base::Callback<void(syncer::ModelTypeSet)>& ready_task); |
192 void DoRetryConfiguration( | 196 void DoRetryConfiguration( |
193 const base::Closure& retry_callback); | 197 const base::Closure& retry_callback); |
194 | 198 |
195 // Set the base request context to use when making HTTP calls. | 199 // Set the base request context to use when making HTTP calls. |
196 // This method will add a reference to the context to persist it | 200 // This method will add a reference to the context to persist it |
197 // on the IO thread. Must be removed from IO thread. | 201 // on the IO thread. Must be removed from IO thread. |
198 | 202 |
199 syncer::SyncManager* sync_manager() { return sync_manager_.get(); } | 203 syncer::SyncManager* sync_manager() { return sync_manager_.get(); } |
200 | 204 |
| 205 SyncedDeviceTracker* synced_device_tracker() { |
| 206 return &synced_device_tracker_; |
| 207 } |
| 208 |
201 // Delete the sync data folder to cleanup backend data. Happens the first | 209 // Delete the sync data folder to cleanup backend data. Happens the first |
202 // time sync is enabled for a user (to prevent accidentally reusing old | 210 // time sync is enabled for a user (to prevent accidentally reusing old |
203 // sync databases), as well as shutdown when you're no longer syncing. | 211 // sync databases), as well as shutdown when you're no longer syncing. |
204 void DeleteSyncDataFolder(); | 212 void DeleteSyncDataFolder(); |
205 | 213 |
206 private: | 214 private: |
207 friend class base::RefCountedThreadSafe<SyncBackendHost::Core>; | 215 friend class base::RefCountedThreadSafe<SyncBackendHost::Core>; |
208 friend class SyncBackendHostForProfileSyncTest; | 216 friend class SyncBackendHostForProfileSyncTest; |
209 | 217 |
210 virtual ~Core(); | 218 virtual ~Core(); |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
243 // Our parent's notification bridge (not owned). Non-NULL only | 251 // Our parent's notification bridge (not owned). Non-NULL only |
244 // between calls to DoInitialize() and DoShutdown(). | 252 // between calls to DoInitialize() and DoShutdown(). |
245 ChromeSyncNotificationBridge* chrome_sync_notification_bridge_; | 253 ChromeSyncNotificationBridge* chrome_sync_notification_bridge_; |
246 | 254 |
247 // The timer used to periodically call SaveChanges. | 255 // The timer used to periodically call SaveChanges. |
248 scoped_ptr<base::RepeatingTimer<Core> > save_changes_timer_; | 256 scoped_ptr<base::RepeatingTimer<Core> > save_changes_timer_; |
249 | 257 |
250 // Our encryptor, which uses Chrome's encryption functions. | 258 // Our encryptor, which uses Chrome's encryption functions. |
251 ChromeEncryptor encryptor_; | 259 ChromeEncryptor encryptor_; |
252 | 260 |
| 261 // A special ChangeProcessor that tracks the DEVICE_INFO type for us. |
| 262 SyncedDeviceTracker synced_device_tracker_; |
| 263 |
253 // The top-level syncapi entry point. Lives on the sync thread. | 264 // The top-level syncapi entry point. Lives on the sync thread. |
254 scoped_ptr<syncer::SyncManager> sync_manager_; | 265 scoped_ptr<syncer::SyncManager> sync_manager_; |
255 | 266 |
256 // Whether or not we registered with |sync_manager_| as an invalidation | 267 // Whether or not we registered with |sync_manager_| as an invalidation |
257 // handler. Necessary since we may end up trying to unregister before we | 268 // handler. Necessary since we may end up trying to unregister before we |
258 // register in tests (in synchronous initialization mode). | 269 // register in tests (in synchronous initialization mode). |
259 // | 270 // |
260 // TODO(akalin): Fix this behavior (see http://crbug.com/140354). | 271 // TODO(akalin): Fix this behavior (see http://crbug.com/140354). |
261 bool registered_as_invalidation_handler_; | 272 bool registered_as_invalidation_handler_; |
262 | 273 |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
349 } | 360 } |
350 | 361 |
351 SyncBackendHost::~SyncBackendHost() { | 362 SyncBackendHost::~SyncBackendHost() { |
352 DCHECK(!core_ && !frontend_) << "Must call Shutdown before destructor."; | 363 DCHECK(!core_ && !frontend_) << "Must call Shutdown before destructor."; |
353 DCHECK(!chrome_sync_notification_bridge_.get()); | 364 DCHECK(!chrome_sync_notification_bridge_.get()); |
354 DCHECK(!registrar_.get()); | 365 DCHECK(!registrar_.get()); |
355 } | 366 } |
356 | 367 |
357 namespace { | 368 namespace { |
358 | 369 |
359 // Helper to construct a user agent string (ASCII) suitable for use by | |
360 // the syncapi for any HTTP communication. This string is used by the sync | |
361 // backend for classifying client types when calculating statistics. | |
362 std::string MakeUserAgentForSyncApi() { | |
363 std::string user_agent; | |
364 user_agent = "Chrome "; | |
365 #if defined(OS_WIN) | |
366 user_agent += "WIN "; | |
367 #elif defined(OS_CHROMEOS) | |
368 user_agent += "CROS "; | |
369 #elif defined(OS_LINUX) | |
370 user_agent += "LINUX "; | |
371 #elif defined(OS_FREEBSD) | |
372 user_agent += "FREEBSD "; | |
373 #elif defined(OS_OPENBSD) | |
374 user_agent += "OPENBSD "; | |
375 #elif defined(OS_MACOSX) | |
376 user_agent += "MAC "; | |
377 #endif | |
378 chrome::VersionInfo version_info; | |
379 if (!version_info.is_valid()) { | |
380 DLOG(ERROR) << "Unable to create chrome::VersionInfo object"; | |
381 return user_agent; | |
382 } | |
383 | |
384 user_agent += version_info.Version(); | |
385 user_agent += " (" + version_info.LastChange() + ")"; | |
386 if (!version_info.IsOfficialBuild()) | |
387 user_agent += "-devel"; | |
388 return user_agent; | |
389 } | |
390 | |
391 scoped_ptr<syncer::HttpPostProviderFactory> MakeHttpBridgeFactory( | 370 scoped_ptr<syncer::HttpPostProviderFactory> MakeHttpBridgeFactory( |
392 const scoped_refptr<net::URLRequestContextGetter>& getter) { | 371 const scoped_refptr<net::URLRequestContextGetter>& getter) { |
393 return scoped_ptr<syncer::HttpPostProviderFactory>( | 372 return scoped_ptr<syncer::HttpPostProviderFactory>( |
394 new syncer::HttpBridgeFactory(getter, MakeUserAgentForSyncApi())); | 373 new syncer::HttpBridgeFactory( |
| 374 getter, DeviceInfo::MakeUserAgentForSyncApi())); |
395 } | 375 } |
396 | 376 |
397 } // namespace | 377 } // namespace |
398 | 378 |
399 void SyncBackendHost::Initialize( | 379 void SyncBackendHost::Initialize( |
400 SyncFrontend* frontend, | 380 SyncFrontend* frontend, |
401 const syncer::WeakHandle<syncer::JsEventHandler>& event_handler, | 381 const syncer::WeakHandle<syncer::JsEventHandler>& event_handler, |
402 const GURL& sync_service_url, | 382 const GURL& sync_service_url, |
403 const SyncCredentials& credentials, | 383 const SyncCredentials& credentials, |
404 bool delete_sync_data_folder, | 384 bool delete_sync_data_folder, |
(...skipping 377 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
782 void SyncBackendHost::GetModelSafeRoutingInfo( | 762 void SyncBackendHost::GetModelSafeRoutingInfo( |
783 syncer::ModelSafeRoutingInfo* out) const { | 763 syncer::ModelSafeRoutingInfo* out) const { |
784 if (initialized()) { | 764 if (initialized()) { |
785 CHECK(registrar_.get()); | 765 CHECK(registrar_.get()); |
786 registrar_->GetModelSafeRoutingInfo(out); | 766 registrar_->GetModelSafeRoutingInfo(out); |
787 } else { | 767 } else { |
788 NOTREACHED(); | 768 NOTREACHED(); |
789 } | 769 } |
790 } | 770 } |
791 | 771 |
| 772 SyncedDeviceTracker* SyncBackendHost::GetSyncedDeviceTrackerForTest() { |
| 773 return core_->synced_device_tracker(); |
| 774 } |
| 775 |
792 void SyncBackendHost::InitCore(const DoInitializeOptions& options) { | 776 void SyncBackendHost::InitCore(const DoInitializeOptions& options) { |
793 sync_thread_.message_loop()->PostTask(FROM_HERE, | 777 sync_thread_.message_loop()->PostTask(FROM_HERE, |
794 base::Bind(&SyncBackendHost::Core::DoInitialize, core_.get(), options)); | 778 base::Bind(&SyncBackendHost::Core::DoInitialize, core_.get(), options)); |
795 } | 779 } |
796 | 780 |
797 void SyncBackendHost::RequestConfigureSyncer( | 781 void SyncBackendHost::RequestConfigureSyncer( |
798 syncer::ConfigureReason reason, | 782 syncer::ConfigureReason reason, |
799 syncer::ModelTypeSet types_to_config, | 783 syncer::ModelTypeSet types_to_config, |
800 const syncer::ModelSafeRoutingInfo& routing_info, | 784 const syncer::ModelSafeRoutingInfo& routing_info, |
801 const base::Callback<void(syncer::ModelTypeSet)>& ready_task, | 785 const base::Callback<void(syncer::ModelTypeSet)>& ready_task, |
(...skipping 292 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1094 #endif | 1078 #endif |
1095 | 1079 |
1096 sync_manager_ = options.sync_manager_factory->CreateSyncManager(name_); | 1080 sync_manager_ = options.sync_manager_factory->CreateSyncManager(name_); |
1097 sync_manager_->AddObserver(this); | 1081 sync_manager_->AddObserver(this); |
1098 sync_manager_->Init( | 1082 sync_manager_->Init( |
1099 sync_data_folder_path_, | 1083 sync_data_folder_path_, |
1100 options.event_handler, | 1084 options.event_handler, |
1101 options.service_url.host() + options.service_url.path(), | 1085 options.service_url.host() + options.service_url.path(), |
1102 options.service_url.EffectiveIntPort(), | 1086 options.service_url.EffectiveIntPort(), |
1103 options.service_url.SchemeIsSecure(), | 1087 options.service_url.SchemeIsSecure(), |
1104 BrowserThread::GetBlockingPool(), | |
1105 options.make_http_bridge_factory_fn.Run().Pass(), | 1088 options.make_http_bridge_factory_fn.Run().Pass(), |
1106 options.workers, | 1089 options.workers, |
1107 options.extensions_activity_monitor, | 1090 options.extensions_activity_monitor, |
1108 options.registrar /* as SyncManager::ChangeDelegate */, | 1091 options.registrar /* as SyncManager::ChangeDelegate */, |
1109 options.credentials, | 1092 options.credentials, |
1110 scoped_ptr<syncer::Invalidator>(new BridgedInvalidator( | 1093 scoped_ptr<syncer::Invalidator>(new BridgedInvalidator( |
1111 options.chrome_sync_notification_bridge, | 1094 options.chrome_sync_notification_bridge, |
1112 options.invalidator_factory->CreateInvalidator(), | 1095 options.invalidator_factory->CreateInvalidator(), |
1113 kDefaultInvalidatorState)), | 1096 kDefaultInvalidatorState)), |
1114 options.restored_key_for_bootstrapping, | 1097 options.restored_key_for_bootstrapping, |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1158 sync_manager_->UpdateRegisteredInvalidationIds(this, ids); | 1141 sync_manager_->UpdateRegisteredInvalidationIds(this, ids); |
1159 } | 1142 } |
1160 } | 1143 } |
1161 | 1144 |
1162 void SyncBackendHost::Core::DoStartSyncing( | 1145 void SyncBackendHost::Core::DoStartSyncing( |
1163 const syncer::ModelSafeRoutingInfo& routing_info) { | 1146 const syncer::ModelSafeRoutingInfo& routing_info) { |
1164 DCHECK_EQ(MessageLoop::current(), sync_loop_); | 1147 DCHECK_EQ(MessageLoop::current(), sync_loop_); |
1165 sync_manager_->StartSyncingNormally(routing_info); | 1148 sync_manager_->StartSyncingNormally(routing_info); |
1166 } | 1149 } |
1167 | 1150 |
1168 void SyncBackendHost::Core::DoAssociateNigori() { | |
1169 DCHECK_EQ(MessageLoop::current(), sync_loop_); | |
1170 sync_manager_->GetEncryptionHandler()->Init(); | |
1171 host_.Call(FROM_HERE, | |
1172 &SyncBackendHost::HandleInitializationCompletedOnFrontendLoop, | |
1173 true); | |
1174 } | |
1175 | |
1176 void SyncBackendHost::Core::DoSetEncryptionPassphrase( | 1151 void SyncBackendHost::Core::DoSetEncryptionPassphrase( |
1177 const std::string& passphrase, | 1152 const std::string& passphrase, |
1178 bool is_explicit) { | 1153 bool is_explicit) { |
1179 DCHECK_EQ(MessageLoop::current(), sync_loop_); | 1154 DCHECK_EQ(MessageLoop::current(), sync_loop_); |
1180 sync_manager_->GetEncryptionHandler()->SetEncryptionPassphrase( | 1155 sync_manager_->GetEncryptionHandler()->SetEncryptionPassphrase( |
1181 passphrase, is_explicit); | 1156 passphrase, is_explicit); |
1182 } | 1157 } |
1183 | 1158 |
| 1159 void SyncBackendHost::Core::DoInitialProcessControlTypes() { |
| 1160 DCHECK_EQ(MessageLoop::current(), sync_loop_); |
| 1161 |
| 1162 // Initialize encryption. |
| 1163 sync_manager_->GetEncryptionHandler()->Init(); |
| 1164 |
| 1165 // Initialize device info. |
| 1166 if (sync_manager_->GetUserShare()) { // NULL in some tests. |
| 1167 registrar_->ActivateDataType(syncer::DEVICE_INFO, |
| 1168 syncer::GROUP_PASSIVE, |
| 1169 &synced_device_tracker_, |
| 1170 sync_manager_->GetUserShare()); |
| 1171 synced_device_tracker_.InitLocalDeviceInfo( |
| 1172 base::Bind(&SyncBackendHost::Core::FinishInitialProcessControlTypes, |
| 1173 this)); |
| 1174 } else { |
| 1175 FinishInitialProcessControlTypes(); |
| 1176 } |
| 1177 } |
| 1178 |
| 1179 void SyncBackendHost::Core::FinishInitialProcessControlTypes() { |
| 1180 host_.Call( |
| 1181 FROM_HERE, |
| 1182 &SyncBackendHost::HandleInitializationCompletedOnFrontendLoop, |
| 1183 true); |
| 1184 } |
| 1185 |
1184 void SyncBackendHost::Core::DoSetDecryptionPassphrase( | 1186 void SyncBackendHost::Core::DoSetDecryptionPassphrase( |
1185 const std::string& passphrase) { | 1187 const std::string& passphrase) { |
1186 DCHECK_EQ(MessageLoop::current(), sync_loop_); | 1188 DCHECK_EQ(MessageLoop::current(), sync_loop_); |
1187 sync_manager_->GetEncryptionHandler()->SetDecryptionPassphrase( | 1189 sync_manager_->GetEncryptionHandler()->SetDecryptionPassphrase( |
1188 passphrase); | 1190 passphrase); |
1189 } | 1191 } |
1190 | 1192 |
1191 void SyncBackendHost::Core::DoEnableEncryptEverything() { | 1193 void SyncBackendHost::Core::DoEnableEncryptEverything() { |
1192 DCHECK_EQ(MessageLoop::current(), sync_loop_); | 1194 DCHECK_EQ(MessageLoop::current(), sync_loop_); |
1193 sync_manager_->GetEncryptionHandler()->EnableEncryptEverything(); | 1195 sync_manager_->GetEncryptionHandler()->EnableEncryptEverything(); |
1194 } | 1196 } |
1195 | 1197 |
1196 void SyncBackendHost::Core::DoStopSyncManagerForShutdown( | 1198 void SyncBackendHost::Core::DoStopSyncManagerForShutdown( |
1197 const base::Closure& closure) { | 1199 const base::Closure& closure) { |
1198 if (sync_manager_.get()) { | 1200 if (sync_manager_.get()) { |
1199 sync_manager_->StopSyncingForShutdown(closure); | 1201 sync_manager_->StopSyncingForShutdown(closure); |
1200 } else { | 1202 } else { |
1201 sync_loop_->PostTask(FROM_HERE, closure); | 1203 sync_loop_->PostTask(FROM_HERE, closure); |
1202 } | 1204 } |
1203 } | 1205 } |
1204 | 1206 |
1205 void SyncBackendHost::Core::DoShutdown(bool sync_disabled) { | 1207 void SyncBackendHost::Core::DoShutdown(bool sync_disabled) { |
1206 DCHECK_EQ(MessageLoop::current(), sync_loop_); | 1208 DCHECK_EQ(MessageLoop::current(), sync_loop_); |
1207 DoDestroySyncManager(); | 1209 DoDestroySyncManager(); |
1208 | 1210 |
| 1211 // It's safe to do this even if the type was never activated. |
| 1212 registrar_->DeactivateDataType(syncer::DEVICE_INFO); |
| 1213 |
1209 chrome_sync_notification_bridge_ = NULL; | 1214 chrome_sync_notification_bridge_ = NULL; |
1210 registrar_ = NULL; | 1215 registrar_ = NULL; |
1211 | 1216 |
1212 if (sync_disabled) | 1217 if (sync_disabled) |
1213 DeleteSyncDataFolder(); | 1218 DeleteSyncDataFolder(); |
1214 | 1219 |
1215 sync_loop_ = NULL; | 1220 sync_loop_ = NULL; |
1216 | 1221 |
1217 host_.Reset(); | 1222 host_.Reset(); |
1218 } | 1223 } |
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1340 | 1345 |
1341 // Run initialization state machine. | 1346 // Run initialization state machine. |
1342 switch (initialization_state_) { | 1347 switch (initialization_state_) { |
1343 case NOT_INITIALIZED: | 1348 case NOT_INITIALIZED: |
1344 // This configuration should result in a download request if the nigori | 1349 // This configuration should result in a download request if the nigori |
1345 // type's initial_sync_ended bit is unset. If the download request | 1350 // type's initial_sync_ended bit is unset. If the download request |
1346 // contains progress markers, there is a risk that the server will try to | 1351 // contains progress markers, there is a risk that the server will try to |
1347 // trigger migration. That would be disastrous, so we must rely on the | 1352 // trigger migration. That would be disastrous, so we must rely on the |
1348 // sync manager to ensure that this type never has both progress markers | 1353 // sync manager to ensure that this type never has both progress markers |
1349 // and !initial_sync_ended. | 1354 // and !initial_sync_ended. |
1350 initialization_state_ = DOWNLOADING_NIGORI; | 1355 initialization_state_ = DOWNLOADING_CONTROL_TYPES; |
1351 ConfigureDataTypes( | 1356 ConfigureDataTypes( |
1352 syncer::CONFIGURE_REASON_NEW_CLIENT, | 1357 syncer::CONFIGURE_REASON_NEW_CLIENT, |
1353 syncer::ModelTypeSet(syncer::ControlTypes()), | 1358 syncer::ModelTypeSet(syncer::ControlTypes()), |
1354 syncer::ModelTypeSet(), | 1359 syncer::ModelTypeSet(), |
1355 // Calls back into this function. | 1360 // Calls back into this function. |
1356 base::Bind( | 1361 base::Bind( |
1357 &SyncBackendHost:: | 1362 &SyncBackendHost:: |
1358 HandleNigoriConfigurationCompletedOnFrontendLoop, | 1363 HandleNigoriConfigurationCompletedOnFrontendLoop, |
1359 weak_ptr_factory_.GetWeakPtr()), | 1364 weak_ptr_factory_.GetWeakPtr()), |
1360 base::Bind(&SyncBackendHost::OnNigoriDownloadRetry, | 1365 base::Bind(&SyncBackendHost::OnNigoriDownloadRetry, |
1361 weak_ptr_factory_.GetWeakPtr())); | 1366 weak_ptr_factory_.GetWeakPtr())); |
1362 break; | 1367 break; |
1363 case DOWNLOADING_NIGORI: | 1368 case DOWNLOADING_CONTROL_TYPES: |
1364 initialization_state_ = ASSOCIATING_NIGORI; | 1369 initialization_state_ = PROCESSING_CONTROL_TYPES; |
1365 // Triggers OnEncryptedTypesChanged() and OnEncryptionComplete() | 1370 // Updates encryption and other metadata. Will call |
1366 // if necessary. | 1371 // OnEncryptedTypesChanged() and OnEncryptionComplete() if necessary. |
1367 sync_thread_.message_loop()->PostTask( | 1372 InitialProcessControlTypes( |
1368 FROM_HERE, | 1373 base::Bind( |
1369 base::Bind(&SyncBackendHost::Core::DoAssociateNigori, | 1374 &SyncBackendHost:: |
1370 core_.get())); | 1375 HandleInitializationCompletedOnFrontendLoop, |
| 1376 weak_ptr_factory_.GetWeakPtr(), true)); |
1371 break; | 1377 break; |
1372 case ASSOCIATING_NIGORI: | 1378 case PROCESSING_CONTROL_TYPES: |
1373 initialization_state_ = INITIALIZED; | 1379 initialization_state_ = INITIALIZED; |
1374 // Now that we've downloaded the nigori node, we can see if there are any | 1380 // Now that we've downloaded the nigori node, we can see if there are any |
1375 // experimental types to enable. This should be done before we inform | 1381 // experimental types to enable. This should be done before we inform |
1376 // the frontend to ensure they're visible in the customize screen. | 1382 // the frontend to ensure they're visible in the customize screen. |
1377 AddExperimentalTypes(); | 1383 AddExperimentalTypes(); |
1378 frontend_->OnBackendInitialized(js_backend_, true); | 1384 frontend_->OnBackendInitialized(js_backend_, true); |
1379 js_backend_.Reset(); | 1385 js_backend_.Reset(); |
1380 break; | 1386 break; |
1381 default: | 1387 default: |
1382 NOTREACHED(); | 1388 NOTREACHED(); |
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1537 | 1543 |
1538 frontend_->OnConnectionStatusChange(status); | 1544 frontend_->OnConnectionStatusChange(status); |
1539 } | 1545 } |
1540 | 1546 |
1541 void SyncBackendHost::HandleNigoriConfigurationCompletedOnFrontendLoop( | 1547 void SyncBackendHost::HandleNigoriConfigurationCompletedOnFrontendLoop( |
1542 const syncer::ModelTypeSet failed_configuration_types) { | 1548 const syncer::ModelTypeSet failed_configuration_types) { |
1543 HandleInitializationCompletedOnFrontendLoop( | 1549 HandleInitializationCompletedOnFrontendLoop( |
1544 failed_configuration_types.Empty()); | 1550 failed_configuration_types.Empty()); |
1545 } | 1551 } |
1546 | 1552 |
| 1553 void SyncBackendHost::InitialProcessControlTypes( |
| 1554 const base::Closure& done_callback) { |
| 1555 DCHECK_EQ(MessageLoop::current(), frontend_loop_); |
| 1556 // Then forward the request to the sync thread. |
| 1557 sync_thread_.message_loop()->PostTask( |
| 1558 FROM_HERE, |
| 1559 base::Bind(&SyncBackendHost::Core::DoInitialProcessControlTypes, |
| 1560 core_.get())); |
| 1561 } |
| 1562 |
1547 #undef SDVLOG | 1563 #undef SDVLOG |
1548 | 1564 |
1549 #undef SLOG | 1565 #undef SLOG |
1550 | 1566 |
1551 } // namespace browser_sync | 1567 } // namespace browser_sync |
OLD | NEW |