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 SYNC_INTERNAL_API_PUBLIC_ENGINE_MODEL_SAFE_WORKER_H_ | 5 #ifndef COMPONENTS_SYNC_ENGINE_MODEL_SAFE_WORKER_H_ |
6 #define SYNC_INTERNAL_API_PUBLIC_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> |
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 "base/message_loop/message_loop.h" | 15 #include "base/message_loop/message_loop.h" |
16 #include "base/single_thread_task_runner.h" | 16 #include "base/single_thread_task_runner.h" |
17 #include "base/synchronization/lock.h" | 17 #include "base/synchronization/lock.h" |
18 #include "base/synchronization/waitable_event.h" | 18 #include "base/synchronization/waitable_event.h" |
19 #include "sync/base/sync_export.h" | 19 #include "components/sync/base/model_type.h" |
20 #include "sync/internal_api/public/base/model_type.h" | 20 #include "components/sync/base/sync_export.h" |
21 #include "sync/internal_api/public/util/syncer_error.h" | 21 #include "components/sync/base/syncer_error.h" |
22 | 22 |
23 namespace base { | 23 namespace base { |
24 class DictionaryValue; | 24 class DictionaryValue; |
25 } // namespace base | 25 } // namespace base |
26 | 26 |
27 namespace syncer { | 27 namespace syncer { |
28 | 28 |
29 // TODO(akalin): Move the non-exported functions in this file to a | 29 // TODO(akalin): Move the non-exported functions in this file to a |
30 // private header. | 30 // private header. |
31 | 31 |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
98 | 98 |
99 protected: | 99 protected: |
100 explicit ModelSafeWorker(WorkerLoopDestructionObserver* observer); | 100 explicit ModelSafeWorker(WorkerLoopDestructionObserver* observer); |
101 ~ModelSafeWorker() override; | 101 ~ModelSafeWorker() override; |
102 | 102 |
103 // Any time the Syncer performs model modifications (e.g employing a | 103 // Any time the Syncer performs model modifications (e.g employing a |
104 // WriteTransaction), it should be done by this method to ensure it is done | 104 // WriteTransaction), it should be done by this method to ensure it is done |
105 // from a model-safe thread. | 105 // from a model-safe thread. |
106 virtual SyncerError DoWorkAndWaitUntilDoneImpl(const WorkCallback& work) = 0; | 106 virtual SyncerError DoWorkAndWaitUntilDoneImpl(const WorkCallback& work) = 0; |
107 | 107 |
108 base::WaitableEvent* work_done_or_stopped() { | 108 base::WaitableEvent* work_done_or_stopped() { return &work_done_or_stopped_; } |
109 return &work_done_or_stopped_; | |
110 } | |
111 | 109 |
112 // Return true if the worker was stopped. Thread safe. | 110 // Return true if the worker was stopped. Thread safe. |
113 bool IsStopped(); | 111 bool IsStopped(); |
114 | 112 |
115 // Subclass should call this in RegisterForLoopDestruction() from the loop | 113 // Subclass should call this in RegisterForLoopDestruction() from the loop |
116 // where work is done. | 114 // where work is done. |
117 void SetWorkingLoopToCurrent(); | 115 void SetWorkingLoopToCurrent(); |
118 | 116 |
119 private: | 117 private: |
120 friend class base::RefCountedThreadSafe<ModelSafeWorker>; | 118 friend class base::RefCountedThreadSafe<ModelSafeWorker>; |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
152 // disabling sync for certain types, as well as model association completions. | 150 // disabling sync for certain types, as well as model association completions. |
153 typedef std::map<ModelType, ModelSafeGroup> ModelSafeRoutingInfo; | 151 typedef std::map<ModelType, ModelSafeGroup> ModelSafeRoutingInfo; |
154 | 152 |
155 // Caller takes ownership of return value. | 153 // Caller takes ownership of return value. |
156 SYNC_EXPORT std::unique_ptr<base::DictionaryValue> ModelSafeRoutingInfoToValue( | 154 SYNC_EXPORT std::unique_ptr<base::DictionaryValue> ModelSafeRoutingInfoToValue( |
157 const ModelSafeRoutingInfo& routing_info); | 155 const ModelSafeRoutingInfo& routing_info); |
158 | 156 |
159 SYNC_EXPORT std::string ModelSafeRoutingInfoToString( | 157 SYNC_EXPORT std::string ModelSafeRoutingInfoToString( |
160 const ModelSafeRoutingInfo& routing_info); | 158 const ModelSafeRoutingInfo& routing_info); |
161 | 159 |
162 SYNC_EXPORT ModelTypeSet GetRoutingInfoTypes( | 160 SYNC_EXPORT ModelTypeSet |
163 const ModelSafeRoutingInfo& routing_info); | 161 GetRoutingInfoTypes(const ModelSafeRoutingInfo& routing_info); |
164 | 162 |
165 SYNC_EXPORT ModelSafeGroup GetGroupForModelType( | 163 SYNC_EXPORT ModelSafeGroup |
166 const ModelType type, | 164 GetGroupForModelType(const ModelType type, const ModelSafeRoutingInfo& routes); |
167 const ModelSafeRoutingInfo& routes); | |
168 | 165 |
169 } // namespace syncer | 166 } // namespace syncer |
170 | 167 |
171 #endif // SYNC_INTERNAL_API_PUBLIC_ENGINE_MODEL_SAFE_WORKER_H_ | 168 #endif // COMPONENTS_SYNC_ENGINE_MODEL_SAFE_WORKER_H_ |
OLD | NEW |