Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(333)

Side by Side Diff: trunk/src/chrome/browser/sync/glue/sync_backend_host.cc

Issue 23658030: Revert 222154 "sync: Gracefully handle very early shutdown" (Closed) Base URL: svn://svn.chromium.org/chrome/
Patch Set: Created 7 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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
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 the SyncManagerStopHandle's RequestStop() from |frontend_loop_| to 201 // 1) Call DoStopSyncManagerForShutdown() from |frontend_loop_| to request
202 // request sync manager to stop as soon as possible. 202 // 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();
205 void DoShutdown(bool sync_disabled); 206 void DoShutdown(bool sync_disabled);
206 void DoDestroySyncManager(); 207 void DoDestroySyncManager();
207 208
208 // Configuration methods that must execute on sync loop. 209 // Configuration methods that must execute on sync loop.
209 void DoConfigureSyncer( 210 void DoConfigureSyncer(
210 syncer::ConfigureReason reason, 211 syncer::ConfigureReason reason,
211 const DoConfigureSyncerTypes& config_types, 212 const DoConfigureSyncerTypes& config_types,
212 const syncer::ModelSafeRoutingInfo routing_info, 213 const syncer::ModelSafeRoutingInfo routing_info,
213 const base::Callback<void(syncer::ModelTypeSet, 214 const base::Callback<void(syncer::ModelTypeSet,
214 syncer::ModelTypeSet)>& ready_task, 215 syncer::ModelTypeSet)>& ready_task,
(...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after
393 credentials, 394 credentials,
394 invalidator_->GetInvalidatorClientId(), 395 invalidator_->GetInvalidatorClientId(),
395 sync_manager_factory.Pass(), 396 sync_manager_factory.Pass(),
396 delete_sync_data_folder, 397 delete_sync_data_folder,
397 sync_prefs_->GetEncryptionBootstrapToken(), 398 sync_prefs_->GetEncryptionBootstrapToken(),
398 sync_prefs_->GetKeystoreEncryptionBootstrapToken(), 399 sync_prefs_->GetKeystoreEncryptionBootstrapToken(),
399 scoped_ptr<InternalComponentsFactory>( 400 scoped_ptr<InternalComponentsFactory>(
400 new InternalComponentsFactoryImpl(factory_switches)).Pass(), 401 new InternalComponentsFactoryImpl(factory_switches)).Pass(),
401 unrecoverable_error_handler.Pass(), 402 unrecoverable_error_handler.Pass(),
402 report_unrecoverable_error_function, 403 report_unrecoverable_error_function,
403 !cl->HasSwitch(switches::kSyncDisableOAuth2Token), 404 !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
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
495 void SyncBackendHost::StopSyncingForShutdown() { 511 void SyncBackendHost::StopSyncingForShutdown() {
496 DCHECK_EQ(base::MessageLoop::current(), frontend_loop_); 512 DCHECK_EQ(base::MessageLoop::current(), frontend_loop_);
497 DCHECK_GT(initialization_state_, NOT_ATTEMPTED);
498 513
499 // Immediately stop sending messages to the frontend. 514 // Immediately stop sending messages to the frontend.
500 frontend_ = NULL; 515 frontend_ = NULL;
501 516
502 // Stop listening for and forwarding locally-triggered sync refresh requests. 517 // Stop listening for and forwarding locally-triggered sync refresh requests.
503 notification_registrar_.RemoveAll(); 518 notification_registrar_.RemoveAll();
504 519
505 DCHECK(registrar_->sync_thread()->IsRunning()); 520 DCHECK(registrar_->sync_thread()->IsRunning());
506 521
507 registrar_->RequestWorkerStopOnUIThread(); 522 registrar_->RequestWorkerStopOnUIThread();
508 523
509 cancelation_signal_.RequestStop(); 524 StopSyncManagerForShutdown();
510 } 525 }
511 526
512 scoped_ptr<base::Thread> SyncBackendHost::Shutdown(ShutdownOption option) { 527 scoped_ptr<base::Thread> SyncBackendHost::Shutdown(ShutdownOption option) {
513 // StopSyncingForShutdown() (which nulls out |frontend_|) should be 528 // StopSyncingForShutdown() (which nulls out |frontend_|) should be
514 // called first. 529 // called first.
515 DCHECK(!frontend_); 530 DCHECK(!frontend_);
516 DCHECK(registrar_->sync_thread()->IsRunning()); 531 DCHECK(registrar_->sync_thread()->IsRunning());
517 532
518 bool sync_disabled = (option == DISABLE_AND_CLAIM_THREAD); 533 bool sync_disabled = (option == DISABLE_AND_CLAIM_THREAD);
519 bool sync_thread_claimed = 534 bool sync_thread_claimed =
(...skipping 341 matching lines...) Expand 10 before | Expand all | Expand 10 after
861 const syncer::SyncCredentials& credentials, 876 const syncer::SyncCredentials& credentials,
862 const std::string& invalidator_client_id, 877 const std::string& invalidator_client_id,
863 scoped_ptr<syncer::SyncManagerFactory> sync_manager_factory, 878 scoped_ptr<syncer::SyncManagerFactory> sync_manager_factory,
864 bool delete_sync_data_folder, 879 bool delete_sync_data_folder,
865 const std::string& restored_key_for_bootstrapping, 880 const std::string& restored_key_for_bootstrapping,
866 const std::string& restored_keystore_key_for_bootstrapping, 881 const std::string& restored_keystore_key_for_bootstrapping,
867 scoped_ptr<InternalComponentsFactory> internal_components_factory, 882 scoped_ptr<InternalComponentsFactory> internal_components_factory,
868 scoped_ptr<syncer::UnrecoverableErrorHandler> unrecoverable_error_handler, 883 scoped_ptr<syncer::UnrecoverableErrorHandler> unrecoverable_error_handler,
869 syncer::ReportUnrecoverableErrorFunction 884 syncer::ReportUnrecoverableErrorFunction
870 report_unrecoverable_error_function, 885 report_unrecoverable_error_function,
871 bool use_oauth2_token, 886 bool use_oauth2_token)
872 syncer::CancelationSignal* const cancelation_signal)
873 : sync_loop(sync_loop), 887 : sync_loop(sync_loop),
874 registrar(registrar), 888 registrar(registrar),
875 routing_info(routing_info), 889 routing_info(routing_info),
876 workers(workers), 890 workers(workers),
877 extensions_activity(extensions_activity), 891 extensions_activity(extensions_activity),
878 event_handler(event_handler), 892 event_handler(event_handler),
879 service_url(service_url), 893 service_url(service_url),
880 make_http_bridge_factory_fn(make_http_bridge_factory_fn), 894 make_http_bridge_factory_fn(make_http_bridge_factory_fn),
881 credentials(credentials), 895 credentials(credentials),
882 invalidator_client_id(invalidator_client_id), 896 invalidator_client_id(invalidator_client_id),
883 sync_manager_factory(sync_manager_factory.Pass()), 897 sync_manager_factory(sync_manager_factory.Pass()),
884 delete_sync_data_folder(delete_sync_data_folder), 898 delete_sync_data_folder(delete_sync_data_folder),
885 restored_key_for_bootstrapping(restored_key_for_bootstrapping), 899 restored_key_for_bootstrapping(restored_key_for_bootstrapping),
886 restored_keystore_key_for_bootstrapping( 900 restored_keystore_key_for_bootstrapping(
887 restored_keystore_key_for_bootstrapping), 901 restored_keystore_key_for_bootstrapping),
888 internal_components_factory(internal_components_factory.Pass()), 902 internal_components_factory(internal_components_factory.Pass()),
889 unrecoverable_error_handler(unrecoverable_error_handler.Pass()), 903 unrecoverable_error_handler(unrecoverable_error_handler.Pass()),
890 report_unrecoverable_error_function( 904 report_unrecoverable_error_function(
891 report_unrecoverable_error_function), 905 report_unrecoverable_error_function),
892 use_oauth2_token(use_oauth2_token), 906 use_oauth2_token(use_oauth2_token) {
893 cancelation_signal(cancelation_signal) {
894 } 907 }
895 908
896 SyncBackendHost::DoInitializeOptions::~DoInitializeOptions() {} 909 SyncBackendHost::DoInitializeOptions::~DoInitializeOptions() {}
897 910
898 SyncBackendHost::Core::Core(const std::string& name, 911 SyncBackendHost::Core::Core(const std::string& name,
899 const base::FilePath& sync_data_folder_path, 912 const base::FilePath& sync_data_folder_path,
900 const base::WeakPtr<SyncBackendHost>& backend) 913 const base::WeakPtr<SyncBackendHost>& backend)
901 : name_(name), 914 : name_(name),
902 sync_data_folder_path_(sync_data_folder_path), 915 sync_data_folder_path_(sync_data_folder_path),
903 host_(backend), 916 host_(backend),
(...skipping 244 matching lines...) Expand 10 before | Expand all | Expand 10 after
1148 options->extensions_activity, 1161 options->extensions_activity,
1149 options->registrar /* as SyncManager::ChangeDelegate */, 1162 options->registrar /* as SyncManager::ChangeDelegate */,
1150 options->credentials, 1163 options->credentials,
1151 options->invalidator_client_id, 1164 options->invalidator_client_id,
1152 options->restored_key_for_bootstrapping, 1165 options->restored_key_for_bootstrapping,
1153 options->restored_keystore_key_for_bootstrapping, 1166 options->restored_keystore_key_for_bootstrapping,
1154 options->internal_components_factory.get(), 1167 options->internal_components_factory.get(),
1155 &encryptor_, 1168 &encryptor_,
1156 options->unrecoverable_error_handler.Pass(), 1169 options->unrecoverable_error_handler.Pass(),
1157 options->report_unrecoverable_error_function, 1170 options->report_unrecoverable_error_function,
1158 options->use_oauth2_token, 1171 options->use_oauth2_token);
1159 options->cancelation_signal);
1160 1172
1161 // |sync_manager_| may end up being NULL here in tests (in 1173 // |sync_manager_| may end up being NULL here in tests (in
1162 // synchronous initialization mode). 1174 // synchronous initialization mode).
1163 // 1175 //
1164 // TODO(akalin): Fix this behavior (see http://crbug.com/140354). 1176 // TODO(akalin): Fix this behavior (see http://crbug.com/140354).
1165 if (sync_manager_) { 1177 if (sync_manager_) {
1166 // Now check the command line to see if we need to simulate an 1178 // Now check the command line to see if we need to simulate an
1167 // unrecoverable error for testing purpose. Note the error is thrown 1179 // unrecoverable error for testing purpose. Note the error is thrown
1168 // only if the initialization succeeded. Also it makes sense to use this 1180 // only if the initialization succeeded. Also it makes sense to use this
1169 // flag only when restarting the browser with an account already setup. If 1181 // flag only when restarting the browser with an account already setup. If
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
1259 DCHECK_EQ(base::MessageLoop::current(), sync_loop_); 1271 DCHECK_EQ(base::MessageLoop::current(), sync_loop_);
1260 sync_manager_->GetEncryptionHandler()->SetDecryptionPassphrase( 1272 sync_manager_->GetEncryptionHandler()->SetDecryptionPassphrase(
1261 passphrase); 1273 passphrase);
1262 } 1274 }
1263 1275
1264 void SyncBackendHost::Core::DoEnableEncryptEverything() { 1276 void SyncBackendHost::Core::DoEnableEncryptEverything() {
1265 DCHECK_EQ(base::MessageLoop::current(), sync_loop_); 1277 DCHECK_EQ(base::MessageLoop::current(), sync_loop_);
1266 sync_manager_->GetEncryptionHandler()->EnableEncryptEverything(); 1278 sync_manager_->GetEncryptionHandler()->EnableEncryptEverything();
1267 } 1279 }
1268 1280
1281 void SyncBackendHost::Core::DoStopSyncManagerForShutdown() {
1282 if (sync_manager_)
1283 sync_manager_->StopSyncingForShutdown();
1284 }
1285
1269 void SyncBackendHost::Core::DoShutdown(bool sync_disabled) { 1286 void SyncBackendHost::Core::DoShutdown(bool sync_disabled) {
1270 DCHECK_EQ(base::MessageLoop::current(), sync_loop_); 1287 DCHECK_EQ(base::MessageLoop::current(), sync_loop_);
1271 // It's safe to do this even if the type was never activated. 1288 // It's safe to do this even if the type was never activated.
1272 registrar_->DeactivateDataType(syncer::DEVICE_INFO); 1289 registrar_->DeactivateDataType(syncer::DEVICE_INFO);
1273 synced_device_tracker_.reset(); 1290 synced_device_tracker_.reset();
1274 1291
1275 DoDestroySyncManager(); 1292 DoDestroySyncManager();
1276 1293
1277 registrar_ = NULL; 1294 registrar_ = NULL;
1278 1295
(...skipping 309 matching lines...) Expand 10 before | Expand all | Expand 10 after
1588 1605
1589 base::MessageLoop* SyncBackendHost::GetSyncLoopForTesting() { 1606 base::MessageLoop* SyncBackendHost::GetSyncLoopForTesting() {
1590 return registrar_->sync_thread()->message_loop(); 1607 return registrar_->sync_thread()->message_loop();
1591 } 1608 }
1592 1609
1593 #undef SDVLOG 1610 #undef SDVLOG
1594 1611
1595 #undef SLOG 1612 #undef SLOG
1596 1613
1597 } // namespace browser_sync 1614 } // namespace browser_sync
OLDNEW
« no previous file with comments | « trunk/src/chrome/browser/sync/glue/sync_backend_host.h ('k') | trunk/src/sync/engine/net/server_connection_manager.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698