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_service_impl.h" | 5 #include "chrome/browser/policy/policy_service_impl.h" |
6 | 6 |
7 #include "base/observer_list.h" | 7 #include "base/observer_list.h" |
8 #include "base/stl_util.h" | 8 #include "base/stl_util.h" |
9 | 9 |
10 namespace policy { | 10 namespace policy { |
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
118 it->second->policies.empty() && | 118 it->second->policies.empty() && |
119 it->second->observers.size() == 0) { | 119 it->second->observers.size() == 0) { |
120 delete it->second; | 120 delete it->second; |
121 entries_.erase(it); | 121 entries_.erase(it); |
122 } | 122 } |
123 } | 123 } |
124 | 124 |
125 void PolicyServiceImpl::MergeAndTriggerUpdates() { | 125 void PolicyServiceImpl::MergeAndTriggerUpdates() { |
126 // TODO(joaodasilva): do this for each namespace once the providers also | 126 // TODO(joaodasilva): do this for each namespace once the providers also |
127 // provide policy for more namespaces. | 127 // provide policy for more namespaces. |
128 PolicyMap new_policies; | 128 PolicyMap policies; |
129 for (ProviderList::iterator it = providers_.begin(); | 129 for (ProviderList::iterator it = providers_.begin(); |
130 it != providers_.end(); ++it) { | 130 it != providers_.end(); ++it) { |
131 new_policies.MergeFrom((*it)->policies); | 131 policies.MergeFrom((*it)->policies); |
132 } | 132 } |
133 | 133 |
134 Entry* entry = GetOrCreate(std::make_pair(POLICY_DOMAIN_CHROME, "")); | 134 Entry* entry = GetOrCreate(std::make_pair(POLICY_DOMAIN_CHROME, "")); |
135 if (!new_policies.Equals(entry->policies)) { | 135 if (!policies.Equals(entry->policies)) { |
136 entry->policies.Swap(&new_policies); | 136 // Swap first, so that observers that call GetPolicies() see the current |
137 FOR_EACH_OBSERVER(PolicyService::Observer, | 137 // values. |
138 entry->observers, | 138 entry->policies.Swap(&policies); |
139 OnPolicyUpdated(POLICY_DOMAIN_CHROME, "")); | 139 // |policies| now contains the previous values, and |entry->policies| |
140 // contains the current values. | |
Mattias Nissler (ping if slow)
2012/04/23 14:20:44
I think this comment is redundant and can be remov
Joao da Silva
2012/04/23 14:53:19
Done.
| |
141 FOR_EACH_OBSERVER( | |
142 PolicyService::Observer, | |
143 entry->observers, | |
144 OnPolicyUpdated(POLICY_DOMAIN_CHROME, "", policies, entry->policies)); | |
140 } | 145 } |
141 | 146 |
142 // Check if all providers became initialized just now, if they weren't before. | 147 // Check if all providers became initialized just now, if they weren't before. |
143 if (!initialization_complete_) { | 148 if (!initialization_complete_) { |
144 initialization_complete_ = true; | 149 initialization_complete_ = true; |
145 for (ProviderList::iterator iter = providers_.begin(); | 150 for (ProviderList::iterator iter = providers_.begin(); |
146 iter != providers_.end(); ++iter) { | 151 iter != providers_.end(); ++iter) { |
147 if (!(*iter)->provider->IsInitializationComplete()) { | 152 if (!(*iter)->provider->IsInitializationComplete()) { |
148 initialization_complete_ = false; | 153 initialization_complete_ = false; |
149 break; | 154 break; |
150 } | 155 } |
151 } | 156 } |
152 if (initialization_complete_) { | 157 if (initialization_complete_) { |
153 for (EntryMap::iterator i = entries_.begin(); i != entries_.end(); ++i) { | 158 for (EntryMap::iterator i = entries_.begin(); i != entries_.end(); ++i) { |
154 FOR_EACH_OBSERVER(PolicyService::Observer, | 159 FOR_EACH_OBSERVER(PolicyService::Observer, |
155 i->second->observers, | 160 i->second->observers, |
156 OnPolicyServiceInitialized()); | 161 OnPolicyServiceInitialized()); |
157 } | 162 } |
158 } | 163 } |
159 } | 164 } |
160 } | 165 } |
161 | 166 |
162 } // namespace policy | 167 } // namespace policy |
OLD | NEW |