Disable view source for Developer Tools.
[chromium-blink-merge.git] / chrome / browser / sync / glue / browser_thread_model_worker.h
blob954a8af5ca3524b1eb13efd96cef2d501451eab0
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"
15 namespace base {
16 class WaitableEvent;
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 {
26 public:
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;
35 protected:
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;
49 private:
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 {
60 public:
61 explicit DatabaseModelWorker(syncer::WorkerLoopDestructionObserver* observer);
63 protected:
64 virtual void CallDoWorkAndSignalTask(
65 const syncer::WorkCallback& work,
66 base::WaitableEvent* done,
67 syncer::SyncerError* error) OVERRIDE;
69 private:
70 virtual ~DatabaseModelWorker();
73 class FileModelWorker : public BrowserThreadModelWorker {
74 public:
75 explicit FileModelWorker(syncer::WorkerLoopDestructionObserver* observer);
77 protected:
78 virtual void CallDoWorkAndSignalTask(
79 const syncer::WorkCallback& work,
80 base::WaitableEvent* done,
81 syncer::SyncerError* error) OVERRIDE;
83 private:
84 virtual ~FileModelWorker();
87 } // namespace browser_sync
89 #endif // CHROME_BROWSER_SYNC_GLUE_BROWSER_THREAD_MODEL_WORKER_H_