| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "sync/sessions/model_type_registry.h" | 5 #include "components/sync/sessions_impl/model_type_registry.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <utility> | 9 #include <utility> |
| 10 | 10 |
| 11 #include "base/bind.h" | 11 #include "base/bind.h" |
| 12 #include "base/memory/ptr_util.h" | 12 #include "base/memory/ptr_util.h" |
| 13 #include "base/observer_list.h" | 13 #include "base/observer_list.h" |
| 14 #include "base/threading/thread_task_runner_handle.h" | 14 #include "base/threading/thread_task_runner_handle.h" |
| 15 #include "sync/engine/commit_queue.h" | 15 #include "components/sync/base/cryptographer.h" |
| 16 #include "sync/engine/directory_commit_contributor.h" | 16 #include "components/sync/core/activation_context.h" |
| 17 #include "sync/engine/directory_update_handler.h" | 17 #include "components/sync/core/model_type_processor.h" |
| 18 #include "sync/engine/model_type_worker.h" | 18 #include "components/sync/engine_impl/commit_queue.h" |
| 19 #include "sync/internal_api/public/activation_context.h" | 19 #include "components/sync/engine_impl/directory_commit_contributor.h" |
| 20 #include "sync/internal_api/public/model_type_processor.h" | 20 #include "components/sync/engine_impl/directory_update_handler.h" |
| 21 #include "sync/sessions/directory_type_debug_info_emitter.h" | 21 #include "components/sync/engine_impl/model_type_worker.h" |
| 22 #include "sync/util/cryptographer.h" | 22 #include "components/sync/sessions_impl/directory_type_debug_info_emitter.h" |
| 23 | 23 |
| 24 namespace syncer { | 24 namespace syncer { |
| 25 | 25 |
| 26 namespace { | 26 namespace { |
| 27 | 27 |
| 28 class CommitQueueProxy : public syncer_v2::CommitQueue { | 28 class CommitQueueProxy : public syncer_v2::CommitQueue { |
| 29 public: | 29 public: |
| 30 CommitQueueProxy(const base::WeakPtr<syncer_v2::ModelTypeWorker>& worker, | 30 CommitQueueProxy(const base::WeakPtr<syncer_v2::ModelTypeWorker>& worker, |
| 31 const scoped_refptr<base::SequencedTaskRunner>& sync_thread); | 31 const scoped_refptr<base::SequencedTaskRunner>& sync_thread); |
| 32 ~CommitQueueProxy() override; | 32 ~CommitQueueProxy() override; |
| (...skipping 15 matching lines...) Expand all Loading... |
| 48 void CommitQueueProxy::EnqueueForCommit( | 48 void CommitQueueProxy::EnqueueForCommit( |
| 49 const syncer_v2::CommitRequestDataList& list) { | 49 const syncer_v2::CommitRequestDataList& list) { |
| 50 sync_thread_->PostTask( | 50 sync_thread_->PostTask( |
| 51 FROM_HERE, | 51 FROM_HERE, |
| 52 base::Bind(&syncer_v2::ModelTypeWorker::EnqueueForCommit, worker_, list)); | 52 base::Bind(&syncer_v2::ModelTypeWorker::EnqueueForCommit, worker_, list)); |
| 53 } | 53 } |
| 54 | 54 |
| 55 } // namespace | 55 } // namespace |
| 56 | 56 |
| 57 ModelTypeRegistry::ModelTypeRegistry( | 57 ModelTypeRegistry::ModelTypeRegistry( |
| 58 const std::vector<scoped_refptr<ModelSafeWorker> >& workers, | 58 const std::vector<scoped_refptr<ModelSafeWorker>>& workers, |
| 59 syncable::Directory* directory, | 59 syncable::Directory* directory, |
| 60 NudgeHandler* nudge_handler) | 60 NudgeHandler* nudge_handler) |
| 61 : directory_(directory), | 61 : directory_(directory), |
| 62 nudge_handler_(nudge_handler), | 62 nudge_handler_(nudge_handler), |
| 63 weak_ptr_factory_(this) { | 63 weak_ptr_factory_(this) { |
| 64 for (size_t i = 0u; i < workers.size(); ++i) { | 64 for (size_t i = 0u; i < workers.size(); ++i) { |
| 65 workers_map_.insert( | 65 workers_map_.insert( |
| 66 std::make_pair(workers[i]->GetModelSafeGroup(), workers[i])); | 66 std::make_pair(workers[i]->GetModelSafeGroup(), workers[i])); |
| 67 } | 67 } |
| 68 } | 68 } |
| 69 | 69 |
| 70 ModelTypeRegistry::~ModelTypeRegistry() { | 70 ModelTypeRegistry::~ModelTypeRegistry() {} |
| 71 } | |
| 72 | 71 |
| 73 void ModelTypeRegistry::SetEnabledDirectoryTypes( | 72 void ModelTypeRegistry::SetEnabledDirectoryTypes( |
| 74 const ModelSafeRoutingInfo& routing_info) { | 73 const ModelSafeRoutingInfo& routing_info) { |
| 75 // Remove all existing directory processors and delete them. The | 74 // Remove all existing directory processors and delete them. The |
| 76 // DebugInfoEmitters are not deleted here, since we want to preserve their | 75 // DebugInfoEmitters are not deleted here, since we want to preserve their |
| 77 // counters. | 76 // counters. |
| 78 for (ModelTypeSet::Iterator it = enabled_directory_types_.First(); | 77 for (ModelTypeSet::Iterator it = enabled_directory_types_.First(); it.Good(); |
| 79 it.Good(); it.Inc()) { | 78 it.Inc()) { |
| 80 size_t result1 = update_handler_map_.erase(it.Get()); | 79 size_t result1 = update_handler_map_.erase(it.Get()); |
| 81 size_t result2 = commit_contributor_map_.erase(it.Get()); | 80 size_t result2 = commit_contributor_map_.erase(it.Get()); |
| 82 DCHECK_EQ(1U, result1); | 81 DCHECK_EQ(1U, result1); |
| 83 DCHECK_EQ(1U, result2); | 82 DCHECK_EQ(1U, result2); |
| 84 } | 83 } |
| 85 | 84 |
| 86 // Clear the old instances of directory update handlers and commit | 85 // Clear the old instances of directory update handlers and commit |
| 87 // contributors, deleting their contents in the processs. | 86 // contributors, deleting their contents in the processs. |
| 88 directory_update_handlers_.clear(); | 87 directory_update_handlers_.clear(); |
| 89 directory_commit_contributors_.clear(); | 88 directory_commit_contributors_.clear(); |
| 90 | 89 |
| 91 enabled_directory_types_.Clear(); | 90 enabled_directory_types_.Clear(); |
| 92 | 91 |
| 93 // Create new ones and add them to the appropriate containers. | 92 // Create new ones and add them to the appropriate containers. |
| 94 for (ModelSafeRoutingInfo::const_iterator routing_iter = routing_info.begin(); | 93 for (ModelSafeRoutingInfo::const_iterator routing_iter = routing_info.begin(); |
| 95 routing_iter != routing_info.end(); ++routing_iter) { | 94 routing_iter != routing_info.end(); ++routing_iter) { |
| 96 ModelType type = routing_iter->first; | 95 ModelType type = routing_iter->first; |
| 97 ModelSafeGroup group = routing_iter->second; | 96 ModelSafeGroup group = routing_iter->second; |
| 98 if (group == GROUP_NON_BLOCKING) | 97 if (group == GROUP_NON_BLOCKING) |
| 99 continue; | 98 continue; |
| 100 std::map<ModelSafeGroup, scoped_refptr<ModelSafeWorker> >::iterator | 99 std::map<ModelSafeGroup, scoped_refptr<ModelSafeWorker>>::iterator |
| 101 worker_it = workers_map_.find(group); | 100 worker_it = workers_map_.find(group); |
| 102 DCHECK(worker_it != workers_map_.end()); | 101 DCHECK(worker_it != workers_map_.end()); |
| 103 scoped_refptr<ModelSafeWorker> worker = worker_it->second; | 102 scoped_refptr<ModelSafeWorker> worker = worker_it->second; |
| 104 | 103 |
| 105 // DebugInfoEmitters are never deleted. Use existing one if we have it. | 104 // DebugInfoEmitters are never deleted. Use existing one if we have it. |
| 106 DirectoryTypeDebugInfoEmitter* emitter = NULL; | 105 DirectoryTypeDebugInfoEmitter* emitter = NULL; |
| 107 DirectoryTypeDebugInfoEmitterMap::iterator it = | 106 DirectoryTypeDebugInfoEmitterMap::iterator it = |
| 108 directory_type_debug_info_emitter_map_.find(type); | 107 directory_type_debug_info_emitter_map_.find(type); |
| 109 if (it != directory_type_debug_info_emitter_map_.end()) { | 108 if (it != directory_type_debug_info_emitter_map_.end()) { |
| 110 emitter = it->second; | 109 emitter = it->second; |
| (...skipping 17 matching lines...) Expand all Loading... |
| 128 bool inserted1 = | 127 bool inserted1 = |
| 129 update_handler_map_.insert(std::make_pair(type, updater)).second; | 128 update_handler_map_.insert(std::make_pair(type, updater)).second; |
| 130 DCHECK(inserted1) << "Attempt to override existing type handler in map"; | 129 DCHECK(inserted1) << "Attempt to override existing type handler in map"; |
| 131 | 130 |
| 132 bool inserted2 = | 131 bool inserted2 = |
| 133 commit_contributor_map_.insert(std::make_pair(type, committer)).second; | 132 commit_contributor_map_.insert(std::make_pair(type, committer)).second; |
| 134 DCHECK(inserted2) << "Attempt to override existing type handler in map"; | 133 DCHECK(inserted2) << "Attempt to override existing type handler in map"; |
| 135 enabled_directory_types_.Put(type); | 134 enabled_directory_types_.Put(type); |
| 136 } | 135 } |
| 137 | 136 |
| 138 DCHECK(Intersection(GetEnabledDirectoryTypes(), | 137 DCHECK(Intersection(GetEnabledDirectoryTypes(), GetEnabledNonBlockingTypes()) |
| 139 GetEnabledNonBlockingTypes()).Empty()); | 138 .Empty()); |
| 140 } | 139 } |
| 141 | 140 |
| 142 void ModelTypeRegistry::ConnectType( | 141 void ModelTypeRegistry::ConnectType( |
| 143 ModelType type, | 142 ModelType type, |
| 144 std::unique_ptr<syncer_v2::ActivationContext> activation_context) { | 143 std::unique_ptr<syncer_v2::ActivationContext> activation_context) { |
| 145 DVLOG(1) << "Enabling an off-thread sync type: " << ModelTypeToString(type); | 144 DVLOG(1) << "Enabling an off-thread sync type: " << ModelTypeToString(type); |
| 146 | 145 |
| 147 // Initialize Worker -> Processor communication channel. | 146 // Initialize Worker -> Processor communication channel. |
| 148 syncer_v2::ModelTypeProcessor* type_processor = | 147 syncer_v2::ModelTypeProcessor* type_processor = |
| 149 activation_context->type_processor.get(); | 148 activation_context->type_processor.get(); |
| (...skipping 18 matching lines...) Expand all Loading... |
| 168 | 167 |
| 169 DCHECK(update_handler_map_.find(type) == update_handler_map_.end()); | 168 DCHECK(update_handler_map_.find(type) == update_handler_map_.end()); |
| 170 DCHECK(commit_contributor_map_.find(type) == commit_contributor_map_.end()); | 169 DCHECK(commit_contributor_map_.find(type) == commit_contributor_map_.end()); |
| 171 | 170 |
| 172 update_handler_map_.insert(std::make_pair(type, worker.get())); | 171 update_handler_map_.insert(std::make_pair(type, worker.get())); |
| 173 commit_contributor_map_.insert(std::make_pair(type, worker.get())); | 172 commit_contributor_map_.insert(std::make_pair(type, worker.get())); |
| 174 | 173 |
| 175 // The container takes ownership. | 174 // The container takes ownership. |
| 176 model_type_workers_.push_back(std::move(worker)); | 175 model_type_workers_.push_back(std::move(worker)); |
| 177 | 176 |
| 178 DCHECK(Intersection(GetEnabledDirectoryTypes(), | 177 DCHECK(Intersection(GetEnabledDirectoryTypes(), GetEnabledNonBlockingTypes()) |
| 179 GetEnabledNonBlockingTypes()).Empty()); | 178 .Empty()); |
| 180 } | 179 } |
| 181 | 180 |
| 182 void ModelTypeRegistry::DisconnectType(ModelType type) { | 181 void ModelTypeRegistry::DisconnectType(ModelType type) { |
| 183 DVLOG(1) << "Disabling an off-thread sync type: " << ModelTypeToString(type); | 182 DVLOG(1) << "Disabling an off-thread sync type: " << ModelTypeToString(type); |
| 184 DCHECK(update_handler_map_.find(type) != update_handler_map_.end()); | 183 DCHECK(update_handler_map_.find(type) != update_handler_map_.end()); |
| 185 DCHECK(commit_contributor_map_.find(type) != commit_contributor_map_.end()); | 184 DCHECK(commit_contributor_map_.find(type) != commit_contributor_map_.end()); |
| 186 | 185 |
| 187 size_t updaters_erased = update_handler_map_.erase(type); | 186 size_t updaters_erased = update_handler_map_.erase(type); |
| 188 size_t committers_erased = commit_contributor_map_.erase(type); | 187 size_t committers_erased = commit_contributor_map_.erase(type); |
| 189 | 188 |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 245 type_debug_info_observers_.RemoveObserver(observer); | 244 type_debug_info_observers_.RemoveObserver(observer); |
| 246 } | 245 } |
| 247 | 246 |
| 248 bool ModelTypeRegistry::HasDirectoryTypeDebugInfoObserver( | 247 bool ModelTypeRegistry::HasDirectoryTypeDebugInfoObserver( |
| 249 const syncer::TypeDebugInfoObserver* observer) const { | 248 const syncer::TypeDebugInfoObserver* observer) const { |
| 250 return type_debug_info_observers_.HasObserver(observer); | 249 return type_debug_info_observers_.HasObserver(observer); |
| 251 } | 250 } |
| 252 | 251 |
| 253 void ModelTypeRegistry::RequestEmitDebugInfo() { | 252 void ModelTypeRegistry::RequestEmitDebugInfo() { |
| 254 for (DirectoryTypeDebugInfoEmitterMap::iterator it = | 253 for (DirectoryTypeDebugInfoEmitterMap::iterator it = |
| 255 directory_type_debug_info_emitter_map_.begin(); | 254 directory_type_debug_info_emitter_map_.begin(); |
| 256 it != directory_type_debug_info_emitter_map_.end(); ++it) { | 255 it != directory_type_debug_info_emitter_map_.end(); ++it) { |
| 257 it->second->EmitCommitCountersUpdate(); | 256 it->second->EmitCommitCountersUpdate(); |
| 258 it->second->EmitUpdateCountersUpdate(); | 257 it->second->EmitUpdateCountersUpdate(); |
| 259 it->second->EmitStatusCountersUpdate(); | 258 it->second->EmitStatusCountersUpdate(); |
| 260 } | 259 } |
| 261 } | 260 } |
| 262 | 261 |
| 263 base::WeakPtr<syncer_v2::ModelTypeConnector> ModelTypeRegistry::AsWeakPtr() { | 262 base::WeakPtr<syncer_v2::ModelTypeConnector> ModelTypeRegistry::AsWeakPtr() { |
| 264 return weak_ptr_factory_.GetWeakPtr(); | 263 return weak_ptr_factory_.GetWeakPtr(); |
| 265 } | 264 } |
| 266 | 265 |
| 267 void ModelTypeRegistry::OnPassphraseRequired( | 266 void ModelTypeRegistry::OnPassphraseRequired( |
| 268 PassphraseRequiredReason reason, | 267 PassphraseRequiredReason reason, |
| 269 const sync_pb::EncryptedData& pending_keys) { | 268 const sync_pb::EncryptedData& pending_keys) {} |
| 270 } | |
| 271 | 269 |
| 272 void ModelTypeRegistry::OnPassphraseAccepted() { | 270 void ModelTypeRegistry::OnPassphraseAccepted() {} |
| 273 } | |
| 274 | 271 |
| 275 void ModelTypeRegistry::OnBootstrapTokenUpdated( | 272 void ModelTypeRegistry::OnBootstrapTokenUpdated( |
| 276 const std::string& bootstrap_token, | 273 const std::string& bootstrap_token, |
| 277 BootstrapTokenType type) { | 274 BootstrapTokenType type) {} |
| 278 } | |
| 279 | 275 |
| 280 void ModelTypeRegistry::OnEncryptedTypesChanged(ModelTypeSet encrypted_types, | 276 void ModelTypeRegistry::OnEncryptedTypesChanged(ModelTypeSet encrypted_types, |
| 281 bool encrypt_everything) { | 277 bool encrypt_everything) { |
| 282 encrypted_types_ = encrypted_types; | 278 encrypted_types_ = encrypted_types; |
| 283 OnEncryptionStateChanged(); | 279 OnEncryptionStateChanged(); |
| 284 } | 280 } |
| 285 | 281 |
| 286 void ModelTypeRegistry::OnEncryptionComplete() { | 282 void ModelTypeRegistry::OnEncryptionComplete() {} |
| 287 } | |
| 288 | 283 |
| 289 void ModelTypeRegistry::OnCryptographerStateChanged( | 284 void ModelTypeRegistry::OnCryptographerStateChanged( |
| 290 Cryptographer* cryptographer) { | 285 Cryptographer* cryptographer) { |
| 291 cryptographer_.reset(new Cryptographer(*cryptographer)); | 286 cryptographer_.reset(new Cryptographer(*cryptographer)); |
| 292 OnEncryptionStateChanged(); | 287 OnEncryptionStateChanged(); |
| 293 } | 288 } |
| 294 | 289 |
| 295 void ModelTypeRegistry::OnPassphraseTypeChanged(PassphraseType type, | 290 void ModelTypeRegistry::OnPassphraseTypeChanged(PassphraseType type, |
| 296 base::Time passphrase_time) { | 291 base::Time passphrase_time) {} |
| 297 } | |
| 298 | 292 |
| 299 void ModelTypeRegistry::OnLocalSetPassphraseEncryption( | 293 void ModelTypeRegistry::OnLocalSetPassphraseEncryption( |
| 300 const SyncEncryptionHandler::NigoriState& nigori_state) { | 294 const SyncEncryptionHandler::NigoriState& nigori_state) {} |
| 301 } | |
| 302 | 295 |
| 303 ModelTypeSet ModelTypeRegistry::GetEnabledDirectoryTypes() const { | 296 ModelTypeSet ModelTypeRegistry::GetEnabledDirectoryTypes() const { |
| 304 return enabled_directory_types_; | 297 return enabled_directory_types_; |
| 305 } | 298 } |
| 306 | 299 |
| 307 void ModelTypeRegistry::OnEncryptionStateChanged() { | 300 void ModelTypeRegistry::OnEncryptionStateChanged() { |
| 308 for (ScopedVector<syncer_v2::ModelTypeWorker>::iterator it = | 301 for (ScopedVector<syncer_v2::ModelTypeWorker>::iterator it = |
| 309 model_type_workers_.begin(); | 302 model_type_workers_.begin(); |
| 310 it != model_type_workers_.end(); ++it) { | 303 it != model_type_workers_.end(); ++it) { |
| 311 if (encrypted_types_.Has((*it)->GetModelType())) { | 304 if (encrypted_types_.Has((*it)->GetModelType())) { |
| 312 (*it)->UpdateCryptographer( | 305 (*it)->UpdateCryptographer( |
| 313 base::WrapUnique(new Cryptographer(*cryptographer_))); | 306 base::WrapUnique(new Cryptographer(*cryptographer_))); |
| 314 } | 307 } |
| 315 } | 308 } |
| 316 } | 309 } |
| 317 | 310 |
| 318 ModelTypeSet ModelTypeRegistry::GetEnabledNonBlockingTypes() const { | 311 ModelTypeSet ModelTypeRegistry::GetEnabledNonBlockingTypes() const { |
| 319 ModelTypeSet enabled_non_blocking_types; | 312 ModelTypeSet enabled_non_blocking_types; |
| 320 for (ScopedVector<syncer_v2::ModelTypeWorker>::const_iterator it = | 313 for (ScopedVector<syncer_v2::ModelTypeWorker>::const_iterator it = |
| 321 model_type_workers_.begin(); | 314 model_type_workers_.begin(); |
| 322 it != model_type_workers_.end(); ++it) { | 315 it != model_type_workers_.end(); ++it) { |
| 323 enabled_non_blocking_types.Put((*it)->GetModelType()); | 316 enabled_non_blocking_types.Put((*it)->GetModelType()); |
| 324 } | 317 } |
| 325 return enabled_non_blocking_types; | 318 return enabled_non_blocking_types; |
| 326 } | 319 } |
| 327 | 320 |
| 328 } // namespace syncer | 321 } // namespace syncer |
| OLD | NEW |