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 #include "chrome/browser/policy/schema_registry.h" | 5 #include "chrome/browser/policy/schema_registry.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 | 8 |
9 namespace policy { | 9 namespace policy { |
10 | 10 |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
46 | 46 |
47 void SchemaRegistry::AddObserver(Observer* observer) { | 47 void SchemaRegistry::AddObserver(Observer* observer) { |
48 observers_.AddObserver(observer); | 48 observers_.AddObserver(observer); |
49 } | 49 } |
50 | 50 |
51 void SchemaRegistry::RemoveObserver(Observer* observer) { | 51 void SchemaRegistry::RemoveObserver(Observer* observer) { |
52 observers_.RemoveObserver(observer); | 52 observers_.RemoveObserver(observer); |
53 } | 53 } |
54 | 54 |
55 void SchemaRegistry::Notify(bool has_new_schemas) { | 55 void SchemaRegistry::Notify(bool has_new_schemas) { |
56 FOR_EACH_OBSERVER(Observer, | 56 FOR_EACH_OBSERVER( |
57 observers_, | 57 Observer, observers_, OnSchemaRegistryUpdated(has_new_schemas)); |
58 OnSchemaRegistryUpdated(schema_map_, has_new_schemas)); | |
59 } | 58 } |
60 | 59 |
61 bool SchemaRegistry::HasObservers() const { | 60 bool SchemaRegistry::HasObservers() const { |
62 return observers_.might_have_observers(); | 61 return observers_.might_have_observers(); |
63 } | 62 } |
64 | 63 |
65 CombinedSchemaRegistry::CombinedSchemaRegistry() | 64 CombinedSchemaRegistry::CombinedSchemaRegistry() |
66 : own_schema_map_(new SchemaMap) {} | 65 : own_schema_map_(new SchemaMap) {} |
67 | 66 |
68 CombinedSchemaRegistry::~CombinedSchemaRegistry() {} | 67 CombinedSchemaRegistry::~CombinedSchemaRegistry() {} |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
101 void CombinedSchemaRegistry::UnregisterComponent(const PolicyNamespace& ns) { | 100 void CombinedSchemaRegistry::UnregisterComponent(const PolicyNamespace& ns) { |
102 DomainMap map(own_schema_map_->GetDomains()); | 101 DomainMap map(own_schema_map_->GetDomains()); |
103 if (map[ns.domain].erase(ns.component_id) != 0) { | 102 if (map[ns.domain].erase(ns.component_id) != 0) { |
104 own_schema_map_ = new SchemaMap(map); | 103 own_schema_map_ = new SchemaMap(map); |
105 Combine(false); | 104 Combine(false); |
106 } else { | 105 } else { |
107 NOTREACHED(); | 106 NOTREACHED(); |
108 } | 107 } |
109 } | 108 } |
110 | 109 |
111 void CombinedSchemaRegistry::OnSchemaRegistryUpdated( | 110 void CombinedSchemaRegistry::OnSchemaRegistryUpdated(bool has_new_schemas) { |
112 const scoped_refptr<SchemaMap>& current_map, | |
113 bool has_new_schemas) { | |
114 Combine(has_new_schemas); | 111 Combine(has_new_schemas); |
115 } | 112 } |
116 | 113 |
117 void CombinedSchemaRegistry::Combine(bool has_new_schemas) { | 114 void CombinedSchemaRegistry::Combine(bool has_new_schemas) { |
118 // If two registries publish a Schema for the same component then it's | 115 // If two registries publish a Schema for the same component then it's |
119 // undefined which version gets in the combined registry. | 116 // undefined which version gets in the combined registry. |
120 // | 117 // |
121 // The common case is that both registries want policy for the same component, | 118 // The common case is that both registries want policy for the same component, |
122 // and the Schemas should be the same; in that case this makes no difference. | 119 // and the Schemas should be the same; in that case this makes no difference. |
123 // | 120 // |
(...skipping 13 matching lines...) Expand all Loading... |
137 comp_it != reg_component_map.end(); ++comp_it) { | 134 comp_it != reg_component_map.end(); ++comp_it) { |
138 map[domain_it->first][comp_it->first] = comp_it->second; | 135 map[domain_it->first][comp_it->first] = comp_it->second; |
139 } | 136 } |
140 } | 137 } |
141 } | 138 } |
142 schema_map_ = new SchemaMap(map); | 139 schema_map_ = new SchemaMap(map); |
143 Notify(has_new_schemas); | 140 Notify(has_new_schemas); |
144 } | 141 } |
145 | 142 |
146 } // namespace policy | 143 } // namespace policy |
OLD | NEW |