| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 <algorithm> | 7 #include <algorithm> |
| 8 #include <cstddef> |
| 8 | 9 |
| 9 #include "base/compiler_specific.h" | 10 #include "base/compiler_specific.h" |
| 10 #include "base/logging.h" | 11 #include "base/logging.h" |
| 11 #include "base/message_loop.h" | 12 #include "base/message_loop.h" |
| 12 #include "chrome/browser/profiles/profile.h" | 13 #include "chrome/browser/profiles/profile.h" |
| 13 #include "chrome/browser/sync/glue/change_processor.h" | 14 #include "chrome/browser/sync/glue/change_processor.h" |
| 14 #include "chrome/browser/sync/glue/browser_thread_model_worker.h" | 15 #include "chrome/browser/sync/glue/browser_thread_model_worker.h" |
| 15 #include "chrome/browser/sync/glue/history_model_worker.h" | 16 #include "chrome/browser/sync/glue/history_model_worker.h" |
| 16 #include "chrome/browser/sync/glue/password_model_worker.h" | 17 #include "chrome/browser/sync/glue/password_model_worker.h" |
| 17 #include "chrome/browser/sync/glue/ui_model_worker.h" | 18 #include "chrome/browser/sync/glue/ui_model_worker.h" |
| (...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 191 | 192 |
| 192 // Start the change processor. | 193 // Start the change processor. |
| 193 change_processor->Start(profile_, user_share); | 194 change_processor->Start(profile_, user_share); |
| 194 DCHECK(GetProcessorUnsafe(type)); | 195 DCHECK(GetProcessorUnsafe(type)); |
| 195 } | 196 } |
| 196 | 197 |
| 197 void SyncBackendRegistrar::DeactivateDataType(syncable::ModelType type) { | 198 void SyncBackendRegistrar::DeactivateDataType(syncable::ModelType type) { |
| 198 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 199 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 199 base::AutoLock lock(lock_); | 200 base::AutoLock lock(lock_); |
| 200 ChangeProcessor* change_processor = GetProcessorUnsafe(type); | 201 ChangeProcessor* change_processor = GetProcessorUnsafe(type); |
| 201 if (change_processor) { | 202 if (change_processor) |
| 202 change_processor->Stop(); | 203 change_processor->Stop(); |
| 203 } | 204 |
| 204 routing_info_.erase(type); | 205 routing_info_.erase(type); |
| 205 ignore_result(processors_.erase(type)); | 206 ignore_result(processors_.erase(type)); |
| 206 DCHECK(!GetProcessorUnsafe(type)); | 207 DCHECK(!GetProcessorUnsafe(type)); |
| 207 } | 208 } |
| 208 | 209 |
| 209 ChangeProcessor* SyncBackendRegistrar::GetProcessor( | 210 bool SyncBackendRegistrar::IsTypeActivatedForTest( |
| 210 syncable::ModelType type) { | 211 syncable::ModelType type) const { |
| 211 base::AutoLock lock(lock_); | 212 return GetProcessor(type) != NULL; |
| 212 ChangeProcessor* processor = GetProcessorUnsafe(type); | 213 } |
| 213 if (!processor) { | 214 |
| 214 return NULL; | 215 void SyncBackendRegistrar::OnChangesApplied( |
| 215 } | 216 syncable::ModelType model_type, |
| 216 // We can only check if |processor| exists, as otherwise the type is | 217 const sync_api::BaseTransaction* trans, |
| 217 // mapped to GROUP_PASSIVE. | 218 const sync_api::ImmutableChangeRecordList& changes) { |
| 218 CHECK(IsCurrentThreadSafeForModel(type)); | 219 ChangeProcessor* processor = GetProcessor(model_type); |
| 219 CHECK(processor->IsRunning()); | 220 if (!processor) |
| 220 return processor; | 221 return; |
| 222 |
| 223 processor->ApplyChangesFromSyncModel(trans, changes); |
| 224 } |
| 225 |
| 226 void SyncBackendRegistrar::OnChangesComplete( |
| 227 syncable::ModelType model_type) { |
| 228 ChangeProcessor* processor = GetProcessor(model_type); |
| 229 if (!processor) |
| 230 return; |
| 231 |
| 232 // This call just notifies the processor that it can commit; it |
| 233 // already buffered any changes it plans to makes so needs no |
| 234 // further information. |
| 235 processor->CommitChangesFromSyncModel(); |
| 221 } | 236 } |
| 222 | 237 |
| 223 void SyncBackendRegistrar::GetWorkers( | 238 void SyncBackendRegistrar::GetWorkers( |
| 224 std::vector<ModelSafeWorker*>* out) { | 239 std::vector<ModelSafeWorker*>* out) { |
| 225 base::AutoLock lock(lock_); | 240 base::AutoLock lock(lock_); |
| 226 out->clear(); | 241 out->clear(); |
| 227 for (WorkerMap::const_iterator it = workers_.begin(); | 242 for (WorkerMap::const_iterator it = workers_.begin(); |
| 228 it != workers_.end(); ++it) { | 243 it != workers_.end(); ++it) { |
| 229 out->push_back(it->second); | 244 out->push_back(it->second); |
| 230 } | 245 } |
| 231 } | 246 } |
| 232 | 247 |
| 233 void SyncBackendRegistrar::GetModelSafeRoutingInfo( | 248 void SyncBackendRegistrar::GetModelSafeRoutingInfo( |
| 234 ModelSafeRoutingInfo* out) { | 249 ModelSafeRoutingInfo* out) { |
| 235 base::AutoLock lock(lock_); | 250 base::AutoLock lock(lock_); |
| 236 ModelSafeRoutingInfo copy(routing_info_); | 251 ModelSafeRoutingInfo copy(routing_info_); |
| 237 out->swap(copy); | 252 out->swap(copy); |
| 238 } | 253 } |
| 239 | 254 |
| 255 ChangeProcessor* SyncBackendRegistrar::GetProcessor( |
| 256 syncable::ModelType type) const { |
| 257 base::AutoLock lock(lock_); |
| 258 ChangeProcessor* processor = GetProcessorUnsafe(type); |
| 259 if (!processor) |
| 260 return NULL; |
| 261 |
| 262 // We can only check if |processor| exists, as otherwise the type is |
| 263 // mapped to GROUP_PASSIVE. |
| 264 CHECK(IsCurrentThreadSafeForModel(type)); |
| 265 CHECK(processor->IsRunning()); |
| 266 return processor; |
| 267 } |
| 268 |
| 240 ChangeProcessor* SyncBackendRegistrar::GetProcessorUnsafe( | 269 ChangeProcessor* SyncBackendRegistrar::GetProcessorUnsafe( |
| 241 syncable::ModelType type) { | 270 syncable::ModelType type) const { |
| 242 lock_.AssertAcquired(); | 271 lock_.AssertAcquired(); |
| 243 std::map<syncable::ModelType, ChangeProcessor*>::const_iterator it = | 272 std::map<syncable::ModelType, ChangeProcessor*>::const_iterator it = |
| 244 processors_.find(type); | 273 processors_.find(type); |
| 245 | 274 |
| 246 // Until model association happens for a datatype, it will not | 275 // Until model association happens for a datatype, it will not |
| 247 // appear in the processors list. During this time, it is OK to | 276 // appear in the processors list. During this time, it is OK to |
| 248 // drop changes on the floor (since model association has not | 277 // drop changes on the floor (since model association has not |
| 249 // happened yet). When the data type is activated, model | 278 // happened yet). When the data type is activated, model |
| 250 // association takes place then the change processor is added to the | 279 // association takes place then the change processor is added to the |
| 251 // |processors_| list. | 280 // |processors_| list. |
| 252 if (it == processors_.end()) | 281 if (it == processors_.end()) |
| 253 return NULL; | 282 return NULL; |
| 254 | 283 |
| 255 return it->second; | 284 return it->second; |
| 256 } | 285 } |
| 257 | 286 |
| 258 bool SyncBackendRegistrar::IsCurrentThreadSafeForModel( | 287 bool SyncBackendRegistrar::IsCurrentThreadSafeForModel( |
| 259 syncable::ModelType model_type) const { | 288 syncable::ModelType model_type) const { |
| 260 lock_.AssertAcquired(); | 289 lock_.AssertAcquired(); |
| 261 return IsOnThreadForGroup(GetGroupForModelType(model_type, routing_info_)); | 290 return IsOnThreadForGroup(GetGroupForModelType(model_type, routing_info_)); |
| 262 } | 291 } |
| 263 | 292 |
| 264 } // namespace browser_sync | 293 } // namespace browser_sync |
| 265 | 294 |
| OLD | NEW |