Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(249)

Unified Diff: components/policy/core/common/schema_registry.cc

Issue 349643002: Decoupled the SchemaRegistryService from SchemaRegistry. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase Created 6 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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..f3cb0ed64ced8236e167a3b0c5da105bcd1a5610 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);
+ // Ignore otherwise.
+}
+
+void ForwardingSchemaRegistry::UnregisterComponent(const PolicyNamespace& ns) {
+ if (wrapped_)
+ wrapped_->UnregisterComponent(ns);
+ // Ignore otherwise.
+}
+
+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
« no previous file with comments | « components/policy/core/common/schema_registry.h ('k') | components/policy/core/common/schema_registry_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698