OLD | NEW |
(Empty) | |
| 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. |
| 4 |
| 5 #include "chrome/browser/policy/schema_map.h" |
| 6 |
| 7 #include "base/values.h" |
| 8 #include "chrome/browser/policy/policy_bundle.h" |
| 9 #include "chrome/browser/policy/policy_map.h" |
| 10 #include "components/policy/core/common/schema.h" |
| 11 |
| 12 namespace policy { |
| 13 |
| 14 SchemaMap::SchemaMap() {} |
| 15 |
| 16 SchemaMap::SchemaMap(DomainMap& map) { |
| 17 map_.swap(map); |
| 18 } |
| 19 |
| 20 SchemaMap::~SchemaMap() {} |
| 21 |
| 22 const DomainMap& SchemaMap::GetDomains() const { |
| 23 return map_; |
| 24 } |
| 25 |
| 26 const ComponentMap& SchemaMap::GetComponents(PolicyDomain domain) const { |
| 27 DomainMap::const_iterator it = map_.find(domain); |
| 28 return it == map_.end() ? kEmptyComponentMap_ : it->second; |
| 29 } |
| 30 |
| 31 const Schema* SchemaMap::GetSchema(PolicyDomain domain, |
| 32 const std::string& component_id) const { |
| 33 const ComponentMap& map = GetComponents(domain); |
| 34 ComponentMap::const_iterator it = map.find(component_id); |
| 35 return it == map.end() ? NULL : &it->second; |
| 36 } |
| 37 |
| 38 const Schema* SchemaMap::GetSchema(const PolicyNamespace& ns) const { |
| 39 return GetSchema(ns.domain, ns.component_id); |
| 40 } |
| 41 |
| 42 void SchemaMap::FilterBundle(PolicyBundle* bundle) const { |
| 43 for (PolicyBundle::iterator it = bundle->begin(); it != bundle->end(); ++it) { |
| 44 // Chrome policies are not filtered, so that typos appear in about:policy. |
| 45 // Everything else gets filtered, so that components only see valid policy. |
| 46 if (it->first.domain == POLICY_DOMAIN_CHROME) |
| 47 continue; |
| 48 |
| 49 const Schema* schema = GetSchema(it->first); |
| 50 |
| 51 if (!schema) { |
| 52 it->second->Clear(); |
| 53 continue; |
| 54 } |
| 55 |
| 56 // TODO(joaodasilva): if a component is registered but doesn't have a schema |
| 57 // then its policies aren't filtered. This behavior is enabled to allow a |
| 58 // graceful update of the Legacy Browser Support extension; it'll be removed |
| 59 // in a future release. http://crbug.com/240704 |
| 60 if (!schema->valid()) |
| 61 continue; |
| 62 |
| 63 PolicyMap* map = it->second; |
| 64 for (PolicyMap::const_iterator it_map = map->begin(); |
| 65 it_map != map->end();) { |
| 66 const std::string& policy_name = it_map->first; |
| 67 const base::Value* policy_value = it_map->second.value; |
| 68 Schema policy_schema = schema->GetProperty(policy_name); |
| 69 ++it_map; |
| 70 if (!policy_value || !policy_schema.Matches(*policy_value)) |
| 71 map->Erase(policy_name); |
| 72 } |
| 73 } |
| 74 } |
| 75 |
| 76 } // namespace policy |
OLD | NEW |