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