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

Side by Side Diff: chrome/browser/sync/glue/sync_backend_registrar.cc

Issue 10698014: [Sync] Rename csync namespace to syncer (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Address comments Created 8 years, 5 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 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 "chrome/browser/sync/glue/sync_backend_registrar.h" 5 #include "chrome/browser/sync/glue/sync_backend_registrar.h"
6 6
7 #include <cstddef> 7 #include <cstddef>
8 8
9 #include "base/compiler_specific.h" 9 #include "base/compiler_specific.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
(...skipping 10 matching lines...) Expand all
21 #include "sync/internal_api/public/engine/passive_model_worker.h" 21 #include "sync/internal_api/public/engine/passive_model_worker.h"
22 22
23 using content::BrowserThread; 23 using content::BrowserThread;
24 24
25 namespace browser_sync { 25 namespace browser_sync {
26 26
27 namespace { 27 namespace {
28 28
29 // Returns true if the current thread is the native thread for the 29 // Returns true if the current thread is the native thread for the
30 // given group (or if it is undeterminable). 30 // given group (or if it is undeterminable).
31 bool IsOnThreadForGroup(csync::ModelSafeGroup group) { 31 bool IsOnThreadForGroup(syncer::ModelSafeGroup group) {
32 switch (group) { 32 switch (group) {
33 case csync::GROUP_PASSIVE: 33 case syncer::GROUP_PASSIVE:
34 return false; 34 return false;
35 case csync::GROUP_UI: 35 case syncer::GROUP_UI:
36 return BrowserThread::CurrentlyOn(BrowserThread::UI); 36 return BrowserThread::CurrentlyOn(BrowserThread::UI);
37 case csync::GROUP_DB: 37 case syncer::GROUP_DB:
38 return BrowserThread::CurrentlyOn(BrowserThread::DB); 38 return BrowserThread::CurrentlyOn(BrowserThread::DB);
39 case csync::GROUP_FILE: 39 case syncer::GROUP_FILE:
40 return BrowserThread::CurrentlyOn(BrowserThread::FILE); 40 return BrowserThread::CurrentlyOn(BrowserThread::FILE);
41 case csync::GROUP_HISTORY: 41 case syncer::GROUP_HISTORY:
42 // TODO(ncarter): How to determine this? 42 // TODO(ncarter): How to determine this?
43 return true; 43 return true;
44 case csync::GROUP_PASSWORD: 44 case syncer::GROUP_PASSWORD:
45 // TODO(ncarter): How to determine this? 45 // TODO(ncarter): How to determine this?
46 return true; 46 return true;
47 case csync::MODEL_SAFE_GROUP_COUNT: 47 case syncer::MODEL_SAFE_GROUP_COUNT:
48 default: 48 default:
49 return false; 49 return false;
50 } 50 }
51 } 51 }
52 52
53 } // namespace 53 } // namespace
54 54
55 SyncBackendRegistrar::SyncBackendRegistrar( 55 SyncBackendRegistrar::SyncBackendRegistrar(
56 syncable::ModelTypeSet initial_types, 56 syncable::ModelTypeSet initial_types,
57 const std::string& name, Profile* profile, 57 const std::string& name, Profile* profile,
58 MessageLoop* sync_loop) : 58 MessageLoop* sync_loop) :
59 name_(name), 59 name_(name),
60 profile_(profile), 60 profile_(profile),
61 sync_loop_(sync_loop), 61 sync_loop_(sync_loop),
62 ui_worker_(new UIModelWorker()), 62 ui_worker_(new UIModelWorker()),
63 stopped_on_ui_thread_(false) { 63 stopped_on_ui_thread_(false) {
64 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 64 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
65 CHECK(profile_); 65 CHECK(profile_);
66 DCHECK(sync_loop_); 66 DCHECK(sync_loop_);
67 workers_[csync::GROUP_DB] = new DatabaseModelWorker(); 67 workers_[syncer::GROUP_DB] = new DatabaseModelWorker();
68 workers_[csync::GROUP_FILE] = new FileModelWorker(); 68 workers_[syncer::GROUP_FILE] = new FileModelWorker();
69 workers_[csync::GROUP_UI] = ui_worker_; 69 workers_[syncer::GROUP_UI] = ui_worker_;
70 workers_[csync::GROUP_PASSIVE] = new csync::PassiveModelWorker(sync_loop_); 70 workers_[syncer::GROUP_PASSIVE] = new syncer::PassiveModelWorker(sync_loop_);
71 71
72 // Any datatypes that we want the syncer to pull down must be in the 72 // Any datatypes that we want the syncer to pull down must be in the
73 // routing_info map. We set them to group passive, meaning that 73 // routing_info map. We set them to group passive, meaning that
74 // updates will be applied to sync, but not dispatched to the native 74 // updates will be applied to sync, but not dispatched to the native
75 // models. 75 // models.
76 for (syncable::ModelTypeSet::Iterator it = initial_types.First(); 76 for (syncable::ModelTypeSet::Iterator it = initial_types.First();
77 it.Good(); it.Inc()) { 77 it.Good(); it.Inc()) {
78 routing_info_[it.Get()] = csync::GROUP_PASSIVE; 78 routing_info_[it.Get()] = syncer::GROUP_PASSIVE;
79 } 79 }
80 80
81 HistoryService* history_service = profile->GetHistoryService( 81 HistoryService* history_service = profile->GetHistoryService(
82 Profile::IMPLICIT_ACCESS); 82 Profile::IMPLICIT_ACCESS);
83 if (history_service) { 83 if (history_service) {
84 workers_[csync::GROUP_HISTORY] = new HistoryModelWorker(history_service); 84 workers_[syncer::GROUP_HISTORY] = new HistoryModelWorker(history_service);
85 } else { 85 } else {
86 LOG_IF(WARNING, initial_types.Has(syncable::TYPED_URLS)) 86 LOG_IF(WARNING, initial_types.Has(syncable::TYPED_URLS))
87 << "History store disabled, cannot sync Omnibox History"; 87 << "History store disabled, cannot sync Omnibox History";
88 routing_info_.erase(syncable::TYPED_URLS); 88 routing_info_.erase(syncable::TYPED_URLS);
89 } 89 }
90 90
91 scoped_refptr<PasswordStore> password_store = 91 scoped_refptr<PasswordStore> password_store =
92 PasswordStoreFactory::GetForProfile(profile, Profile::IMPLICIT_ACCESS); 92 PasswordStoreFactory::GetForProfile(profile, Profile::IMPLICIT_ACCESS);
93 if (password_store.get()) { 93 if (password_store.get()) {
94 workers_[csync::GROUP_PASSWORD] = new PasswordModelWorker(password_store); 94 workers_[syncer::GROUP_PASSWORD] = new PasswordModelWorker(password_store);
95 } else { 95 } else {
96 LOG_IF(WARNING, initial_types.Has(syncable::PASSWORDS)) 96 LOG_IF(WARNING, initial_types.Has(syncable::PASSWORDS))
97 << "Password store not initialized, cannot sync passwords"; 97 << "Password store not initialized, cannot sync passwords";
98 routing_info_.erase(syncable::PASSWORDS); 98 routing_info_.erase(syncable::PASSWORDS);
99 } 99 }
100 } 100 }
101 101
102 SyncBackendRegistrar::~SyncBackendRegistrar() { 102 SyncBackendRegistrar::~SyncBackendRegistrar() {
103 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 103 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
104 DCHECK(stopped_on_ui_thread_); 104 DCHECK(stopped_on_ui_thread_);
105 } 105 }
106 106
107 bool SyncBackendRegistrar::IsNigoriEnabled() const { 107 bool SyncBackendRegistrar::IsNigoriEnabled() const {
108 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 108 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
109 base::AutoLock lock(lock_); 109 base::AutoLock lock(lock_);
110 return routing_info_.find(syncable::NIGORI) != routing_info_.end(); 110 return routing_info_.find(syncable::NIGORI) != routing_info_.end();
111 } 111 }
112 112
113 syncable::ModelTypeSet SyncBackendRegistrar::ConfigureDataTypes( 113 syncable::ModelTypeSet SyncBackendRegistrar::ConfigureDataTypes(
114 syncable::ModelTypeSet types_to_add, 114 syncable::ModelTypeSet types_to_add,
115 syncable::ModelTypeSet types_to_remove) { 115 syncable::ModelTypeSet types_to_remove) {
116 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 116 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
117 DCHECK(Intersection(types_to_add, types_to_remove).Empty()); 117 DCHECK(Intersection(types_to_add, types_to_remove).Empty());
118 syncable::ModelTypeSet filtered_types_to_add = types_to_add; 118 syncable::ModelTypeSet filtered_types_to_add = types_to_add;
119 if (workers_.count(csync::GROUP_HISTORY) == 0) { 119 if (workers_.count(syncer::GROUP_HISTORY) == 0) {
120 LOG(WARNING) << "No history worker -- removing TYPED_URLS"; 120 LOG(WARNING) << "No history worker -- removing TYPED_URLS";
121 filtered_types_to_add.Remove(syncable::TYPED_URLS); 121 filtered_types_to_add.Remove(syncable::TYPED_URLS);
122 } 122 }
123 if (workers_.count(csync::GROUP_PASSWORD) == 0) { 123 if (workers_.count(syncer::GROUP_PASSWORD) == 0) {
124 LOG(WARNING) << "No password worker -- removing PASSWORDS"; 124 LOG(WARNING) << "No password worker -- removing PASSWORDS";
125 filtered_types_to_add.Remove(syncable::PASSWORDS); 125 filtered_types_to_add.Remove(syncable::PASSWORDS);
126 } 126 }
127 127
128 base::AutoLock lock(lock_); 128 base::AutoLock lock(lock_);
129 syncable::ModelTypeSet newly_added_types; 129 syncable::ModelTypeSet newly_added_types;
130 for (syncable::ModelTypeSet::Iterator it = 130 for (syncable::ModelTypeSet::Iterator it =
131 filtered_types_to_add.First(); 131 filtered_types_to_add.First();
132 it.Good(); it.Inc()) { 132 it.Good(); it.Inc()) {
133 // Add a newly specified data type as csync::GROUP_PASSIVE into the 133 // Add a newly specified data type as syncer::GROUP_PASSIVE into the
134 // routing_info, if it does not already exist. 134 // routing_info, if it does not already exist.
135 if (routing_info_.count(it.Get()) == 0) { 135 if (routing_info_.count(it.Get()) == 0) {
136 routing_info_[it.Get()] = csync::GROUP_PASSIVE; 136 routing_info_[it.Get()] = syncer::GROUP_PASSIVE;
137 newly_added_types.Put(it.Get()); 137 newly_added_types.Put(it.Get());
138 } 138 }
139 } 139 }
140 for (syncable::ModelTypeSet::Iterator it = types_to_remove.First(); 140 for (syncable::ModelTypeSet::Iterator it = types_to_remove.First();
141 it.Good(); it.Inc()) { 141 it.Good(); it.Inc()) {
142 routing_info_.erase(it.Get()); 142 routing_info_.erase(it.Get());
143 } 143 }
144 144
145 // TODO(akalin): Use SVLOG/SLOG if we add any more logging. 145 // TODO(akalin): Use SVLOG/SLOG if we add any more logging.
146 DVLOG(1) << name_ << ": Adding types " 146 DVLOG(1) << name_ << ": Adding types "
147 << syncable::ModelTypeSetToString(types_to_add) 147 << syncable::ModelTypeSetToString(types_to_add)
148 << " (with newly-added types " 148 << " (with newly-added types "
149 << syncable::ModelTypeSetToString(newly_added_types) 149 << syncable::ModelTypeSetToString(newly_added_types)
150 << ") and removing types " 150 << ") and removing types "
151 << syncable::ModelTypeSetToString(types_to_remove) 151 << syncable::ModelTypeSetToString(types_to_remove)
152 << " to get new routing info " 152 << " to get new routing info "
153 <<csync::ModelSafeRoutingInfoToString(routing_info_); 153 <<syncer::ModelSafeRoutingInfoToString(routing_info_);
154 154
155 return newly_added_types; 155 return newly_added_types;
156 } 156 }
157 157
158 void SyncBackendRegistrar::StopOnUIThread() { 158 void SyncBackendRegistrar::StopOnUIThread() {
159 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 159 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
160 DCHECK(!stopped_on_ui_thread_); 160 DCHECK(!stopped_on_ui_thread_);
161 ui_worker_->Stop(); 161 ui_worker_->Stop();
162 stopped_on_ui_thread_ = true; 162 stopped_on_ui_thread_ = true;
163 } 163 }
164 164
165 void SyncBackendRegistrar::OnSyncerShutdownComplete() { 165 void SyncBackendRegistrar::OnSyncerShutdownComplete() {
166 DCHECK_EQ(MessageLoop::current(), sync_loop_); 166 DCHECK_EQ(MessageLoop::current(), sync_loop_);
167 ui_worker_->OnSyncerShutdownComplete(); 167 ui_worker_->OnSyncerShutdownComplete();
168 } 168 }
169 169
170 void SyncBackendRegistrar::ActivateDataType( 170 void SyncBackendRegistrar::ActivateDataType(
171 syncable::ModelType type, 171 syncable::ModelType type,
172 csync::ModelSafeGroup group, 172 syncer::ModelSafeGroup group,
173 ChangeProcessor* change_processor, 173 ChangeProcessor* change_processor,
174 csync::UserShare* user_share) { 174 syncer::UserShare* user_share) {
175 CHECK(IsOnThreadForGroup(group)); 175 CHECK(IsOnThreadForGroup(group));
176 base::AutoLock lock(lock_); 176 base::AutoLock lock(lock_);
177 // Ensure that the given data type is in the PASSIVE group. 177 // Ensure that the given data type is in the PASSIVE group.
178 csync::ModelSafeRoutingInfo::iterator i = routing_info_.find(type); 178 syncer::ModelSafeRoutingInfo::iterator i = routing_info_.find(type);
179 DCHECK(i != routing_info_.end()); 179 DCHECK(i != routing_info_.end());
180 DCHECK_EQ(i->second, csync::GROUP_PASSIVE); 180 DCHECK_EQ(i->second, syncer::GROUP_PASSIVE);
181 routing_info_[type] = group; 181 routing_info_[type] = group;
182 CHECK(IsCurrentThreadSafeForModel(type)); 182 CHECK(IsCurrentThreadSafeForModel(type));
183 183
184 // Add the data type's change processor to the list of change 184 // Add the data type's change processor to the list of change
185 // processors so it can receive updates. 185 // processors so it can receive updates.
186 DCHECK_EQ(processors_.count(type), 0U); 186 DCHECK_EQ(processors_.count(type), 0U);
187 processors_[type] = change_processor; 187 processors_[type] = change_processor;
188 188
189 // Start the change processor. 189 // Start the change processor.
190 change_processor->Start(profile_, user_share); 190 change_processor->Start(profile_, user_share);
(...skipping 12 matching lines...) Expand all
203 DCHECK(!GetProcessorUnsafe(type)); 203 DCHECK(!GetProcessorUnsafe(type));
204 } 204 }
205 205
206 bool SyncBackendRegistrar::IsTypeActivatedForTest( 206 bool SyncBackendRegistrar::IsTypeActivatedForTest(
207 syncable::ModelType type) const { 207 syncable::ModelType type) const {
208 return GetProcessor(type) != NULL; 208 return GetProcessor(type) != NULL;
209 } 209 }
210 210
211 void SyncBackendRegistrar::OnChangesApplied( 211 void SyncBackendRegistrar::OnChangesApplied(
212 syncable::ModelType model_type, 212 syncable::ModelType model_type,
213 const csync::BaseTransaction* trans, 213 const syncer::BaseTransaction* trans,
214 const csync::ImmutableChangeRecordList& changes) { 214 const syncer::ImmutableChangeRecordList& changes) {
215 ChangeProcessor* processor = GetProcessor(model_type); 215 ChangeProcessor* processor = GetProcessor(model_type);
216 if (!processor) 216 if (!processor)
217 return; 217 return;
218 218
219 processor->ApplyChangesFromSyncModel(trans, changes); 219 processor->ApplyChangesFromSyncModel(trans, changes);
220 } 220 }
221 221
222 void SyncBackendRegistrar::OnChangesComplete( 222 void SyncBackendRegistrar::OnChangesComplete(
223 syncable::ModelType model_type) { 223 syncable::ModelType model_type) {
224 ChangeProcessor* processor = GetProcessor(model_type); 224 ChangeProcessor* processor = GetProcessor(model_type);
225 if (!processor) 225 if (!processor)
226 return; 226 return;
227 227
228 // This call just notifies the processor that it can commit; it 228 // This call just notifies the processor that it can commit; it
229 // already buffered any changes it plans to makes so needs no 229 // already buffered any changes it plans to makes so needs no
230 // further information. 230 // further information.
231 processor->CommitChangesFromSyncModel(); 231 processor->CommitChangesFromSyncModel();
232 } 232 }
233 233
234 void SyncBackendRegistrar::GetWorkers( 234 void SyncBackendRegistrar::GetWorkers(
235 std::vector<csync::ModelSafeWorker*>* out) { 235 std::vector<syncer::ModelSafeWorker*>* out) {
236 base::AutoLock lock(lock_); 236 base::AutoLock lock(lock_);
237 out->clear(); 237 out->clear();
238 for (WorkerMap::const_iterator it = workers_.begin(); 238 for (WorkerMap::const_iterator it = workers_.begin();
239 it != workers_.end(); ++it) { 239 it != workers_.end(); ++it) {
240 out->push_back(it->second); 240 out->push_back(it->second);
241 } 241 }
242 } 242 }
243 243
244 void SyncBackendRegistrar::GetModelSafeRoutingInfo( 244 void SyncBackendRegistrar::GetModelSafeRoutingInfo(
245 csync::ModelSafeRoutingInfo* out) { 245 syncer::ModelSafeRoutingInfo* out) {
246 base::AutoLock lock(lock_); 246 base::AutoLock lock(lock_);
247 csync::ModelSafeRoutingInfo copy(routing_info_); 247 syncer::ModelSafeRoutingInfo copy(routing_info_);
248 out->swap(copy); 248 out->swap(copy);
249 } 249 }
250 250
251 ChangeProcessor* SyncBackendRegistrar::GetProcessor( 251 ChangeProcessor* SyncBackendRegistrar::GetProcessor(
252 syncable::ModelType type) const { 252 syncable::ModelType type) const {
253 base::AutoLock lock(lock_); 253 base::AutoLock lock(lock_);
254 ChangeProcessor* processor = GetProcessorUnsafe(type); 254 ChangeProcessor* processor = GetProcessorUnsafe(type);
255 if (!processor) 255 if (!processor)
256 return NULL; 256 return NULL;
257 257
258 // We can only check if |processor| exists, as otherwise the type is 258 // We can only check if |processor| exists, as otherwise the type is
259 // mapped to csync::GROUP_PASSIVE. 259 // mapped to syncer::GROUP_PASSIVE.
260 CHECK(IsCurrentThreadSafeForModel(type)); 260 CHECK(IsCurrentThreadSafeForModel(type));
261 CHECK(processor->IsRunning()); 261 CHECK(processor->IsRunning());
262 return processor; 262 return processor;
263 } 263 }
264 264
265 ChangeProcessor* SyncBackendRegistrar::GetProcessorUnsafe( 265 ChangeProcessor* SyncBackendRegistrar::GetProcessorUnsafe(
266 syncable::ModelType type) const { 266 syncable::ModelType type) const {
267 lock_.AssertAcquired(); 267 lock_.AssertAcquired();
268 std::map<syncable::ModelType, ChangeProcessor*>::const_iterator it = 268 std::map<syncable::ModelType, ChangeProcessor*>::const_iterator it =
269 processors_.find(type); 269 processors_.find(type);
(...skipping 10 matching lines...) Expand all
280 return it->second; 280 return it->second;
281 } 281 }
282 282
283 bool SyncBackendRegistrar::IsCurrentThreadSafeForModel( 283 bool SyncBackendRegistrar::IsCurrentThreadSafeForModel(
284 syncable::ModelType model_type) const { 284 syncable::ModelType model_type) const {
285 lock_.AssertAcquired(); 285 lock_.AssertAcquired();
286 return IsOnThreadForGroup(GetGroupForModelType(model_type, routing_info_)); 286 return IsOnThreadForGroup(GetGroupForModelType(model_type, routing_info_));
287 } 287 }
288 288
289 } // namespace browser_sync 289 } // namespace browser_sync
OLDNEW
« no previous file with comments | « chrome/browser/sync/glue/sync_backend_registrar.h ('k') | chrome/browser/sync/glue/sync_backend_registrar_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698