Chromium Code Reviews| Index: chrome/browser/sync/glue/browser_thread_model_worker.cc |
| diff --git a/chrome/browser/sync/glue/browser_thread_model_worker.cc b/chrome/browser/sync/glue/browser_thread_model_worker.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..dd752d3314d40107e152ec6203dec8ca1e54afe4 |
| --- /dev/null |
| +++ b/chrome/browser/sync/glue/browser_thread_model_worker.cc |
| @@ -0,0 +1,52 @@ |
| +// Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "chrome/browser/sync/glue/browser_thread_model_worker.h" |
| + |
| +#include "base/synchronization/waitable_event.h" |
| +#include "content/browser/browser_thread.h" |
| + |
| +using base::WaitableEvent; |
| + |
| +namespace browser_sync { |
| + |
| +BrowserThreadModelWorker::BrowserThreadModelWorker( |
| + BrowserThread::ID thread, ModelSafeGroup group) |
| + : thread_(thread), group_(group) {} |
| + |
| +BrowserThreadModelWorker::~BrowserThreadModelWorker() {} |
| + |
| +void BrowserThreadModelWorker::DoWorkAndWaitUntilDone(Callback0::Type* work) { |
| + if (BrowserThread::CurrentlyOn(thread_)) { |
| + DLOG(WARNING) << "Already on the appropriate thread."; |
|
akalin
2011/09/14 19:16:32
log the thread ID, i.e.
DLOG(WARNING) << "Already
not at google - send to devlin
2011/09/14 20:39:03
It would be nice if I could print out "FILE" inste
|
| + work->Run(); |
| + return; |
| + } |
| + WaitableEvent done(false, false); |
| + if (!BrowserThread::PostTask( |
| + thread_, |
| + FROM_HERE, |
| + NewRunnableMethod( |
| + this, |
| + &BrowserThreadModelWorker::CallDoWorkAndSignalTask, |
| + work, |
| + &done))) { |
| + NOTREACHED() << "Failed to post task to the appropriate thread."; |
|
akalin
2011/09/14 19:16:32
same here
not at google - send to devlin
2011/09/14 20:39:03
Done.
|
| + return; |
| + } |
| + done.Wait(); |
| +} |
| + |
| +void BrowserThreadModelWorker::CallDoWorkAndSignalTask( |
| + Callback0::Type* work, WaitableEvent* done) { |
| + DCHECK(BrowserThread::CurrentlyOn(thread_)); |
| + work->Run(); |
| + done->Signal(); |
| +} |
| + |
| +ModelSafeGroup BrowserThreadModelWorker::GetModelSafeGroup() { |
| + return group_; |
| +} |
| + |
| +} // namespace browser_sync |