| 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 FOR_EACH_OBSERVER( |
| 140 PolicyService::Observer, |
| 141 entry->observers, |
| 142 OnPolicyUpdated(POLICY_DOMAIN_CHROME, "", policies, entry->policies)); |
| 140 } | 143 } |
| 141 | 144 |
| 142 // Check if all providers became initialized just now, if they weren't before. | 145 // Check if all providers became initialized just now, if they weren't before. |
| 143 if (!initialization_complete_) { | 146 if (!initialization_complete_) { |
| 144 initialization_complete_ = true; | 147 initialization_complete_ = true; |
| 145 for (ProviderList::iterator iter = providers_.begin(); | 148 for (ProviderList::iterator iter = providers_.begin(); |
| 146 iter != providers_.end(); ++iter) { | 149 iter != providers_.end(); ++iter) { |
| 147 if (!(*iter)->provider->IsInitializationComplete()) { | 150 if (!(*iter)->provider->IsInitializationComplete()) { |
| 148 initialization_complete_ = false; | 151 initialization_complete_ = false; |
| 149 break; | 152 break; |
| 150 } | 153 } |
| 151 } | 154 } |
| 152 if (initialization_complete_) { | 155 if (initialization_complete_) { |
| 153 for (EntryMap::iterator i = entries_.begin(); i != entries_.end(); ++i) { | 156 for (EntryMap::iterator i = entries_.begin(); i != entries_.end(); ++i) { |
| 154 FOR_EACH_OBSERVER(PolicyService::Observer, | 157 FOR_EACH_OBSERVER(PolicyService::Observer, |
| 155 i->second->observers, | 158 i->second->observers, |
| 156 OnPolicyServiceInitialized()); | 159 OnPolicyServiceInitialized()); |
| 157 } | 160 } |
| 158 } | 161 } |
| 159 } | 162 } |
| 160 } | 163 } |
| 161 | 164 |
| 162 } // namespace policy | 165 } // namespace policy |
| OLD | NEW |