Commit 6754203e authored by skym's avatar skym Committed by Commit bot

[Sync] Removed ScopdVector and raw news from ModelTypeRegistry.

BUG=658053

Review-Url: https://chromiumcodereview.appspot.com/2437873006
Cr-Commit-Position: refs/heads/master@{#426856}
parent 78760ccd
...@@ -17,20 +17,20 @@ namespace { ...@@ -17,20 +17,20 @@ namespace {
void NonPassiveApplyUpdates(ModelTypeSet gu_types, void NonPassiveApplyUpdates(ModelTypeSet gu_types,
StatusController* status_controller, StatusController* status_controller,
UpdateHandlerMap* update_handler_map) { UpdateHandlerMap* update_handler_map) {
for (UpdateHandlerMap::iterator it = update_handler_map->begin(); for (const auto& kv : *update_handler_map) {
it != update_handler_map->end(); ++it) { if (gu_types.Has(kv.first)) {
if (gu_types.Has(it->first)) kv.second->ApplyUpdates(status_controller);
it->second->ApplyUpdates(status_controller); }
} }
} }
void PassiveApplyUpdates(ModelTypeSet gu_types, void PassiveApplyUpdates(ModelTypeSet gu_types,
StatusController* status_controller, StatusController* status_controller,
UpdateHandlerMap* update_handler_map) { UpdateHandlerMap* update_handler_map) {
for (UpdateHandlerMap::iterator it = update_handler_map->begin(); for (const auto& kv : *update_handler_map) {
it != update_handler_map->end(); ++it) { if (gu_types.Has(kv.first)) {
if (gu_types.Has(it->first)) kv.second->PassiveApplyUpdates(status_controller);
it->second->PassiveApplyUpdates(status_controller); }
} }
} }
......
...@@ -88,47 +88,36 @@ void ModelTypeRegistry::SetEnabledDirectoryTypes( ...@@ -88,47 +88,36 @@ void ModelTypeRegistry::SetEnabledDirectoryTypes(
enabled_directory_types_.Clear(); enabled_directory_types_.Clear();
// Create new ones and add them to the appropriate containers. // Create new ones and add them to the appropriate containers.
for (ModelSafeRoutingInfo::const_iterator routing_iter = routing_info.begin(); for (const auto& routing_kv : routing_info) {
routing_iter != routing_info.end(); ++routing_iter) { ModelType type = routing_kv.first;
ModelType type = routing_iter->first; ModelSafeGroup group = routing_kv.second;
ModelSafeGroup group = routing_iter->second;
if (group == GROUP_NON_BLOCKING) if (group == GROUP_NON_BLOCKING)
continue; continue;
std::map<ModelSafeGroup, scoped_refptr<ModelSafeWorker>>::iterator std::map<ModelSafeGroup, scoped_refptr<ModelSafeWorker>>::iterator
worker_it = workers_map_.find(group); worker_it = workers_map_.find(group);
DCHECK(worker_it != workers_map_.end()); DCHECK(worker_it != workers_map_.end());
scoped_refptr<ModelSafeWorker> worker = worker_it->second; scoped_refptr<ModelSafeWorker> worker = worker_it->second;
// DebugInfoEmitters are never deleted. Use existing one if we have it. DirectoryTypeDebugInfoEmitter* emitter = GetOrCreateEmitter(type);
DirectoryTypeDebugInfoEmitter* emitter = nullptr;
DirectoryTypeDebugInfoEmitterMap::iterator it = auto updater = base::MakeUnique<DirectoryUpdateHandler>(directory_, type,
directory_type_debug_info_emitter_map_.find(type); worker, emitter);
if (it != directory_type_debug_info_emitter_map_.end()) { bool updater_inserted =
emitter = it->second; update_handler_map_.insert(std::make_pair(type, updater.get())).second;
} else { DCHECK(updater_inserted)
emitter = new DirectoryTypeDebugInfoEmitter(directory_, type, << "Attempt to override existing type handler in map";
&type_debug_info_observers_); directory_update_handlers_.push_back(std::move(updater));
directory_type_debug_info_emitter_map_.insert(
std::make_pair(type, emitter)); auto committer =
directory_type_debug_info_emitters_.push_back(emitter); base::MakeUnique<DirectoryCommitContributor>(directory_, type, emitter);
} bool committer_inserted =
commit_contributor_map_.insert(std::make_pair(type, committer.get()))
DirectoryCommitContributor* committer = .second;
new DirectoryCommitContributor(directory_, type, emitter); DCHECK(committer_inserted)
DirectoryUpdateHandler* updater = << "Attempt to override existing type handler in map";
new DirectoryUpdateHandler(directory_, type, worker, emitter); directory_commit_contributors_.push_back(std::move(committer));
// These containers take ownership of their contents.
directory_commit_contributors_.push_back(committer);
directory_update_handlers_.push_back(updater);
bool inserted1 =
update_handler_map_.insert(std::make_pair(type, updater)).second;
DCHECK(inserted1) << "Attempt to override existing type handler in map";
bool inserted2 =
commit_contributor_map_.insert(std::make_pair(type, committer)).second;
DCHECK(inserted2) << "Attempt to override existing type handler in map";
enabled_directory_types_.Put(type); enabled_directory_types_.Put(type);
} }
...@@ -148,14 +137,13 @@ void ModelTypeRegistry::ConnectType( ...@@ -148,14 +137,13 @@ void ModelTypeRegistry::ConnectType(
if (encrypted_types_.Has(type)) if (encrypted_types_.Has(type))
cryptographer_copy = base::MakeUnique<Cryptographer>(*cryptographer_); cryptographer_copy = base::MakeUnique<Cryptographer>(*cryptographer_);
std::unique_ptr<ModelTypeWorker> worker(new ModelTypeWorker( auto worker = base::MakeUnique<ModelTypeWorker>(
type, activation_context->model_type_state, std::move(cryptographer_copy), type, activation_context->model_type_state, std::move(cryptographer_copy),
nudge_handler_, std::move(activation_context->type_processor))); nudge_handler_, std::move(activation_context->type_processor));
// Initialize Processor -> Worker communication channel. // Initialize Processor -> Worker communication channel.
std::unique_ptr<CommitQueue> commit_queue_proxy(new CommitQueueProxy( auto commit_queue_proxy = base::MakeUnique<CommitQueueProxy>(
worker->AsWeakPtr(), scoped_refptr<base::SequencedTaskRunner>( worker->AsWeakPtr(), base::ThreadTaskRunnerHandle::Get());
base::ThreadTaskRunnerHandle::Get())));
type_processor->ConnectSync(std::move(commit_queue_proxy)); type_processor->ConnectSync(std::move(commit_queue_proxy));
...@@ -183,14 +171,11 @@ void ModelTypeRegistry::DisconnectType(ModelType type) { ...@@ -183,14 +171,11 @@ void ModelTypeRegistry::DisconnectType(ModelType type) {
DCHECK_EQ(1U, updaters_erased); DCHECK_EQ(1U, updaters_erased);
DCHECK_EQ(1U, committers_erased); DCHECK_EQ(1U, committers_erased);
// Remove from the ScopedVector, deleting the worker in the process. model_type_workers_.erase(std::remove_if(
for (ScopedVector<ModelTypeWorker>::iterator it = model_type_workers_.begin(); model_type_workers_.begin(), model_type_workers_.end(),
it != model_type_workers_.end(); ++it) { [type](const std::unique_ptr<ModelTypeWorker>& worker) -> bool {
if ((*it)->GetModelType() == type) { return worker->GetModelType() == type;
model_type_workers_.erase(it); }));
break;
}
}
} }
ModelTypeSet ModelTypeRegistry::GetEnabledTypes() const { ModelTypeSet ModelTypeRegistry::GetEnabledTypes() const {
...@@ -221,11 +206,6 @@ CommitContributorMap* ModelTypeRegistry::commit_contributor_map() { ...@@ -221,11 +206,6 @@ CommitContributorMap* ModelTypeRegistry::commit_contributor_map() {
return &commit_contributor_map_; return &commit_contributor_map_;
} }
DirectoryTypeDebugInfoEmitterMap*
ModelTypeRegistry::directory_type_debug_info_emitter_map() {
return &directory_type_debug_info_emitter_map_;
}
void ModelTypeRegistry::RegisterDirectoryTypeDebugInfoObserver( void ModelTypeRegistry::RegisterDirectoryTypeDebugInfoObserver(
TypeDebugInfoObserver* observer) { TypeDebugInfoObserver* observer) {
if (!type_debug_info_observers_.HasObserver(observer)) if (!type_debug_info_observers_.HasObserver(observer))
...@@ -243,12 +223,10 @@ bool ModelTypeRegistry::HasDirectoryTypeDebugInfoObserver( ...@@ -243,12 +223,10 @@ bool ModelTypeRegistry::HasDirectoryTypeDebugInfoObserver(
} }
void ModelTypeRegistry::RequestEmitDebugInfo() { void ModelTypeRegistry::RequestEmitDebugInfo() {
for (DirectoryTypeDebugInfoEmitterMap::iterator it = for (const auto& kv : directory_type_debug_info_emitter_map_) {
directory_type_debug_info_emitter_map_.begin(); kv.second->EmitCommitCountersUpdate();
it != directory_type_debug_info_emitter_map_.end(); ++it) { kv.second->EmitUpdateCountersUpdate();
it->second->EmitCommitCountersUpdate(); kv.second->EmitStatusCountersUpdate();
it->second->EmitUpdateCountersUpdate();
it->second->EmitStatusCountersUpdate();
} }
} }
...@@ -261,10 +239,9 @@ void ModelTypeRegistry::OnPassphraseRequired( ...@@ -261,10 +239,9 @@ void ModelTypeRegistry::OnPassphraseRequired(
const sync_pb::EncryptedData& pending_keys) {} const sync_pb::EncryptedData& pending_keys) {}
void ModelTypeRegistry::OnPassphraseAccepted() { void ModelTypeRegistry::OnPassphraseAccepted() {
for (ScopedVector<ModelTypeWorker>::iterator it = model_type_workers_.begin(); for (const auto& worker : model_type_workers_) {
it != model_type_workers_.end(); ++it) { if (encrypted_types_.Has(worker->GetModelType())) {
if (encrypted_types_.Has((*it)->GetModelType())) { worker->EncryptionAcceptedApplyUpdates();
(*it)->EncryptionAcceptedApplyUpdates();
} }
} }
} }
...@@ -298,26 +275,39 @@ void ModelTypeRegistry::OnPassphraseTypeChanged(PassphraseType type, ...@@ -298,26 +275,39 @@ void ModelTypeRegistry::OnPassphraseTypeChanged(PassphraseType type,
void ModelTypeRegistry::OnLocalSetPassphraseEncryption( void ModelTypeRegistry::OnLocalSetPassphraseEncryption(
const SyncEncryptionHandler::NigoriState& nigori_state) {} const SyncEncryptionHandler::NigoriState& nigori_state) {}
ModelTypeSet ModelTypeRegistry::GetEnabledDirectoryTypes() const {
return enabled_directory_types_;
}
void ModelTypeRegistry::OnEncryptionStateChanged() { void ModelTypeRegistry::OnEncryptionStateChanged() {
for (ScopedVector<ModelTypeWorker>::iterator it = model_type_workers_.begin(); for (const auto& worker : model_type_workers_) {
it != model_type_workers_.end(); ++it) { if (encrypted_types_.Has(worker->GetModelType())) {
if (encrypted_types_.Has((*it)->GetModelType())) { worker->UpdateCryptographer(
(*it)->UpdateCryptographer(
base::MakeUnique<Cryptographer>(*cryptographer_)); base::MakeUnique<Cryptographer>(*cryptographer_));
} }
} }
} }
DirectoryTypeDebugInfoEmitter* ModelTypeRegistry::GetOrCreateEmitter(
ModelType type) {
DirectoryTypeDebugInfoEmitter* raw_emitter = nullptr;
auto it = directory_type_debug_info_emitter_map_.find(type);
if (it != directory_type_debug_info_emitter_map_.end()) {
raw_emitter = it->second.get();
} else {
auto emitter = base::MakeUnique<DirectoryTypeDebugInfoEmitter>(
directory_, type, &type_debug_info_observers_);
raw_emitter = emitter.get();
directory_type_debug_info_emitter_map_.insert(
std::make_pair(type, std::move(emitter)));
}
return raw_emitter;
}
ModelTypeSet ModelTypeRegistry::GetEnabledDirectoryTypes() const {
return enabled_directory_types_;
}
ModelTypeSet ModelTypeRegistry::GetEnabledNonBlockingTypes() const { ModelTypeSet ModelTypeRegistry::GetEnabledNonBlockingTypes() const {
ModelTypeSet enabled_non_blocking_types; ModelTypeSet enabled_non_blocking_types;
for (ScopedVector<ModelTypeWorker>::const_iterator it = for (const auto& worker : model_type_workers_) {
model_type_workers_.begin(); enabled_non_blocking_types.Put(worker->GetModelType());
it != model_type_workers_.end(); ++it) {
enabled_non_blocking_types.Put((*it)->GetModelType());
} }
return enabled_non_blocking_types; return enabled_non_blocking_types;
} }
......
...@@ -11,7 +11,6 @@ ...@@ -11,7 +11,6 @@
#include <vector> #include <vector>
#include "base/macros.h" #include "base/macros.h"
#include "base/memory/scoped_vector.h"
#include "base/memory/weak_ptr.h" #include "base/memory/weak_ptr.h"
#include "components/sync/base/model_type.h" #include "components/sync/base/model_type.h"
#include "components/sync/engine/cycle/type_debug_info_observer.h" #include "components/sync/engine/cycle/type_debug_info_observer.h"
...@@ -38,8 +37,6 @@ class Directory; ...@@ -38,8 +37,6 @@ class Directory;
typedef std::map<ModelType, UpdateHandler*> UpdateHandlerMap; typedef std::map<ModelType, UpdateHandler*> UpdateHandlerMap;
typedef std::map<ModelType, CommitContributor*> CommitContributorMap; typedef std::map<ModelType, CommitContributor*> CommitContributorMap;
typedef std::map<ModelType, DirectoryTypeDebugInfoEmitter*>
DirectoryTypeDebugInfoEmitterMap;
// Keeps track of the sets of active update handlers and commit contributors. // Keeps track of the sets of active update handlers and commit contributors.
class ModelTypeRegistry : public ModelTypeConnector, class ModelTypeRegistry : public ModelTypeConnector,
...@@ -94,7 +91,6 @@ class ModelTypeRegistry : public ModelTypeConnector, ...@@ -94,7 +91,6 @@ class ModelTypeRegistry : public ModelTypeConnector,
// Simple getters. // Simple getters.
UpdateHandlerMap* update_handler_map(); UpdateHandlerMap* update_handler_map();
CommitContributorMap* commit_contributor_map(); CommitContributorMap* commit_contributor_map();
DirectoryTypeDebugInfoEmitterMap* directory_type_debug_info_emitter_map();
void RegisterDirectoryTypeDebugInfoObserver(TypeDebugInfoObserver* observer); void RegisterDirectoryTypeDebugInfoObserver(TypeDebugInfoObserver* observer);
void UnregisterDirectoryTypeDebugInfoObserver( void UnregisterDirectoryTypeDebugInfoObserver(
...@@ -106,18 +102,24 @@ class ModelTypeRegistry : public ModelTypeConnector, ...@@ -106,18 +102,24 @@ class ModelTypeRegistry : public ModelTypeConnector,
base::WeakPtr<ModelTypeConnector> AsWeakPtr(); base::WeakPtr<ModelTypeConnector> AsWeakPtr();
private: private:
typedef std::map<ModelType, std::unique_ptr<DirectoryTypeDebugInfoEmitter>>
DirectoryTypeDebugInfoEmitterMap;
void OnEncryptionStateChanged(); void OnEncryptionStateChanged();
// DebugInfoEmitters are never deleted. Returns an existing one if we have it.
DirectoryTypeDebugInfoEmitter* GetOrCreateEmitter(ModelType type);
ModelTypeSet GetEnabledNonBlockingTypes() const; ModelTypeSet GetEnabledNonBlockingTypes() const;
ModelTypeSet GetEnabledDirectoryTypes() const; ModelTypeSet GetEnabledDirectoryTypes() const;
// Sets of handlers and contributors. // Sets of handlers and contributors.
ScopedVector<DirectoryCommitContributor> directory_commit_contributors_; std::vector<std::unique_ptr<DirectoryCommitContributor>>
ScopedVector<DirectoryUpdateHandler> directory_update_handlers_; directory_commit_contributors_;
ScopedVector<DirectoryTypeDebugInfoEmitter> std::vector<std::unique_ptr<DirectoryUpdateHandler>>
directory_type_debug_info_emitters_; directory_update_handlers_;
ScopedVector<ModelTypeWorker> model_type_workers_; std::vector<std::unique_ptr<ModelTypeWorker>> model_type_workers_;
// Maps of UpdateHandlers and CommitContributors. // Maps of UpdateHandlers and CommitContributors.
// They do not own any of the objects they point to. // They do not own any of the objects they point to.
...@@ -126,7 +128,6 @@ class ModelTypeRegistry : public ModelTypeConnector, ...@@ -126,7 +128,6 @@ class ModelTypeRegistry : public ModelTypeConnector,
// Map of DebugInfoEmitters for directory types. // Map of DebugInfoEmitters for directory types.
// Non-blocking types handle debug info differently. // Non-blocking types handle debug info differently.
// Does not own its contents.
DirectoryTypeDebugInfoEmitterMap directory_type_debug_info_emitter_map_; DirectoryTypeDebugInfoEmitterMap directory_type_debug_info_emitter_map_;
// The known ModelSafeWorkers. // The known ModelSafeWorkers.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment