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 "chrome/browser/sync/glue/sync_backend_host.h" | 5 #include "chrome/browser/sync/glue/sync_backend_host.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <map> | 8 #include <map> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
(...skipping 26 matching lines...) Expand all Loading... | |
37 #include "content/public/browser/browser_thread.h" | 37 #include "content/public/browser/browser_thread.h" |
38 #include "content/public/browser/notification_details.h" | 38 #include "content/public/browser/notification_details.h" |
39 #include "content/public/browser/notification_service.h" | 39 #include "content/public/browser/notification_service.h" |
40 #include "content/public/browser/notification_source.h" | 40 #include "content/public/browser/notification_source.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" |
44 #include "jingle/notifier/base/notifier_options.h" | 44 #include "jingle/notifier/base/notifier_options.h" |
45 #include "net/base/host_port_pair.h" | 45 #include "net/base/host_port_pair.h" |
46 #include "net/url_request/url_request_context_getter.h" | 46 #include "net/url_request/url_request_context_getter.h" |
47 #include "sync/internal_api/public/base/cancelation_signal.h" | |
47 #include "sync/internal_api/public/base_transaction.h" | 48 #include "sync/internal_api/public/base_transaction.h" |
48 #include "sync/internal_api/public/engine/model_safe_worker.h" | 49 #include "sync/internal_api/public/engine/model_safe_worker.h" |
49 #include "sync/internal_api/public/http_bridge.h" | 50 #include "sync/internal_api/public/http_bridge.h" |
50 #include "sync/internal_api/public/internal_components_factory_impl.h" | 51 #include "sync/internal_api/public/internal_components_factory_impl.h" |
51 #include "sync/internal_api/public/read_transaction.h" | 52 #include "sync/internal_api/public/read_transaction.h" |
52 #include "sync/internal_api/public/sync_manager_factory.h" | 53 #include "sync/internal_api/public/sync_manager_factory.h" |
53 #include "sync/internal_api/public/util/experiments.h" | 54 #include "sync/internal_api/public/util/experiments.h" |
54 #include "sync/internal_api/public/util/sync_string_conversions.h" | 55 #include "sync/internal_api/public/util/sync_string_conversions.h" |
55 #include "sync/protocol/encryption.pb.h" | 56 #include "sync/protocol/encryption.pb.h" |
56 #include "sync/protocol/sync.pb.h" | 57 #include "sync/protocol/sync.pb.h" |
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
191 // This includes refreshing encryption, setting up the device info change | 192 // This includes refreshing encryption, setting up the device info change |
192 // processor, etc. | 193 // processor, etc. |
193 void DoInitialProcessControlTypes(); | 194 void DoInitialProcessControlTypes(); |
194 | 195 |
195 // Some parts of DoInitialProcessControlTypes() may be executed on a different | 196 // Some parts of DoInitialProcessControlTypes() may be executed on a different |
196 // thread. This function asynchronously continues the work started in | 197 // thread. This function asynchronously continues the work started in |
197 // DoInitialProcessControlTypes() once that other thread gets back to us. | 198 // DoInitialProcessControlTypes() once that other thread gets back to us. |
198 void DoFinishInitialProcessControlTypes(); | 199 void DoFinishInitialProcessControlTypes(); |
199 | 200 |
200 // The shutdown order is a bit complicated: | 201 // The shutdown order is a bit complicated: |
201 // 1) Call DoStopSyncManagerForShutdown() from |frontend_loop_| to request | 202 // 1) Call ShutdownOnUIThread() from |frontend_loop_| to request sync manager |
202 // sync manager to stop as soon as possible. | 203 // to stop as soon as possible. |
203 // 2) Post DoShutdown() to sync loop to clean up backend state, save | 204 // 2) Post DoShutdown() to sync loop to clean up backend state, save |
204 // directory and destroy sync manager. | 205 // directory and destroy sync manager. |
205 void DoStopSyncManagerForShutdown(); | 206 void ShutdownOnUIThread(); |
206 void DoShutdown(bool sync_disabled); | 207 void DoShutdown(bool sync_disabled); |
207 void DoDestroySyncManager(); | 208 void DoDestroySyncManager(); |
208 | 209 |
209 // Configuration methods that must execute on sync loop. | 210 // Configuration methods that must execute on sync loop. |
210 void DoConfigureSyncer( | 211 void DoConfigureSyncer( |
211 syncer::ConfigureReason reason, | 212 syncer::ConfigureReason reason, |
212 const DoConfigureSyncerTypes& config_types, | 213 const DoConfigureSyncerTypes& config_types, |
213 const syncer::ModelSafeRoutingInfo routing_info, | 214 const syncer::ModelSafeRoutingInfo routing_info, |
214 const base::Callback<void(syncer::ModelTypeSet, | 215 const base::Callback<void(syncer::ModelTypeSet, |
215 syncer::ModelTypeSet)>& ready_task, | 216 syncer::ModelTypeSet)>& ready_task, |
(...skipping 13 matching lines...) Expand all Loading... | |
229 | 230 |
230 SyncedDeviceTracker* synced_device_tracker() { | 231 SyncedDeviceTracker* synced_device_tracker() { |
231 return synced_device_tracker_.get(); | 232 return synced_device_tracker_.get(); |
232 } | 233 } |
233 | 234 |
234 // Delete the sync data folder to cleanup backend data. Happens the first | 235 // Delete the sync data folder to cleanup backend data. Happens the first |
235 // time sync is enabled for a user (to prevent accidentally reusing old | 236 // time sync is enabled for a user (to prevent accidentally reusing old |
236 // sync databases), as well as shutdown when you're no longer syncing. | 237 // sync databases), as well as shutdown when you're no longer syncing. |
237 void DeleteSyncDataFolder(); | 238 void DeleteSyncDataFolder(); |
238 | 239 |
240 // We expose this member because it's required in the construction of the | |
241 // HttpBridgeFactory. | |
242 syncer::CancelationSignal* GetFactoryCancelationSignal() { | |
243 return &factory_cancelation_signal_; | |
tim (not reviewing)
2013/09/16 23:01:31
|factory| in the name might not be the best choice
rlarocque
2013/09/17 00:03:22
What about the UrlRequestContextGetter? That obje
tim (not reviewing)
2013/09/17 21:56:41
Hm. That's more confusing I think. http_bridge_c
rlarocque
2013/09/17 22:46:02
I don't think http_bridge_construction_signal_ is
tim (not reviewing)
2013/09/18 00:37:56
I see. Logically we're just trying to sever ties
rlarocque
2013/09/18 00:45:09
That's not bad. Maybe we should make their names
| |
244 } | |
245 | |
239 private: | 246 private: |
240 friend class base::RefCountedThreadSafe<SyncBackendHost::Core>; | 247 friend class base::RefCountedThreadSafe<SyncBackendHost::Core>; |
241 friend class SyncBackendHostForProfileSyncTest; | 248 friend class SyncBackendHostForProfileSyncTest; |
242 | 249 |
243 virtual ~Core(); | 250 virtual ~Core(); |
244 | 251 |
245 // Invoked when initialization of syncapi is complete and we can start | 252 // Invoked when initialization of syncapi is complete and we can start |
246 // our timer. | 253 // our timer. |
247 // This must be called from the thread on which SaveChanges is intended to | 254 // This must be called from the thread on which SaveChanges is intended to |
248 // be run on; the host's |registrar_->sync_thread()|. | 255 // be run on; the host's |registrar_->sync_thread()|. |
(...skipping 30 matching lines...) Expand all Loading... | |
279 ChromeEncryptor encryptor_; | 286 ChromeEncryptor encryptor_; |
280 | 287 |
281 // A special ChangeProcessor that tracks the DEVICE_INFO type for us. | 288 // A special ChangeProcessor that tracks the DEVICE_INFO type for us. |
282 scoped_ptr<SyncedDeviceTracker> synced_device_tracker_; | 289 scoped_ptr<SyncedDeviceTracker> synced_device_tracker_; |
283 | 290 |
284 // The top-level syncapi entry point. Lives on the sync thread. | 291 // The top-level syncapi entry point. Lives on the sync thread. |
285 scoped_ptr<syncer::SyncManager> sync_manager_; | 292 scoped_ptr<syncer::SyncManager> sync_manager_; |
286 | 293 |
287 base::WeakPtrFactory<Core> weak_ptr_factory_; | 294 base::WeakPtrFactory<Core> weak_ptr_factory_; |
288 | 295 |
296 // These signals allow us to send requests to shut down the HttpBridgeFactory | |
297 // and ServerConnectionManager without having to wait for those classes to | |
298 // finish initializing first. | |
299 // | |
300 // See comments in Core::ShutdownOnUIThread() for more details. | |
301 syncer::CancelationSignal factory_cancelation_signal_; | |
302 syncer::CancelationSignal scm_cancelation_signal_; | |
303 | |
289 DISALLOW_COPY_AND_ASSIGN(Core); | 304 DISALLOW_COPY_AND_ASSIGN(Core); |
290 }; | 305 }; |
291 | 306 |
292 SyncBackendHost::SyncBackendHost( | 307 SyncBackendHost::SyncBackendHost( |
293 const std::string& name, | 308 const std::string& name, |
294 Profile* profile, | 309 Profile* profile, |
295 const base::WeakPtr<SyncPrefs>& sync_prefs) | 310 const base::WeakPtr<SyncPrefs>& sync_prefs) |
296 : weak_ptr_factory_(this), | 311 : weak_ptr_factory_(this), |
297 frontend_loop_(base::MessageLoop::current()), | 312 frontend_loop_(base::MessageLoop::current()), |
298 profile_(profile), | 313 profile_(profile), |
(...skipping 18 matching lines...) Expand all Loading... | |
317 frontend_(NULL), | 332 frontend_(NULL), |
318 cached_passphrase_type_(syncer::IMPLICIT_PASSPHRASE), | 333 cached_passphrase_type_(syncer::IMPLICIT_PASSPHRASE), |
319 invalidation_handler_registered_(false) { | 334 invalidation_handler_registered_(false) { |
320 } | 335 } |
321 | 336 |
322 SyncBackendHost::~SyncBackendHost() { | 337 SyncBackendHost::~SyncBackendHost() { |
323 DCHECK(!core_.get() && !frontend_) << "Must call Shutdown before destructor."; | 338 DCHECK(!core_.get() && !frontend_) << "Must call Shutdown before destructor."; |
324 DCHECK(!registrar_.get()); | 339 DCHECK(!registrar_.get()); |
325 } | 340 } |
326 | 341 |
327 namespace { | |
328 | |
329 scoped_ptr<syncer::HttpPostProviderFactory> MakeHttpBridgeFactory( | |
330 const scoped_refptr<net::URLRequestContextGetter>& getter, | |
331 const NetworkTimeTracker::UpdateCallback& update_callback) { | |
332 chrome::VersionInfo version_info; | |
333 return scoped_ptr<syncer::HttpPostProviderFactory>( | |
334 new syncer::HttpBridgeFactory( | |
335 getter.get(), | |
336 DeviceInfo::MakeUserAgentForSyncApi(version_info), | |
337 update_callback)); | |
338 } | |
339 | |
340 } // namespace | |
341 | |
342 void SyncBackendHost::Initialize( | 342 void SyncBackendHost::Initialize( |
343 SyncFrontend* frontend, | 343 SyncFrontend* frontend, |
344 scoped_ptr<base::Thread> sync_thread, | 344 scoped_ptr<base::Thread> sync_thread, |
345 const syncer::WeakHandle<syncer::JsEventHandler>& event_handler, | 345 const syncer::WeakHandle<syncer::JsEventHandler>& event_handler, |
346 const GURL& sync_service_url, | 346 const GURL& sync_service_url, |
347 const SyncCredentials& credentials, | 347 const SyncCredentials& credentials, |
348 bool delete_sync_data_folder, | 348 bool delete_sync_data_folder, |
349 scoped_ptr<syncer::SyncManagerFactory> sync_manager_factory, | 349 scoped_ptr<syncer::SyncManagerFactory> sync_manager_factory, |
350 scoped_ptr<syncer::UnrecoverableErrorHandler> unrecoverable_error_handler, | 350 scoped_ptr<syncer::UnrecoverableErrorHandler> unrecoverable_error_handler, |
351 syncer::ReportUnrecoverableErrorFunction | 351 syncer::ReportUnrecoverableErrorFunction |
(...skipping 29 matching lines...) Expand all Loading... | |
381 initialization_state_ = CREATING_SYNC_MANAGER; | 381 initialization_state_ = CREATING_SYNC_MANAGER; |
382 | 382 |
383 scoped_ptr<DoInitializeOptions> init_opts(new DoInitializeOptions( | 383 scoped_ptr<DoInitializeOptions> init_opts(new DoInitializeOptions( |
384 registrar_->sync_thread()->message_loop(), | 384 registrar_->sync_thread()->message_loop(), |
385 registrar_.get(), | 385 registrar_.get(), |
386 routing_info, | 386 routing_info, |
387 workers, | 387 workers, |
388 extensions_activity_monitor_.GetExtensionsActivity(), | 388 extensions_activity_monitor_.GetExtensionsActivity(), |
389 event_handler, | 389 event_handler, |
390 sync_service_url, | 390 sync_service_url, |
391 base::Bind(&MakeHttpBridgeFactory, | 391 scoped_ptr<syncer::HttpPostProviderFactory>( |
392 make_scoped_refptr(profile_->GetRequestContext()), | 392 new syncer::HttpBridgeFactory( |
393 NetworkTimeTracker::BuildNotifierUpdateCallback()), | 393 make_scoped_refptr(profile_->GetRequestContext()), |
394 NetworkTimeTracker::BuildNotifierUpdateCallback(), | |
395 core_->GetFactoryCancelationSignal())), | |
394 credentials, | 396 credentials, |
395 invalidator_->GetInvalidatorClientId(), | 397 invalidator_->GetInvalidatorClientId(), |
396 sync_manager_factory.Pass(), | 398 sync_manager_factory.Pass(), |
397 delete_sync_data_folder, | 399 delete_sync_data_folder, |
398 sync_prefs_->GetEncryptionBootstrapToken(), | 400 sync_prefs_->GetEncryptionBootstrapToken(), |
399 sync_prefs_->GetKeystoreEncryptionBootstrapToken(), | 401 sync_prefs_->GetKeystoreEncryptionBootstrapToken(), |
400 scoped_ptr<InternalComponentsFactory>( | 402 scoped_ptr<InternalComponentsFactory>( |
401 new InternalComponentsFactoryImpl(factory_switches)).Pass(), | 403 new InternalComponentsFactoryImpl(factory_switches)).Pass(), |
402 unrecoverable_error_handler.Pass(), | 404 unrecoverable_error_handler.Pass(), |
403 report_unrecoverable_error_function, | 405 report_unrecoverable_error_function, |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
485 // clicks OK, immediately reopens the advanced settings dialog, and gets an | 487 // clicks OK, immediately reopens the advanced settings dialog, and gets an |
486 // unnecessary prompt for a passphrase. | 488 // unnecessary prompt for a passphrase. |
487 // Note: It is not guaranteed that the passphrase will be accepted by the | 489 // Note: It is not guaranteed that the passphrase will be accepted by the |
488 // syncer thread, since we could receive a new nigori node while the task is | 490 // syncer thread, since we could receive a new nigori node while the task is |
489 // pending. This scenario is a valid race, and SetDecryptionPassphrase can | 491 // pending. This scenario is a valid race, and SetDecryptionPassphrase can |
490 // trigger a new OnPassphraseRequired if it needs to. | 492 // trigger a new OnPassphraseRequired if it needs to. |
491 NotifyPassphraseAccepted(); | 493 NotifyPassphraseAccepted(); |
492 return true; | 494 return true; |
493 } | 495 } |
494 | 496 |
495 void SyncBackendHost::StopSyncManagerForShutdown() { | |
496 DCHECK_GT(initialization_state_, NOT_ATTEMPTED); | |
497 if (initialization_state_ == CREATING_SYNC_MANAGER) { | |
498 // We post here to implicitly wait for the SyncManager to be created, | |
499 // if needed. We have to wait, since we need to shutdown immediately, | |
500 // and we need to tell the SyncManager so it can abort any activity | |
501 // (net I/O, data application). | |
502 DCHECK(registrar_->sync_thread()->IsRunning()); | |
503 registrar_->sync_thread()->message_loop()->PostTask(FROM_HERE, | |
504 base::Bind(&SyncBackendHost::Core::DoStopSyncManagerForShutdown, | |
505 core_.get())); | |
506 } else { | |
507 core_->DoStopSyncManagerForShutdown(); | |
508 } | |
509 } | |
510 | |
511 void SyncBackendHost::StopSyncingForShutdown() { | 497 void SyncBackendHost::StopSyncingForShutdown() { |
512 DCHECK_EQ(base::MessageLoop::current(), frontend_loop_); | 498 DCHECK_EQ(base::MessageLoop::current(), frontend_loop_); |
499 DCHECK_GT(initialization_state_, NOT_ATTEMPTED); | |
513 | 500 |
514 // Immediately stop sending messages to the frontend. | 501 // Immediately stop sending messages to the frontend. |
515 frontend_ = NULL; | 502 frontend_ = NULL; |
516 | 503 |
517 // Stop listening for and forwarding locally-triggered sync refresh requests. | 504 // Stop listening for and forwarding locally-triggered sync refresh requests. |
518 notification_registrar_.RemoveAll(); | 505 notification_registrar_.RemoveAll(); |
519 | 506 |
520 DCHECK(registrar_->sync_thread()->IsRunning()); | 507 DCHECK(registrar_->sync_thread()->IsRunning()); |
521 | 508 |
522 registrar_->RequestWorkerStopOnUIThread(); | 509 registrar_->RequestWorkerStopOnUIThread(); |
523 | 510 |
524 StopSyncManagerForShutdown(); | 511 core_->ShutdownOnUIThread(); |
525 } | 512 } |
526 | 513 |
527 scoped_ptr<base::Thread> SyncBackendHost::Shutdown(ShutdownOption option) { | 514 scoped_ptr<base::Thread> SyncBackendHost::Shutdown(ShutdownOption option) { |
528 // StopSyncingForShutdown() (which nulls out |frontend_|) should be | 515 // StopSyncingForShutdown() (which nulls out |frontend_|) should be |
529 // called first. | 516 // called first. |
530 DCHECK(!frontend_); | 517 DCHECK(!frontend_); |
531 DCHECK(registrar_->sync_thread()->IsRunning()); | 518 DCHECK(registrar_->sync_thread()->IsRunning()); |
532 | 519 |
533 bool sync_disabled = (option == DISABLE_AND_CLAIM_THREAD); | 520 bool sync_disabled = (option == DISABLE_AND_CLAIM_THREAD); |
534 bool sync_thread_claimed = | 521 bool sync_thread_claimed = |
(...skipping 330 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
865 } | 852 } |
866 | 853 |
867 SyncBackendHost::DoInitializeOptions::DoInitializeOptions( | 854 SyncBackendHost::DoInitializeOptions::DoInitializeOptions( |
868 base::MessageLoop* sync_loop, | 855 base::MessageLoop* sync_loop, |
869 SyncBackendRegistrar* registrar, | 856 SyncBackendRegistrar* registrar, |
870 const syncer::ModelSafeRoutingInfo& routing_info, | 857 const syncer::ModelSafeRoutingInfo& routing_info, |
871 const std::vector<syncer::ModelSafeWorker*>& workers, | 858 const std::vector<syncer::ModelSafeWorker*>& workers, |
872 const scoped_refptr<syncer::ExtensionsActivity>& extensions_activity, | 859 const scoped_refptr<syncer::ExtensionsActivity>& extensions_activity, |
873 const syncer::WeakHandle<syncer::JsEventHandler>& event_handler, | 860 const syncer::WeakHandle<syncer::JsEventHandler>& event_handler, |
874 const GURL& service_url, | 861 const GURL& service_url, |
875 MakeHttpBridgeFactoryFn make_http_bridge_factory_fn, | 862 scoped_ptr<syncer::HttpPostProviderFactory> http_bridge_factory, |
876 const syncer::SyncCredentials& credentials, | 863 const syncer::SyncCredentials& credentials, |
877 const std::string& invalidator_client_id, | 864 const std::string& invalidator_client_id, |
878 scoped_ptr<syncer::SyncManagerFactory> sync_manager_factory, | 865 scoped_ptr<syncer::SyncManagerFactory> sync_manager_factory, |
879 bool delete_sync_data_folder, | 866 bool delete_sync_data_folder, |
880 const std::string& restored_key_for_bootstrapping, | 867 const std::string& restored_key_for_bootstrapping, |
881 const std::string& restored_keystore_key_for_bootstrapping, | 868 const std::string& restored_keystore_key_for_bootstrapping, |
882 scoped_ptr<InternalComponentsFactory> internal_components_factory, | 869 scoped_ptr<InternalComponentsFactory> internal_components_factory, |
883 scoped_ptr<syncer::UnrecoverableErrorHandler> unrecoverable_error_handler, | 870 scoped_ptr<syncer::UnrecoverableErrorHandler> unrecoverable_error_handler, |
884 syncer::ReportUnrecoverableErrorFunction | 871 syncer::ReportUnrecoverableErrorFunction |
885 report_unrecoverable_error_function, | 872 report_unrecoverable_error_function, |
886 bool use_oauth2_token) | 873 bool use_oauth2_token) |
887 : sync_loop(sync_loop), | 874 : sync_loop(sync_loop), |
888 registrar(registrar), | 875 registrar(registrar), |
889 routing_info(routing_info), | 876 routing_info(routing_info), |
890 workers(workers), | 877 workers(workers), |
891 extensions_activity(extensions_activity), | 878 extensions_activity(extensions_activity), |
892 event_handler(event_handler), | 879 event_handler(event_handler), |
893 service_url(service_url), | 880 service_url(service_url), |
894 make_http_bridge_factory_fn(make_http_bridge_factory_fn), | 881 http_bridge_factory(http_bridge_factory.Pass()), |
895 credentials(credentials), | 882 credentials(credentials), |
896 invalidator_client_id(invalidator_client_id), | 883 invalidator_client_id(invalidator_client_id), |
897 sync_manager_factory(sync_manager_factory.Pass()), | 884 sync_manager_factory(sync_manager_factory.Pass()), |
898 delete_sync_data_folder(delete_sync_data_folder), | 885 delete_sync_data_folder(delete_sync_data_folder), |
899 restored_key_for_bootstrapping(restored_key_for_bootstrapping), | 886 restored_key_for_bootstrapping(restored_key_for_bootstrapping), |
900 restored_keystore_key_for_bootstrapping( | 887 restored_keystore_key_for_bootstrapping( |
901 restored_keystore_key_for_bootstrapping), | 888 restored_keystore_key_for_bootstrapping), |
902 internal_components_factory(internal_components_factory.Pass()), | 889 internal_components_factory(internal_components_factory.Pass()), |
903 unrecoverable_error_handler(unrecoverable_error_handler.Pass()), | 890 unrecoverable_error_handler(unrecoverable_error_handler.Pass()), |
904 report_unrecoverable_error_function( | 891 report_unrecoverable_error_function( |
(...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1126 DCHECK_EQ(base::MessageLoop::current(), sync_loop_); | 1113 DCHECK_EQ(base::MessageLoop::current(), sync_loop_); |
1127 sync_manager_->OnIncomingInvalidation(invalidation_map); | 1114 sync_manager_->OnIncomingInvalidation(invalidation_map); |
1128 } | 1115 } |
1129 | 1116 |
1130 void SyncBackendHost::Core::DoInitialize( | 1117 void SyncBackendHost::Core::DoInitialize( |
1131 scoped_ptr<DoInitializeOptions> options) { | 1118 scoped_ptr<DoInitializeOptions> options) { |
1132 DCHECK(!sync_loop_); | 1119 DCHECK(!sync_loop_); |
1133 sync_loop_ = options->sync_loop; | 1120 sync_loop_ = options->sync_loop; |
1134 DCHECK(sync_loop_); | 1121 DCHECK(sync_loop_); |
1135 | 1122 |
1123 // Finish initializing the HttpBridgeFactory. We do this here because | |
1124 // building the user agent may block on some platforms. | |
1125 chrome::VersionInfo version_info; | |
1126 options->http_bridge_factory->Init( | |
1127 DeviceInfo::MakeUserAgentForSyncApi(version_info)); | |
1128 | |
1136 // Blow away the partial or corrupt sync data folder before doing any more | 1129 // Blow away the partial or corrupt sync data folder before doing any more |
1137 // initialization, if necessary. | 1130 // initialization, if necessary. |
1138 if (options->delete_sync_data_folder) { | 1131 if (options->delete_sync_data_folder) { |
1139 DeleteSyncDataFolder(); | 1132 DeleteSyncDataFolder(); |
1140 } | 1133 } |
1141 | 1134 |
1142 // Make sure that the directory exists before initializing the backend. | 1135 // Make sure that the directory exists before initializing the backend. |
1143 // If it already exists, this will do no harm. | 1136 // If it already exists, this will do no harm. |
1144 if (!file_util::CreateDirectory(sync_data_folder_path_)) { | 1137 if (!file_util::CreateDirectory(sync_data_folder_path_)) { |
1145 DLOG(FATAL) << "Sync Data directory creation failed."; | 1138 DLOG(FATAL) << "Sync Data directory creation failed."; |
1146 } | 1139 } |
1147 | 1140 |
1148 DCHECK(!registrar_); | 1141 DCHECK(!registrar_); |
1149 registrar_ = options->registrar; | 1142 registrar_ = options->registrar; |
1150 DCHECK(registrar_); | 1143 DCHECK(registrar_); |
1151 | 1144 |
1152 sync_manager_ = options->sync_manager_factory->CreateSyncManager(name_); | 1145 sync_manager_ = options->sync_manager_factory->CreateSyncManager(name_); |
1153 sync_manager_->AddObserver(this); | 1146 sync_manager_->AddObserver(this); |
1154 sync_manager_->Init(sync_data_folder_path_, | 1147 sync_manager_->Init(sync_data_folder_path_, |
1155 options->event_handler, | 1148 options->event_handler, |
1156 options->service_url.host() + options->service_url.path(), | 1149 options->service_url.host() + options->service_url.path(), |
1157 options->service_url.EffectiveIntPort(), | 1150 options->service_url.EffectiveIntPort(), |
1158 options->service_url.SchemeIsSecure(), | 1151 options->service_url.SchemeIsSecure(), |
1159 options->make_http_bridge_factory_fn.Run().Pass(), | 1152 options->http_bridge_factory.Pass(), |
1160 options->workers, | 1153 options->workers, |
1161 options->extensions_activity, | 1154 options->extensions_activity, |
1162 options->registrar /* as SyncManager::ChangeDelegate */, | 1155 options->registrar /* as SyncManager::ChangeDelegate */, |
1163 options->credentials, | 1156 options->credentials, |
1164 options->invalidator_client_id, | 1157 options->invalidator_client_id, |
1165 options->restored_key_for_bootstrapping, | 1158 options->restored_key_for_bootstrapping, |
1166 options->restored_keystore_key_for_bootstrapping, | 1159 options->restored_keystore_key_for_bootstrapping, |
1167 options->internal_components_factory.get(), | 1160 options->internal_components_factory.get(), |
1168 &encryptor_, | 1161 &encryptor_, |
1169 options->unrecoverable_error_handler.Pass(), | 1162 options->unrecoverable_error_handler.Pass(), |
1170 options->report_unrecoverable_error_function, | 1163 options->report_unrecoverable_error_function, |
1171 options->use_oauth2_token); | 1164 options->use_oauth2_token, |
1165 &scm_cancelation_signal_); | |
tim (not reviewing)
2013/09/16 23:01:31
Hm, don't we pass this to the syncer? (yet it's ca
rlarocque
2013/09/17 00:03:22
Syncer and SCM, yes. This signal is the descendan
| |
1172 | 1166 |
1173 // |sync_manager_| may end up being NULL here in tests (in | 1167 // |sync_manager_| may end up being NULL here in tests (in |
1174 // synchronous initialization mode). | 1168 // synchronous initialization mode). |
1175 // | 1169 // |
1176 // TODO(akalin): Fix this behavior (see http://crbug.com/140354). | 1170 // TODO(akalin): Fix this behavior (see http://crbug.com/140354). |
1177 if (sync_manager_) { | 1171 if (sync_manager_) { |
1178 // Now check the command line to see if we need to simulate an | 1172 // Now check the command line to see if we need to simulate an |
1179 // unrecoverable error for testing purpose. Note the error is thrown | 1173 // unrecoverable error for testing purpose. Note the error is thrown |
1180 // only if the initialization succeeded. Also it makes sense to use this | 1174 // only if the initialization succeeded. Also it makes sense to use this |
1181 // flag only when restarting the browser with an account already setup. If | 1175 // flag only when restarting the browser with an account already setup. If |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1271 DCHECK_EQ(base::MessageLoop::current(), sync_loop_); | 1265 DCHECK_EQ(base::MessageLoop::current(), sync_loop_); |
1272 sync_manager_->GetEncryptionHandler()->SetDecryptionPassphrase( | 1266 sync_manager_->GetEncryptionHandler()->SetDecryptionPassphrase( |
1273 passphrase); | 1267 passphrase); |
1274 } | 1268 } |
1275 | 1269 |
1276 void SyncBackendHost::Core::DoEnableEncryptEverything() { | 1270 void SyncBackendHost::Core::DoEnableEncryptEverything() { |
1277 DCHECK_EQ(base::MessageLoop::current(), sync_loop_); | 1271 DCHECK_EQ(base::MessageLoop::current(), sync_loop_); |
1278 sync_manager_->GetEncryptionHandler()->EnableEncryptEverything(); | 1272 sync_manager_->GetEncryptionHandler()->EnableEncryptEverything(); |
1279 } | 1273 } |
1280 | 1274 |
1281 void SyncBackendHost::Core::DoStopSyncManagerForShutdown() { | 1275 void SyncBackendHost::Core::ShutdownOnUIThread() { |
1282 if (sync_manager_) | 1276 // This will cut short any blocking network tasks, cut short any in-progress |
1283 sync_manager_->StopSyncingForShutdown(); | 1277 // sync cycles, and prevent the creation of new blocking network tasks and new |
1278 // sync cycles. If there was an in-progress network request, it would have | |
1279 // had a reference to the RequestContextGetter. This reference will be | |
1280 // dropped by the time this function returns. | |
1281 // | |
1282 // It is safe to call this even if Sync's backend classes have not been | |
1283 // initialized yet. Those classes will receive the message when the sync | |
1284 // thread finally getes around to constructing them. | |
1285 scm_cancelation_signal_.RequestStop(); | |
1286 | |
1287 // This will drop the HttpBridgeFactory's reference to the | |
1288 // RequestContextGetter. Once this has been called, the HttpBridgeFactory can | |
1289 // no longer be used to create new HttpBridge instances. We can get away with | |
1290 // this because the scm_cancelation_signal_ has already been signalled, which | |
1291 // guarantees that the ServerConnectionManager will no longer attempt to | |
1292 // create new connections. | |
1293 factory_cancelation_signal_.RequestStop(); | |
1284 } | 1294 } |
1285 | 1295 |
1286 void SyncBackendHost::Core::DoShutdown(bool sync_disabled) { | 1296 void SyncBackendHost::Core::DoShutdown(bool sync_disabled) { |
1287 DCHECK_EQ(base::MessageLoop::current(), sync_loop_); | 1297 DCHECK_EQ(base::MessageLoop::current(), sync_loop_); |
1298 | |
1288 // It's safe to do this even if the type was never activated. | 1299 // It's safe to do this even if the type was never activated. |
1289 registrar_->DeactivateDataType(syncer::DEVICE_INFO); | 1300 registrar_->DeactivateDataType(syncer::DEVICE_INFO); |
1290 synced_device_tracker_.reset(); | 1301 synced_device_tracker_.reset(); |
1291 | 1302 |
1292 DoDestroySyncManager(); | 1303 DoDestroySyncManager(); |
1293 | 1304 |
1294 registrar_ = NULL; | 1305 registrar_ = NULL; |
1295 | 1306 |
1296 if (sync_disabled) | 1307 if (sync_disabled) |
1297 DeleteSyncDataFolder(); | 1308 DeleteSyncDataFolder(); |
(...skipping 307 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1605 | 1616 |
1606 base::MessageLoop* SyncBackendHost::GetSyncLoopForTesting() { | 1617 base::MessageLoop* SyncBackendHost::GetSyncLoopForTesting() { |
1607 return registrar_->sync_thread()->message_loop(); | 1618 return registrar_->sync_thread()->message_loop(); |
1608 } | 1619 } |
1609 | 1620 |
1610 #undef SDVLOG | 1621 #undef SDVLOG |
1611 | 1622 |
1612 #undef SLOG | 1623 #undef SLOG |
1613 | 1624 |
1614 } // namespace browser_sync | 1625 } // namespace browser_sync |
OLD | NEW |