Home | History | Annotate | Download | only in glue
      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
      3 // found in the LICENSE file.
      4 
      5 #include "chrome/browser/sync/glue/history_model_worker.h"
      6 
      7 #include "base/memory/ref_counted.h"
      8 #include "base/message_loop.h"
      9 #include "base/task.h"
     10 #include "base/synchronization/waitable_event.h"
     11 #include "chrome/browser/history/history.h"
     12 
     13 using base::WaitableEvent;
     14 
     15 namespace browser_sync {
     16 
     17 class WorkerTask : public HistoryDBTask {
     18  public:
     19   WorkerTask(Callback0::Type* work, WaitableEvent* done)
     20     : work_(work), done_(done) {}
     21 
     22   virtual bool RunOnDBThread(history::HistoryBackend* backend,
     23                              history::HistoryDatabase* db) {
     24     work_->Run();
     25     done_->Signal();
     26     return true;
     27   }
     28 
     29   // Since the DoWorkAndWaitUntilDone() is syncronous, we don't need to run any
     30   // code asynchronously on the main thread after completion.
     31   virtual void DoneRunOnMainThread() {}
     32 
     33  protected:
     34   Callback0::Type* work_;
     35   WaitableEvent* done_;
     36 };
     37 
     38 
     39 HistoryModelWorker::HistoryModelWorker(HistoryService* history_service)
     40   : history_service_(history_service) {
     41 }
     42 
     43 HistoryModelWorker::~HistoryModelWorker() {
     44 }
     45 
     46 void HistoryModelWorker::DoWorkAndWaitUntilDone(Callback0::Type* work) {
     47   WaitableEvent done(false, false);
     48   scoped_refptr<WorkerTask> task(new WorkerTask(work, &done));
     49   history_service_->ScheduleDBTask(task.get(), this);
     50   done.Wait();
     51 }
     52 
     53 ModelSafeGroup HistoryModelWorker::GetModelSafeGroup() {
     54   return GROUP_HISTORY;
     55 }
     56 
     57 bool HistoryModelWorker::CurrentThreadIsWorkThread() {
     58   // TODO(ncarter): How to determine this?
     59   return true;
     60 }
     61 
     62 }  // namespace browser_sync
     63