Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(163)

Side by Side Diff: components/sync/driver/glue/sync_backend_registrar.cc

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

Powered by Google App Engine
This is Rietveld 408576698