Home | History | Annotate | Download | only in glue
      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/synchronization/waitable_event.h"
      8 #include "content/browser/browser_thread.h"
      9 
     10 using base::WaitableEvent;
     11 
     12 namespace browser_sync {
     13 
     14 void DatabaseModelWorker::DoWorkAndWaitUntilDone(Callback0::Type* work) {
     15   if (BrowserThread::CurrentlyOn(BrowserThread::DB)) {
     16     DLOG(WARNING) << "DoWorkAndWaitUntilDone called from the DB thread.";
     17     work->Run();
     18     return;
     19   }
     20   WaitableEvent done(false, false);
     21   if (!BrowserThread::PostTask(BrowserThread::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 
     30 void DatabaseModelWorker::CallDoWorkAndSignalTask(Callback0::Type* work,
     31                                                   WaitableEvent* done) {
     32   DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB));
     33   work->Run();
     34   done->Signal();
     35 }
     36 
     37 ModelSafeGroup DatabaseModelWorker::GetModelSafeGroup() {
     38   return GROUP_DB;
     39 }
     40 
     41 bool DatabaseModelWorker::CurrentThreadIsWorkThread() {
     42   return BrowserThread::CurrentlyOn(BrowserThread::DB);
     43 }
     44 
     45 }  // namespace browser_sync
     46