OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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/policy_domain_descriptor.h" | 5 #include "chrome/browser/policy/policy_domain_descriptor.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "base/stl_util.h" | 8 #include "base/stl_util.h" |
9 #include "base/values.h" | 9 #include "base/values.h" |
10 #include "chrome/browser/policy/policy_bundle.h" | 10 #include "chrome/browser/policy/policy_bundle.h" |
11 #include "chrome/browser/policy/policy_map.h" | 11 #include "chrome/browser/policy/policy_map.h" |
12 | 12 |
13 namespace policy { | 13 namespace policy { |
14 | 14 |
15 namespace { | |
16 | |
17 bool Matches(Schema schema, const base::Value& value) { | |
18 if (!schema.valid()) { | |
19 // Schema not found, invalid entry. | |
20 return false; | |
21 } | |
22 | |
23 if (!value.IsType(schema.type())) | |
24 return false; | |
25 | |
26 const base::DictionaryValue* dict = NULL; | |
27 const base::ListValue* list = NULL; | |
28 if (value.GetAsDictionary(&dict)) { | |
29 for (base::DictionaryValue::Iterator it(*dict); !it.IsAtEnd(); | |
30 it.Advance()) { | |
31 if (!Matches(schema.GetProperty(it.key()), it.value())) | |
32 return false; | |
33 } | |
34 } else if (value.GetAsList(&list)) { | |
35 for (base::ListValue::const_iterator it = list->begin(); | |
36 it != list->end(); ++it) { | |
37 if (!*it || !Matches(schema.GetItems(), **it)) | |
38 return false; | |
39 } | |
40 } | |
41 | |
42 return true; | |
43 } | |
44 | |
45 } // namespace | |
46 | |
47 PolicyDomainDescriptor::PolicyDomainDescriptor(PolicyDomain domain) | 15 PolicyDomainDescriptor::PolicyDomainDescriptor(PolicyDomain domain) |
48 : domain_(domain) {} | 16 : domain_(domain) {} |
49 | 17 |
50 void PolicyDomainDescriptor::RegisterComponent(const std::string& component_id, | 18 void PolicyDomainDescriptor::RegisterComponent(const std::string& component_id, |
51 Schema schema) { | 19 Schema schema) { |
52 schema_map_[component_id] = schema; | 20 schema_map_[component_id] = schema; |
53 } | 21 } |
54 | 22 |
55 void PolicyDomainDescriptor::FilterBundle(PolicyBundle* bundle) const { | 23 void PolicyDomainDescriptor::FilterBundle(PolicyBundle* bundle) const { |
56 // Chrome policies are not filtered, so that typos appear in about:policy. | 24 // Chrome policies are not filtered, so that typos appear in about:policy. |
(...skipping 20 matching lines...) Expand all Loading... |
77 if (!schema.valid()) | 45 if (!schema.valid()) |
78 continue; | 46 continue; |
79 | 47 |
80 PolicyMap* map = it_bundle->second; | 48 PolicyMap* map = it_bundle->second; |
81 for (PolicyMap::const_iterator it_map = map->begin(); | 49 for (PolicyMap::const_iterator it_map = map->begin(); |
82 it_map != map->end();) { | 50 it_map != map->end();) { |
83 const std::string& policy_name = it_map->first; | 51 const std::string& policy_name = it_map->first; |
84 const base::Value* policy_value = it_map->second.value; | 52 const base::Value* policy_value = it_map->second.value; |
85 Schema policy_schema = schema.GetProperty(policy_name); | 53 Schema policy_schema = schema.GetProperty(policy_name); |
86 ++it_map; | 54 ++it_map; |
87 if (!policy_value || !Matches(policy_schema, *policy_value)) | 55 if (!policy_value || !policy_schema.Validate(*policy_value)) |
88 map->Erase(policy_name); | 56 map->Erase(policy_name); |
89 } | 57 } |
90 } | 58 } |
91 } | 59 } |
92 | 60 |
93 PolicyDomainDescriptor::~PolicyDomainDescriptor() {} | 61 PolicyDomainDescriptor::~PolicyDomainDescriptor() {} |
94 | 62 |
95 } // namespace policy | 63 } // namespace policy |
OLD | NEW |