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 #include "components/sync/driver/glue/sync_backend_registrar.h" | 5 #include "components/sync/driver/glue/sync_backend_registrar.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <cstddef> | 8 #include <cstddef> |
9 #include <utility> | 9 #include <utility> |
10 | 10 |
11 #include "base/logging.h" | 11 #include "base/logging.h" |
12 #include "base/message_loop/message_loop.h" | 12 #include "base/message_loop/message_loop.h" |
13 #include "components/sync/core/user_share.h" | 13 #include "components/sync/core/user_share.h" |
14 #include "components/sync/driver/change_processor.h" | 14 #include "components/sync/driver/change_processor.h" |
15 #include "components/sync/driver/sync_client.h" | 15 #include "components/sync/driver/sync_client.h" |
16 | 16 |
17 namespace syncer { | 17 using syncer::ModelSafeGroup; |
| 18 using syncer::ModelSafeRoutingInfo; |
| 19 using syncer::ModelType; |
| 20 using syncer::ModelTypeSet; |
| 21 |
| 22 namespace browser_sync { |
18 | 23 |
19 SyncBackendRegistrar::SyncBackendRegistrar( | 24 SyncBackendRegistrar::SyncBackendRegistrar( |
20 const std::string& name, | 25 const std::string& name, |
21 SyncClient* sync_client, | 26 sync_driver::SyncClient* sync_client, |
22 std::unique_ptr<base::Thread> sync_thread, | 27 std::unique_ptr<base::Thread> sync_thread, |
23 const scoped_refptr<base::SingleThreadTaskRunner>& ui_thread, | 28 const scoped_refptr<base::SingleThreadTaskRunner>& ui_thread, |
24 const scoped_refptr<base::SingleThreadTaskRunner>& db_thread, | 29 const scoped_refptr<base::SingleThreadTaskRunner>& db_thread, |
25 const scoped_refptr<base::SingleThreadTaskRunner>& file_thread) | 30 const scoped_refptr<base::SingleThreadTaskRunner>& file_thread) |
26 : name_(name), | 31 : name_(name), |
27 sync_client_(sync_client), | 32 sync_client_(sync_client), |
28 ui_thread_(ui_thread), | 33 ui_thread_(ui_thread), |
29 db_thread_(db_thread), | 34 db_thread_(db_thread), |
30 file_thread_(file_thread) { | 35 file_thread_(file_thread) { |
31 DCHECK(ui_thread_->BelongsToCurrentThread()); | 36 DCHECK(ui_thread_->BelongsToCurrentThread()); |
32 DCHECK(sync_client_); | 37 DCHECK(sync_client_); |
33 | 38 |
34 sync_thread_ = std::move(sync_thread); | 39 sync_thread_ = std::move(sync_thread); |
35 if (!sync_thread_) { | 40 if (!sync_thread_) { |
36 sync_thread_.reset(new base::Thread("Chrome_SyncThread")); | 41 sync_thread_.reset(new base::Thread("Chrome_SyncThread")); |
37 base::Thread::Options options; | 42 base::Thread::Options options; |
38 options.timer_slack = base::TIMER_SLACK_MAXIMUM; | 43 options.timer_slack = base::TIMER_SLACK_MAXIMUM; |
39 CHECK(sync_thread_->StartWithOptions(options)); | 44 CHECK(sync_thread_->StartWithOptions(options)); |
40 } | 45 } |
41 | 46 |
42 MaybeAddWorker(GROUP_DB); | 47 MaybeAddWorker(syncer::GROUP_DB); |
43 MaybeAddWorker(GROUP_FILE); | 48 MaybeAddWorker(syncer::GROUP_FILE); |
44 MaybeAddWorker(GROUP_UI); | 49 MaybeAddWorker(syncer::GROUP_UI); |
45 MaybeAddWorker(GROUP_PASSIVE); | 50 MaybeAddWorker(syncer::GROUP_PASSIVE); |
46 MaybeAddWorker(GROUP_HISTORY); | 51 MaybeAddWorker(syncer::GROUP_HISTORY); |
47 MaybeAddWorker(GROUP_PASSWORD); | 52 MaybeAddWorker(syncer::GROUP_PASSWORD); |
48 | 53 |
49 // Must have at least one worker for SyncBackendRegistrar to be destroyed | 54 // Must have at least one worker for SyncBackendRegistrar to be destroyed |
50 // correctly, as it is destroyed after the last worker dies. | 55 // correctly, as it is destroyed after the last worker dies. |
51 DCHECK_GT(workers_.size(), 0u); | 56 DCHECK_GT(workers_.size(), 0u); |
52 } | 57 } |
53 | 58 |
54 void SyncBackendRegistrar::RegisterNonBlockingType(ModelType type) { | 59 void SyncBackendRegistrar::RegisterNonBlockingType(ModelType type) { |
55 DCHECK(ui_thread_->BelongsToCurrentThread()); | 60 DCHECK(ui_thread_->BelongsToCurrentThread()); |
56 base::AutoLock lock(lock_); | 61 base::AutoLock lock(lock_); |
57 // There may have been a previously successful sync of a type when passive, | 62 // There may have been a previously successful sync of a type when passive, |
58 // which is now NonBlocking. We're not sure what order these two sets of types | 63 // which is now NonBlocking. We're not sure what order these two sets of types |
59 // are being registered in, so guard against SetInitialTypes(...) having been | 64 // are being registered in, so guard against SetInitialTypes(...) having been |
60 // already called by undoing everything to these types. | 65 // already called by undoing everything to these types. |
61 if (routing_info_.find(type) != routing_info_.end() && | 66 if (routing_info_.find(type) != routing_info_.end() && |
62 routing_info_[type] != GROUP_NON_BLOCKING) { | 67 routing_info_[type] != syncer::GROUP_NON_BLOCKING) { |
63 routing_info_.erase(type); | 68 routing_info_.erase(type); |
64 last_configured_types_.Remove(type); | 69 last_configured_types_.Remove(type); |
65 } | 70 } |
66 non_blocking_types_.Put(type); | 71 non_blocking_types_.Put(type); |
67 } | 72 } |
68 | 73 |
69 void SyncBackendRegistrar::SetInitialTypes(ModelTypeSet initial_types) { | 74 void SyncBackendRegistrar::SetInitialTypes(ModelTypeSet initial_types) { |
70 base::AutoLock lock(lock_); | 75 base::AutoLock lock(lock_); |
71 | 76 |
72 // This function should be called only once, shortly after construction. The | 77 // This function should be called only once, shortly after construction. The |
73 // routing info at that point is expected to be empty. | 78 // routing info at that point is expected to be empty. |
74 DCHECK(routing_info_.empty()); | 79 DCHECK(routing_info_.empty()); |
75 | 80 |
76 // Set our initial state to reflect the current status of the sync directory. | 81 // Set our initial state to reflect the current status of the sync directory. |
77 // This will ensure that our calculations in ConfigureDataTypes() will always | 82 // This will ensure that our calculations in ConfigureDataTypes() will always |
78 // return correct results. | 83 // return correct results. |
79 for (ModelTypeSet::Iterator it = initial_types.First(); it.Good(); it.Inc()) { | 84 for (ModelTypeSet::Iterator it = initial_types.First(); it.Good(); it.Inc()) { |
80 // If this type is also registered as NonBlocking, assume that it shouldn't | 85 // If this type is also registered as NonBlocking, assume that it shouldn't |
81 // be registered as passive. The NonBlocking path will eventually take care | 86 // be registered as passive. The NonBlocking path will eventually take care |
82 // of adding to routing_info_ later on. | 87 // of adding to routing_info_ later on. |
83 if (!non_blocking_types_.Has(it.Get())) { | 88 if (!non_blocking_types_.Has(it.Get())) { |
84 routing_info_[it.Get()] = GROUP_PASSIVE; | 89 routing_info_[it.Get()] = syncer::GROUP_PASSIVE; |
85 } | 90 } |
86 } | 91 } |
87 | 92 |
88 if (!workers_.count(GROUP_HISTORY)) { | 93 if (!workers_.count(syncer::GROUP_HISTORY)) { |
89 LOG_IF(WARNING, initial_types.Has(TYPED_URLS)) | 94 LOG_IF(WARNING, initial_types.Has(syncer::TYPED_URLS)) |
90 << "History store disabled, cannot sync Omnibox History"; | 95 << "History store disabled, cannot sync Omnibox History"; |
91 routing_info_.erase(TYPED_URLS); | 96 routing_info_.erase(syncer::TYPED_URLS); |
92 } | 97 } |
93 | 98 |
94 if (!workers_.count(GROUP_PASSWORD)) { | 99 if (!workers_.count(syncer::GROUP_PASSWORD)) { |
95 LOG_IF(WARNING, initial_types.Has(PASSWORDS)) | 100 LOG_IF(WARNING, initial_types.Has(syncer::PASSWORDS)) |
96 << "Password store not initialized, cannot sync passwords"; | 101 << "Password store not initialized, cannot sync passwords"; |
97 routing_info_.erase(PASSWORDS); | 102 routing_info_.erase(syncer::PASSWORDS); |
98 } | 103 } |
99 | 104 |
100 // Although this can re-set NonBlocking types, this should be idempotent. | 105 // Although this can re-set NonBlocking types, this should be idempotent. |
101 last_configured_types_ = GetRoutingInfoTypes(routing_info_); | 106 last_configured_types_ = syncer::GetRoutingInfoTypes(routing_info_); |
102 } | 107 } |
103 | 108 |
104 void SyncBackendRegistrar::AddRestoredNonBlockingType(ModelType type) { | 109 void SyncBackendRegistrar::AddRestoredNonBlockingType(ModelType type) { |
105 DCHECK(ui_thread_->BelongsToCurrentThread()); | 110 DCHECK(ui_thread_->BelongsToCurrentThread()); |
106 base::AutoLock lock(lock_); | 111 base::AutoLock lock(lock_); |
107 DCHECK(non_blocking_types_.Has(type)); | 112 DCHECK(non_blocking_types_.Has(type)); |
108 DCHECK(routing_info_.find(type) == routing_info_.end()); | 113 DCHECK(routing_info_.find(type) == routing_info_.end()); |
109 routing_info_[type] = GROUP_NON_BLOCKING; | 114 routing_info_[type] = syncer::GROUP_NON_BLOCKING; |
110 last_configured_types_.Put(type); | 115 last_configured_types_.Put(type); |
111 } | 116 } |
112 | 117 |
113 bool SyncBackendRegistrar::IsNigoriEnabled() const { | 118 bool SyncBackendRegistrar::IsNigoriEnabled() const { |
114 DCHECK(ui_thread_->BelongsToCurrentThread()); | 119 DCHECK(ui_thread_->BelongsToCurrentThread()); |
115 base::AutoLock lock(lock_); | 120 base::AutoLock lock(lock_); |
116 return routing_info_.find(NIGORI) != routing_info_.end(); | 121 return routing_info_.find(syncer::NIGORI) != routing_info_.end(); |
117 } | 122 } |
118 | 123 |
119 ModelTypeSet SyncBackendRegistrar::ConfigureDataTypes( | 124 ModelTypeSet SyncBackendRegistrar::ConfigureDataTypes( |
120 ModelTypeSet types_to_add, | 125 ModelTypeSet types_to_add, |
121 ModelTypeSet types_to_remove) { | 126 ModelTypeSet types_to_remove) { |
122 DCHECK(Intersection(types_to_add, types_to_remove).Empty()); | 127 DCHECK(Intersection(types_to_add, types_to_remove).Empty()); |
123 ModelTypeSet filtered_types_to_add = types_to_add; | 128 ModelTypeSet filtered_types_to_add = types_to_add; |
124 if (workers_.count(GROUP_HISTORY) == 0) { | 129 if (workers_.count(syncer::GROUP_HISTORY) == 0) { |
125 LOG(WARNING) << "No history worker -- removing TYPED_URLS"; | 130 LOG(WARNING) << "No history worker -- removing TYPED_URLS"; |
126 filtered_types_to_add.Remove(TYPED_URLS); | 131 filtered_types_to_add.Remove(syncer::TYPED_URLS); |
127 } | 132 } |
128 if (workers_.count(GROUP_PASSWORD) == 0) { | 133 if (workers_.count(syncer::GROUP_PASSWORD) == 0) { |
129 LOG(WARNING) << "No password worker -- removing PASSWORDS"; | 134 LOG(WARNING) << "No password worker -- removing PASSWORDS"; |
130 filtered_types_to_add.Remove(PASSWORDS); | 135 filtered_types_to_add.Remove(syncer::PASSWORDS); |
131 } | 136 } |
132 | 137 |
133 base::AutoLock lock(lock_); | 138 base::AutoLock lock(lock_); |
134 ModelTypeSet newly_added_types; | 139 ModelTypeSet newly_added_types; |
135 for (ModelTypeSet::Iterator it = filtered_types_to_add.First(); it.Good(); | 140 for (ModelTypeSet::Iterator it = filtered_types_to_add.First(); it.Good(); |
136 it.Inc()) { | 141 it.Inc()) { |
137 // Add a newly specified data type corresponding initial group into the | 142 // Add a newly specified data type corresponding initial group into the |
138 // routing_info, if it does not already exist. | 143 // routing_info, if it does not already exist. |
139 if (routing_info_.count(it.Get()) == 0) { | 144 if (routing_info_.count(it.Get()) == 0) { |
140 routing_info_[it.Get()] = GetInitialGroupForType(it.Get()); | 145 routing_info_[it.Get()] = GetInitialGroupForType(it.Get()); |
141 newly_added_types.Put(it.Get()); | 146 newly_added_types.Put(it.Get()); |
142 } | 147 } |
143 } | 148 } |
144 for (ModelTypeSet::Iterator it = types_to_remove.First(); it.Good(); | 149 for (ModelTypeSet::Iterator it = types_to_remove.First(); it.Good(); |
145 it.Inc()) { | 150 it.Inc()) { |
146 routing_info_.erase(it.Get()); | 151 routing_info_.erase(it.Get()); |
147 } | 152 } |
148 | 153 |
149 // TODO(akalin): Use SVLOG/SLOG if we add any more logging. | 154 // TODO(akalin): Use SVLOG/SLOG if we add any more logging. |
150 DVLOG(1) << name_ << ": Adding types " << ModelTypeSetToString(types_to_add) | 155 DVLOG(1) << name_ << ": Adding types " << ModelTypeSetToString(types_to_add) |
151 << " (with newly-added types " | 156 << " (with newly-added types " |
152 << ModelTypeSetToString(newly_added_types) << ") and removing types " | 157 << ModelTypeSetToString(newly_added_types) << ") and removing types " |
153 << ModelTypeSetToString(types_to_remove) | 158 << ModelTypeSetToString(types_to_remove) |
154 << " to get new routing info " | 159 << " to get new routing info " |
155 << ModelSafeRoutingInfoToString(routing_info_); | 160 << ModelSafeRoutingInfoToString(routing_info_); |
156 last_configured_types_ = GetRoutingInfoTypes(routing_info_); | 161 last_configured_types_ = syncer::GetRoutingInfoTypes(routing_info_); |
157 | 162 |
158 return newly_added_types; | 163 return newly_added_types; |
159 } | 164 } |
160 | 165 |
161 ModelTypeSet SyncBackendRegistrar::GetLastConfiguredTypes() const { | 166 ModelTypeSet SyncBackendRegistrar::GetLastConfiguredTypes() const { |
162 return last_configured_types_; | 167 return last_configured_types_; |
163 } | 168 } |
164 | 169 |
165 void SyncBackendRegistrar::RequestWorkerStopOnUIThread() { | 170 void SyncBackendRegistrar::RequestWorkerStopOnUIThread() { |
166 DCHECK(ui_thread_->BelongsToCurrentThread()); | 171 DCHECK(ui_thread_->BelongsToCurrentThread()); |
167 base::AutoLock lock(lock_); | 172 base::AutoLock lock(lock_); |
168 for (WorkerMap::const_iterator it = workers_.begin(); it != workers_.end(); | 173 for (WorkerMap::const_iterator it = workers_.begin(); it != workers_.end(); |
169 ++it) { | 174 ++it) { |
170 it->second->RequestStop(); | 175 it->second->RequestStop(); |
171 } | 176 } |
172 } | 177 } |
173 | 178 |
174 void SyncBackendRegistrar::ActivateDataType(ModelType type, | 179 void SyncBackendRegistrar::ActivateDataType( |
175 ModelSafeGroup group, | 180 ModelType type, |
176 ChangeProcessor* change_processor, | 181 ModelSafeGroup group, |
177 UserShare* user_share) { | 182 sync_driver::ChangeProcessor* change_processor, |
| 183 syncer::UserShare* user_share) { |
178 DVLOG(1) << "Activate: " << ModelTypeToString(type); | 184 DVLOG(1) << "Activate: " << ModelTypeToString(type); |
179 | 185 |
180 base::AutoLock lock(lock_); | 186 base::AutoLock lock(lock_); |
181 // Ensure that the given data type is in the PASSIVE group. | 187 // Ensure that the given data type is in the PASSIVE group. |
182 ModelSafeRoutingInfo::iterator i = routing_info_.find(type); | 188 ModelSafeRoutingInfo::iterator i = routing_info_.find(type); |
183 DCHECK(i != routing_info_.end()); | 189 DCHECK(i != routing_info_.end()); |
184 DCHECK_EQ(i->second, GROUP_PASSIVE); | 190 DCHECK_EQ(i->second, syncer::GROUP_PASSIVE); |
185 routing_info_[type] = group; | 191 routing_info_[type] = group; |
186 | 192 |
187 // Add the data type's change processor to the list of change | 193 // Add the data type's change processor to the list of change |
188 // processors so it can receive updates. | 194 // processors so it can receive updates. |
189 DCHECK_EQ(processors_.count(type), 0U); | 195 DCHECK_EQ(processors_.count(type), 0U); |
190 processors_[type] = change_processor; | 196 processors_[type] = change_processor; |
191 | 197 |
192 // Start the change processor. | 198 // Start the change processor. |
193 change_processor->Start(user_share); | 199 change_processor->Start(user_share); |
194 DCHECK(GetProcessorUnsafe(type)); | 200 DCHECK(GetProcessorUnsafe(type)); |
(...skipping 10 matching lines...) Expand all Loading... |
205 DCHECK(!GetProcessorUnsafe(type)); | 211 DCHECK(!GetProcessorUnsafe(type)); |
206 } | 212 } |
207 | 213 |
208 bool SyncBackendRegistrar::IsTypeActivatedForTest(ModelType type) const { | 214 bool SyncBackendRegistrar::IsTypeActivatedForTest(ModelType type) const { |
209 return GetProcessor(type) != NULL; | 215 return GetProcessor(type) != NULL; |
210 } | 216 } |
211 | 217 |
212 void SyncBackendRegistrar::OnChangesApplied( | 218 void SyncBackendRegistrar::OnChangesApplied( |
213 ModelType model_type, | 219 ModelType model_type, |
214 int64_t model_version, | 220 int64_t model_version, |
215 const BaseTransaction* trans, | 221 const syncer::BaseTransaction* trans, |
216 const ImmutableChangeRecordList& changes) { | 222 const syncer::ImmutableChangeRecordList& changes) { |
217 ChangeProcessor* processor = GetProcessor(model_type); | 223 sync_driver::ChangeProcessor* processor = GetProcessor(model_type); |
218 if (!processor) | 224 if (!processor) |
219 return; | 225 return; |
220 | 226 |
221 processor->ApplyChangesFromSyncModel(trans, model_version, changes); | 227 processor->ApplyChangesFromSyncModel(trans, model_version, changes); |
222 } | 228 } |
223 | 229 |
224 void SyncBackendRegistrar::OnChangesComplete(ModelType model_type) { | 230 void SyncBackendRegistrar::OnChangesComplete(ModelType model_type) { |
225 ChangeProcessor* processor = GetProcessor(model_type); | 231 sync_driver::ChangeProcessor* processor = GetProcessor(model_type); |
226 if (!processor) | 232 if (!processor) |
227 return; | 233 return; |
228 | 234 |
229 // This call just notifies the processor that it can commit; it | 235 // This call just notifies the processor that it can commit; it |
230 // already buffered any changes it plans to makes so needs no | 236 // already buffered any changes it plans to makes so needs no |
231 // further information. | 237 // further information. |
232 processor->CommitChangesFromSyncModel(); | 238 processor->CommitChangesFromSyncModel(); |
233 } | 239 } |
234 | 240 |
235 void SyncBackendRegistrar::GetWorkers( | 241 void SyncBackendRegistrar::GetWorkers( |
236 std::vector<scoped_refptr<ModelSafeWorker>>* out) { | 242 std::vector<scoped_refptr<syncer::ModelSafeWorker>>* out) { |
237 base::AutoLock lock(lock_); | 243 base::AutoLock lock(lock_); |
238 out->clear(); | 244 out->clear(); |
239 for (WorkerMap::const_iterator it = workers_.begin(); it != workers_.end(); | 245 for (WorkerMap::const_iterator it = workers_.begin(); it != workers_.end(); |
240 ++it) { | 246 ++it) { |
241 out->push_back(it->second.get()); | 247 out->push_back(it->second.get()); |
242 } | 248 } |
243 } | 249 } |
244 | 250 |
245 void SyncBackendRegistrar::GetModelSafeRoutingInfo(ModelSafeRoutingInfo* out) { | 251 void SyncBackendRegistrar::GetModelSafeRoutingInfo(ModelSafeRoutingInfo* out) { |
246 base::AutoLock lock(lock_); | 252 base::AutoLock lock(lock_); |
247 ModelSafeRoutingInfo copy(routing_info_); | 253 ModelSafeRoutingInfo copy(routing_info_); |
248 out->swap(copy); | 254 out->swap(copy); |
249 } | 255 } |
250 | 256 |
251 ChangeProcessor* SyncBackendRegistrar::GetProcessor(ModelType type) const { | 257 sync_driver::ChangeProcessor* SyncBackendRegistrar::GetProcessor( |
| 258 ModelType type) const { |
252 base::AutoLock lock(lock_); | 259 base::AutoLock lock(lock_); |
253 ChangeProcessor* processor = GetProcessorUnsafe(type); | 260 sync_driver::ChangeProcessor* processor = GetProcessorUnsafe(type); |
254 if (!processor) | 261 if (!processor) |
255 return NULL; | 262 return NULL; |
256 | 263 |
257 // We can only check if |processor| exists, as otherwise the type is | 264 // We can only check if |processor| exists, as otherwise the type is |
258 // mapped to GROUP_PASSIVE. | 265 // mapped to syncer::GROUP_PASSIVE. |
259 CHECK(IsCurrentThreadSafeForModel(type)); | 266 CHECK(IsCurrentThreadSafeForModel(type)); |
260 return processor; | 267 return processor; |
261 } | 268 } |
262 | 269 |
263 ChangeProcessor* SyncBackendRegistrar::GetProcessorUnsafe( | 270 sync_driver::ChangeProcessor* SyncBackendRegistrar::GetProcessorUnsafe( |
264 ModelType type) const { | 271 ModelType type) const { |
265 lock_.AssertAcquired(); | 272 lock_.AssertAcquired(); |
266 std::map<ModelType, ChangeProcessor*>::const_iterator it = | 273 std::map<ModelType, sync_driver::ChangeProcessor*>::const_iterator it = |
267 processors_.find(type); | 274 processors_.find(type); |
268 | 275 |
269 // Until model association happens for a datatype, it will not | 276 // Until model association happens for a datatype, it will not |
270 // appear in the processors list. During this time, it is OK to | 277 // appear in the processors list. During this time, it is OK to |
271 // drop changes on the floor (since model association has not | 278 // drop changes on the floor (since model association has not |
272 // happened yet). When the data type is activated, model | 279 // happened yet). When the data type is activated, model |
273 // association takes place then the change processor is added to the | 280 // association takes place then the change processor is added to the |
274 // |processors_| list. | 281 // |processors_| list. |
275 if (it == processors_.end()) | 282 if (it == processors_.end()) |
276 return NULL; | 283 return NULL; |
277 | 284 |
278 return it->second; | 285 return it->second; |
279 } | 286 } |
280 | 287 |
281 bool SyncBackendRegistrar::IsCurrentThreadSafeForModel( | 288 bool SyncBackendRegistrar::IsCurrentThreadSafeForModel( |
282 ModelType model_type) const { | 289 ModelType model_type) const { |
283 lock_.AssertAcquired(); | 290 lock_.AssertAcquired(); |
284 return IsOnThreadForGroup(model_type, | 291 return IsOnThreadForGroup(model_type, |
285 GetGroupForModelType(model_type, routing_info_)); | 292 GetGroupForModelType(model_type, routing_info_)); |
286 } | 293 } |
287 | 294 |
288 bool SyncBackendRegistrar::IsOnThreadForGroup(ModelType type, | 295 bool SyncBackendRegistrar::IsOnThreadForGroup(ModelType type, |
289 ModelSafeGroup group) const { | 296 ModelSafeGroup group) const { |
290 switch (group) { | 297 switch (group) { |
291 case GROUP_PASSIVE: | 298 case syncer::GROUP_PASSIVE: |
292 return IsControlType(type); | 299 return IsControlType(type); |
293 case GROUP_UI: | 300 case syncer::GROUP_UI: |
294 return ui_thread_->BelongsToCurrentThread(); | 301 return ui_thread_->BelongsToCurrentThread(); |
295 case GROUP_DB: | 302 case syncer::GROUP_DB: |
296 return db_thread_->BelongsToCurrentThread(); | 303 return db_thread_->BelongsToCurrentThread(); |
297 case GROUP_FILE: | 304 case syncer::GROUP_FILE: |
298 return file_thread_->BelongsToCurrentThread(); | 305 return file_thread_->BelongsToCurrentThread(); |
299 case GROUP_HISTORY: | 306 case syncer::GROUP_HISTORY: |
300 // TODO(sync): How to check we're on the right thread? | 307 // TODO(sync): How to check we're on the right thread? |
301 return type == TYPED_URLS; | 308 return type == syncer::TYPED_URLS; |
302 case GROUP_PASSWORD: | 309 case syncer::GROUP_PASSWORD: |
303 // TODO(sync): How to check we're on the right thread? | 310 // TODO(sync): How to check we're on the right thread? |
304 return type == PASSWORDS; | 311 return type == syncer::PASSWORDS; |
305 case GROUP_NON_BLOCKING: | 312 case syncer::GROUP_NON_BLOCKING: |
306 // IsOnThreadForGroup shouldn't be called for non-blocking types. | 313 // IsOnThreadForGroup shouldn't be called for non-blocking types. |
307 return false; | 314 return false; |
308 } | 315 } |
309 NOTREACHED(); | 316 NOTREACHED(); |
310 return false; | 317 return false; |
311 } | 318 } |
312 | 319 |
313 SyncBackendRegistrar::~SyncBackendRegistrar() { | 320 SyncBackendRegistrar::~SyncBackendRegistrar() { |
314 DCHECK(workers_.empty()); | 321 DCHECK(workers_.empty()); |
315 } | 322 } |
316 | 323 |
317 void SyncBackendRegistrar::OnWorkerLoopDestroyed(ModelSafeGroup group) { | 324 void SyncBackendRegistrar::OnWorkerLoopDestroyed(ModelSafeGroup group) { |
318 RemoveWorker(group); | 325 RemoveWorker(group); |
319 } | 326 } |
320 | 327 |
321 void SyncBackendRegistrar::MaybeAddWorker(ModelSafeGroup group) { | 328 void SyncBackendRegistrar::MaybeAddWorker(ModelSafeGroup group) { |
322 const scoped_refptr<ModelSafeWorker> worker = | 329 const scoped_refptr<syncer::ModelSafeWorker> worker = |
323 sync_client_->CreateModelWorkerForGroup(group, this); | 330 sync_client_->CreateModelWorkerForGroup(group, this); |
324 if (worker) { | 331 if (worker) { |
325 DCHECK(workers_.find(group) == workers_.end()); | 332 DCHECK(workers_.find(group) == workers_.end()); |
326 workers_[group] = worker; | 333 workers_[group] = worker; |
327 workers_[group]->RegisterForLoopDestruction(); | 334 workers_[group]->RegisterForLoopDestruction(); |
328 } | 335 } |
329 } | 336 } |
330 | 337 |
331 void SyncBackendRegistrar::OnWorkerUnregistrationDone(ModelSafeGroup group) { | 338 void SyncBackendRegistrar::OnWorkerUnregistrationDone(ModelSafeGroup group) { |
332 RemoveWorker(group); | 339 RemoveWorker(group); |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
369 base::Unretained(this))); | 376 base::Unretained(this))); |
370 } | 377 } |
371 } | 378 } |
372 | 379 |
373 base::Thread* SyncBackendRegistrar::sync_thread() { | 380 base::Thread* SyncBackendRegistrar::sync_thread() { |
374 return sync_thread_.get(); | 381 return sync_thread_.get(); |
375 } | 382 } |
376 | 383 |
377 ModelSafeGroup SyncBackendRegistrar::GetInitialGroupForType( | 384 ModelSafeGroup SyncBackendRegistrar::GetInitialGroupForType( |
378 ModelType type) const { | 385 ModelType type) const { |
379 return non_blocking_types_.Has(type) ? GROUP_NON_BLOCKING : GROUP_PASSIVE; | 386 return non_blocking_types_.Has(type) ? syncer::GROUP_NON_BLOCKING |
| 387 : syncer::GROUP_PASSIVE; |
380 } | 388 } |
381 | 389 |
382 } // namespace syncer | 390 } // namespace browser_sync |
OLD | NEW |