Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(218)

Side by Side Diff: chrome/browser/policy/schema_map.cc

Issue 50143010: Added a SchemaMap. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@chrome-policy-schema-5-ref-counted-schema
Patch Set: rebase Created 7 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « chrome/browser/policy/schema_map.h ('k') | chrome/browser/policy/schema_map_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(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
11 namespace policy {
12
13 SchemaMap::SchemaMap() {}
14
15 SchemaMap::SchemaMap(DomainMap& map) {
16 map_.swap(map);
17 }
18
19 SchemaMap::~SchemaMap() {}
20
21 const DomainMap& SchemaMap::GetDomains() const {
22 return map_;
23 }
24
25 const ComponentMap* SchemaMap::GetComponents(PolicyDomain domain) const {
26 DomainMap::const_iterator it = map_.find(domain);
27 return it == map_.end() ? NULL : &it->second;
28 }
29
30 const Schema* SchemaMap::GetSchema(const PolicyNamespace& ns) const {
31 const ComponentMap* map = GetComponents(ns.domain);
32 if (!map)
33 return NULL;
34 ComponentMap::const_iterator it = map->find(ns.component_id);
35 return it == map->end() ? NULL : &it->second;
36 }
37
38 void SchemaMap::FilterBundle(PolicyBundle* bundle) const {
39 for (PolicyBundle::iterator it = bundle->begin(); it != bundle->end(); ++it) {
40 // Chrome policies are not filtered, so that typos appear in about:policy.
41 // Everything else gets filtered, so that components only see valid policy.
42 if (it->first.domain == POLICY_DOMAIN_CHROME)
43 continue;
44
45 const Schema* schema = GetSchema(it->first);
46
47 if (!schema) {
48 it->second->Clear();
49 continue;
50 }
51
52 // TODO(joaodasilva): if a component is registered but doesn't have a schema
53 // then its policies aren't filtered. This behavior is enabled to allow a
54 // graceful update of the Legacy Browser Support extension; it'll be removed
55 // in a future release. http://crbug.com/240704
56 if (!schema->valid())
57 continue;
58
59 PolicyMap* map = it->second;
60 for (PolicyMap::const_iterator it_map = map->begin();
61 it_map != map->end();) {
62 const std::string& policy_name = it_map->first;
63 const base::Value* policy_value = it_map->second.value;
64 Schema policy_schema = schema->GetProperty(policy_name);
65 ++it_map;
66 if (!policy_value || !policy_schema.Validate(*policy_value))
67 map->Erase(policy_name);
68 }
69 }
70 }
71
72 } // namespace policy
OLDNEW
« no previous file with comments | « chrome/browser/policy/schema_map.h ('k') | chrome/browser/policy/schema_map_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698