Home | History | Annotate | Download | only in glue
      1 // Copyright (c) 2012 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 #ifndef CHROME_BROWSER_SYNC_GLUE_BROWSER_THREAD_MODEL_WORKER_H_
      6 #define CHROME_BROWSER_SYNC_GLUE_BROWSER_THREAD_MODEL_WORKER_H_
      7 
      8 #include "base/basictypes.h"
      9 #include "base/callback_forward.h"
     10 #include "base/compiler_specific.h"
     11 #include "content/public/browser/browser_thread.h"
     12 #include "sync/internal_api/public/engine/model_safe_worker.h"
     13 #include "sync/internal_api/public/util/syncer_error.h"
     14 
     15 namespace base {
     16 class WaitableEvent;
     17 }
     18 
     19 namespace browser_sync {
     20 
     21 // A syncer::ModelSafeWorker for models that accept requests from the
     22 // syncapi that need to be fulfilled on a browser thread, for example
     23 // autofill on the DB thread.
     24 // TODO(sync): Try to generalize other ModelWorkers (e.g. history, etc).
     25 class BrowserThreadModelWorker : public syncer::ModelSafeWorker {
     26  public:
     27   BrowserThreadModelWorker(content::BrowserThread::ID thread,
     28                            syncer::ModelSafeGroup group,
     29                            syncer::WorkerLoopDestructionObserver* observer);
     30 
     31   // syncer::ModelSafeWorker implementation. Called on the sync thread.
     32   virtual void RegisterForLoopDestruction() OVERRIDE;
     33   virtual syncer::ModelSafeGroup GetModelSafeGroup() OVERRIDE;
     34 
     35  protected:
     36   virtual ~BrowserThreadModelWorker();
     37 
     38   virtual syncer::SyncerError DoWorkAndWaitUntilDoneImpl(
     39       const syncer::WorkCallback& work) OVERRIDE;
     40 
     41   // Marked pure virtual so subclasses have to override, but there is
     42   // an implementation that subclasses should use.  This is so that
     43   // (subclass)::CallDoWorkAndSignalTask shows up in callstacks.
     44   virtual void CallDoWorkAndSignalTask(
     45       const syncer::WorkCallback& work,
     46       base::WaitableEvent* done,
     47       syncer::SyncerError* error) = 0;
     48 
     49  private:
     50   content::BrowserThread::ID thread_;
     51   syncer::ModelSafeGroup group_;
     52 
     53   DISALLOW_COPY_AND_ASSIGN(BrowserThreadModelWorker);
     54 };
     55 
     56 // Subclass BrowserThreadModelWorker so that we can distinguish them
     57 // from stack traces alone.
     58 
     59 class DatabaseModelWorker : public BrowserThreadModelWorker {
     60  public:
     61   explicit DatabaseModelWorker(syncer::WorkerLoopDestructionObserver* observer);
     62 
     63  protected:
     64   virtual void CallDoWorkAndSignalTask(
     65       const syncer::WorkCallback& work,
     66       base::WaitableEvent* done,
     67       syncer::SyncerError* error) OVERRIDE;
     68 
     69  private:
     70   virtual ~DatabaseModelWorker();
     71 };
     72 
     73 class FileModelWorker : public BrowserThreadModelWorker {
     74  public:
     75   explicit FileModelWorker(syncer::WorkerLoopDestructionObserver* observer);
     76 
     77  protected:
     78   virtual void CallDoWorkAndSignalTask(
     79       const syncer::WorkCallback& work,
     80       base::WaitableEvent* done,
     81       syncer::SyncerError* error) OVERRIDE;
     82 
     83  private:
     84   virtual ~FileModelWorker();
     85 };
     86 
     87 }  // namespace browser_sync
     88 
     89 #endif  // CHROME_BROWSER_SYNC_GLUE_BROWSER_THREAD_MODEL_WORKER_H_
     90