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