| 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 "sync/sessions/model_type_registry.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/message_loop/message_loop_proxy.h" | 8 #include "base/message_loop/message_loop_proxy.h" |
| 9 #include "sync/engine/directory_commit_contributor.h" | 9 #include "sync/engine/directory_commit_contributor.h" |
| 10 #include "sync/engine/directory_type_debug_info_emitter.h" |
| 10 #include "sync/engine/directory_update_handler.h" | 11 #include "sync/engine/directory_update_handler.h" |
| 11 #include "sync/engine/non_blocking_type_processor_core.h" | 12 #include "sync/engine/non_blocking_type_processor_core.h" |
| 12 #include "sync/internal_api/public/non_blocking_type_processor.h" | 13 #include "sync/internal_api/public/non_blocking_type_processor.h" |
| 13 | 14 |
| 14 namespace syncer { | 15 namespace syncer { |
| 15 | 16 |
| 16 ModelTypeRegistry::ModelTypeRegistry() : directory_(NULL) {} | 17 ModelTypeRegistry::ModelTypeRegistry() : directory_(NULL) {} |
| 17 | 18 |
| 18 ModelTypeRegistry::ModelTypeRegistry( | 19 ModelTypeRegistry::ModelTypeRegistry( |
| 19 const std::vector<scoped_refptr<ModelSafeWorker> >& workers, | 20 const std::vector<scoped_refptr<ModelSafeWorker> >& workers, |
| 20 syncable::Directory* directory) | 21 syncable::Directory* directory) |
| 21 : directory_(directory) { | 22 : directory_(directory) { |
| 22 for (size_t i = 0u; i < workers.size(); ++i) { | 23 for (size_t i = 0u; i < workers.size(); ++i) { |
| 23 workers_map_.insert( | 24 workers_map_.insert( |
| 24 std::make_pair(workers[i]->GetModelSafeGroup(), workers[i])); | 25 std::make_pair(workers[i]->GetModelSafeGroup(), workers[i])); |
| 25 } | 26 } |
| 26 } | 27 } |
| 27 | 28 |
| 28 ModelTypeRegistry::~ModelTypeRegistry() {} | 29 ModelTypeRegistry::~ModelTypeRegistry() {} |
| 29 | 30 |
| 30 void ModelTypeRegistry::SetEnabledDirectoryTypes( | 31 void ModelTypeRegistry::SetEnabledDirectoryTypes( |
| 31 const ModelSafeRoutingInfo& routing_info) { | 32 const ModelSafeRoutingInfo& routing_info) { |
| 32 // Remove all existing directory processors and delete them. | 33 // Remove all existing directory processors and delete them. |
| 33 for (ModelTypeSet::Iterator it = enabled_directory_types_.First(); | 34 for (ModelTypeSet::Iterator it = enabled_directory_types_.First(); |
| 34 it.Good(); it.Inc()) { | 35 it.Good(); it.Inc()) { |
| 35 size_t result1 = update_handler_map_.erase(it.Get()); | 36 size_t result1 = update_handler_map_.erase(it.Get()); |
| 36 size_t result2 = commit_contributor_map_.erase(it.Get()); | 37 size_t result2 = commit_contributor_map_.erase(it.Get()); |
| 38 size_t result3 = directory_type_debug_info_emitter_map_.erase(it.Get()); |
| 37 DCHECK_EQ(1U, result1); | 39 DCHECK_EQ(1U, result1); |
| 38 DCHECK_EQ(1U, result2); | 40 DCHECK_EQ(1U, result2); |
| 41 DCHECK_EQ(1U, result3); |
| 39 } | 42 } |
| 40 | 43 |
| 41 // Clear the old instances of directory update handlers and commit | 44 // Clear the old instances of directory update handlers and commit |
| 42 // contributors, deleting their contents in the processs. | 45 // contributors, deleting their contents in the processs. |
| 43 directory_update_handlers_.clear(); | 46 directory_update_handlers_.clear(); |
| 44 directory_commit_contributors_.clear(); | 47 directory_commit_contributors_.clear(); |
| 48 directory_type_debug_info_emitters_.clear(); |
| 45 | 49 |
| 46 // Create new ones and add them to the appropriate containers. | 50 // Create new ones and add them to the appropriate containers. |
| 47 for (ModelSafeRoutingInfo::const_iterator routing_iter = routing_info.begin(); | 51 for (ModelSafeRoutingInfo::const_iterator routing_iter = routing_info.begin(); |
| 48 routing_iter != routing_info.end(); ++routing_iter) { | 52 routing_iter != routing_info.end(); ++routing_iter) { |
| 49 ModelType type = routing_iter->first; | 53 ModelType type = routing_iter->first; |
| 50 ModelSafeGroup group = routing_iter->second; | 54 ModelSafeGroup group = routing_iter->second; |
| 51 std::map<ModelSafeGroup, scoped_refptr<ModelSafeWorker> >::iterator | 55 std::map<ModelSafeGroup, scoped_refptr<ModelSafeWorker> >::iterator |
| 52 worker_it = workers_map_.find(group); | 56 worker_it = workers_map_.find(group); |
| 53 DCHECK(worker_it != workers_map_.end()); | 57 DCHECK(worker_it != workers_map_.end()); |
| 54 scoped_refptr<ModelSafeWorker> worker = worker_it->second; | 58 scoped_refptr<ModelSafeWorker> worker = worker_it->second; |
| 55 | 59 |
| 56 DirectoryCommitContributor* committer = | 60 DirectoryCommitContributor* committer = |
| 57 new DirectoryCommitContributor(directory_, type); | 61 new DirectoryCommitContributor(directory_, type); |
| 58 DirectoryUpdateHandler* updater = | 62 DirectoryUpdateHandler* updater = |
| 59 new DirectoryUpdateHandler(directory_, type, worker); | 63 new DirectoryUpdateHandler(directory_, type, worker); |
| 64 DirectoryTypeDebugInfoEmitter* emitter = |
| 65 new DirectoryTypeDebugInfoEmitter(directory_, type); |
| 60 | 66 |
| 61 // These containers take ownership of their contents. | 67 // These containers take ownership of their contents. |
| 62 directory_commit_contributors_.push_back(committer); | 68 directory_commit_contributors_.push_back(committer); |
| 63 directory_update_handlers_.push_back(updater); | 69 directory_update_handlers_.push_back(updater); |
| 70 directory_type_debug_info_emitters_.push_back(emitter); |
| 64 | 71 |
| 65 bool inserted1 = | 72 bool inserted1 = |
| 66 update_handler_map_.insert(std::make_pair(type, updater)).second; | 73 update_handler_map_.insert(std::make_pair(type, updater)).second; |
| 67 DCHECK(inserted1) << "Attempt to override existing type handler in map"; | 74 DCHECK(inserted1) << "Attempt to override existing type handler in map"; |
| 68 | 75 |
| 69 bool inserted2 = | 76 bool inserted2 = |
| 70 commit_contributor_map_.insert(std::make_pair(type, committer)).second; | 77 commit_contributor_map_.insert(std::make_pair(type, committer)).second; |
| 71 DCHECK(inserted2) << "Attempt to override existing type handler in map"; | 78 DCHECK(inserted2) << "Attempt to override existing type handler in map"; |
| 79 |
| 80 bool inserted3 = |
| 81 directory_type_debug_info_emitter_map_.insert( |
| 82 std::make_pair(type, emitter)).second; |
| 83 DCHECK(inserted3) << "Attempt to override existing type handler in map"; |
| 72 } | 84 } |
| 73 | 85 |
| 74 enabled_directory_types_ = GetRoutingInfoTypes(routing_info); | 86 enabled_directory_types_ = GetRoutingInfoTypes(routing_info); |
| 75 DCHECK(Intersection(GetEnabledDirectoryTypes(), | 87 DCHECK(Intersection(GetEnabledDirectoryTypes(), |
| 76 GetEnabledNonBlockingTypes()).Empty()); | 88 GetEnabledNonBlockingTypes()).Empty()); |
| 77 } | 89 } |
| 78 | 90 |
| 79 void ModelTypeRegistry::InitializeNonBlockingType( | 91 void ModelTypeRegistry::InitializeNonBlockingType( |
| 80 ModelType type, | 92 ModelType type, |
| 81 scoped_refptr<base::SequencedTaskRunner> type_task_runner, | 93 scoped_refptr<base::SequencedTaskRunner> type_task_runner, |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 135 } | 147 } |
| 136 | 148 |
| 137 UpdateHandlerMap* ModelTypeRegistry::update_handler_map() { | 149 UpdateHandlerMap* ModelTypeRegistry::update_handler_map() { |
| 138 return &update_handler_map_; | 150 return &update_handler_map_; |
| 139 } | 151 } |
| 140 | 152 |
| 141 CommitContributorMap* ModelTypeRegistry::commit_contributor_map() { | 153 CommitContributorMap* ModelTypeRegistry::commit_contributor_map() { |
| 142 return &commit_contributor_map_; | 154 return &commit_contributor_map_; |
| 143 } | 155 } |
| 144 | 156 |
| 157 DirectoryTypeDebugInfoEmitterMap* |
| 158 ModelTypeRegistry::directory_type_debug_info_emitter_map() { |
| 159 return &directory_type_debug_info_emitter_map_; |
| 160 } |
| 161 |
| 145 ModelTypeSet ModelTypeRegistry::GetEnabledDirectoryTypes() const { | 162 ModelTypeSet ModelTypeRegistry::GetEnabledDirectoryTypes() const { |
| 146 return enabled_directory_types_; | 163 return enabled_directory_types_; |
| 147 } | 164 } |
| 148 | 165 |
| 149 ModelTypeSet ModelTypeRegistry::GetEnabledNonBlockingTypes() const { | 166 ModelTypeSet ModelTypeRegistry::GetEnabledNonBlockingTypes() const { |
| 150 ModelTypeSet enabled_off_thread_types; | 167 ModelTypeSet enabled_off_thread_types; |
| 151 for (ScopedVector<NonBlockingTypeProcessorCore>::const_iterator it = | 168 for (ScopedVector<NonBlockingTypeProcessorCore>::const_iterator it = |
| 152 non_blocking_type_processor_cores_.begin(); | 169 non_blocking_type_processor_cores_.begin(); |
| 153 it != non_blocking_type_processor_cores_.end(); ++it) { | 170 it != non_blocking_type_processor_cores_.end(); ++it) { |
| 154 enabled_off_thread_types.Put((*it)->GetModelType()); | 171 enabled_off_thread_types.Put((*it)->GetModelType()); |
| 155 } | 172 } |
| 156 return enabled_off_thread_types; | 173 return enabled_off_thread_types; |
| 157 } | 174 } |
| 158 | 175 |
| 159 } // namespace syncer | 176 } // namespace syncer |
| OLD | NEW |