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

Unified Diff: components/sync/driver/glue/sync_backend_host_impl.cc

Issue 2471183003: Do not observe MessageLoop destruction from ModelSafeWorker. (Closed)
Patch Set: CR maxbogue #23 Created 4 years, 1 month 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 side-by-side diff with in-line comments
Download patch
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..36b4fac26e1212034bc5150125c8825d59a3d647 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,21 @@ 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>();
+ return released_sync_thread;
}
void SyncBackendHostImpl::UnregisterInvalidationIds() {
« no previous file with comments | « components/sync/driver/glue/sync_backend_host.h ('k') | components/sync/driver/glue/sync_backend_host_impl_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698