Chromium Code Reviews| Index: components/sync/driver/glue/sync_backend_host_impl.cc |
| diff --git a/components/sync/driver/glue/sync_backend_host_impl.cc b/components/sync/driver/glue/sync_backend_host_impl.cc |
| index 1132f50c6571a61ac4abea5fef3c9d70db4aa936..295913591b6009d3b23cb301c0db184ecdaf3230 100644 |
| --- a/components/sync/driver/glue/sync_backend_host_impl.cc |
| +++ b/components/sync/driver/glue/sync_backend_host_impl.cc |
| @@ -6,6 +6,7 @@ |
| #include <utility> |
| +#include "base/bind.h" |
| #include "base/command_line.h" |
| #include "base/feature_list.h" |
| #include "base/location.h" |
| @@ -241,8 +242,6 @@ std::unique_ptr<base::Thread> SyncBackendHostImpl::Shutdown( |
| DCHECK(!frontend_); |
| DCHECK(registrar_->sync_thread()->IsRunning()); |
| - bool sync_thread_claimed = (reason != BROWSER_SHUTDOWN); |
| - |
| if (invalidation_handler_registered_) { |
| if (reason == DISABLE_SYNC) { |
| UnregisterInvalidationIds(); |
| @@ -254,22 +253,23 @@ std::unique_ptr<base::Thread> SyncBackendHostImpl::Shutdown( |
| model_type_connector_.reset(); |
| - // Shut down and destroy sync manager. |
| + // Shut down and destroy SyncManager. SyncManager holds a pointer to |
| + // |registrar_| so its destruction must be sequenced before the destruction of |
| + // |registrar_|. |
| registrar_->sync_thread()->task_runner()->PostTask( |
| FROM_HERE, |
| base::Bind(&SyncBackendHostCore::DoShutdown, core_, reason)); |
| core_ = nullptr; |
| - // Worker cleanup. |
| - SyncBackendRegistrar* detached_registrar = registrar_.release(); |
| - detached_registrar->sync_thread()->task_runner()->PostTask( |
| - FROM_HERE, base::Bind(&SyncBackendRegistrar::Shutdown, |
| - base::Unretained(detached_registrar))); |
| + // Destroy |registrar_|. |
| + std::unique_ptr<base::Thread> released_sync_thread = |
| + registrar_->ReleaseSyncThread(); |
| + released_sync_thread->task_runner()->DeleteSoon(FROM_HERE, |
| + registrar_.release()); |
| - if (sync_thread_claimed) |
| - return detached_registrar->ReleaseSyncThread(); |
| - else |
| - return std::unique_ptr<base::Thread>(); |
| + if (reason == BROWSER_SHUTDOWN) |
| + return nullptr; |
| + return released_sync_thread; |
|
maxbogue
2016/11/03 17:05:31
So my understanding of the current weird structure
maxbogue
2016/11/03 17:10:23
Additionally note that I'm not actually positive t
maxbogue
2016/11/03 17:29:11
Update: it seems that we currently don't block the
fdoray
2016/11/03 19:11:05
Before AND after this CL, SyncBackendHostImpl::Shu
maxbogue
2016/11/03 23:48:33
Prior to this CL, the sync thread was joined whene
fdoray
2016/11/04 12:24:01
Done. You're right. I didn't read this code correc
maxbogue
2016/11/04 17:34:57
Ah, didn't realize that PSS joins it there, I thou
|
| } |
| void SyncBackendHostImpl::UnregisterInvalidationIds() { |