database_model_worker.cc revision 3345a6884c488ff3a535c2c9acdd33d74b37e311
1// Copyright (c) 2010 The Chromium Authors. All rights reserved. 2// Use of this source code is governed by a BSD-style license that can be 3// found in the LICENSE file. 4 5#include "chrome/browser/sync/glue/database_model_worker.h" 6 7#include "base/waitable_event.h" 8#include "chrome/browser/chrome_thread.h" 9 10using base::WaitableEvent; 11 12namespace browser_sync { 13 14void DatabaseModelWorker::DoWorkAndWaitUntilDone(Callback0::Type* work) { 15 if (ChromeThread::CurrentlyOn(ChromeThread::DB)) { 16 DLOG(WARNING) << "DoWorkAndWaitUntilDone called from the DB thread."; 17 work->Run(); 18 return; 19 } 20 WaitableEvent done(false, false); 21 if (!ChromeThread::PostTask(ChromeThread::DB, FROM_HERE, 22 NewRunnableMethod(this, &DatabaseModelWorker::CallDoWorkAndSignalTask, 23 work, &done))) { 24 NOTREACHED() << "Failed to post task to the db thread."; 25 return; 26 } 27 done.Wait(); 28} 29 30void DatabaseModelWorker::CallDoWorkAndSignalTask(Callback0::Type* work, 31 WaitableEvent* done) { 32 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::DB)); 33 work->Run(); 34 done->Signal(); 35} 36 37bool DatabaseModelWorker::CurrentThreadIsWorkThread() { 38 return ChromeThread::CurrentlyOn(ChromeThread::DB); 39} 40 41} // namespace browser_sync 42