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 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
191 // This includes refreshing encryption, setting up the device info change | 191 // This includes refreshing encryption, setting up the device info change |
192 // processor, etc. | 192 // processor, etc. |
193 void DoInitialProcessControlTypes(); | 193 void DoInitialProcessControlTypes(); |
194 | 194 |
195 // Some parts of DoInitialProcessControlTypes() may be executed on a different | 195 // Some parts of DoInitialProcessControlTypes() may be executed on a different |
196 // thread. This function asynchronously continues the work started in | 196 // thread. This function asynchronously continues the work started in |
197 // DoInitialProcessControlTypes() once that other thread gets back to us. | 197 // DoInitialProcessControlTypes() once that other thread gets back to us. |
198 void DoFinishInitialProcessControlTypes(); | 198 void DoFinishInitialProcessControlTypes(); |
199 | 199 |
200 // The shutdown order is a bit complicated: | 200 // The shutdown order is a bit complicated: |
201 // 1) Call DoStopSyncManagerForShutdown() from |frontend_loop_| to request | 201 // 1) Call the SyncManagerStopHandle's RequestStop() from |frontend_loop_| to |
202 // sync manager to stop as soon as possible. | 202 // request sync manager to stop as soon as possible. |
203 // 2) Post DoShutdown() to sync loop to clean up backend state, save | 203 // 2) Post DoShutdown() to sync loop to clean up backend state, save |
204 // directory and destroy sync manager. | 204 // directory and destroy sync manager. |
205 void DoStopSyncManagerForShutdown(); | |
206 void DoShutdown(bool sync_disabled); | 205 void DoShutdown(bool sync_disabled); |
207 void DoDestroySyncManager(); | 206 void DoDestroySyncManager(); |
208 | 207 |
209 // Configuration methods that must execute on sync loop. | 208 // Configuration methods that must execute on sync loop. |
210 void DoConfigureSyncer( | 209 void DoConfigureSyncer( |
211 syncer::ConfigureReason reason, | 210 syncer::ConfigureReason reason, |
212 const DoConfigureSyncerTypes& config_types, | 211 const DoConfigureSyncerTypes& config_types, |
213 const syncer::ModelSafeRoutingInfo routing_info, | 212 const syncer::ModelSafeRoutingInfo routing_info, |
214 const base::Callback<void(syncer::ModelTypeSet, | 213 const base::Callback<void(syncer::ModelTypeSet, |
215 syncer::ModelTypeSet)>& ready_task, | 214 syncer::ModelTypeSet)>& ready_task, |
(...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
394 credentials, | 393 credentials, |
395 invalidator_->GetInvalidatorClientId(), | 394 invalidator_->GetInvalidatorClientId(), |
396 sync_manager_factory.Pass(), | 395 sync_manager_factory.Pass(), |
397 delete_sync_data_folder, | 396 delete_sync_data_folder, |
398 sync_prefs_->GetEncryptionBootstrapToken(), | 397 sync_prefs_->GetEncryptionBootstrapToken(), |
399 sync_prefs_->GetKeystoreEncryptionBootstrapToken(), | 398 sync_prefs_->GetKeystoreEncryptionBootstrapToken(), |
400 scoped_ptr<InternalComponentsFactory>( | 399 scoped_ptr<InternalComponentsFactory>( |
401 new InternalComponentsFactoryImpl(factory_switches)).Pass(), | 400 new InternalComponentsFactoryImpl(factory_switches)).Pass(), |
402 unrecoverable_error_handler.Pass(), | 401 unrecoverable_error_handler.Pass(), |
403 report_unrecoverable_error_function, | 402 report_unrecoverable_error_function, |
404 !cl->HasSwitch(switches::kSyncDisableOAuth2Token))); | 403 !cl->HasSwitch(switches::kSyncDisableOAuth2Token), |
| 404 &cancelation_signal_)); |
405 InitCore(init_opts.Pass()); | 405 InitCore(init_opts.Pass()); |
406 } | 406 } |
407 | 407 |
408 void SyncBackendHost::UpdateCredentials(const SyncCredentials& credentials) { | 408 void SyncBackendHost::UpdateCredentials(const SyncCredentials& credentials) { |
409 DCHECK(registrar_->sync_thread()->IsRunning()); | 409 DCHECK(registrar_->sync_thread()->IsRunning()); |
410 registrar_->sync_thread()->message_loop()->PostTask(FROM_HERE, | 410 registrar_->sync_thread()->message_loop()->PostTask(FROM_HERE, |
411 base::Bind(&SyncBackendHost::Core::DoUpdateCredentials, | 411 base::Bind(&SyncBackendHost::Core::DoUpdateCredentials, |
412 core_.get(), | 412 core_.get(), |
413 credentials)); | 413 credentials)); |
414 } | 414 } |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
485 // clicks OK, immediately reopens the advanced settings dialog, and gets an | 485 // clicks OK, immediately reopens the advanced settings dialog, and gets an |
486 // unnecessary prompt for a passphrase. | 486 // unnecessary prompt for a passphrase. |
487 // Note: It is not guaranteed that the passphrase will be accepted by the | 487 // 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 | 488 // 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 | 489 // pending. This scenario is a valid race, and SetDecryptionPassphrase can |
490 // trigger a new OnPassphraseRequired if it needs to. | 490 // trigger a new OnPassphraseRequired if it needs to. |
491 NotifyPassphraseAccepted(); | 491 NotifyPassphraseAccepted(); |
492 return true; | 492 return true; |
493 } | 493 } |
494 | 494 |
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() { | 495 void SyncBackendHost::StopSyncingForShutdown() { |
512 DCHECK_EQ(base::MessageLoop::current(), frontend_loop_); | 496 DCHECK_EQ(base::MessageLoop::current(), frontend_loop_); |
| 497 DCHECK_GT(initialization_state_, NOT_ATTEMPTED); |
513 | 498 |
514 // Immediately stop sending messages to the frontend. | 499 // Immediately stop sending messages to the frontend. |
515 frontend_ = NULL; | 500 frontend_ = NULL; |
516 | 501 |
517 // Stop listening for and forwarding locally-triggered sync refresh requests. | 502 // Stop listening for and forwarding locally-triggered sync refresh requests. |
518 notification_registrar_.RemoveAll(); | 503 notification_registrar_.RemoveAll(); |
519 | 504 |
520 DCHECK(registrar_->sync_thread()->IsRunning()); | 505 DCHECK(registrar_->sync_thread()->IsRunning()); |
521 | 506 |
522 registrar_->RequestWorkerStopOnUIThread(); | 507 registrar_->RequestWorkerStopOnUIThread(); |
523 | 508 |
524 StopSyncManagerForShutdown(); | 509 cancelation_signal_.RequestStop(); |
525 } | 510 } |
526 | 511 |
527 scoped_ptr<base::Thread> SyncBackendHost::Shutdown(ShutdownOption option) { | 512 scoped_ptr<base::Thread> SyncBackendHost::Shutdown(ShutdownOption option) { |
528 // StopSyncingForShutdown() (which nulls out |frontend_|) should be | 513 // StopSyncingForShutdown() (which nulls out |frontend_|) should be |
529 // called first. | 514 // called first. |
530 DCHECK(!frontend_); | 515 DCHECK(!frontend_); |
531 DCHECK(registrar_->sync_thread()->IsRunning()); | 516 DCHECK(registrar_->sync_thread()->IsRunning()); |
532 | 517 |
533 bool sync_disabled = (option == DISABLE_AND_CLAIM_THREAD); | 518 bool sync_disabled = (option == DISABLE_AND_CLAIM_THREAD); |
534 bool sync_thread_claimed = | 519 bool sync_thread_claimed = |
(...skipping 341 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
876 const syncer::SyncCredentials& credentials, | 861 const syncer::SyncCredentials& credentials, |
877 const std::string& invalidator_client_id, | 862 const std::string& invalidator_client_id, |
878 scoped_ptr<syncer::SyncManagerFactory> sync_manager_factory, | 863 scoped_ptr<syncer::SyncManagerFactory> sync_manager_factory, |
879 bool delete_sync_data_folder, | 864 bool delete_sync_data_folder, |
880 const std::string& restored_key_for_bootstrapping, | 865 const std::string& restored_key_for_bootstrapping, |
881 const std::string& restored_keystore_key_for_bootstrapping, | 866 const std::string& restored_keystore_key_for_bootstrapping, |
882 scoped_ptr<InternalComponentsFactory> internal_components_factory, | 867 scoped_ptr<InternalComponentsFactory> internal_components_factory, |
883 scoped_ptr<syncer::UnrecoverableErrorHandler> unrecoverable_error_handler, | 868 scoped_ptr<syncer::UnrecoverableErrorHandler> unrecoverable_error_handler, |
884 syncer::ReportUnrecoverableErrorFunction | 869 syncer::ReportUnrecoverableErrorFunction |
885 report_unrecoverable_error_function, | 870 report_unrecoverable_error_function, |
886 bool use_oauth2_token) | 871 bool use_oauth2_token, |
| 872 syncer::CancelationSignal* const cancelation_signal) |
887 : sync_loop(sync_loop), | 873 : sync_loop(sync_loop), |
888 registrar(registrar), | 874 registrar(registrar), |
889 routing_info(routing_info), | 875 routing_info(routing_info), |
890 workers(workers), | 876 workers(workers), |
891 extensions_activity(extensions_activity), | 877 extensions_activity(extensions_activity), |
892 event_handler(event_handler), | 878 event_handler(event_handler), |
893 service_url(service_url), | 879 service_url(service_url), |
894 make_http_bridge_factory_fn(make_http_bridge_factory_fn), | 880 make_http_bridge_factory_fn(make_http_bridge_factory_fn), |
895 credentials(credentials), | 881 credentials(credentials), |
896 invalidator_client_id(invalidator_client_id), | 882 invalidator_client_id(invalidator_client_id), |
897 sync_manager_factory(sync_manager_factory.Pass()), | 883 sync_manager_factory(sync_manager_factory.Pass()), |
898 delete_sync_data_folder(delete_sync_data_folder), | 884 delete_sync_data_folder(delete_sync_data_folder), |
899 restored_key_for_bootstrapping(restored_key_for_bootstrapping), | 885 restored_key_for_bootstrapping(restored_key_for_bootstrapping), |
900 restored_keystore_key_for_bootstrapping( | 886 restored_keystore_key_for_bootstrapping( |
901 restored_keystore_key_for_bootstrapping), | 887 restored_keystore_key_for_bootstrapping), |
902 internal_components_factory(internal_components_factory.Pass()), | 888 internal_components_factory(internal_components_factory.Pass()), |
903 unrecoverable_error_handler(unrecoverable_error_handler.Pass()), | 889 unrecoverable_error_handler(unrecoverable_error_handler.Pass()), |
904 report_unrecoverable_error_function( | 890 report_unrecoverable_error_function( |
905 report_unrecoverable_error_function), | 891 report_unrecoverable_error_function), |
906 use_oauth2_token(use_oauth2_token) { | 892 use_oauth2_token(use_oauth2_token), |
| 893 cancelation_signal(cancelation_signal) { |
907 } | 894 } |
908 | 895 |
909 SyncBackendHost::DoInitializeOptions::~DoInitializeOptions() {} | 896 SyncBackendHost::DoInitializeOptions::~DoInitializeOptions() {} |
910 | 897 |
911 SyncBackendHost::Core::Core(const std::string& name, | 898 SyncBackendHost::Core::Core(const std::string& name, |
912 const base::FilePath& sync_data_folder_path, | 899 const base::FilePath& sync_data_folder_path, |
913 const base::WeakPtr<SyncBackendHost>& backend) | 900 const base::WeakPtr<SyncBackendHost>& backend) |
914 : name_(name), | 901 : name_(name), |
915 sync_data_folder_path_(sync_data_folder_path), | 902 sync_data_folder_path_(sync_data_folder_path), |
916 host_(backend), | 903 host_(backend), |
(...skipping 244 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1161 options->extensions_activity, | 1148 options->extensions_activity, |
1162 options->registrar /* as SyncManager::ChangeDelegate */, | 1149 options->registrar /* as SyncManager::ChangeDelegate */, |
1163 options->credentials, | 1150 options->credentials, |
1164 options->invalidator_client_id, | 1151 options->invalidator_client_id, |
1165 options->restored_key_for_bootstrapping, | 1152 options->restored_key_for_bootstrapping, |
1166 options->restored_keystore_key_for_bootstrapping, | 1153 options->restored_keystore_key_for_bootstrapping, |
1167 options->internal_components_factory.get(), | 1154 options->internal_components_factory.get(), |
1168 &encryptor_, | 1155 &encryptor_, |
1169 options->unrecoverable_error_handler.Pass(), | 1156 options->unrecoverable_error_handler.Pass(), |
1170 options->report_unrecoverable_error_function, | 1157 options->report_unrecoverable_error_function, |
1171 options->use_oauth2_token); | 1158 options->use_oauth2_token, |
| 1159 options->cancelation_signal); |
1172 | 1160 |
1173 // |sync_manager_| may end up being NULL here in tests (in | 1161 // |sync_manager_| may end up being NULL here in tests (in |
1174 // synchronous initialization mode). | 1162 // synchronous initialization mode). |
1175 // | 1163 // |
1176 // TODO(akalin): Fix this behavior (see http://crbug.com/140354). | 1164 // TODO(akalin): Fix this behavior (see http://crbug.com/140354). |
1177 if (sync_manager_) { | 1165 if (sync_manager_) { |
1178 // Now check the command line to see if we need to simulate an | 1166 // Now check the command line to see if we need to simulate an |
1179 // unrecoverable error for testing purpose. Note the error is thrown | 1167 // unrecoverable error for testing purpose. Note the error is thrown |
1180 // only if the initialization succeeded. Also it makes sense to use this | 1168 // 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 | 1169 // 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_); | 1259 DCHECK_EQ(base::MessageLoop::current(), sync_loop_); |
1272 sync_manager_->GetEncryptionHandler()->SetDecryptionPassphrase( | 1260 sync_manager_->GetEncryptionHandler()->SetDecryptionPassphrase( |
1273 passphrase); | 1261 passphrase); |
1274 } | 1262 } |
1275 | 1263 |
1276 void SyncBackendHost::Core::DoEnableEncryptEverything() { | 1264 void SyncBackendHost::Core::DoEnableEncryptEverything() { |
1277 DCHECK_EQ(base::MessageLoop::current(), sync_loop_); | 1265 DCHECK_EQ(base::MessageLoop::current(), sync_loop_); |
1278 sync_manager_->GetEncryptionHandler()->EnableEncryptEverything(); | 1266 sync_manager_->GetEncryptionHandler()->EnableEncryptEverything(); |
1279 } | 1267 } |
1280 | 1268 |
1281 void SyncBackendHost::Core::DoStopSyncManagerForShutdown() { | |
1282 if (sync_manager_) | |
1283 sync_manager_->StopSyncingForShutdown(); | |
1284 } | |
1285 | |
1286 void SyncBackendHost::Core::DoShutdown(bool sync_disabled) { | 1269 void SyncBackendHost::Core::DoShutdown(bool sync_disabled) { |
1287 DCHECK_EQ(base::MessageLoop::current(), sync_loop_); | 1270 DCHECK_EQ(base::MessageLoop::current(), sync_loop_); |
1288 // It's safe to do this even if the type was never activated. | 1271 // It's safe to do this even if the type was never activated. |
1289 registrar_->DeactivateDataType(syncer::DEVICE_INFO); | 1272 registrar_->DeactivateDataType(syncer::DEVICE_INFO); |
1290 synced_device_tracker_.reset(); | 1273 synced_device_tracker_.reset(); |
1291 | 1274 |
1292 DoDestroySyncManager(); | 1275 DoDestroySyncManager(); |
1293 | 1276 |
1294 registrar_ = NULL; | 1277 registrar_ = NULL; |
1295 | 1278 |
(...skipping 309 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1605 | 1588 |
1606 base::MessageLoop* SyncBackendHost::GetSyncLoopForTesting() { | 1589 base::MessageLoop* SyncBackendHost::GetSyncLoopForTesting() { |
1607 return registrar_->sync_thread()->message_loop(); | 1590 return registrar_->sync_thread()->message_loop(); |
1608 } | 1591 } |
1609 | 1592 |
1610 #undef SDVLOG | 1593 #undef SDVLOG |
1611 | 1594 |
1612 #undef SLOG | 1595 #undef SLOG |
1613 | 1596 |
1614 } // namespace browser_sync | 1597 } // namespace browser_sync |
OLD | NEW |