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

Side by Side Diff: components/sync/driver/glue/sync_backend_host_impl.cc

Issue 2471183003: Do not observe MessageLoop destruction from ModelSafeWorker. (Closed)
Patch Set: self-review 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 unified diff | Download patch
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 "components/sync/driver/glue/sync_backend_host_impl.h" 5 #include "components/sync/driver/glue/sync_backend_host_impl.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "base/bind.h"
9 #include "base/command_line.h" 10 #include "base/command_line.h"
10 #include "base/feature_list.h" 11 #include "base/feature_list.h"
11 #include "base/location.h" 12 #include "base/location.h"
12 #include "base/logging.h" 13 #include "base/logging.h"
13 #include "base/memory/ptr_util.h" 14 #include "base/memory/ptr_util.h"
14 #include "base/threading/thread_task_runner_handle.h" 15 #include "base/threading/thread_task_runner_handle.h"
15 #include "components/invalidation/public/invalidation_service.h" 16 #include "components/invalidation/public/invalidation_service.h"
16 #include "components/invalidation/public/object_id_invalidation_map.h" 17 #include "components/invalidation/public/object_id_invalidation_map.h"
17 #include "components/signin/core/browser/signin_client.h" 18 #include "components/signin/core/browser/signin_client.h"
18 #include "components/sync/base/experiments.h" 19 #include "components/sync/base/experiments.h"
(...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after
234 core_->ShutdownOnUIThread(); 235 core_->ShutdownOnUIThread();
235 } 236 }
236 237
237 std::unique_ptr<base::Thread> SyncBackendHostImpl::Shutdown( 238 std::unique_ptr<base::Thread> SyncBackendHostImpl::Shutdown(
238 ShutdownReason reason) { 239 ShutdownReason reason) {
239 // StopSyncingForShutdown() (which nulls out |frontend_|) should be 240 // StopSyncingForShutdown() (which nulls out |frontend_|) should be
240 // called first. 241 // called first.
241 DCHECK(!frontend_); 242 DCHECK(!frontend_);
242 DCHECK(registrar_->sync_thread()->IsRunning()); 243 DCHECK(registrar_->sync_thread()->IsRunning());
243 244
244 bool sync_thread_claimed = (reason != BROWSER_SHUTDOWN);
245
246 if (invalidation_handler_registered_) { 245 if (invalidation_handler_registered_) {
247 if (reason == DISABLE_SYNC) { 246 if (reason == DISABLE_SYNC) {
248 UnregisterInvalidationIds(); 247 UnregisterInvalidationIds();
249 } 248 }
250 invalidator_->UnregisterInvalidationHandler(this); 249 invalidator_->UnregisterInvalidationHandler(this);
251 invalidator_ = nullptr; 250 invalidator_ = nullptr;
252 } 251 }
253 invalidation_handler_registered_ = false; 252 invalidation_handler_registered_ = false;
254 253
255 model_type_connector_.reset(); 254 model_type_connector_.reset();
256 255
257 // Shut down and destroy sync manager. 256 // Shut down and destroy SyncManager. SyncManager holds a pointer to
257 // |registrar_| so its destruction must be sequenced before the destruction of
258 // |registrar_|.
258 registrar_->sync_thread()->task_runner()->PostTask( 259 registrar_->sync_thread()->task_runner()->PostTask(
259 FROM_HERE, 260 FROM_HERE,
260 base::Bind(&SyncBackendHostCore::DoShutdown, core_, reason)); 261 base::Bind(&SyncBackendHostCore::DoShutdown, core_, reason));
261 core_ = nullptr; 262 core_ = nullptr;
262 263
263 // Worker cleanup. 264 // Destroy |registrar_|.
264 SyncBackendRegistrar* detached_registrar = registrar_.release(); 265 std::unique_ptr<base::Thread> released_sync_thread =
265 detached_registrar->sync_thread()->task_runner()->PostTask( 266 registrar_->ReleaseSyncThread();
266 FROM_HERE, base::Bind(&SyncBackendRegistrar::Shutdown, 267 released_sync_thread->task_runner()->DeleteSoon(FROM_HERE,
267 base::Unretained(detached_registrar))); 268 registrar_.release());
268 269
269 if (sync_thread_claimed) 270 if (reason == BROWSER_SHUTDOWN)
270 return detached_registrar->ReleaseSyncThread(); 271 return nullptr;
271 else 272 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
272 return std::unique_ptr<base::Thread>();
273 } 273 }
274 274
275 void SyncBackendHostImpl::UnregisterInvalidationIds() { 275 void SyncBackendHostImpl::UnregisterInvalidationIds() {
276 if (invalidation_handler_registered_) { 276 if (invalidation_handler_registered_) {
277 CHECK(invalidator_->UpdateRegisteredInvalidationIds(this, ObjectIdSet())); 277 CHECK(invalidator_->UpdateRegisteredInvalidationIds(this, ObjectIdSet()));
278 } 278 }
279 } 279 }
280 280
281 ModelTypeSet SyncBackendHostImpl::ConfigureDataTypes( 281 ModelTypeSet SyncBackendHostImpl::ConfigureDataTypes(
282 ConfigureReason reason, 282 ConfigureReason reason,
(...skipping 534 matching lines...) Expand 10 before | Expand all | Expand 10 after
817 const SyncManager::ClearServerDataCallback& frontend_callback) { 817 const SyncManager::ClearServerDataCallback& frontend_callback) {
818 DCHECK(ui_thread_->BelongsToCurrentThread()); 818 DCHECK(ui_thread_->BelongsToCurrentThread());
819 frontend_callback.Run(); 819 frontend_callback.Run();
820 } 820 }
821 821
822 } // namespace syncer 822 } // namespace syncer
823 823
824 #undef SDVLOG 824 #undef SDVLOG
825 825
826 #undef SLOG 826 #undef SLOG
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698