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

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

Issue 1350913006: Revert of Add source column to chrome://policy showing the origins of policies. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 3 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/policy_map.h" 5 #include "components/policy/core/common/policy_map.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/callback.h" 9 #include "base/callback.h"
10 #include "base/stl_util.h" 10 #include "base/stl_util.h"
(...skipping 10 matching lines...) Expand all
21 delete value; 21 delete value;
22 value = NULL; 22 value = NULL;
23 delete external_data_fetcher; 23 delete external_data_fetcher;
24 external_data_fetcher = NULL; 24 external_data_fetcher = NULL;
25 } 25 }
26 26
27 scoped_ptr<PolicyMap::Entry> PolicyMap::Entry::DeepCopy() const { 27 scoped_ptr<PolicyMap::Entry> PolicyMap::Entry::DeepCopy() const {
28 scoped_ptr<Entry> copy(new Entry); 28 scoped_ptr<Entry> copy(new Entry);
29 copy->level = level; 29 copy->level = level;
30 copy->scope = scope; 30 copy->scope = scope;
31 copy->source = source;
32 if (value) 31 if (value)
33 copy->value = value->DeepCopy(); 32 copy->value = value->DeepCopy();
34 if (external_data_fetcher) { 33 if (external_data_fetcher) {
35 copy->external_data_fetcher = 34 copy->external_data_fetcher =
36 new ExternalDataFetcher(*external_data_fetcher); 35 new ExternalDataFetcher(*external_data_fetcher);
37 } 36 }
38 return copy.Pass(); 37 return copy.Pass();
39 } 38 }
40 39
41 bool PolicyMap::Entry::has_higher_priority_than( 40 bool PolicyMap::Entry::has_higher_priority_than(
42 const PolicyMap::Entry& other) const { 41 const PolicyMap::Entry& other) const {
43 if (level == other.level) 42 if (level == other.level)
44 return scope > other.scope; 43 return scope > other.scope;
45 else 44 else
46 return level > other.level; 45 return level > other.level;
47 } 46 }
48 47
49 bool PolicyMap::Entry::Equals(const PolicyMap::Entry& other) const { 48 bool PolicyMap::Entry::Equals(const PolicyMap::Entry& other) const {
50 return level == other.level && 49 return level == other.level &&
51 scope == other.scope && 50 scope == other.scope &&
52 source == other.source && // Necessary for PolicyUIHandler observers.
53 // They have to update when sources change.
54 base::Value::Equals(value, other.value) && 51 base::Value::Equals(value, other.value) &&
55 ExternalDataFetcher::Equals(external_data_fetcher, 52 ExternalDataFetcher::Equals(external_data_fetcher,
56 other.external_data_fetcher); 53 other.external_data_fetcher);
57 } 54 }
58 55
59 PolicyMap::PolicyMap() { 56 PolicyMap::PolicyMap() {
60 } 57 }
61 58
62 PolicyMap::~PolicyMap() { 59 PolicyMap::~PolicyMap() {
63 Clear(); 60 Clear();
64 } 61 }
65 62
66 const PolicyMap::Entry* PolicyMap::Get(const std::string& policy) const { 63 const PolicyMap::Entry* PolicyMap::Get(const std::string& policy) const {
67 PolicyMapType::const_iterator entry = map_.find(policy); 64 PolicyMapType::const_iterator entry = map_.find(policy);
68 return entry == map_.end() ? NULL : &entry->second; 65 return entry == map_.end() ? NULL : &entry->second;
69 } 66 }
70 67
71 const base::Value* PolicyMap::GetValue(const std::string& policy) const { 68 const base::Value* PolicyMap::GetValue(const std::string& policy) const {
72 PolicyMapType::const_iterator entry = map_.find(policy); 69 PolicyMapType::const_iterator entry = map_.find(policy);
73 return entry == map_.end() ? NULL : entry->second.value; 70 return entry == map_.end() ? NULL : entry->second.value;
74 } 71 }
75 72
76 void PolicyMap::Set(const std::string& policy, 73 void PolicyMap::Set(const std::string& policy,
77 PolicyLevel level, 74 PolicyLevel level,
78 PolicyScope scope, 75 PolicyScope scope,
79 PolicySource source,
80 base::Value* value, 76 base::Value* value,
81 ExternalDataFetcher* external_data_fetcher) { 77 ExternalDataFetcher* external_data_fetcher) {
82 Entry& entry = map_[policy]; 78 Entry& entry = map_[policy];
83 entry.DeleteOwnedMembers(); 79 entry.DeleteOwnedMembers();
84 entry.level = level; 80 entry.level = level;
85 entry.scope = scope; 81 entry.scope = scope;
86 entry.source = source;
87 entry.value = value; 82 entry.value = value;
88 entry.external_data_fetcher = external_data_fetcher; 83 entry.external_data_fetcher = external_data_fetcher;
89 } 84 }
90 85
91 void PolicyMap::Erase(const std::string& policy) { 86 void PolicyMap::Erase(const std::string& policy) {
92 PolicyMapType::iterator it = map_.find(policy); 87 PolicyMapType::iterator it = map_.find(policy);
93 if (it != map_.end()) { 88 if (it != map_.end()) {
94 it->second.DeleteOwnedMembers(); 89 it->second.DeleteOwnedMembers();
95 map_.erase(it); 90 map_.erase(it);
96 } 91 }
97 } 92 }
98 93
99 void PolicyMap::Swap(PolicyMap* other) { 94 void PolicyMap::Swap(PolicyMap* other) {
100 map_.swap(other->map_); 95 map_.swap(other->map_);
101 } 96 }
102 97
103 void PolicyMap::CopyFrom(const PolicyMap& other) { 98 void PolicyMap::CopyFrom(const PolicyMap& other) {
104 Clear(); 99 Clear();
105 for (const_iterator it = other.begin(); it != other.end(); ++it) { 100 for (const_iterator it = other.begin(); it != other.end(); ++it) {
106 const Entry& entry = it->second; 101 const Entry& entry = it->second;
107 Set(it->first, entry.level, entry.scope, entry.source, 102 Set(it->first, entry.level, entry.scope,
108 entry.value->DeepCopy(), 103 entry.value->DeepCopy(), entry.external_data_fetcher ?
109 entry.external_data_fetcher 104 new ExternalDataFetcher(*entry.external_data_fetcher) : NULL);
110 ? new ExternalDataFetcher(*entry.external_data_fetcher)
111 : nullptr);
112 } 105 }
113 } 106 }
114 107
115 scoped_ptr<PolicyMap> PolicyMap::DeepCopy() const { 108 scoped_ptr<PolicyMap> PolicyMap::DeepCopy() const {
116 PolicyMap* copy = new PolicyMap(); 109 PolicyMap* copy = new PolicyMap();
117 copy->CopyFrom(*this); 110 copy->CopyFrom(*this);
118 return make_scoped_ptr(copy); 111 return make_scoped_ptr(copy);
119 } 112 }
120 113
121 void PolicyMap::MergeFrom(const PolicyMap& other) { 114 void PolicyMap::MergeFrom(const PolicyMap& other) {
122 for (const_iterator it = other.begin(); it != other.end(); ++it) { 115 for (const_iterator it = other.begin(); it != other.end(); ++it) {
123 const Entry* entry = Get(it->first); 116 const Entry* entry = Get(it->first);
124 if (!entry || it->second.has_higher_priority_than(*entry)) { 117 if (!entry || it->second.has_higher_priority_than(*entry)) {
125 Set(it->first, it->second.level, it->second.scope, it->second.source, 118 Set(it->first, it->second.level, it->second.scope,
126 it->second.value->DeepCopy(), 119 it->second.value->DeepCopy(), it->second.external_data_fetcher ?
127 it->second.external_data_fetcher 120 new ExternalDataFetcher(*it->second.external_data_fetcher) :
128 ? new ExternalDataFetcher( 121 NULL);
129 *it->second.external_data_fetcher)
130 : nullptr);
131 } 122 }
132 } 123 }
133 } 124 }
134 125
135 void PolicyMap::LoadFrom( 126 void PolicyMap::LoadFrom(
136 const base::DictionaryValue* policies, 127 const base::DictionaryValue* policies,
137 PolicyLevel level, 128 PolicyLevel level,
138 PolicyScope scope, 129 PolicyScope scope) {
139 PolicySource source) {
140 for (base::DictionaryValue::Iterator it(*policies); 130 for (base::DictionaryValue::Iterator it(*policies);
141 !it.IsAtEnd(); it.Advance()) { 131 !it.IsAtEnd(); it.Advance()) {
142 Set(it.key(), level, scope, source, it.value().DeepCopy(), nullptr); 132 Set(it.key(), level, scope, it.value().DeepCopy(), NULL);
143 } 133 }
144 } 134 }
145 135
146 void PolicyMap::GetDifferingKeys(const PolicyMap& other, 136 void PolicyMap::GetDifferingKeys(const PolicyMap& other,
147 std::set<std::string>* differing_keys) const { 137 std::set<std::string>* differing_keys) const {
148 // Walk over the maps in lockstep, adding everything that is different. 138 // Walk over the maps in lockstep, adding everything that is different.
149 const_iterator iter_this(begin()); 139 const_iterator iter_this(begin());
150 const_iterator iter_other(other.begin()); 140 const_iterator iter_other(other.begin());
151 while (iter_this != end() && iter_other != other.end()) { 141 while (iter_this != end() && iter_other != other.end()) {
152 const int diff = iter_this->first.compare(iter_other->first); 142 const int diff = iter_this->first.compare(iter_other->first);
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
210 map_.clear(); 200 map_.clear();
211 } 201 }
212 202
213 // static 203 // static
214 bool PolicyMap::MapEntryEquals(const PolicyMap::PolicyMapType::value_type& a, 204 bool PolicyMap::MapEntryEquals(const PolicyMap::PolicyMapType::value_type& a,
215 const PolicyMap::PolicyMapType::value_type& b) { 205 const PolicyMap::PolicyMapType::value_type& b) {
216 return a.first == b.first && a.second.Equals(b.second); 206 return a.first == b.first && a.second.Equals(b.second);
217 } 207 }
218 208
219 } // namespace policy 209 } // namespace policy
OLDNEW
« no previous file with comments | « components/policy/core/common/policy_map.h ('k') | components/policy/core/common/policy_map_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698