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.
5 #ifndef CHROME_BROWSER_SYNC_GLUE_BROWSER_THREAD_MODEL_WORKER_H_
6 #define CHROME_BROWSER_SYNC_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 "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"
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(content::BrowserThread::ID thread
,
28 syncer::ModelSafeGroup group
,
29 syncer::WorkerLoopDestructionObserver
* observer
);
31 // syncer::ModelSafeWorker implementation. Called on the sync thread.
32 virtual void RegisterForLoopDestruction() OVERRIDE
;
33 virtual syncer::ModelSafeGroup
GetModelSafeGroup() OVERRIDE
;
36 virtual ~BrowserThreadModelWorker();
38 virtual syncer::SyncerError
DoWorkAndWaitUntilDoneImpl(
39 const syncer::WorkCallback
& work
) OVERRIDE
;
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;
50 content::BrowserThread::ID thread_
;
51 syncer::ModelSafeGroup group_
;
53 DISALLOW_COPY_AND_ASSIGN(BrowserThreadModelWorker
);
56 // Subclass BrowserThreadModelWorker so that we can distinguish them
57 // from stack traces alone.
59 class DatabaseModelWorker
: public BrowserThreadModelWorker
{
61 explicit DatabaseModelWorker(syncer::WorkerLoopDestructionObserver
* observer
);
64 virtual void CallDoWorkAndSignalTask(
65 const syncer::WorkCallback
& work
,
66 base::WaitableEvent
* done
,
67 syncer::SyncerError
* error
) OVERRIDE
;
70 virtual ~DatabaseModelWorker();
73 class FileModelWorker
: public BrowserThreadModelWorker
{
75 explicit FileModelWorker(syncer::WorkerLoopDestructionObserver
* observer
);
78 virtual void CallDoWorkAndSignalTask(
79 const syncer::WorkCallback
& work
,
80 base::WaitableEvent
* done
,
81 syncer::SyncerError
* error
) OVERRIDE
;
84 virtual ~FileModelWorker();
87 } // namespace browser_sync
89 #endif // CHROME_BROWSER_SYNC_GLUE_BROWSER_THREAD_MODEL_WORKER_H_