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