Ignore title parameter for navigator.registerProtocolHandler
[chromium-blink-merge.git] / components / policy / core / common / schema_map.cc
blob90c30ee51cd4e66011fbafe961698c115ce44d8e
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
3 // found in the LICENSE file.
5 #include "components/policy/core/common/schema_map.h"
7 #include "base/logging.h"
8 #include "base/values.h"
9 #include "components/policy/core/common/policy_bundle.h"
10 #include "components/policy/core/common/policy_map.h"
12 namespace policy {
14 SchemaMap::SchemaMap() {}
16 SchemaMap::SchemaMap(DomainMap& map) {
17 map_.swap(map);
20 SchemaMap::~SchemaMap() {}
22 const DomainMap& SchemaMap::GetDomains() const {
23 return map_;
26 const ComponentMap* SchemaMap::GetComponents(PolicyDomain domain) const {
27 DomainMap::const_iterator it = map_.find(domain);
28 return it == map_.end() ? NULL : &it->second;
31 const Schema* SchemaMap::GetSchema(const PolicyNamespace& ns) const {
32 const ComponentMap* map = GetComponents(ns.domain);
33 if (!map)
34 return NULL;
35 ComponentMap::const_iterator it = map->find(ns.component_id);
36 return it == map->end() ? NULL : &it->second;
39 void SchemaMap::FilterBundle(PolicyBundle* bundle) const {
40 for (PolicyBundle::iterator it = bundle->begin(); it != bundle->end(); ++it) {
41 // Chrome policies are not filtered, so that typos appear in about:policy.
42 // Everything else gets filtered, so that components only see valid policy.
43 if (it->first.domain == POLICY_DOMAIN_CHROME)
44 continue;
46 const Schema* schema = GetSchema(it->first);
48 if (!schema) {
49 it->second->Clear();
50 continue;
53 // TODO(joaodasilva): if a component is registered but doesn't have a schema
54 // then its policies aren't filtered. This behavior is enabled to allow a
55 // graceful update of the Legacy Browser Support extension; it'll be removed
56 // in a future release. http://crbug.com/240704
57 if (!schema->valid())
58 continue;
60 PolicyMap* map = it->second;
61 for (PolicyMap::const_iterator it_map = map->begin();
62 it_map != map->end();) {
63 const std::string& policy_name = it_map->first;
64 const base::Value* policy_value = it_map->second.value;
65 Schema policy_schema = schema->GetProperty(policy_name);
66 ++it_map;
67 std::string error_path;
68 std::string error;
69 if (!policy_value ||
70 !policy_schema.Validate(*policy_value,
71 SCHEMA_STRICT,
72 &error_path,
73 &error)) {
74 LOG(ERROR) << "Dropping policy " << policy_name << " for "
75 << it->first.component_id
76 << " because it's not valid: " << error
77 << " at " << error_path;
78 map->Erase(policy_name);
84 bool SchemaMap::HasComponents() const {
85 for (DomainMap::const_iterator domain = map_.begin();
86 domain != map_.end(); ++domain) {
87 if (domain->first == POLICY_DOMAIN_CHROME)
88 continue;
89 if (!domain->second.empty())
90 return true;
92 return false;
95 void SchemaMap::GetChanges(const scoped_refptr<SchemaMap>& older,
96 PolicyNamespaceList* removed,
97 PolicyNamespaceList* added) const {
98 GetNamespacesNotInOther(older, added);
99 older->GetNamespacesNotInOther(this, removed);
102 void SchemaMap::GetNamespacesNotInOther(const SchemaMap* other,
103 PolicyNamespaceList* list) const {
104 list->clear();
105 for (DomainMap::const_iterator domain = map_.begin();
106 domain != map_.end(); ++domain) {
107 const ComponentMap& components = domain->second;
108 for (ComponentMap::const_iterator comp = components.begin();
109 comp != components.end(); ++comp) {
110 PolicyNamespace ns(domain->first, comp->first);
111 if (!other->GetSchema(ns))
112 list->push_back(ns);
117 } // namespace policy