OLD | NEW |
| (Empty) |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #include "chrome/browser/policy/policy_domain_descriptor.h" | |
6 | |
7 #include "base/logging.h" | |
8 #include "base/stl_util.h" | |
9 #include "base/values.h" | |
10 #include "chrome/browser/policy/policy_bundle.h" | |
11 #include "chrome/browser/policy/policy_map.h" | |
12 | |
13 namespace policy { | |
14 | |
15 PolicyDomainDescriptor::PolicyDomainDescriptor(PolicyDomain domain) | |
16 : domain_(domain) {} | |
17 | |
18 void PolicyDomainDescriptor::RegisterComponent(const std::string& component_id, | |
19 Schema schema) { | |
20 schema_map_[component_id] = schema; | |
21 } | |
22 | |
23 void PolicyDomainDescriptor::FilterBundle(PolicyBundle* bundle) const { | |
24 // Chrome policies are not filtered, so that typos appear in about:policy. | |
25 DCHECK_NE(POLICY_DOMAIN_CHROME, domain_); | |
26 | |
27 for (PolicyBundle::iterator it_bundle = bundle->begin(); | |
28 it_bundle != bundle->end(); ++it_bundle) { | |
29 const PolicyNamespace& ns = it_bundle->first; | |
30 if (ns.domain != domain_) | |
31 continue; | |
32 | |
33 SchemaMap::const_iterator it_schema = schema_map_.find(ns.component_id); | |
34 if (it_schema == schema_map_.end()) { | |
35 // Component ID not found. | |
36 it_bundle->second->Clear(); | |
37 continue; | |
38 } | |
39 | |
40 // TODO(joaodasilva): if a component is registered but doesn't have a schema | |
41 // then its policies aren't filtered. This behavior is enabled for M29 to | |
42 // allow a graceful update of the Legacy Browser Support extension; it'll | |
43 // be removed for M32. http://crbug.com/240704 | |
44 Schema schema = it_schema->second; | |
45 if (!schema.valid()) | |
46 continue; | |
47 | |
48 PolicyMap* map = it_bundle->second; | |
49 for (PolicyMap::const_iterator it_map = map->begin(); | |
50 it_map != map->end();) { | |
51 const std::string& policy_name = it_map->first; | |
52 const base::Value* policy_value = it_map->second.value; | |
53 Schema policy_schema = schema.GetProperty(policy_name); | |
54 ++it_map; | |
55 if (!policy_value || !policy_schema.Validate(*policy_value)) | |
56 map->Erase(policy_name); | |
57 } | |
58 } | |
59 } | |
60 | |
61 PolicyDomainDescriptor::~PolicyDomainDescriptor() {} | |
62 | |
63 } // namespace policy | |
OLD | NEW |