Chromium Code Reviews| Index: components/policy/core/common/schema_registry.cc |
| diff --git a/components/policy/core/common/schema_registry.cc b/components/policy/core/common/schema_registry.cc |
| index ff9557956f3fcde42a78097caccd60f814d825bc..930d94f429eecb1c1f2dc8a307d1414b0dbf6e39 100644 |
| --- a/components/policy/core/common/schema_registry.cc |
| +++ b/components/policy/core/common/schema_registry.cc |
| @@ -10,6 +10,8 @@ namespace policy { |
| SchemaRegistry::Observer::~Observer() {} |
| +SchemaRegistry::InternalObserver::~InternalObserver() {} |
| + |
| SchemaRegistry::SchemaRegistry() : schema_map_(new SchemaMap) { |
| for (int i = 0; i < POLICY_DOMAIN_SIZE; ++i) |
| domains_ready_[i] = false; |
| @@ -18,7 +20,11 @@ SchemaRegistry::SchemaRegistry() : schema_map_(new SchemaMap) { |
| #endif |
| } |
| -SchemaRegistry::~SchemaRegistry() {} |
| +SchemaRegistry::~SchemaRegistry() { |
| + FOR_EACH_OBSERVER(InternalObserver, |
| + internal_observers_, |
| + OnSchemaRegistryShuttingDown(this)); |
| +} |
| void SchemaRegistry::RegisterComponent(const PolicyNamespace& ns, |
| const Schema& schema) { |
| @@ -77,15 +83,19 @@ void SchemaRegistry::RemoveObserver(Observer* observer) { |
| observers_.RemoveObserver(observer); |
| } |
| +void SchemaRegistry::AddInternalObserver(InternalObserver* observer) { |
| + internal_observers_.AddObserver(observer); |
| +} |
| + |
| +void SchemaRegistry::RemoveInternalObserver(InternalObserver* observer) { |
| + internal_observers_.RemoveObserver(observer); |
| +} |
| + |
| void SchemaRegistry::Notify(bool has_new_schemas) { |
| FOR_EACH_OBSERVER( |
| Observer, observers_, OnSchemaRegistryUpdated(has_new_schemas)); |
| } |
| -bool SchemaRegistry::HasObservers() const { |
| - return observers_.might_have_observers(); |
| -} |
| - |
| CombinedSchemaRegistry::CombinedSchemaRegistry() |
| : own_schema_map_(new SchemaMap) { |
| // The combined registry is always ready, since it can always start tracking |
| @@ -100,22 +110,13 @@ CombinedSchemaRegistry::~CombinedSchemaRegistry() {} |
| void CombinedSchemaRegistry::Track(SchemaRegistry* registry) { |
| registries_.insert(registry); |
| registry->AddObserver(this); |
| + registry->AddInternalObserver(this); |
| // Recombine the maps only if the |registry| has any components other than |
| // POLICY_DOMAIN_CHROME. |
| if (registry->schema_map()->HasComponents()) |
| Combine(true); |
| } |
| -void CombinedSchemaRegistry::Untrack(SchemaRegistry* registry) { |
| - registry->RemoveObserver(this); |
| - if (registries_.erase(registry) != 0) { |
| - if (registry->schema_map()->HasComponents()) |
| - Combine(false); |
| - } else { |
| - NOTREACHED(); |
| - } |
| -} |
| - |
| void CombinedSchemaRegistry::RegisterComponents( |
| PolicyDomain domain, |
| const ComponentMap& components) { |
| @@ -146,6 +147,18 @@ void CombinedSchemaRegistry::OnSchemaRegistryReady() { |
| // Ignore. |
| } |
| +void CombinedSchemaRegistry::OnSchemaRegistryShuttingDown( |
| + SchemaRegistry* registry) { |
| + registry->RemoveObserver(this); |
| + registry->RemoveInternalObserver(this); |
| + if (registries_.erase(registry) != 0) { |
| + if (registry->schema_map()->HasComponents()) |
| + Combine(false); |
| + } else { |
| + NOTREACHED(); |
| + } |
| +} |
| + |
| void CombinedSchemaRegistry::Combine(bool has_new_schemas) { |
| // If two registries publish a Schema for the same component then it's |
| // undefined which version gets in the combined registry. |
| @@ -175,4 +188,53 @@ void CombinedSchemaRegistry::Combine(bool has_new_schemas) { |
| Notify(has_new_schemas); |
| } |
| +ForwardingSchemaRegistry::ForwardingSchemaRegistry(SchemaRegistry* wrapped) |
| + : wrapped_(wrapped) { |
| + schema_map_ = wrapped_->schema_map(); |
| + wrapped_->AddObserver(this); |
| + wrapped_->AddInternalObserver(this); |
| + // This registry is always ready. |
| + for (int i = 0; i < POLICY_DOMAIN_SIZE; ++i) |
| + SetReady(static_cast<PolicyDomain>(i)); |
| +} |
| + |
| +ForwardingSchemaRegistry::~ForwardingSchemaRegistry() { |
| + if (wrapped_) { |
| + wrapped_->RemoveObserver(this); |
| + wrapped_->RemoveInternalObserver(this); |
| + } |
| +} |
| + |
| +void ForwardingSchemaRegistry::RegisterComponents( |
| + PolicyDomain domain, |
| + const ComponentMap& components) { |
| + if (wrapped_) |
| + wrapped_->RegisterComponents(domain, components); |
| + // else ignore. |
|
bartfab (slow)
2014/06/20 14:48:01
Nit: Make this more like a sentence, e.g. "Ignore
Joao da Silva
2014/06/20 15:30:14
Done.
|
| +} |
| + |
| +void ForwardingSchemaRegistry::UnregisterComponent(const PolicyNamespace& ns) { |
| + if (wrapped_) |
| + wrapped_->UnregisterComponent(ns); |
| + // else ignore. |
|
bartfab (slow)
2014/06/20 14:48:01
Nit: Make this more like a sentence, e.g. "Ignore
Joao da Silva
2014/06/20 15:30:14
Done.
|
| +} |
| + |
| +void ForwardingSchemaRegistry::OnSchemaRegistryUpdated(bool has_new_schemas) { |
| + schema_map_ = wrapped_->schema_map(); |
| + Notify(has_new_schemas); |
| +} |
| + |
| +void ForwardingSchemaRegistry::OnSchemaRegistryReady() { |
| + // Ignore. |
| +} |
| + |
| +void ForwardingSchemaRegistry::OnSchemaRegistryShuttingDown( |
| + SchemaRegistry* registry) { |
| + DCHECK_EQ(wrapped_, registry); |
| + wrapped_->RemoveObserver(this); |
| + wrapped_->RemoveInternalObserver(this); |
| + wrapped_ = NULL; |
| + // Keep serving the same |schema_map_|. |
| +} |
| + |
| } // namespace policy |