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

Side by Side Diff: chrome/browser/policy/policy_bundle.cc

Issue 10384145: Removed ConfigurationPolicyProvider::Provide(). (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Rebased Created 8 years, 7 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 (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
11 namespace policy { 11 namespace policy {
12 12
13 namespace {
14
15 // Comparison predicate for std::equal in PolicyBundle::Equals.
16 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
17 const PolicyBundle::MapType::value_type& b) {
18 return a.first == b.first && a.second->Equals(*b.second);
19 }
20
21 } // namespace
22
13 PolicyBundle::PolicyBundle() {} 23 PolicyBundle::PolicyBundle() {}
14 24
15 PolicyBundle::~PolicyBundle() { 25 PolicyBundle::~PolicyBundle() {
16 Clear(); 26 Clear();
17 } 27 }
18 28
19 PolicyMap& PolicyBundle::Get(PolicyDomain domain, 29 PolicyMap& PolicyBundle::Get(PolicyDomain domain,
20 const std::string& component_id) { 30 const std::string& component_id) {
21 DCHECK(domain != POLICY_DOMAIN_CHROME || component_id.empty()); 31 DCHECK(domain != POLICY_DOMAIN_CHROME || component_id.empty());
22 PolicyMap*& policy = policy_bundle_[PolicyNamespace(domain, component_id)]; 32 PolicyMap*& policy = policy_bundle_[PolicyNamespace(domain, component_id)];
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
79 // Add extra PolicyMaps at the end. 89 // Add extra PolicyMaps at the end.
80 while (it_other != end_other) { 90 while (it_other != end_other) {
81 PolicyMap*& policy = policy_bundle_[it_other->first]; 91 PolicyMap*& policy = policy_bundle_[it_other->first];
82 DCHECK(!policy); 92 DCHECK(!policy);
83 policy = new PolicyMap(); 93 policy = new PolicyMap();
84 policy->CopyFrom(*it_other->second); 94 policy->CopyFrom(*it_other->second);
85 ++it_other; 95 ++it_other;
86 } 96 }
87 } 97 }
88 98
99 bool PolicyBundle::Equals(const PolicyBundle& other) const {
100 // Equals() has the peculiarity that an entry with an empty PolicyMap equals
101 // an non-existant entry. This handles usage of non-const Get() that doesn't
102 // insert any policies.
103 const_iterator it_this = begin();
104 const_iterator it_other = other.begin();
105
106 for (;;) {
107 // Skip empty PolicyMaps.
108 while (it_this != end() && it_this->second->empty())
109 ++it_this;
110 while (it_other != other.end() && it_other->second->empty())
111 ++it_other;
112 if (it_this != end() && it_other != other.end()) {
113 if (it_this->first != it_other->first ||
114 !it_this->second->Equals(*it_other->second))
115 return false;
116 ++it_this;
117 ++it_other;
118 } else {
119 return it_this == end() && it_other == other.end();
120 }
121 }
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.
122 }
123
89 PolicyBundle::const_iterator PolicyBundle::begin() const { 124 PolicyBundle::const_iterator PolicyBundle::begin() const {
90 return policy_bundle_.begin(); 125 return policy_bundle_.begin();
91 } 126 }
92 127
93 PolicyBundle::const_iterator PolicyBundle::end() const { 128 PolicyBundle::const_iterator PolicyBundle::end() const {
94 return policy_bundle_.end(); 129 return policy_bundle_.end();
95 } 130 }
96 131
97 void PolicyBundle::Clear() { 132 void PolicyBundle::Clear() {
98 STLDeleteValues(&policy_bundle_); 133 STLDeleteValues(&policy_bundle_);
99 } 134 }
100 135
136 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.
137 LOG(ERROR) << "----------------- PolicyBundle Dump";
138 for (const_iterator it = begin(); it != end(); ++it) {
139 LOG(ERROR) << "-- Domain " << it->first.first << " component \""
140 << it->first.second << "\"";
141 const PolicyMap* policies = it->second;
142 for (PolicyMap::const_iterator it2 = policies->begin();
143 it2 != policies->end(); ++it2) {
144 LOG(ERROR) << "\"" << it2->first << "\"";
145 }
146 }
147 }
148
101 } // namespace policy 149 } // namespace policy
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698