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

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

Issue 1824743002: Drop non-user policy in ConfigDirPolicyLoader on Chrome OS. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase. Created 4 years, 5 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/memory/ptr_util.h" 10 #include "base/memory/ptr_util.h"
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
86 } 86 }
87 87
88 void PolicyMap::Set(const std::string& policy, Entry entry) { 88 void PolicyMap::Set(const std::string& policy, Entry entry) {
89 map_[policy] = std::move(entry); 89 map_[policy] = std::move(entry);
90 } 90 }
91 91
92 void PolicyMap::Erase(const std::string& policy) { 92 void PolicyMap::Erase(const std::string& policy) {
93 map_.erase(policy); 93 map_.erase(policy);
94 } 94 }
95 95
96 void PolicyMap::EraseNonmatching(
97 const base::Callback<bool(const const_iterator)>& filter) {
98 PolicyMapType::iterator iter(map_.begin());
99 while (iter != map_.end()) {
100 if (!filter.Run(iter)) {
101 map_.erase(iter++);
102 } else {
103 ++iter;
104 }
105 }
106 }
107
96 void PolicyMap::Swap(PolicyMap* other) { 108 void PolicyMap::Swap(PolicyMap* other) {
97 map_.swap(other->map_); 109 map_.swap(other->map_);
98 } 110 }
99 111
100 void PolicyMap::CopyFrom(const PolicyMap& other) { 112 void PolicyMap::CopyFrom(const PolicyMap& other) {
101 Clear(); 113 Clear();
102 for (const auto& it : other) 114 for (const auto& it : other)
103 Set(it.first, it.second.DeepCopy()); 115 Set(it.first, it.second.DeepCopy());
104 } 116 }
105 117
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
149 } 161 }
150 } 162 }
151 163
152 // Add the remaining entries. 164 // Add the remaining entries.
153 for ( ; iter_this != end(); ++iter_this) 165 for ( ; iter_this != end(); ++iter_this)
154 differing_keys->insert(iter_this->first); 166 differing_keys->insert(iter_this->first);
155 for ( ; iter_other != other.end(); ++iter_other) 167 for ( ; iter_other != other.end(); ++iter_other)
156 differing_keys->insert(iter_other->first); 168 differing_keys->insert(iter_other->first);
157 } 169 }
158 170
159 void PolicyMap::FilterLevel(PolicyLevel level) {
160 PolicyMapType::iterator iter(map_.begin());
161 while (iter != map_.end()) {
162 if (iter->second.level != level) {
163 map_.erase(iter++);
164 } else {
165 ++iter;
166 }
167 }
168 }
169
170 bool PolicyMap::Equals(const PolicyMap& other) const { 171 bool PolicyMap::Equals(const PolicyMap& other) const {
171 return other.size() == size() && 172 return other.size() == size() &&
172 std::equal(begin(), end(), other.begin(), MapEntryEquals); 173 std::equal(begin(), end(), other.begin(), MapEntryEquals);
173 } 174 }
174 175
175 bool PolicyMap::empty() const { 176 bool PolicyMap::empty() const {
176 return map_.empty(); 177 return map_.empty();
177 } 178 }
178 179
179 size_t PolicyMap::size() const { 180 size_t PolicyMap::size() const {
(...skipping 12 matching lines...) Expand all
192 map_.clear(); 193 map_.clear();
193 } 194 }
194 195
195 // static 196 // static
196 bool PolicyMap::MapEntryEquals(const PolicyMap::PolicyMapType::value_type& a, 197 bool PolicyMap::MapEntryEquals(const PolicyMap::PolicyMapType::value_type& a,
197 const PolicyMap::PolicyMapType::value_type& b) { 198 const PolicyMap::PolicyMapType::value_type& b) {
198 return a.first == b.first && a.second.Equals(b.second); 199 return a.first == b.first && a.second.Equals(b.second);
199 } 200 }
200 201
201 } // namespace policy 202 } // 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