Chromium Code Reviews| Index: chrome/browser/policy/policy_domain_descriptor.cc |
| diff --git a/chrome/browser/policy/policy_domain_descriptor.cc b/chrome/browser/policy/policy_domain_descriptor.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..b268719717f59ffa0986945a724f1f16ddff713c |
| --- /dev/null |
| +++ b/chrome/browser/policy/policy_domain_descriptor.cc |
| @@ -0,0 +1,68 @@ |
| +// Copyright (c) 2013 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "chrome/browser/policy/policy_domain_descriptor.h" |
| + |
| +#include "base/stl_util.h" |
| +#include "chrome/browser/policy/policy_bundle.h" |
| +#include "chrome/browser/policy/policy_map.h" |
| +#include "chrome/browser/policy/policy_schema.h" |
| + |
| +namespace policy { |
| + |
| +PolicyDomainDescriptor::PolicyDomainDescriptor(PolicyDomain domain) |
| + : domain_(domain) {} |
| + |
| +void PolicyDomainDescriptor::AddComponent(const std::string& component_id, |
| + scoped_ptr<PolicySchema> schema) { |
| + const PolicySchema*& previous = schema_map_[component_id]; |
| + delete previous; |
| + previous = schema.release(); |
| +} |
| + |
| +void PolicyDomainDescriptor::FilterBundle(PolicyBundle* bundle) const { |
| + for (PolicyBundle::const_iterator it_bundle = bundle->begin(); |
| + it_bundle != bundle->end(); ++it_bundle) { |
| + const PolicyNamespace& ns = it_bundle->first; |
| + if (ns.domain != domain_) |
| + continue; |
| + |
| + SchemaMap::const_iterator it_schema = schema_map_.find(ns.component_id); |
| + if (it_schema == schema_map_.end()) { |
| + // Component ID not found. |
| + bundle->Get(ns).Clear(); |
| + continue; |
| + } |
| + |
| + // TODO(joaodasilva): if a component is registered but doesn't have a schema |
| + // then its policies aren't filtered. This behavior is enabled for M29 to |
| + // allow a graceful update of the Legacy Browser Support extension; it'll |
| + // be removed for M30. http://crbug.com/240704 |
|
Mattias Nissler (ping if slow)
2013/05/15 10:24:06
Have you made sure that the extension gets updated
Joao da Silva
2013/05/19 13:17:55
Yes, I'm in sync with Julian here.
|
| + if (!it_schema->second) |
| + continue; |
| + |
| + const PolicySchema::TypeMap& type_map = it_schema->second->type_map(); |
| + PolicyMap& map = bundle->Get(ns); |
| + PolicyMap::const_iterator it_map = map.begin(); |
| + while (it_map != map.end()) { |
| + PolicySchema::TypeMap::const_iterator it_type = |
| + type_map.find(it_map->first); |
|
Mattias Nissler (ping if slow)
2013/05/15 10:24:06
Given these are both indexed by name, we might be
Joao da Silva
2013/05/19 13:17:55
This has changed after the PolicySchema changes.
|
| + if (it_type == type_map.end() || |
| + !it_map->second.value || |
| + !it_map->second.value->IsType(it_type->second)) { |
| + const std::string& name = it_map->first; |
| + ++it_map; |
| + map.Erase(name); |
| + } else { |
| + ++it_map; |
| + } |
| + } |
| + } |
| +} |
| + |
| +PolicyDomainDescriptor::~PolicyDomainDescriptor() { |
| + STLDeleteValues(&schema_map_); |
| +} |
| + |
| +} // namespace policy |