OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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_ENGINE_MODEL_SAFE_WORKER_H_ | 5 #ifndef CHROME_BROWSER_SYNC_ENGINE_MODEL_SAFE_WORKER_H_ |
6 #define CHROME_BROWSER_SYNC_ENGINE_MODEL_SAFE_WORKER_H_ | 6 #define CHROME_BROWSER_SYNC_ENGINE_MODEL_SAFE_WORKER_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
9 #include <map> | 9 #include <map> |
10 #include <string> | 10 #include <string> |
11 #include <vector> | 11 #include <vector> |
12 | 12 |
13 #include "base/callback.h" | 13 #include "base/callback.h" |
14 #include "base/memory/ref_counted.h" | 14 #include "base/memory/ref_counted.h" |
| 15 #include "chrome/browser/sync/engine/syncer_error.h" |
15 #include "chrome/browser/sync/syncable/model_type.h" | 16 #include "chrome/browser/sync/syncable/model_type.h" |
16 #include "chrome/browser/sync/util/unrecoverable_error_info.h" | |
17 | 17 |
18 namespace base { | 18 namespace base { |
19 class DictionaryValue; | 19 class DictionaryValue; |
20 } // namespace | 20 } // namespace |
21 | 21 |
22 namespace browser_sync { | 22 namespace browser_sync { |
23 | 23 |
24 typedef base::Callback<UnrecoverableErrorInfo(void)> WorkCallback; | 24 typedef base::Callback<enum SyncerError(void)> WorkCallback; |
25 | 25 |
26 enum ModelSafeGroup { | 26 enum ModelSafeGroup { |
27 GROUP_PASSIVE = 0, // Models that are just "passively" being synced; e.g. | 27 GROUP_PASSIVE = 0, // Models that are just "passively" being synced; e.g. |
28 // changes to these models don't need to be pushed to a | 28 // changes to these models don't need to be pushed to a |
29 // native model. | 29 // native model. |
30 GROUP_UI, // Models that live on UI thread and are being synced. | 30 GROUP_UI, // Models that live on UI thread and are being synced. |
31 GROUP_DB, // Models that live on DB thread and are being synced. | 31 GROUP_DB, // Models that live on DB thread and are being synced. |
32 GROUP_FILE, // Models that live on FILE thread and are being synced. | 32 GROUP_FILE, // Models that live on FILE thread and are being synced. |
33 GROUP_HISTORY, // Models that live on history thread and are being | 33 GROUP_HISTORY, // Models that live on history thread and are being |
34 // synced. | 34 // synced. |
(...skipping 10 matching lines...) Expand all Loading... |
45 // only knows how to do one thing, and that is take some work (in a fully | 45 // only knows how to do one thing, and that is take some work (in a fully |
46 // pre-bound callback) and have it performed (as in Run()) from a thread which | 46 // pre-bound callback) and have it performed (as in Run()) from a thread which |
47 // is guaranteed to be "model-safe", where "safe" refers to not allowing us to | 47 // is guaranteed to be "model-safe", where "safe" refers to not allowing us to |
48 // cause an embedding application model to fall out of sync with the | 48 // cause an embedding application model to fall out of sync with the |
49 // syncable::Directory due to a race. | 49 // syncable::Directory due to a race. |
50 class ModelSafeWorker : public base::RefCountedThreadSafe<ModelSafeWorker> { | 50 class ModelSafeWorker : public base::RefCountedThreadSafe<ModelSafeWorker> { |
51 public: | 51 public: |
52 // Any time the Syncer performs model modifications (e.g employing a | 52 // Any time the Syncer performs model modifications (e.g employing a |
53 // WriteTransaction), it should be done by this method to ensure it is done | 53 // WriteTransaction), it should be done by this method to ensure it is done |
54 // from a model-safe thread. | 54 // from a model-safe thread. |
55 virtual UnrecoverableErrorInfo DoWorkAndWaitUntilDone( | 55 virtual SyncerError DoWorkAndWaitUntilDone(const WorkCallback& work) = 0; |
56 const WorkCallback& work) = 0; | |
57 | 56 |
58 virtual ModelSafeGroup GetModelSafeGroup() = 0; | 57 virtual ModelSafeGroup GetModelSafeGroup() = 0; |
59 | 58 |
60 protected: | 59 protected: |
61 virtual ~ModelSafeWorker(); | 60 virtual ~ModelSafeWorker(); |
62 | 61 |
63 private: | 62 private: |
64 friend class base::RefCountedThreadSafe<ModelSafeWorker>; | 63 friend class base::RefCountedThreadSafe<ModelSafeWorker>; |
65 }; | 64 }; |
66 | 65 |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
104 virtual void GetModelSafeRoutingInfo(ModelSafeRoutingInfo* out) = 0; | 103 virtual void GetModelSafeRoutingInfo(ModelSafeRoutingInfo* out) = 0; |
105 protected: | 104 protected: |
106 virtual ~ModelSafeWorkerRegistrar() {} | 105 virtual ~ModelSafeWorkerRegistrar() {} |
107 private: | 106 private: |
108 DISALLOW_COPY_AND_ASSIGN(ModelSafeWorkerRegistrar); | 107 DISALLOW_COPY_AND_ASSIGN(ModelSafeWorkerRegistrar); |
109 }; | 108 }; |
110 | 109 |
111 } // namespace browser_sync | 110 } // namespace browser_sync |
112 | 111 |
113 #endif // CHROME_BROWSER_SYNC_ENGINE_MODEL_SAFE_WORKER_H_ | 112 #endif // CHROME_BROWSER_SYNC_ENGINE_MODEL_SAFE_WORKER_H_ |
OLD | NEW |