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

Side by Side Diff: components/sync/driver/glue/browser_thread_model_worker.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 2012 The Chromium Authors. All rights reserved. 1 // Copyright 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 "components/sync/driver/glue/browser_thread_model_worker.h" 5 #include "components/sync/driver/glue/browser_thread_model_worker.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/callback.h"
8 #include "base/single_thread_task_runner.h" 9 #include "base/single_thread_task_runner.h"
9 #include "base/synchronization/waitable_event.h" 10 #include "base/synchronization/waitable_event.h"
10 11
11 using base::SingleThreadTaskRunner; 12 using base::SingleThreadTaskRunner;
12 13
13 namespace syncer { 14 namespace syncer {
14 15
15 BrowserThreadModelWorker::BrowserThreadModelWorker( 16 BrowserThreadModelWorker::BrowserThreadModelWorker(
16 const scoped_refptr<SingleThreadTaskRunner>& runner, 17 const scoped_refptr<SingleThreadTaskRunner>& runner,
17 ModelSafeGroup group, 18 ModelSafeGroup group)
18 WorkerLoopDestructionObserver* observer) 19 : runner_(runner), group_(group) {}
19 : ModelSafeWorker(observer), runner_(runner), group_(group) {}
20 20
21 SyncerError BrowserThreadModelWorker::DoWorkAndWaitUntilDoneImpl( 21 SyncerError BrowserThreadModelWorker::DoWorkAndWaitUntilDoneImpl(
22 const WorkCallback& work) { 22 const WorkCallback& work) {
23 SyncerError error = UNSET; 23 SyncerError error = UNSET;
24 if (runner_->BelongsToCurrentThread()) { 24 if (runner_->BelongsToCurrentThread()) {
25 DLOG(WARNING) << "Already on thread " << runner_; 25 DLOG(WARNING) << "Already on thread " << runner_;
26 return work.Run(); 26 return work.Run();
27 } 27 }
28 28
29 // Signaled when the task is deleted, i.e. after it runs or when it is 29 // Signaled when the task is deleted, i.e. after it runs or when it is
(...skipping 15 matching lines...) Expand all
45 work_done_or_abandoned.Wait(); 45 work_done_or_abandoned.Wait();
46 return error; 46 return error;
47 } 47 }
48 48
49 ModelSafeGroup BrowserThreadModelWorker::GetModelSafeGroup() { 49 ModelSafeGroup BrowserThreadModelWorker::GetModelSafeGroup() {
50 return group_; 50 return group_;
51 } 51 }
52 52
53 BrowserThreadModelWorker::~BrowserThreadModelWorker() {} 53 BrowserThreadModelWorker::~BrowserThreadModelWorker() {}
54 54
55 void BrowserThreadModelWorker::RegisterForLoopDestruction() {
56 if (runner_->BelongsToCurrentThread()) {
57 SetWorkingLoopToCurrent();
58 } else {
59 runner_->PostTask(
60 FROM_HERE,
61 Bind(&BrowserThreadModelWorker::RegisterForLoopDestruction, this));
62 }
63 }
64
65 void BrowserThreadModelWorker::CallDoWorkAndSignalTask( 55 void BrowserThreadModelWorker::CallDoWorkAndSignalTask(
66 const WorkCallback& work, 56 const WorkCallback& work,
67 syncer::ScopedEventSignal scoped_event_signal, 57 syncer::ScopedEventSignal scoped_event_signal,
68 SyncerError* error) { 58 SyncerError* error) {
69 DCHECK(runner_->BelongsToCurrentThread()); 59 DCHECK(runner_->BelongsToCurrentThread());
70 if (!IsStopped()) 60 if (!IsStopped())
71 *error = work.Run(); 61 *error = work.Run();
72 // The event in |scoped_event_signal| is signaled at the end of this scope. 62 // The event in |scoped_event_signal| is signaled at the end of this scope.
73 } 63 }
74 64
75 } // namespace syncer 65 } // namespace syncer
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698