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

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

Issue 10696087: [Sync] Move ModelType and related classes to 'syncer' namespace (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: sort headers, update copyrights 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 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
46 return true; 46 return true;
47 case syncer::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 syncer::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_[syncer::GROUP_DB] = new DatabaseModelWorker(); 67 workers_[syncer::GROUP_DB] = new DatabaseModelWorker();
68 workers_[syncer::GROUP_FILE] = new FileModelWorker(); 68 workers_[syncer::GROUP_FILE] = new FileModelWorker();
69 workers_[syncer::GROUP_UI] = ui_worker_; 69 workers_[syncer::GROUP_UI] = ui_worker_;
70 workers_[syncer::GROUP_PASSIVE] = new syncer::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 (syncer::ModelTypeSet::Iterator it = initial_types.First();
77 it.Good(); it.Inc()) { 77 it.Good(); it.Inc()) {
78 routing_info_[it.Get()] = syncer::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_[syncer::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(syncer::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(syncer::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_[syncer::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(syncer::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(syncer::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(syncer::NIGORI) != routing_info_.end();
111 } 111 }
112 112
113 syncable::ModelTypeSet SyncBackendRegistrar::ConfigureDataTypes( 113 syncer::ModelTypeSet SyncBackendRegistrar::ConfigureDataTypes(
114 syncable::ModelTypeSet types_to_add, 114 syncer::ModelTypeSet types_to_add,
115 syncable::ModelTypeSet types_to_remove) { 115 syncer::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 syncer::ModelTypeSet filtered_types_to_add = types_to_add;
119 if (workers_.count(syncer::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(syncer::TYPED_URLS);
122 } 122 }
123 if (workers_.count(syncer::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(syncer::PASSWORDS);
126 } 126 }
127 127
128 base::AutoLock lock(lock_); 128 base::AutoLock lock(lock_);
129 syncable::ModelTypeSet newly_added_types; 129 syncer::ModelTypeSet newly_added_types;
130 for (syncable::ModelTypeSet::Iterator it = 130 for (syncer::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 syncer::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()] = syncer::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 (syncer::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 << syncer::ModelTypeSetToString(types_to_add)
148 << " (with newly-added types " 148 << " (with newly-added types "
149 << syncable::ModelTypeSetToString(newly_added_types) 149 << syncer::ModelTypeSetToString(newly_added_types)
150 << ") and removing types " 150 << ") and removing types "
151 << syncable::ModelTypeSetToString(types_to_remove) 151 << syncer::ModelTypeSetToString(types_to_remove)
152 << " to get new routing info " 152 << " to get new routing info "
153 <<syncer::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 syncer::ModelType type,
172 syncer::ModelSafeGroup group, 172 syncer::ModelSafeGroup group,
173 ChangeProcessor* change_processor, 173 ChangeProcessor* change_processor,
174 syncer::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 syncer::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, syncer::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);
191 DCHECK(GetProcessorUnsafe(type)); 191 DCHECK(GetProcessorUnsafe(type));
192 } 192 }
193 193
194 void SyncBackendRegistrar::DeactivateDataType(syncable::ModelType type) { 194 void SyncBackendRegistrar::DeactivateDataType(syncer::ModelType type) {
195 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 195 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
196 base::AutoLock lock(lock_); 196 base::AutoLock lock(lock_);
197 ChangeProcessor* change_processor = GetProcessorUnsafe(type); 197 ChangeProcessor* change_processor = GetProcessorUnsafe(type);
198 if (change_processor) 198 if (change_processor)
199 change_processor->Stop(); 199 change_processor->Stop();
200 200
201 routing_info_.erase(type); 201 routing_info_.erase(type);
202 ignore_result(processors_.erase(type)); 202 ignore_result(processors_.erase(type));
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 syncer::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 syncer::ModelType model_type,
213 const syncer::BaseTransaction* trans, 213 const syncer::BaseTransaction* trans,
214 const syncer::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(syncer::ModelType model_type) {
223 syncable::ModelType model_type) {
224 ChangeProcessor* processor = GetProcessor(model_type); 223 ChangeProcessor* processor = GetProcessor(model_type);
225 if (!processor) 224 if (!processor)
226 return; 225 return;
227 226
228 // This call just notifies the processor that it can commit; it 227 // This call just notifies the processor that it can commit; it
229 // already buffered any changes it plans to makes so needs no 228 // already buffered any changes it plans to makes so needs no
230 // further information. 229 // further information.
231 processor->CommitChangesFromSyncModel(); 230 processor->CommitChangesFromSyncModel();
232 } 231 }
233 232
234 void SyncBackendRegistrar::GetWorkers( 233 void SyncBackendRegistrar::GetWorkers(
235 std::vector<syncer::ModelSafeWorker*>* out) { 234 std::vector<syncer::ModelSafeWorker*>* out) {
236 base::AutoLock lock(lock_); 235 base::AutoLock lock(lock_);
237 out->clear(); 236 out->clear();
238 for (WorkerMap::const_iterator it = workers_.begin(); 237 for (WorkerMap::const_iterator it = workers_.begin();
239 it != workers_.end(); ++it) { 238 it != workers_.end(); ++it) {
240 out->push_back(it->second); 239 out->push_back(it->second);
241 } 240 }
242 } 241 }
243 242
244 void SyncBackendRegistrar::GetModelSafeRoutingInfo( 243 void SyncBackendRegistrar::GetModelSafeRoutingInfo(
245 syncer::ModelSafeRoutingInfo* out) { 244 syncer::ModelSafeRoutingInfo* out) {
246 base::AutoLock lock(lock_); 245 base::AutoLock lock(lock_);
247 syncer::ModelSafeRoutingInfo copy(routing_info_); 246 syncer::ModelSafeRoutingInfo copy(routing_info_);
248 out->swap(copy); 247 out->swap(copy);
249 } 248 }
250 249
251 ChangeProcessor* SyncBackendRegistrar::GetProcessor( 250 ChangeProcessor* SyncBackendRegistrar::GetProcessor(
252 syncable::ModelType type) const { 251 syncer::ModelType type) const {
253 base::AutoLock lock(lock_); 252 base::AutoLock lock(lock_);
254 ChangeProcessor* processor = GetProcessorUnsafe(type); 253 ChangeProcessor* processor = GetProcessorUnsafe(type);
255 if (!processor) 254 if (!processor)
256 return NULL; 255 return NULL;
257 256
258 // 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
259 // mapped to syncer::GROUP_PASSIVE. 258 // mapped to syncer::GROUP_PASSIVE.
260 CHECK(IsCurrentThreadSafeForModel(type)); 259 CHECK(IsCurrentThreadSafeForModel(type));
261 CHECK(processor->IsRunning()); 260 CHECK(processor->IsRunning());
262 return processor; 261 return processor;
263 } 262 }
264 263
265 ChangeProcessor* SyncBackendRegistrar::GetProcessorUnsafe( 264 ChangeProcessor* SyncBackendRegistrar::GetProcessorUnsafe(
266 syncable::ModelType type) const { 265 syncer::ModelType type) const {
267 lock_.AssertAcquired(); 266 lock_.AssertAcquired();
268 std::map<syncable::ModelType, ChangeProcessor*>::const_iterator it = 267 std::map<syncer::ModelType, ChangeProcessor*>::const_iterator it =
269 processors_.find(type); 268 processors_.find(type);
270 269
271 // Until model association happens for a datatype, it will not 270 // Until model association happens for a datatype, it will not
272 // appear in the processors list. During this time, it is OK to 271 // appear in the processors list. During this time, it is OK to
273 // drop changes on the floor (since model association has not 272 // drop changes on the floor (since model association has not
274 // happened yet). When the data type is activated, model 273 // happened yet). When the data type is activated, model
275 // association takes place then the change processor is added to the 274 // association takes place then the change processor is added to the
276 // |processors_| list. 275 // |processors_| list.
277 if (it == processors_.end()) 276 if (it == processors_.end())
278 return NULL; 277 return NULL;
279 278
280 return it->second; 279 return it->second;
281 } 280 }
282 281
283 bool SyncBackendRegistrar::IsCurrentThreadSafeForModel( 282 bool SyncBackendRegistrar::IsCurrentThreadSafeForModel(
284 syncable::ModelType model_type) const { 283 syncer::ModelType model_type) const {
285 lock_.AssertAcquired(); 284 lock_.AssertAcquired();
286 return IsOnThreadForGroup(GetGroupForModelType(model_type, routing_info_)); 285 return IsOnThreadForGroup(GetGroupForModelType(model_type, routing_info_));
287 } 286 }
288 287
289 } // namespace browser_sync 288 } // 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