OLD | NEW |
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 Loading... |
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 Loading... |
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 Loading... |
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 |
OLD | NEW |