OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "chrome/browser/sync/glue/browser_thread_model_worker.h" | 5 #include "chrome/browser/sync/glue/browser_thread_model_worker.h" |
6 | 6 |
| 7 #include "base/bind.h" |
7 #include "base/synchronization/waitable_event.h" | 8 #include "base/synchronization/waitable_event.h" |
8 #include "content/public/browser/browser_thread.h" | 9 #include "content/public/browser/browser_thread.h" |
9 | 10 |
10 using base::WaitableEvent; | 11 using base::WaitableEvent; |
11 | 12 |
12 namespace browser_sync { | 13 namespace browser_sync { |
13 | 14 |
14 BrowserThreadModelWorker::BrowserThreadModelWorker( | 15 BrowserThreadModelWorker::BrowserThreadModelWorker( |
15 BrowserThread::ID thread, ModelSafeGroup group) | 16 BrowserThread::ID thread, ModelSafeGroup group) |
16 : thread_(thread), group_(group) {} | 17 : thread_(thread), group_(group) {} |
17 | 18 |
18 BrowserThreadModelWorker::~BrowserThreadModelWorker() {} | 19 BrowserThreadModelWorker::~BrowserThreadModelWorker() {} |
19 | 20 |
20 UnrecoverableErrorInfo BrowserThreadModelWorker::DoWorkAndWaitUntilDone( | 21 UnrecoverableErrorInfo BrowserThreadModelWorker::DoWorkAndWaitUntilDone( |
21 const WorkCallback& work) { | 22 const WorkCallback& work) { |
22 UnrecoverableErrorInfo error_info; | 23 UnrecoverableErrorInfo error_info; |
23 if (BrowserThread::CurrentlyOn(thread_)) { | 24 if (BrowserThread::CurrentlyOn(thread_)) { |
24 DLOG(WARNING) << "Already on thread " << thread_; | 25 DLOG(WARNING) << "Already on thread " << thread_; |
25 return work.Run(); | 26 return work.Run(); |
26 } | 27 } |
27 WaitableEvent done(false, false); | 28 WaitableEvent done(false, false); |
28 if (!BrowserThread::PostTask( | 29 if (!BrowserThread::PostTask( |
29 thread_, | 30 thread_, |
30 FROM_HERE, | 31 FROM_HERE, |
31 NewRunnableMethod( | 32 base::Bind(&BrowserThreadModelWorker::CallDoWorkAndSignalTask, this, |
32 this, | 33 work, &done, &error_info))) { |
33 &BrowserThreadModelWorker::CallDoWorkAndSignalTask, | |
34 work, | |
35 &done, | |
36 &error_info))) { | |
37 NOTREACHED() << "Failed to post task to thread " << thread_; | 34 NOTREACHED() << "Failed to post task to thread " << thread_; |
38 return error_info; | 35 return error_info; |
39 } | 36 } |
40 done.Wait(); | 37 done.Wait(); |
41 return error_info; | 38 return error_info; |
42 } | 39 } |
43 | 40 |
44 void BrowserThreadModelWorker::CallDoWorkAndSignalTask( | 41 void BrowserThreadModelWorker::CallDoWorkAndSignalTask( |
45 const WorkCallback& work, | 42 const WorkCallback& work, |
46 WaitableEvent* done, | 43 WaitableEvent* done, |
(...skipping 25 matching lines...) Expand all Loading... |
72 FileModelWorker::~FileModelWorker() {} | 69 FileModelWorker::~FileModelWorker() {} |
73 | 70 |
74 void FileModelWorker::CallDoWorkAndSignalTask( | 71 void FileModelWorker::CallDoWorkAndSignalTask( |
75 const WorkCallback& work, | 72 const WorkCallback& work, |
76 WaitableEvent* done, | 73 WaitableEvent* done, |
77 UnrecoverableErrorInfo* error_info) { | 74 UnrecoverableErrorInfo* error_info) { |
78 BrowserThreadModelWorker::CallDoWorkAndSignalTask(work, done, error_info); | 75 BrowserThreadModelWorker::CallDoWorkAndSignalTask(work, done, error_info); |
79 } | 76 } |
80 | 77 |
81 } // namespace browser_sync | 78 } // namespace browser_sync |
OLD | NEW |