Chromium Code Reviews| 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_update_handler.h" | 10 #include "sync/engine/directory_update_handler.h" |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 24 workers_map_.insert( | 24 workers_map_.insert( |
| 25 std::make_pair(workers[i]->GetModelSafeGroup(), workers[i])); | 25 std::make_pair(workers[i]->GetModelSafeGroup(), workers[i])); |
| 26 } | 26 } |
| 27 } | 27 } |
| 28 | 28 |
| 29 ModelTypeRegistry::~ModelTypeRegistry() {} | 29 ModelTypeRegistry::~ModelTypeRegistry() {} |
| 30 | 30 |
| 31 void ModelTypeRegistry::SetEnabledDirectoryTypes( | 31 void ModelTypeRegistry::SetEnabledDirectoryTypes( |
| 32 const ModelSafeRoutingInfo& routing_info) { | 32 const ModelSafeRoutingInfo& routing_info) { |
| 33 // Remove all existing directory processors and delete them. | 33 // Remove all existing directory processors and delete them. |
| 34 // The DebugInfoEmitters are not deleted, since we want to keep their counts | |
|
tim (not reviewing)
2014/04/30 23:24:50
I wouldn't use the term "not deleted" or "never de
rlarocque
2014/04/30 23:44:13
I figured that including disabled types would be a
| |
| 35 // in case the type is ever re-enabled. | |
| 34 for (ModelTypeSet::Iterator it = enabled_directory_types_.First(); | 36 for (ModelTypeSet::Iterator it = enabled_directory_types_.First(); |
| 35 it.Good(); it.Inc()) { | 37 it.Good(); it.Inc()) { |
| 36 size_t result1 = update_handler_map_.erase(it.Get()); | 38 size_t result1 = update_handler_map_.erase(it.Get()); |
| 37 size_t result2 = commit_contributor_map_.erase(it.Get()); | 39 size_t result2 = commit_contributor_map_.erase(it.Get()); |
| 38 size_t result3 = directory_type_debug_info_emitter_map_.erase(it.Get()); | |
| 39 DCHECK_EQ(1U, result1); | 40 DCHECK_EQ(1U, result1); |
| 40 DCHECK_EQ(1U, result2); | 41 DCHECK_EQ(1U, result2); |
| 41 DCHECK_EQ(1U, result3); | |
| 42 } | 42 } |
| 43 | 43 |
| 44 // Clear the old instances of directory update handlers and commit | 44 // Clear the old instances of directory update handlers and commit |
| 45 // contributors, deleting their contents in the processs. | 45 // contributors, deleting their contents in the processs. |
| 46 directory_update_handlers_.clear(); | 46 directory_update_handlers_.clear(); |
| 47 directory_commit_contributors_.clear(); | 47 directory_commit_contributors_.clear(); |
| 48 directory_type_debug_info_emitters_.clear(); | |
| 49 | 48 |
| 50 // Create new ones and add them to the appropriate containers. | 49 // Create new ones and add them to the appropriate containers. |
| 51 for (ModelSafeRoutingInfo::const_iterator routing_iter = routing_info.begin(); | 50 for (ModelSafeRoutingInfo::const_iterator routing_iter = routing_info.begin(); |
| 52 routing_iter != routing_info.end(); ++routing_iter) { | 51 routing_iter != routing_info.end(); ++routing_iter) { |
| 53 ModelType type = routing_iter->first; | 52 ModelType type = routing_iter->first; |
| 54 ModelSafeGroup group = routing_iter->second; | 53 ModelSafeGroup group = routing_iter->second; |
| 55 std::map<ModelSafeGroup, scoped_refptr<ModelSafeWorker> >::iterator | 54 std::map<ModelSafeGroup, scoped_refptr<ModelSafeWorker> >::iterator |
| 56 worker_it = workers_map_.find(group); | 55 worker_it = workers_map_.find(group); |
| 57 DCHECK(worker_it != workers_map_.end()); | 56 DCHECK(worker_it != workers_map_.end()); |
| 58 scoped_refptr<ModelSafeWorker> worker = worker_it->second; | 57 scoped_refptr<ModelSafeWorker> worker = worker_it->second; |
| 59 | 58 |
| 60 DirectoryTypeDebugInfoEmitter* emitter = | 59 // DebugInfoEmitters are never deleted. Use existing one if we have it. |
| 61 new DirectoryTypeDebugInfoEmitter(directory_, type, | 60 DirectoryTypeDebugInfoEmitter* emitter = NULL; |
| 62 &type_debug_info_observers_); | 61 DirectoryTypeDebugInfoEmitterMap::iterator it = |
| 62 directory_type_debug_info_emitter_map_.find(type); | |
| 63 if (it != directory_type_debug_info_emitter_map_.end()) { | |
| 64 emitter = it->second; | |
| 65 } else { | |
| 66 emitter = new DirectoryTypeDebugInfoEmitter(directory_, type, | |
| 67 &type_debug_info_observers_); | |
| 68 directory_type_debug_info_emitter_map_.insert( | |
| 69 std::make_pair(type, emitter)); | |
| 70 directory_type_debug_info_emitters_.push_back(emitter); | |
| 71 } | |
| 72 | |
| 63 DirectoryCommitContributor* committer = | 73 DirectoryCommitContributor* committer = |
| 64 new DirectoryCommitContributor(directory_, type); | 74 new DirectoryCommitContributor(directory_, type, emitter); |
| 65 DirectoryUpdateHandler* updater = | 75 DirectoryUpdateHandler* updater = |
| 66 new DirectoryUpdateHandler(directory_, type, worker); | 76 new DirectoryUpdateHandler(directory_, type, worker, emitter); |
| 67 | 77 |
| 68 // These containers take ownership of their contents. | 78 // These containers take ownership of their contents. |
| 69 directory_commit_contributors_.push_back(committer); | 79 directory_commit_contributors_.push_back(committer); |
| 70 directory_update_handlers_.push_back(updater); | 80 directory_update_handlers_.push_back(updater); |
| 71 directory_type_debug_info_emitters_.push_back(emitter); | |
| 72 | 81 |
| 73 bool inserted1 = | 82 bool inserted1 = |
| 74 update_handler_map_.insert(std::make_pair(type, updater)).second; | 83 update_handler_map_.insert(std::make_pair(type, updater)).second; |
| 75 DCHECK(inserted1) << "Attempt to override existing type handler in map"; | 84 DCHECK(inserted1) << "Attempt to override existing type handler in map"; |
| 76 | 85 |
| 77 bool inserted2 = | 86 bool inserted2 = |
| 78 commit_contributor_map_.insert(std::make_pair(type, committer)).second; | 87 commit_contributor_map_.insert(std::make_pair(type, committer)).second; |
| 79 DCHECK(inserted2) << "Attempt to override existing type handler in map"; | 88 DCHECK(inserted2) << "Attempt to override existing type handler in map"; |
| 80 | |
| 81 bool inserted3 = | |
| 82 directory_type_debug_info_emitter_map_.insert( | |
| 83 std::make_pair(type, emitter)).second; | |
| 84 DCHECK(inserted3) << "Attempt to override existing type handler in map"; | |
| 85 } | 89 } |
| 86 | 90 |
| 87 enabled_directory_types_ = GetRoutingInfoTypes(routing_info); | 91 enabled_directory_types_ = GetRoutingInfoTypes(routing_info); |
| 88 DCHECK(Intersection(GetEnabledDirectoryTypes(), | 92 DCHECK(Intersection(GetEnabledDirectoryTypes(), |
| 89 GetEnabledNonBlockingTypes()).Empty()); | 93 GetEnabledNonBlockingTypes()).Empty()); |
| 90 } | 94 } |
| 91 | 95 |
| 92 void ModelTypeRegistry::InitializeNonBlockingType( | 96 void ModelTypeRegistry::InitializeNonBlockingType( |
| 93 ModelType type, | 97 ModelType type, |
| 94 scoped_refptr<base::SequencedTaskRunner> type_task_runner, | 98 scoped_refptr<base::SequencedTaskRunner> type_task_runner, |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 168 ModelTypeSet enabled_off_thread_types; | 172 ModelTypeSet enabled_off_thread_types; |
| 169 for (ScopedVector<NonBlockingTypeProcessorCore>::const_iterator it = | 173 for (ScopedVector<NonBlockingTypeProcessorCore>::const_iterator it = |
| 170 non_blocking_type_processor_cores_.begin(); | 174 non_blocking_type_processor_cores_.begin(); |
| 171 it != non_blocking_type_processor_cores_.end(); ++it) { | 175 it != non_blocking_type_processor_cores_.end(); ++it) { |
| 172 enabled_off_thread_types.Put((*it)->GetModelType()); | 176 enabled_off_thread_types.Put((*it)->GetModelType()); |
| 173 } | 177 } |
| 174 return enabled_off_thread_types; | 178 return enabled_off_thread_types; |
| 175 } | 179 } |
| 176 | 180 |
| 177 } // namespace syncer | 181 } // namespace syncer |
| OLD | NEW |