Chromium Code Reviews| Index: chrome/browser/policy/policy_bundle.cc |
| diff --git a/chrome/browser/policy/policy_bundle.cc b/chrome/browser/policy/policy_bundle.cc |
| index ed852cd79a6d6b0e383f46104821b436102d0b80..c197aeca00cd9aab7f04a5440e126e3664661a37 100644 |
| --- a/chrome/browser/policy/policy_bundle.cc |
| +++ b/chrome/browser/policy/policy_bundle.cc |
| @@ -10,6 +10,16 @@ |
| namespace policy { |
| +namespace { |
| + |
| +// Comparison predicate for std::equal in PolicyBundle::Equals. |
| +bool BundleEntryEquals(const PolicyBundle::MapType::value_type& a, |
|
Mattias Nissler (ping if slow)
2012/05/14 16:55:59
Unused?
Joao da Silva
2012/05/15 13:07:05
Yes. Equals() was initially implemented as std::eq
|
| + const PolicyBundle::MapType::value_type& b) { |
| + return a.first == b.first && a.second->Equals(*b.second); |
| +} |
| + |
| +} // namespace |
| + |
| PolicyBundle::PolicyBundle() {} |
| PolicyBundle::~PolicyBundle() { |
| @@ -86,6 +96,31 @@ void PolicyBundle::MergeFrom(const PolicyBundle& other) { |
| } |
| } |
| +bool PolicyBundle::Equals(const PolicyBundle& other) const { |
| + // Equals() has the peculiarity that an entry with an empty PolicyMap equals |
| + // an non-existant entry. This handles usage of non-const Get() that doesn't |
| + // insert any policies. |
| + const_iterator it_this = begin(); |
| + const_iterator it_other = other.begin(); |
| + |
| + for (;;) { |
| + // Skip empty PolicyMaps. |
| + while (it_this != end() && it_this->second->empty()) |
| + ++it_this; |
| + while (it_other != other.end() && it_other->second->empty()) |
| + ++it_other; |
| + if (it_this != end() && it_other != other.end()) { |
| + if (it_this->first != it_other->first || |
| + !it_this->second->Equals(*it_other->second)) |
| + return false; |
| + ++it_this; |
| + ++it_other; |
| + } else { |
| + return it_this == end() && it_other == other.end(); |
| + } |
| + } |
|
Mattias Nissler (ping if slow)
2012/05/14 16:55:59
return false? Could as well put the statement in l
Joao da Silva
2012/05/15 13:07:05
Done.
|
| +} |
| + |
| PolicyBundle::const_iterator PolicyBundle::begin() const { |
| return policy_bundle_.begin(); |
| } |
| @@ -98,4 +133,17 @@ void PolicyBundle::Clear() { |
| STLDeleteValues(&policy_bundle_); |
| } |
| +void PolicyBundle::Dump() const { |
|
Mattias Nissler (ping if slow)
2012/05/14 16:55:59
Remove?
Joao da Silva
2012/05/15 13:07:05
Done.
|
| + LOG(ERROR) << "----------------- PolicyBundle Dump"; |
| + for (const_iterator it = begin(); it != end(); ++it) { |
| + LOG(ERROR) << "-- Domain " << it->first.first << " component \"" |
| + << it->first.second << "\""; |
| + const PolicyMap* policies = it->second; |
| + for (PolicyMap::const_iterator it2 = policies->begin(); |
| + it2 != policies->end(); ++it2) { |
| + LOG(ERROR) << "\"" << it2->first << "\""; |
| + } |
| + } |
| +} |
| + |
| } // namespace policy |