1 // Copyright 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.
5 #ifndef COMPONENTS_SYNC_DRIVER_GLUE_BROWSER_THREAD_MODEL_WORKER_H_
6 #define COMPONENTS_SYNC_DRIVER_GLUE_BROWSER_THREAD_MODEL_WORKER_H_
8 #include "base/basictypes.h"
9 #include "base/callback_forward.h"
10 #include "base/compiler_specific.h"
11 #include "sync/internal_api/public/engine/model_safe_worker.h"
12 #include "sync/internal_api/public/util/syncer_error.h"
15 class SingleThreadTaskRunner
;
19 namespace browser_sync
{
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
{
27 BrowserThreadModelWorker(
28 const scoped_refptr
<base::SingleThreadTaskRunner
>& runner
,
29 syncer::ModelSafeGroup group
,
30 syncer::WorkerLoopDestructionObserver
* observer
);
32 // syncer::ModelSafeWorker implementation. Called on the sync thread.
33 void RegisterForLoopDestruction() override
;
34 syncer::ModelSafeGroup
GetModelSafeGroup() override
;
37 ~BrowserThreadModelWorker() override
;
39 syncer::SyncerError
DoWorkAndWaitUntilDoneImpl(
40 const syncer::WorkCallback
& work
) override
;
42 // Marked pure virtual so subclasses have to override, but there is
43 // an implementation that subclasses should use. This is so that
44 // (subclass)::CallDoWorkAndSignalTask shows up in callstacks.
45 virtual void CallDoWorkAndSignalTask(const syncer::WorkCallback
& work
,
46 base::WaitableEvent
* done
,
47 syncer::SyncerError
* error
);
50 scoped_refptr
<base::SingleThreadTaskRunner
> runner_
;
51 syncer::ModelSafeGroup group_
;
53 DISALLOW_COPY_AND_ASSIGN(BrowserThreadModelWorker
);
56 } // namespace browser_sync
58 #endif // COMPONENTS_SYNC_DRIVER_GLUE_BROWSER_THREAD_MODEL_WORKER_H_