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

Side by Side Diff: components/sync_driver/glue/sync_backend_registrar.cc

Issue 1848793006: [Sync] Register USS types with ModelTypeRegistry before download (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix build. Created 4 years, 8 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 <cstddef> 7 #include <cstddef>
8 #include <utility> 8 #include <utility>
9 9
10 #include "base/compiler_specific.h" 10 #include "base/compiler_specific.h"
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
44 MaybeAddWorker(syncer::GROUP_UI); 44 MaybeAddWorker(syncer::GROUP_UI);
45 MaybeAddWorker(syncer::GROUP_PASSIVE); 45 MaybeAddWorker(syncer::GROUP_PASSIVE);
46 MaybeAddWorker(syncer::GROUP_HISTORY); 46 MaybeAddWorker(syncer::GROUP_HISTORY);
47 MaybeAddWorker(syncer::GROUP_PASSWORD); 47 MaybeAddWorker(syncer::GROUP_PASSWORD);
48 48
49 // Must have at least one worker for SyncBackendRegistrar to be destroyed 49 // Must have at least one worker for SyncBackendRegistrar to be destroyed
50 // correctly, as it is destroyed after the last worker dies. 50 // correctly, as it is destroyed after the last worker dies.
51 DCHECK_GT(workers_.size(), 0u); 51 DCHECK_GT(workers_.size(), 0u);
52 } 52 }
53 53
54 void SyncBackendRegistrar::RegisterNonBlockingType(syncer::ModelType type) {
55 DCHECK(routing_info_.find(type) == routing_info_.end() ||
56 routing_info_[type] == syncer::GROUP_NON_BLOCKING);
57 non_blocking_types_.Put(type);
58 }
59
54 void SyncBackendRegistrar::SetInitialTypes(syncer::ModelTypeSet initial_types) { 60 void SyncBackendRegistrar::SetInitialTypes(syncer::ModelTypeSet initial_types) {
55 base::AutoLock lock(lock_); 61 base::AutoLock lock(lock_);
56 62
57 // This function should be called only once, shortly after construction. The 63 // This function should be called only once, shortly after construction. The
58 // routing info at that point is expected to be empty. 64 // routing info at that point is expected to be empty.
59 DCHECK(routing_info_.empty()); 65 DCHECK(routing_info_.empty());
60 66
61 // Set our initial state to reflect the current status of the sync directory. 67 // Set our initial state to reflect the current status of the sync directory.
62 // This will ensure that our calculations in ConfigureDataTypes() will always 68 // This will ensure that our calculations in ConfigureDataTypes() will always
63 // return correct results. 69 // return correct results.
64 for (syncer::ModelTypeSet::Iterator it = initial_types.First(); it.Good(); 70 for (syncer::ModelTypeSet::Iterator it = initial_types.First(); it.Good();
65 it.Inc()) { 71 it.Inc()) {
66 routing_info_[it.Get()] = syncer::GROUP_PASSIVE; 72 routing_info_[it.Get()] = GetInitialGroupForType(it.Get());
67 } 73 }
68 74
69 if (!workers_.count(syncer::GROUP_HISTORY)) { 75 if (!workers_.count(syncer::GROUP_HISTORY)) {
70 LOG_IF(WARNING, initial_types.Has(syncer::TYPED_URLS)) 76 LOG_IF(WARNING, initial_types.Has(syncer::TYPED_URLS))
71 << "History store disabled, cannot sync Omnibox History"; 77 << "History store disabled, cannot sync Omnibox History";
72 routing_info_.erase(syncer::TYPED_URLS); 78 routing_info_.erase(syncer::TYPED_URLS);
73 } 79 }
74 80
75 if (!workers_.count(syncer::GROUP_PASSWORD)) { 81 if (!workers_.count(syncer::GROUP_PASSWORD)) {
76 LOG_IF(WARNING, initial_types.Has(syncer::PASSWORDS)) 82 LOG_IF(WARNING, initial_types.Has(syncer::PASSWORDS))
(...skipping 24 matching lines...) Expand all
101 filtered_types_to_add.Remove(syncer::PASSWORDS); 107 filtered_types_to_add.Remove(syncer::PASSWORDS);
102 } 108 }
103 109
104 base::AutoLock lock(lock_); 110 base::AutoLock lock(lock_);
105 syncer::ModelTypeSet newly_added_types; 111 syncer::ModelTypeSet newly_added_types;
106 for (syncer::ModelTypeSet::Iterator it = filtered_types_to_add.First(); 112 for (syncer::ModelTypeSet::Iterator it = filtered_types_to_add.First();
107 it.Good(); it.Inc()) { 113 it.Good(); it.Inc()) {
108 // Add a newly specified data type as syncer::GROUP_PASSIVE into the 114 // Add a newly specified data type as syncer::GROUP_PASSIVE into the
109 // routing_info, if it does not already exist. 115 // routing_info, if it does not already exist.
110 if (routing_info_.count(it.Get()) == 0) { 116 if (routing_info_.count(it.Get()) == 0) {
111 routing_info_[it.Get()] = syncer::GROUP_PASSIVE; 117 routing_info_[it.Get()] = GetInitialGroupForType(it.Get());
112 newly_added_types.Put(it.Get()); 118 newly_added_types.Put(it.Get());
113 } 119 }
114 } 120 }
115 for (syncer::ModelTypeSet::Iterator it = types_to_remove.First(); it.Good(); 121 for (syncer::ModelTypeSet::Iterator it = types_to_remove.First(); it.Good();
116 it.Inc()) { 122 it.Inc()) {
117 routing_info_.erase(it.Get()); 123 routing_info_.erase(it.Get());
118 } 124 }
119 125
120 // TODO(akalin): Use SVLOG/SLOG if we add any more logging. 126 // TODO(akalin): Use SVLOG/SLOG if we add any more logging.
121 DVLOG(1) << name_ << ": Adding types " 127 DVLOG(1) << name_ << ": Adding types "
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after
273 case syncer::GROUP_DB: 279 case syncer::GROUP_DB:
274 return db_thread_->BelongsToCurrentThread(); 280 return db_thread_->BelongsToCurrentThread();
275 case syncer::GROUP_FILE: 281 case syncer::GROUP_FILE:
276 return file_thread_->BelongsToCurrentThread(); 282 return file_thread_->BelongsToCurrentThread();
277 case syncer::GROUP_HISTORY: 283 case syncer::GROUP_HISTORY:
278 // TODO(sync): How to check we're on the right thread? 284 // TODO(sync): How to check we're on the right thread?
279 return type == syncer::TYPED_URLS; 285 return type == syncer::TYPED_URLS;
280 case syncer::GROUP_PASSWORD: 286 case syncer::GROUP_PASSWORD:
281 // TODO(sync): How to check we're on the right thread? 287 // TODO(sync): How to check we're on the right thread?
282 return type == syncer::PASSWORDS; 288 return type == syncer::PASSWORDS;
283 case syncer::MODEL_SAFE_GROUP_COUNT: 289 case syncer::GROUP_NON_BLOCKING:
284 default: 290 // IsOnThreadForGroup shouldn't be called for non-blocking types.
285 return false; 291 return false;
286 } 292 }
293 NOTREACHED();
294 return false;
287 } 295 }
288 296
289 SyncBackendRegistrar::~SyncBackendRegistrar() { 297 SyncBackendRegistrar::~SyncBackendRegistrar() {
290 DCHECK(workers_.empty()); 298 DCHECK(workers_.empty());
291 } 299 }
292 300
293 void SyncBackendRegistrar::OnWorkerLoopDestroyed(syncer::ModelSafeGroup group) { 301 void SyncBackendRegistrar::OnWorkerLoopDestroyed(syncer::ModelSafeGroup group) {
294 RemoveWorker(group); 302 RemoveWorker(group);
295 } 303 }
296 304
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
344 it->second->UnregisterForLoopDestruction( 352 it->second->UnregisterForLoopDestruction(
345 base::Bind(&SyncBackendRegistrar::OnWorkerUnregistrationDone, 353 base::Bind(&SyncBackendRegistrar::OnWorkerUnregistrationDone,
346 base::Unretained(this))); 354 base::Unretained(this)));
347 } 355 }
348 } 356 }
349 357
350 base::Thread* SyncBackendRegistrar::sync_thread() { 358 base::Thread* SyncBackendRegistrar::sync_thread() {
351 return sync_thread_.get(); 359 return sync_thread_.get();
352 } 360 }
353 361
362 syncer::ModelSafeGroup SyncBackendRegistrar::GetInitialGroupForType(
363 syncer::ModelType type) const {
364 if (non_blocking_types_.Has(type))
365 return syncer::GROUP_NON_BLOCKING;
366 else
367 return syncer::GROUP_PASSIVE;
368 }
369
354 } // namespace browser_sync 370 } // namespace browser_sync
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