OLD | NEW |
1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 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 COMPONENTS_SYNC_ENGINE_MODEL_SAFE_WORKER_H_ | 5 #ifndef COMPONENTS_SYNC_ENGINE_MODEL_SAFE_WORKER_H_ |
6 #define COMPONENTS_SYNC_ENGINE_MODEL_SAFE_WORKER_H_ | 6 #define COMPONENTS_SYNC_ENGINE_MODEL_SAFE_WORKER_H_ |
7 | 7 |
8 #include <map> | 8 #include <map> |
9 #include <memory> | 9 #include <memory> |
10 #include <string> | 10 #include <string> |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
55 class ModelSafeWorker : public base::RefCountedThreadSafe<ModelSafeWorker> { | 55 class ModelSafeWorker : public base::RefCountedThreadSafe<ModelSafeWorker> { |
56 public: | 56 public: |
57 // If not stopped, call DoWorkAndWaitUntilDoneImpl() to do work. Otherwise | 57 // If not stopped, call DoWorkAndWaitUntilDoneImpl() to do work. Otherwise |
58 // return CANNOT_DO_WORK. | 58 // return CANNOT_DO_WORK. |
59 SyncerError DoWorkAndWaitUntilDone(const WorkCallback& work); | 59 SyncerError DoWorkAndWaitUntilDone(const WorkCallback& work); |
60 | 60 |
61 // Soft stop worker by setting stopped_ flag. Called when sync is disabled | 61 // Soft stop worker by setting stopped_ flag. Called when sync is disabled |
62 // or browser is shutting down. Called on UI loop. | 62 // or browser is shutting down. Called on UI loop. |
63 virtual void RequestStop(); | 63 virtual void RequestStop(); |
64 | 64 |
| 65 // Return true if the worker was stopped. Thread safe. |
| 66 bool IsStopped(); |
| 67 |
65 virtual ModelSafeGroup GetModelSafeGroup() = 0; | 68 virtual ModelSafeGroup GetModelSafeGroup() = 0; |
66 | 69 |
67 // Returns true if called on the thread this worker works on. | 70 // Returns true if called on the thread this worker works on. |
68 virtual bool IsOnModelThread() = 0; | 71 virtual bool IsOnModelThread() = 0; |
69 | 72 |
70 protected: | 73 protected: |
71 ModelSafeWorker(); | 74 ModelSafeWorker(); |
72 virtual ~ModelSafeWorker(); | 75 virtual ~ModelSafeWorker(); |
73 | 76 |
74 // Any time the Syncer performs model modifications (e.g employing a | 77 // Any time the Syncer performs model modifications (e.g employing a |
75 // WriteTransaction), it should be done by this method to ensure it is done | 78 // WriteTransaction), it should be done by this method to ensure it is done |
76 // from a model-safe thread. | 79 // from a model-safe thread. |
77 virtual SyncerError DoWorkAndWaitUntilDoneImpl(const WorkCallback& work) = 0; | 80 virtual SyncerError DoWorkAndWaitUntilDoneImpl(const WorkCallback& work) = 0; |
78 | 81 |
79 // Return true if the worker was stopped. Thread safe. | |
80 bool IsStopped(); | |
81 | |
82 private: | 82 private: |
83 friend class base::RefCountedThreadSafe<ModelSafeWorker>; | 83 friend class base::RefCountedThreadSafe<ModelSafeWorker>; |
84 | 84 |
85 // Whether the worker should do more work. Set when sync is disabled. | 85 // Whether the worker should do more work. Set when sync is disabled. |
86 base::AtomicFlag stopped_; | 86 base::AtomicFlag stopped_; |
87 | 87 |
88 DISALLOW_COPY_AND_ASSIGN(ModelSafeWorker); | 88 DISALLOW_COPY_AND_ASSIGN(ModelSafeWorker); |
89 }; | 89 }; |
90 | 90 |
91 // A map that details which ModelSafeGroup each ModelType | 91 // A map that details which ModelSafeGroup each ModelType |
92 // belongs to. Routing info can change in response to the user enabling / | 92 // belongs to. Routing info can change in response to the user enabling / |
93 // disabling sync for certain types, as well as model association completions. | 93 // disabling sync for certain types, as well as model association completions. |
94 typedef std::map<ModelType, ModelSafeGroup> ModelSafeRoutingInfo; | 94 typedef std::map<ModelType, ModelSafeGroup> ModelSafeRoutingInfo; |
95 | 95 |
96 // Caller takes ownership of return value. | 96 // Caller takes ownership of return value. |
97 std::unique_ptr<base::DictionaryValue> ModelSafeRoutingInfoToValue( | 97 std::unique_ptr<base::DictionaryValue> ModelSafeRoutingInfoToValue( |
98 const ModelSafeRoutingInfo& routing_info); | 98 const ModelSafeRoutingInfo& routing_info); |
99 | 99 |
100 std::string ModelSafeRoutingInfoToString( | 100 std::string ModelSafeRoutingInfoToString( |
101 const ModelSafeRoutingInfo& routing_info); | 101 const ModelSafeRoutingInfo& routing_info); |
102 | 102 |
103 ModelTypeSet GetRoutingInfoTypes(const ModelSafeRoutingInfo& routing_info); | 103 ModelTypeSet GetRoutingInfoTypes(const ModelSafeRoutingInfo& routing_info); |
104 | 104 |
105 ModelSafeGroup GetGroupForModelType(const ModelType type, | 105 ModelSafeGroup GetGroupForModelType(const ModelType type, |
106 const ModelSafeRoutingInfo& routes); | 106 const ModelSafeRoutingInfo& routes); |
107 | 107 |
108 } // namespace syncer | 108 } // namespace syncer |
109 | 109 |
110 #endif // COMPONENTS_SYNC_ENGINE_MODEL_SAFE_WORKER_H_ | 110 #endif // COMPONENTS_SYNC_ENGINE_MODEL_SAFE_WORKER_H_ |
OLD | NEW |