| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 #ifndef COMPONENTS_POLICY_CORE_COMMON_SCHEMA_REGISTRY_H_ | 5 #ifndef COMPONENTS_POLICY_CORE_COMMON_SCHEMA_REGISTRY_H_ |
| 6 #define COMPONENTS_POLICY_CORE_COMMON_SCHEMA_REGISTRY_H_ | 6 #define COMPONENTS_POLICY_CORE_COMMON_SCHEMA_REGISTRY_H_ |
| 7 | 7 |
| 8 #include <set> | 8 #include <set> |
| 9 | 9 |
| 10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
| (...skipping 25 matching lines...) Expand all Loading... |
| 36 // (e.g. for periodic reloads). | 36 // (e.g. for periodic reloads). |
| 37 virtual void OnSchemaRegistryUpdated(bool has_new_schemas) = 0; | 37 virtual void OnSchemaRegistryUpdated(bool has_new_schemas) = 0; |
| 38 | 38 |
| 39 // Invoked when all policy domains become ready. | 39 // Invoked when all policy domains become ready. |
| 40 virtual void OnSchemaRegistryReady() = 0; | 40 virtual void OnSchemaRegistryReady() = 0; |
| 41 | 41 |
| 42 protected: | 42 protected: |
| 43 virtual ~Observer(); | 43 virtual ~Observer(); |
| 44 }; | 44 }; |
| 45 | 45 |
| 46 // This observer is only meant to be used by subclasses. |
| 47 class POLICY_EXPORT InternalObserver { |
| 48 public: |
| 49 // Invoked when |registry| is about to be destroyed. |
| 50 virtual void OnSchemaRegistryShuttingDown(SchemaRegistry* registry) = 0; |
| 51 |
| 52 protected: |
| 53 virtual ~InternalObserver(); |
| 54 }; |
| 55 |
| 46 SchemaRegistry(); | 56 SchemaRegistry(); |
| 47 virtual ~SchemaRegistry(); | 57 virtual ~SchemaRegistry(); |
| 48 | 58 |
| 49 const scoped_refptr<SchemaMap>& schema_map() const { return schema_map_; } | 59 const scoped_refptr<SchemaMap>& schema_map() const { return schema_map_; } |
| 50 | 60 |
| 51 // Register a single component. | 61 // Register a single component. |
| 52 void RegisterComponent(const PolicyNamespace& ns, | 62 void RegisterComponent(const PolicyNamespace& ns, |
| 53 const Schema& schema); | 63 const Schema& schema); |
| 54 | 64 |
| 55 // Register a list of components for a given domain. | 65 // Register a list of components for a given domain. |
| 56 virtual void RegisterComponents(PolicyDomain domain, | 66 virtual void RegisterComponents(PolicyDomain domain, |
| 57 const ComponentMap& components); | 67 const ComponentMap& components); |
| 58 | 68 |
| 59 virtual void UnregisterComponent(const PolicyNamespace& ns); | 69 virtual void UnregisterComponent(const PolicyNamespace& ns); |
| 60 | 70 |
| 61 // Returns true if all domains have registered the initial components. | 71 // Returns true if all domains have registered the initial components. |
| 62 bool IsReady() const; | 72 bool IsReady() const; |
| 63 | 73 |
| 64 // This indicates that the initial components for |domain| have all been | 74 // This indicates that the initial components for |domain| have all been |
| 65 // registered. It must be invoked at least once for each policy domain; | 75 // registered. It must be invoked at least once for each policy domain; |
| 66 // subsequent calls for the same domain are ignored. | 76 // subsequent calls for the same domain are ignored. |
| 67 void SetReady(PolicyDomain domain); | 77 void SetReady(PolicyDomain domain); |
| 68 | 78 |
| 69 void AddObserver(Observer* observer); | 79 void AddObserver(Observer* observer); |
| 70 void RemoveObserver(Observer* observer); | 80 void RemoveObserver(Observer* observer); |
| 71 | 81 |
| 72 bool HasObservers() const; | 82 void AddInternalObserver(InternalObserver* observer); |
| 83 void RemoveInternalObserver(InternalObserver* observer); |
| 73 | 84 |
| 74 protected: | 85 protected: |
| 75 void Notify(bool has_new_schemas); | 86 void Notify(bool has_new_schemas); |
| 76 | 87 |
| 77 scoped_refptr<SchemaMap> schema_map_; | 88 scoped_refptr<SchemaMap> schema_map_; |
| 78 | 89 |
| 79 private: | 90 private: |
| 80 ObserverList<Observer, true> observers_; | 91 ObserverList<Observer, true> observers_; |
| 92 ObserverList<InternalObserver, true> internal_observers_; |
| 81 bool domains_ready_[POLICY_DOMAIN_SIZE]; | 93 bool domains_ready_[POLICY_DOMAIN_SIZE]; |
| 82 | 94 |
| 83 DISALLOW_COPY_AND_ASSIGN(SchemaRegistry); | 95 DISALLOW_COPY_AND_ASSIGN(SchemaRegistry); |
| 84 }; | 96 }; |
| 85 | 97 |
| 86 // A registry that combines the maps of other registries. | 98 // A registry that combines the maps of other registries. |
| 87 class POLICY_EXPORT CombinedSchemaRegistry : public SchemaRegistry, | 99 class POLICY_EXPORT CombinedSchemaRegistry |
| 88 public SchemaRegistry::Observer { | 100 : public SchemaRegistry, |
| 101 public SchemaRegistry::Observer, |
| 102 public SchemaRegistry::InternalObserver { |
| 89 public: | 103 public: |
| 90 CombinedSchemaRegistry(); | 104 CombinedSchemaRegistry(); |
| 91 virtual ~CombinedSchemaRegistry(); | 105 virtual ~CombinedSchemaRegistry(); |
| 92 | 106 |
| 93 void Track(SchemaRegistry* registry); | 107 void Track(SchemaRegistry* registry); |
| 94 void Untrack(SchemaRegistry* registry); | |
| 95 | 108 |
| 109 // SchemaRegistry: |
| 96 virtual void RegisterComponents(PolicyDomain domain, | 110 virtual void RegisterComponents(PolicyDomain domain, |
| 97 const ComponentMap& components) OVERRIDE; | 111 const ComponentMap& components) OVERRIDE; |
| 98 | |
| 99 virtual void UnregisterComponent(const PolicyNamespace& ns) OVERRIDE; | 112 virtual void UnregisterComponent(const PolicyNamespace& ns) OVERRIDE; |
| 100 | 113 |
| 114 // SchemaRegistry::Observer: |
| 101 virtual void OnSchemaRegistryUpdated(bool has_new_schemas) OVERRIDE; | 115 virtual void OnSchemaRegistryUpdated(bool has_new_schemas) OVERRIDE; |
| 116 virtual void OnSchemaRegistryReady() OVERRIDE; |
| 102 | 117 |
| 103 virtual void OnSchemaRegistryReady() OVERRIDE; | 118 // SchemaRegistry::InternalObserver: |
| 119 virtual void OnSchemaRegistryShuttingDown(SchemaRegistry* registry) OVERRIDE; |
| 104 | 120 |
| 105 private: | 121 private: |
| 106 void Combine(bool has_new_schemas); | 122 void Combine(bool has_new_schemas); |
| 107 | 123 |
| 108 std::set<SchemaRegistry*> registries_; | 124 std::set<SchemaRegistry*> registries_; |
| 109 scoped_refptr<SchemaMap> own_schema_map_; | 125 scoped_refptr<SchemaMap> own_schema_map_; |
| 110 | 126 |
| 111 DISALLOW_COPY_AND_ASSIGN(CombinedSchemaRegistry); | 127 DISALLOW_COPY_AND_ASSIGN(CombinedSchemaRegistry); |
| 112 }; | 128 }; |
| 113 | 129 |
| 130 // A registry that wraps another schema registry. |
| 131 class POLICY_EXPORT ForwardingSchemaRegistry |
| 132 : public SchemaRegistry, |
| 133 public SchemaRegistry::Observer, |
| 134 public SchemaRegistry::InternalObserver { |
| 135 public: |
| 136 // This registry will stop updating its SchemaMap when |wrapped| is |
| 137 // destroyed. |
| 138 explicit ForwardingSchemaRegistry(SchemaRegistry* wrapped); |
| 139 virtual ~ForwardingSchemaRegistry(); |
| 140 |
| 141 // SchemaRegistry: |
| 142 virtual void RegisterComponents(PolicyDomain domain, |
| 143 const ComponentMap& components) OVERRIDE; |
| 144 virtual void UnregisterComponent(const PolicyNamespace& ns) OVERRIDE; |
| 145 |
| 146 // SchemaRegistry::Observer: |
| 147 virtual void OnSchemaRegistryUpdated(bool has_new_schemas) OVERRIDE; |
| 148 virtual void OnSchemaRegistryReady() OVERRIDE; |
| 149 |
| 150 // SchemaRegistry::InternalObserver: |
| 151 virtual void OnSchemaRegistryShuttingDown(SchemaRegistry* registry) OVERRIDE; |
| 152 |
| 153 private: |
| 154 SchemaRegistry* wrapped_; |
| 155 |
| 156 DISALLOW_COPY_AND_ASSIGN(ForwardingSchemaRegistry); |
| 157 }; |
| 158 |
| 114 } // namespace policy | 159 } // namespace policy |
| 115 | 160 |
| 116 #endif // COMPONENTS_POLICY_CORE_COMMON_SCHEMA_REGISTRY_H_ | 161 #endif // COMPONENTS_POLICY_CORE_COMMON_SCHEMA_REGISTRY_H_ |
| OLD | NEW |