Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "chrome/browser/policy/policy_bundle.h" | 5 #include "chrome/browser/policy/policy_bundle.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "base/stl_util.h" | 8 #include "base/stl_util.h" |
| 9 #include "chrome/browser/policy/policy_map.h" | 9 #include "chrome/browser/policy/policy_map.h" |
| 10 | 10 |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 79 // Add extra PolicyMaps at the end. | 79 // Add extra PolicyMaps at the end. |
| 80 while (it_other != end_other) { | 80 while (it_other != end_other) { |
| 81 PolicyMap*& policy = policy_bundle_[it_other->first]; | 81 PolicyMap*& policy = policy_bundle_[it_other->first]; |
| 82 DCHECK(!policy); | 82 DCHECK(!policy); |
| 83 policy = new PolicyMap(); | 83 policy = new PolicyMap(); |
| 84 policy->CopyFrom(*it_other->second); | 84 policy->CopyFrom(*it_other->second); |
| 85 ++it_other; | 85 ++it_other; |
| 86 } | 86 } |
| 87 } | 87 } |
| 88 | 88 |
| 89 bool PolicyBundle::Equals(const PolicyBundle& other) const { | |
| 90 // Equals() has the peculiarity that an entry with an empty PolicyMap equals | |
| 91 // an non-existant entry. This handles usage of non-const Get() that doesn't | |
| 92 // insert any policies. | |
| 93 const_iterator it_this = begin(); | |
| 94 const_iterator it_other = other.begin(); | |
| 95 | |
| 96 for (;;) { | |
|
Mattias Nissler (ping if slow)
2012/05/15 17:07:24
not sure what the style rule for this is, but whil
Joao da Silva
2012/05/16 10:25:44
I find this style cute:
#define ever ;;
for (eve
| |
| 97 // Skip empty PolicyMaps. | |
| 98 while (it_this != end() && it_this->second->empty()) | |
| 99 ++it_this; | |
| 100 while (it_other != other.end() && it_other->second->empty()) | |
| 101 ++it_other; | |
| 102 if (it_this != end() && it_other != other.end()) { | |
|
Mattias Nissler (ping if slow)
2012/05/15 17:07:24
It's probably easier to read this if you were to p
Joao da Silva
2012/05/16 10:25:44
Done. I think you meant that the test for the brea
| |
| 103 if (it_this->first != it_other->first || | |
| 104 !it_this->second->Equals(*it_other->second)) | |
| 105 return false; | |
| 106 ++it_this; | |
| 107 ++it_other; | |
| 108 } else { | |
| 109 break; | |
| 110 } | |
| 111 } | |
| 112 return it_this == end() && it_other == other.end(); | |
| 113 } | |
| 114 | |
| 89 PolicyBundle::const_iterator PolicyBundle::begin() const { | 115 PolicyBundle::const_iterator PolicyBundle::begin() const { |
| 90 return policy_bundle_.begin(); | 116 return policy_bundle_.begin(); |
| 91 } | 117 } |
| 92 | 118 |
| 93 PolicyBundle::const_iterator PolicyBundle::end() const { | 119 PolicyBundle::const_iterator PolicyBundle::end() const { |
| 94 return policy_bundle_.end(); | 120 return policy_bundle_.end(); |
| 95 } | 121 } |
| 96 | 122 |
| 97 void PolicyBundle::Clear() { | 123 void PolicyBundle::Clear() { |
| 98 STLDeleteValues(&policy_bundle_); | 124 STLDeleteValues(&policy_bundle_); |
| 99 } | 125 } |
| 100 | 126 |
| 101 } // namespace policy | 127 } // namespace policy |
| OLD | NEW |