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 CHROME_BROWSER_POLICY_SCHEMA_REGISTRY_H_ | 5 #ifndef CHROME_BROWSER_POLICY_SCHEMA_REGISTRY_H_ |
6 #define CHROME_BROWSER_POLICY_SCHEMA_REGISTRY_H_ | 6 #define CHROME_BROWSER_POLICY_SCHEMA_REGISTRY_H_ |
7 | 7 |
8 #include <set> | 8 #include <set> |
9 | 9 |
10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
(...skipping 17 matching lines...) Expand all Loading... |
28 public: | 28 public: |
29 class Observer { | 29 class Observer { |
30 public: | 30 public: |
31 // Invoked whenever schemas are registered or unregistered. | 31 // Invoked whenever schemas are registered or unregistered. |
32 // |has_new_schemas| is true if a new component has been registered since | 32 // |has_new_schemas| is true if a new component has been registered since |
33 // the last update; this allows observers to ignore updates when | 33 // the last update; this allows observers to ignore updates when |
34 // components are unregistered but still get a handle to the current map | 34 // components are unregistered but still get a handle to the current map |
35 // (e.g. for periodic reloads). | 35 // (e.g. for periodic reloads). |
36 virtual void OnSchemaRegistryUpdated(bool has_new_schemas) = 0; | 36 virtual void OnSchemaRegistryUpdated(bool has_new_schemas) = 0; |
37 | 37 |
| 38 // Invoked when all policy domains become ready. |
| 39 virtual void OnSchemaRegistryReady() = 0; |
| 40 |
38 protected: | 41 protected: |
39 virtual ~Observer(); | 42 virtual ~Observer(); |
40 }; | 43 }; |
41 | 44 |
42 SchemaRegistry(); | 45 SchemaRegistry(); |
43 virtual ~SchemaRegistry(); | 46 virtual ~SchemaRegistry(); |
44 | 47 |
45 const scoped_refptr<SchemaMap>& schema_map() const { return schema_map_; } | 48 const scoped_refptr<SchemaMap>& schema_map() const { return schema_map_; } |
46 | 49 |
47 // Register a single component. | 50 // Register a single component. |
48 void RegisterComponent(const PolicyNamespace& ns, | 51 void RegisterComponent(const PolicyNamespace& ns, |
49 const Schema& schema); | 52 const Schema& schema); |
50 | 53 |
51 // Register a list of components for a given domain. | 54 // Register a list of components for a given domain. |
52 virtual void RegisterComponents(PolicyDomain domain, | 55 virtual void RegisterComponents(PolicyDomain domain, |
53 const ComponentMap& components); | 56 const ComponentMap& components); |
54 | 57 |
55 virtual void UnregisterComponent(const PolicyNamespace& ns); | 58 virtual void UnregisterComponent(const PolicyNamespace& ns); |
56 | 59 |
| 60 // Returns true if all domains have registered the initial components. |
| 61 bool IsReady() const; |
| 62 |
| 63 // This indicates that the initial components for |domain| have all been |
| 64 // registered. It must be invoked at least once for each policy domain; |
| 65 // subsequent calls for the same domain are ignored. |
| 66 void SetReady(PolicyDomain domain); |
| 67 |
57 void AddObserver(Observer* observer); | 68 void AddObserver(Observer* observer); |
58 void RemoveObserver(Observer* observer); | 69 void RemoveObserver(Observer* observer); |
59 | 70 |
60 bool HasObservers() const; | 71 bool HasObservers() const; |
61 | 72 |
62 protected: | 73 protected: |
63 void Notify(bool has_new_schemas); | 74 void Notify(bool has_new_schemas); |
64 | 75 |
65 scoped_refptr<SchemaMap> schema_map_; | 76 scoped_refptr<SchemaMap> schema_map_; |
66 | 77 |
67 private: | 78 private: |
68 ObserverList<Observer, true> observers_; | 79 ObserverList<Observer, true> observers_; |
| 80 bool domains_ready_[POLICY_DOMAIN_SIZE]; |
69 | 81 |
70 DISALLOW_COPY_AND_ASSIGN(SchemaRegistry); | 82 DISALLOW_COPY_AND_ASSIGN(SchemaRegistry); |
71 }; | 83 }; |
72 | 84 |
73 // A registry that combines the maps of other registries. | 85 // A registry that combines the maps of other registries. |
74 class CombinedSchemaRegistry : public SchemaRegistry, | 86 class CombinedSchemaRegistry : public SchemaRegistry, |
75 public SchemaRegistry::Observer { | 87 public SchemaRegistry::Observer { |
76 public: | 88 public: |
77 CombinedSchemaRegistry(); | 89 CombinedSchemaRegistry(); |
78 virtual ~CombinedSchemaRegistry(); | 90 virtual ~CombinedSchemaRegistry(); |
79 | 91 |
80 void Track(SchemaRegistry* registry); | 92 void Track(SchemaRegistry* registry); |
81 void Untrack(SchemaRegistry* registry); | 93 void Untrack(SchemaRegistry* registry); |
82 | 94 |
83 virtual void RegisterComponents(PolicyDomain domain, | 95 virtual void RegisterComponents(PolicyDomain domain, |
84 const ComponentMap& components) OVERRIDE; | 96 const ComponentMap& components) OVERRIDE; |
85 | 97 |
86 virtual void UnregisterComponent(const PolicyNamespace& ns) OVERRIDE; | 98 virtual void UnregisterComponent(const PolicyNamespace& ns) OVERRIDE; |
87 | 99 |
88 virtual void OnSchemaRegistryUpdated(bool has_new_schemas) OVERRIDE; | 100 virtual void OnSchemaRegistryUpdated(bool has_new_schemas) OVERRIDE; |
89 | 101 |
| 102 virtual void OnSchemaRegistryReady() OVERRIDE; |
| 103 |
90 private: | 104 private: |
91 void Combine(bool has_new_schemas); | 105 void Combine(bool has_new_schemas); |
92 | 106 |
93 std::set<SchemaRegistry*> registries_; | 107 std::set<SchemaRegistry*> registries_; |
94 scoped_refptr<SchemaMap> own_schema_map_; | 108 scoped_refptr<SchemaMap> own_schema_map_; |
95 | 109 |
96 DISALLOW_COPY_AND_ASSIGN(CombinedSchemaRegistry); | 110 DISALLOW_COPY_AND_ASSIGN(CombinedSchemaRegistry); |
97 }; | 111 }; |
98 | 112 |
99 } // namespace policy | 113 } // namespace policy |
100 | 114 |
101 #endif // CHROME_BROWSER_POLICY_SCHEMA_REGISTRY_H_ | 115 #endif // CHROME_BROWSER_POLICY_SCHEMA_REGISTRY_H_ |
OLD | NEW |