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> |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
43 | 43 |
44 // The Syncer uses a ModelSafeWorker for all tasks that could potentially | 44 // The Syncer uses a ModelSafeWorker for all tasks that could potentially |
45 // modify syncable entries (e.g under a WriteTransaction). The ModelSafeWorker | 45 // modify syncable entries (e.g under a WriteTransaction). The ModelSafeWorker |
46 // only knows how to do one thing, and that is take some work (in a fully | 46 // only knows how to do one thing, and that is take some work (in a fully |
47 // pre-bound callback) and have it performed (as in Run()) from a thread which | 47 // pre-bound callback) and have it performed (as in Run()) from a thread which |
48 // is guaranteed to be "model-safe", where "safe" refers to not allowing us to | 48 // is guaranteed to be "model-safe", where "safe" refers to not allowing us to |
49 // cause an embedding application model to fall out of sync with the | 49 // cause an embedding application model to fall out of sync with the |
50 // syncable::Directory due to a race. | 50 // syncable::Directory due to a race. |
51 class ModelSafeWorker : public base::RefCountedThreadSafe<ModelSafeWorker> { | 51 class ModelSafeWorker : public base::RefCountedThreadSafe<ModelSafeWorker> { |
52 public: | 52 public: |
53 ModelSafeWorker(); | |
54 virtual ~ModelSafeWorker(); | |
55 | |
56 // Any time the Syncer performs model modifications (e.g employing a | 53 // Any time the Syncer performs model modifications (e.g employing a |
57 // WriteTransaction), it should be done by this method to ensure it is done | 54 // WriteTransaction), it should be done by this method to ensure it is done |
58 // from a model-safe thread. | 55 // from a model-safe thread. |
59 virtual UnrecoverableErrorInfo DoWorkAndWaitUntilDone( | 56 virtual UnrecoverableErrorInfo DoWorkAndWaitUntilDone( |
60 const WorkCallback& work); | 57 const WorkCallback& work) = 0; |
61 | 58 |
62 virtual ModelSafeGroup GetModelSafeGroup(); | 59 virtual ModelSafeGroup GetModelSafeGroup() = 0; |
| 60 |
| 61 protected: |
| 62 virtual ~ModelSafeWorker(); |
63 | 63 |
64 private: | 64 private: |
65 friend class base::RefCountedThreadSafe<ModelSafeWorker>; | 65 friend class base::RefCountedThreadSafe<ModelSafeWorker>; |
66 | |
67 DISALLOW_COPY_AND_ASSIGN(ModelSafeWorker); | |
68 }; | 66 }; |
69 | 67 |
70 // A map that details which ModelSafeGroup each syncable::ModelType | 68 // A map that details which ModelSafeGroup each syncable::ModelType |
71 // belongs to. Routing info can change in response to the user enabling / | 69 // belongs to. Routing info can change in response to the user enabling / |
72 // disabling sync for certain types, as well as model association completions. | 70 // disabling sync for certain types, as well as model association completions. |
73 typedef std::map<syncable::ModelType, ModelSafeGroup> | 71 typedef std::map<syncable::ModelType, ModelSafeGroup> |
74 ModelSafeRoutingInfo; | 72 ModelSafeRoutingInfo; |
75 | 73 |
76 // Caller takes ownership of return value. | 74 // Caller takes ownership of return value. |
77 base::DictionaryValue* ModelSafeRoutingInfoToValue( | 75 base::DictionaryValue* ModelSafeRoutingInfoToValue( |
(...skipping 29 matching lines...) Expand all Loading... |
107 virtual void GetModelSafeRoutingInfo(ModelSafeRoutingInfo* out) = 0; | 105 virtual void GetModelSafeRoutingInfo(ModelSafeRoutingInfo* out) = 0; |
108 protected: | 106 protected: |
109 virtual ~ModelSafeWorkerRegistrar() {} | 107 virtual ~ModelSafeWorkerRegistrar() {} |
110 private: | 108 private: |
111 DISALLOW_COPY_AND_ASSIGN(ModelSafeWorkerRegistrar); | 109 DISALLOW_COPY_AND_ASSIGN(ModelSafeWorkerRegistrar); |
112 }; | 110 }; |
113 | 111 |
114 } // namespace browser_sync | 112 } // namespace browser_sync |
115 | 113 |
116 #endif // CHROME_BROWSER_SYNC_ENGINE_MODEL_SAFE_WORKER_H_ | 114 #endif // CHROME_BROWSER_SYNC_ENGINE_MODEL_SAFE_WORKER_H_ |
OLD | NEW |