1f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)// Copyright 2013 The Chromium Authors. All rights reserved.
2f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be
3f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)// found in the LICENSE file.
4f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)
5f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)#include "components/policy/core/common/schema_registry.h"
6f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)
7f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)#include "base/logging.h"
8f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)
9f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)namespace policy {
10f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)
11f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)SchemaRegistry::Observer::~Observer() {}
12f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)
136d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles)SchemaRegistry::InternalObserver::~InternalObserver() {}
146d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles)
15f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)SchemaRegistry::SchemaRegistry() : schema_map_(new SchemaMap) {
16f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  for (int i = 0; i < POLICY_DOMAIN_SIZE; ++i)
17f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)    domains_ready_[i] = false;
18f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)#if !defined(ENABLE_EXTENSIONS)
19f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  domains_ready_[POLICY_DOMAIN_EXTENSIONS] = true;
20f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)#endif
21f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)}
22f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)
236d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles)SchemaRegistry::~SchemaRegistry() {
246d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles)  FOR_EACH_OBSERVER(InternalObserver,
256d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles)                    internal_observers_,
266d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles)                    OnSchemaRegistryShuttingDown(this));
276d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles)}
28f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)
29f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)void SchemaRegistry::RegisterComponent(const PolicyNamespace& ns,
30f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)                                       const Schema& schema) {
31f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  ComponentMap map;
32f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  map[ns.component_id] = schema;
33f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  RegisterComponents(ns.domain, map);
34f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)}
35f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)
36f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)void SchemaRegistry::RegisterComponents(PolicyDomain domain,
37f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)                                        const ComponentMap& components) {
38f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  // Don't issue notifications if nothing is being registered.
39f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  if (components.empty())
40f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)    return;
41f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  // Assume that a schema was updated if the namespace was already registered
42f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  // before.
43f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  DomainMap map(schema_map_->GetDomains());
44f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  for (ComponentMap::const_iterator it = components.begin();
45f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)       it != components.end(); ++it) {
46f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)    map[domain][it->first] = it->second;
47f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  }
48f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  schema_map_ = new SchemaMap(map);
49f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  Notify(true);
50f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)}
51f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)
52f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)void SchemaRegistry::UnregisterComponent(const PolicyNamespace& ns) {
53f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  DomainMap map(schema_map_->GetDomains());
54f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  if (map[ns.domain].erase(ns.component_id) != 0) {
55f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)    schema_map_ = new SchemaMap(map);
56f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)    Notify(false);
57f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  } else {
58f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)    NOTREACHED();
59f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  }
60f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)}
61f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)
62f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)bool SchemaRegistry::IsReady() const {
63f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  for (int i = 0; i < POLICY_DOMAIN_SIZE; ++i) {
64f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)    if (!domains_ready_[i])
65f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)      return false;
66f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  }
67f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  return true;
68f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)}
69f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)
70f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)void SchemaRegistry::SetReady(PolicyDomain domain) {
71f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  if (domains_ready_[domain])
72f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)    return;
73f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  domains_ready_[domain] = true;
74f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  if (IsReady())
75f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)    FOR_EACH_OBSERVER(Observer, observers_, OnSchemaRegistryReady());
76f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)}
77f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)
78f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)void SchemaRegistry::AddObserver(Observer* observer) {
79f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  observers_.AddObserver(observer);
80f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)}
81f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)
82f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)void SchemaRegistry::RemoveObserver(Observer* observer) {
83f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  observers_.RemoveObserver(observer);
84f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)}
85f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)
866d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles)void SchemaRegistry::AddInternalObserver(InternalObserver* observer) {
876d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles)  internal_observers_.AddObserver(observer);
886d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles)}
896d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles)
906d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles)void SchemaRegistry::RemoveInternalObserver(InternalObserver* observer) {
916d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles)  internal_observers_.RemoveObserver(observer);
926d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles)}
936d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles)
94f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)void SchemaRegistry::Notify(bool has_new_schemas) {
95f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  FOR_EACH_OBSERVER(
96f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)      Observer, observers_, OnSchemaRegistryUpdated(has_new_schemas));
97f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)}
98f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)
99f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)CombinedSchemaRegistry::CombinedSchemaRegistry()
100f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)    : own_schema_map_(new SchemaMap) {
101f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  // The combined registry is always ready, since it can always start tracking
102f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  // another registry that is not ready yet and going from "ready" to "not
103f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  // ready" is not allowed.
104f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  for (int i = 0; i < POLICY_DOMAIN_SIZE; ++i)
105f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)    SetReady(static_cast<PolicyDomain>(i));
106f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)}
107f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)
108f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)CombinedSchemaRegistry::~CombinedSchemaRegistry() {}
109f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)
110f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)void CombinedSchemaRegistry::Track(SchemaRegistry* registry) {
111f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  registries_.insert(registry);
112f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  registry->AddObserver(this);
1136d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles)  registry->AddInternalObserver(this);
114f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  // Recombine the maps only if the |registry| has any components other than
115f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  // POLICY_DOMAIN_CHROME.
116f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  if (registry->schema_map()->HasComponents())
117f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)    Combine(true);
118f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)}
119f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)
120f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)void CombinedSchemaRegistry::RegisterComponents(
121f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)    PolicyDomain domain,
122f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)    const ComponentMap& components) {
123f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  DomainMap map(own_schema_map_->GetDomains());
124f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  for (ComponentMap::const_iterator it = components.begin();
125f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)       it != components.end(); ++it) {
126f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)    map[domain][it->first] = it->second;
127f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  }
128f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  own_schema_map_ = new SchemaMap(map);
129f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  Combine(true);
130f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)}
131f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)
132f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)void CombinedSchemaRegistry::UnregisterComponent(const PolicyNamespace& ns) {
133f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  DomainMap map(own_schema_map_->GetDomains());
134f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  if (map[ns.domain].erase(ns.component_id) != 0) {
135f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)    own_schema_map_ = new SchemaMap(map);
136f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)    Combine(false);
137f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  } else {
138f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)    NOTREACHED();
139f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  }
140f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)}
141f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)
142f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)void CombinedSchemaRegistry::OnSchemaRegistryUpdated(bool has_new_schemas) {
143f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  Combine(has_new_schemas);
144f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)}
145f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)
146f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)void CombinedSchemaRegistry::OnSchemaRegistryReady() {
147f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  // Ignore.
148f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)}
149f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)
1506d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles)void CombinedSchemaRegistry::OnSchemaRegistryShuttingDown(
1516d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles)    SchemaRegistry* registry) {
1526d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles)  registry->RemoveObserver(this);
1536d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles)  registry->RemoveInternalObserver(this);
1546d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles)  if (registries_.erase(registry) != 0) {
1556d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles)    if (registry->schema_map()->HasComponents())
1566d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles)      Combine(false);
1576d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles)  } else {
1586d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles)    NOTREACHED();
1596d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles)  }
1606d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles)}
1616d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles)
162f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)void CombinedSchemaRegistry::Combine(bool has_new_schemas) {
163f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  // If two registries publish a Schema for the same component then it's
164f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  // undefined which version gets in the combined registry.
165f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  //
166f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  // The common case is that both registries want policy for the same component,
167f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  // and the Schemas should be the same; in that case this makes no difference.
168f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  //
169f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  // But if the Schemas are different then one of the components is out of date.
170f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  // In that case the policy loaded will be valid only for one of them, until
171f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  // the outdated components are updated. This is a known limitation of the
172f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  // way policies are loaded currently, but isn't a problem worth fixing for
173f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  // the time being.
174f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  DomainMap map(own_schema_map_->GetDomains());
175f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  for (std::set<SchemaRegistry*>::const_iterator reg_it = registries_.begin();
176f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)       reg_it != registries_.end(); ++reg_it) {
177f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)    const DomainMap& reg_domain_map = (*reg_it)->schema_map()->GetDomains();
178f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)    for (DomainMap::const_iterator domain_it = reg_domain_map.begin();
179f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)         domain_it != reg_domain_map.end(); ++domain_it) {
180f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)      const ComponentMap& reg_component_map = domain_it->second;
181f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)      for (ComponentMap::const_iterator comp_it = reg_component_map.begin();
182f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)           comp_it != reg_component_map.end(); ++comp_it) {
183f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)        map[domain_it->first][comp_it->first] = comp_it->second;
184f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)      }
185f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)    }
186f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  }
187f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  schema_map_ = new SchemaMap(map);
188f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  Notify(has_new_schemas);
189f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)}
190f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)
1916d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles)ForwardingSchemaRegistry::ForwardingSchemaRegistry(SchemaRegistry* wrapped)
1926d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles)    : wrapped_(wrapped) {
1936d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles)  schema_map_ = wrapped_->schema_map();
1946d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles)  wrapped_->AddObserver(this);
1956d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles)  wrapped_->AddInternalObserver(this);
1966d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles)}
1976d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles)
1986d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles)ForwardingSchemaRegistry::~ForwardingSchemaRegistry() {
1996d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles)  if (wrapped_) {
2006d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles)    wrapped_->RemoveObserver(this);
2016d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles)    wrapped_->RemoveInternalObserver(this);
2026d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles)  }
2036d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles)}
2046d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles)
2056d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles)void ForwardingSchemaRegistry::RegisterComponents(
2066d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles)    PolicyDomain domain,
2076d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles)    const ComponentMap& components) {
208116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  // POLICY_DOMAIN_CHROME is skipped to avoid spurious updates when a new
209116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  // Profile is created. If the ForwardingSchemaRegistry is used outside
210116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  // device-level accounts then this should become configurable.
211116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  if (wrapped_ && domain != POLICY_DOMAIN_CHROME)
2126d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles)    wrapped_->RegisterComponents(domain, components);
2136d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles)  // Ignore otherwise.
2146d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles)}
2156d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles)
2166d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles)void ForwardingSchemaRegistry::UnregisterComponent(const PolicyNamespace& ns) {
2176d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles)  if (wrapped_)
2186d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles)    wrapped_->UnregisterComponent(ns);
2196d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles)  // Ignore otherwise.
2206d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles)}
2216d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles)
2226d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles)void ForwardingSchemaRegistry::OnSchemaRegistryUpdated(bool has_new_schemas) {
2236d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles)  schema_map_ = wrapped_->schema_map();
2246d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles)  Notify(has_new_schemas);
2256d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles)}
2266d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles)
2276d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles)void ForwardingSchemaRegistry::OnSchemaRegistryReady() {
2286d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles)  // Ignore.
2296d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles)}
2306d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles)
2316d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles)void ForwardingSchemaRegistry::OnSchemaRegistryShuttingDown(
2326d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles)    SchemaRegistry* registry) {
2336d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles)  DCHECK_EQ(wrapped_, registry);
2346d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles)  wrapped_->RemoveObserver(this);
2356d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles)  wrapped_->RemoveInternalObserver(this);
2366d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles)  wrapped_ = NULL;
2376d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles)  // Keep serving the same |schema_map_|.
2386d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles)}
2396d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles)
240f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)}  // namespace policy
241