OLD | NEW |
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/single_thread_task_runner.h" | 8 #include "base/single_thread_task_runner.h" |
9 #include "base/synchronization/waitable_event.h" | 9 #include "base/synchronization/waitable_event.h" |
10 | 10 |
11 using base::SingleThreadTaskRunner; | 11 using base::SingleThreadTaskRunner; |
12 using base::WaitableEvent; | 12 using base::WaitableEvent; |
13 | 13 |
14 namespace syncer { | 14 namespace browser_sync { |
15 | 15 |
16 BrowserThreadModelWorker::BrowserThreadModelWorker( | 16 BrowserThreadModelWorker::BrowserThreadModelWorker( |
17 const scoped_refptr<SingleThreadTaskRunner>& runner, | 17 const scoped_refptr<SingleThreadTaskRunner>& runner, |
18 ModelSafeGroup group, | 18 syncer::ModelSafeGroup group, |
19 WorkerLoopDestructionObserver* observer) | 19 syncer::WorkerLoopDestructionObserver* observer) |
20 : ModelSafeWorker(observer), runner_(runner), group_(group) {} | 20 : ModelSafeWorker(observer), runner_(runner), group_(group) {} |
21 | 21 |
22 SyncerError BrowserThreadModelWorker::DoWorkAndWaitUntilDoneImpl( | 22 syncer::SyncerError BrowserThreadModelWorker::DoWorkAndWaitUntilDoneImpl( |
23 const WorkCallback& work) { | 23 const syncer::WorkCallback& work) { |
24 SyncerError error = UNSET; | 24 syncer::SyncerError error = syncer::UNSET; |
25 if (runner_->BelongsToCurrentThread()) { | 25 if (runner_->BelongsToCurrentThread()) { |
26 DLOG(WARNING) << "Already on thread " << runner_; | 26 DLOG(WARNING) << "Already on thread " << runner_; |
27 return work.Run(); | 27 return work.Run(); |
28 } | 28 } |
29 | 29 |
30 if (!runner_->PostTask( | 30 if (!runner_->PostTask( |
31 FROM_HERE, | 31 FROM_HERE, |
32 base::Bind(&BrowserThreadModelWorker::CallDoWorkAndSignalTask, this, | 32 base::Bind(&BrowserThreadModelWorker::CallDoWorkAndSignalTask, this, |
33 work, work_done_or_stopped(), &error))) { | 33 work, work_done_or_stopped(), &error))) { |
34 DLOG(WARNING) << "Failed to post task to runner " << runner_; | 34 DLOG(WARNING) << "Failed to post task to runner " << runner_; |
35 error = CANNOT_DO_WORK; | 35 error = syncer::CANNOT_DO_WORK; |
36 return error; | 36 return error; |
37 } | 37 } |
38 work_done_or_stopped()->Wait(); | 38 work_done_or_stopped()->Wait(); |
39 return error; | 39 return error; |
40 } | 40 } |
41 | 41 |
42 ModelSafeGroup BrowserThreadModelWorker::GetModelSafeGroup() { | 42 syncer::ModelSafeGroup BrowserThreadModelWorker::GetModelSafeGroup() { |
43 return group_; | 43 return group_; |
44 } | 44 } |
45 | 45 |
46 BrowserThreadModelWorker::~BrowserThreadModelWorker() {} | 46 BrowserThreadModelWorker::~BrowserThreadModelWorker() {} |
47 | 47 |
48 void BrowserThreadModelWorker::RegisterForLoopDestruction() { | 48 void BrowserThreadModelWorker::RegisterForLoopDestruction() { |
49 if (runner_->BelongsToCurrentThread()) { | 49 if (runner_->BelongsToCurrentThread()) { |
50 SetWorkingLoopToCurrent(); | 50 SetWorkingLoopToCurrent(); |
51 } else { | 51 } else { |
52 runner_->PostTask( | 52 runner_->PostTask( |
53 FROM_HERE, | 53 FROM_HERE, |
54 Bind(&BrowserThreadModelWorker::RegisterForLoopDestruction, this)); | 54 Bind(&BrowserThreadModelWorker::RegisterForLoopDestruction, this)); |
55 } | 55 } |
56 } | 56 } |
57 | 57 |
58 void BrowserThreadModelWorker::CallDoWorkAndSignalTask(const WorkCallback& work, | 58 void BrowserThreadModelWorker::CallDoWorkAndSignalTask( |
59 WaitableEvent* done, | 59 const syncer::WorkCallback& work, |
60 SyncerError* error) { | 60 WaitableEvent* done, |
| 61 syncer::SyncerError* error) { |
61 DCHECK(runner_->BelongsToCurrentThread()); | 62 DCHECK(runner_->BelongsToCurrentThread()); |
62 if (!IsStopped()) | 63 if (!IsStopped()) |
63 *error = work.Run(); | 64 *error = work.Run(); |
64 done->Signal(); | 65 done->Signal(); |
65 } | 66 } |
66 | 67 |
67 } // namespace syncer | 68 } // namespace browser_sync |
OLD | NEW |