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

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: 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 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 return released_sync_thread;
270 return detached_registrar->ReleaseSyncThread();
271 else
272 return std::unique_ptr<base::Thread>();
273 } 271 }
274 272
275 void SyncBackendHostImpl::UnregisterInvalidationIds() { 273 void SyncBackendHostImpl::UnregisterInvalidationIds() {
276 if (invalidation_handler_registered_) { 274 if (invalidation_handler_registered_) {
277 CHECK(invalidator_->UpdateRegisteredInvalidationIds(this, ObjectIdSet())); 275 CHECK(invalidator_->UpdateRegisteredInvalidationIds(this, ObjectIdSet()));
278 } 276 }
279 } 277 }
280 278
281 ModelTypeSet SyncBackendHostImpl::ConfigureDataTypes( 279 ModelTypeSet SyncBackendHostImpl::ConfigureDataTypes(
282 ConfigureReason reason, 280 ConfigureReason reason,
(...skipping 534 matching lines...) Expand 10 before | Expand all | Expand 10 after
817 const SyncManager::ClearServerDataCallback& frontend_callback) { 815 const SyncManager::ClearServerDataCallback& frontend_callback) {
818 DCHECK(ui_thread_->BelongsToCurrentThread()); 816 DCHECK(ui_thread_->BelongsToCurrentThread());
819 frontend_callback.Run(); 817 frontend_callback.Run();
820 } 818 }
821 819
822 } // namespace syncer 820 } // namespace syncer
823 821
824 #undef SDVLOG 822 #undef SDVLOG
825 823
826 #undef SLOG 824 #undef SLOG
OLDNEW
« 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