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

Side by Side Diff: components/policy/core/common/schema_map.cc

Issue 134153005: Add strictness to Schema::Validate() (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@expand-policy-schema-2
Patch Set: fix a bug and enhance tests Created 6 years, 11 months 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
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 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 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 "components/policy/core/common/schema_map.h" 5 #include "components/policy/core/common/schema_map.h"
6 6
7 #include "base/logging.h"
7 #include "base/values.h" 8 #include "base/values.h"
8 #include "components/policy/core/common/policy_bundle.h" 9 #include "components/policy/core/common/policy_bundle.h"
9 #include "components/policy/core/common/policy_map.h" 10 #include "components/policy/core/common/policy_map.h"
10 11
11 namespace policy { 12 namespace policy {
12 13
13 SchemaMap::SchemaMap() {} 14 SchemaMap::SchemaMap() {}
14 15
15 SchemaMap::SchemaMap(DomainMap& map) { 16 SchemaMap::SchemaMap(DomainMap& map) {
16 map_.swap(map); 17 map_.swap(map);
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
56 if (!schema->valid()) 57 if (!schema->valid())
57 continue; 58 continue;
58 59
59 PolicyMap* map = it->second; 60 PolicyMap* map = it->second;
60 for (PolicyMap::const_iterator it_map = map->begin(); 61 for (PolicyMap::const_iterator it_map = map->begin();
61 it_map != map->end();) { 62 it_map != map->end();) {
62 const std::string& policy_name = it_map->first; 63 const std::string& policy_name = it_map->first;
63 const base::Value* policy_value = it_map->second.value; 64 const base::Value* policy_value = it_map->second.value;
64 Schema policy_schema = schema->GetProperty(policy_name); 65 Schema policy_schema = schema->GetProperty(policy_name);
65 ++it_map; 66 ++it_map;
66 if (!policy_value || !policy_schema.Validate(*policy_value)) 67 std::string error;
68 if (!policy_value || !policy_schema.Validate(*policy_value,
69 SCHEMA_STRICT, &error)) {
Joao da Silva 2014/01/23 15:52:36 Try formatting this line with clang-format:
binjin 2014/01/23 17:20:13 Done.
70 LOG(ERROR) << "Dropping policy " << policy_name << " for " <<
71 it->first.component_id << " because it's not valid: " << error;
Joao da Silva 2014/01/23 15:52:36 Run clang-format on this one too; I didn't format
binjin 2014/01/23 17:20:13 Done.
67 map->Erase(policy_name); 72 map->Erase(policy_name);
73 }
68 } 74 }
69 } 75 }
70 } 76 }
71 77
72 bool SchemaMap::HasComponents() const { 78 bool SchemaMap::HasComponents() const {
73 for (DomainMap::const_iterator domain = map_.begin(); 79 for (DomainMap::const_iterator domain = map_.begin();
74 domain != map_.end(); ++domain) { 80 domain != map_.end(); ++domain) {
75 if (domain->first == POLICY_DOMAIN_CHROME) 81 if (domain->first == POLICY_DOMAIN_CHROME)
76 continue; 82 continue;
77 if (!domain->second.empty()) 83 if (!domain->second.empty())
(...skipping 18 matching lines...) Expand all
96 for (ComponentMap::const_iterator comp = components.begin(); 102 for (ComponentMap::const_iterator comp = components.begin();
97 comp != components.end(); ++comp) { 103 comp != components.end(); ++comp) {
98 PolicyNamespace ns(domain->first, comp->first); 104 PolicyNamespace ns(domain->first, comp->first);
99 if (!other->GetSchema(ns)) 105 if (!other->GetSchema(ns))
100 list->push_back(ns); 106 list->push_back(ns);
101 } 107 }
102 } 108 }
103 } 109 }
104 110
105 } // namespace policy 111 } // namespace policy
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698