| 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/stl_util.h" | 7 #include "base/stl_util.h" |
| 8 #include "chrome/browser/policy/policy_map.h" | 8 #include "chrome/browser/policy/policy_map.h" |
| 9 | 9 |
| 10 namespace policy { | 10 namespace policy { |
| (...skipping 12 matching lines...) Expand all Loading... |
| 23 // the processed policy values. | 23 // the processed policy values. |
| 24 MergeAndTriggerUpdates(); | 24 MergeAndTriggerUpdates(); |
| 25 } | 25 } |
| 26 | 26 |
| 27 PolicyServiceImpl::~PolicyServiceImpl() { | 27 PolicyServiceImpl::~PolicyServiceImpl() { |
| 28 STLDeleteElements(®istrars_); | 28 STLDeleteElements(®istrars_); |
| 29 STLDeleteValues(&observers_); | 29 STLDeleteValues(&observers_); |
| 30 } | 30 } |
| 31 | 31 |
| 32 void PolicyServiceImpl::AddObserver(PolicyDomain domain, | 32 void PolicyServiceImpl::AddObserver(PolicyDomain domain, |
| 33 const std::string& component_id, | |
| 34 PolicyService::Observer* observer) { | 33 PolicyService::Observer* observer) { |
| 35 PolicyBundle::PolicyNamespace ns(domain, component_id); | 34 Observers*& list = observers_[domain]; |
| 36 Observers*& list = observers_[ns]; | |
| 37 if (!list) | 35 if (!list) |
| 38 list = new Observers(); | 36 list = new Observers(); |
| 39 list->AddObserver(observer); | 37 list->AddObserver(observer); |
| 40 } | 38 } |
| 41 | 39 |
| 42 void PolicyServiceImpl::RemoveObserver(PolicyDomain domain, | 40 void PolicyServiceImpl::RemoveObserver(PolicyDomain domain, |
| 43 const std::string& component_id, | |
| 44 PolicyService::Observer* observer) { | 41 PolicyService::Observer* observer) { |
| 45 PolicyBundle::PolicyNamespace ns(domain, component_id); | 42 ObserverMap::iterator it = observers_.find(domain); |
| 46 ObserverMap::iterator it = observers_.find(ns); | |
| 47 if (it == observers_.end()) { | 43 if (it == observers_.end()) { |
| 48 NOTREACHED(); | 44 NOTREACHED(); |
| 49 return; | 45 return; |
| 50 } | 46 } |
| 51 it->second->RemoveObserver(observer); | 47 it->second->RemoveObserver(observer); |
| 52 if (it->second->size() == 0) { | 48 if (it->second->size() == 0) { |
| 53 delete it->second; | 49 delete it->second; |
| 54 observers_.erase(it); | 50 observers_.erase(it); |
| 55 } | 51 } |
| 56 } | 52 } |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 110 return it; | 106 return it; |
| 111 } | 107 } |
| 112 NOTREACHED(); | 108 NOTREACHED(); |
| 113 return registrars_.end(); | 109 return registrars_.end(); |
| 114 } | 110 } |
| 115 | 111 |
| 116 void PolicyServiceImpl::NotifyNamespaceUpdated( | 112 void PolicyServiceImpl::NotifyNamespaceUpdated( |
| 117 const PolicyBundle::PolicyNamespace& ns, | 113 const PolicyBundle::PolicyNamespace& ns, |
| 118 const PolicyMap& previous, | 114 const PolicyMap& previous, |
| 119 const PolicyMap& current) { | 115 const PolicyMap& current) { |
| 120 ObserverMap::iterator iterator = observers_.find(ns); | 116 ObserverMap::iterator iterator = observers_.find(ns.first); |
| 121 if (iterator != observers_.end()) { | 117 if (iterator != observers_.end()) { |
| 122 FOR_EACH_OBSERVER( | 118 FOR_EACH_OBSERVER( |
| 123 PolicyService::Observer, | 119 PolicyService::Observer, |
| 124 *iterator->second, | 120 *iterator->second, |
| 125 OnPolicyUpdated(ns.first, ns.second, previous, current)); | 121 OnPolicyUpdated(ns.first, ns.second, previous, current)); |
| 126 } | 122 } |
| 127 } | 123 } |
| 128 | 124 |
| 129 void PolicyServiceImpl::MergeAndTriggerUpdates() { | 125 void PolicyServiceImpl::MergeAndTriggerUpdates() { |
| 130 // Merge from each provider in their order of priority. | 126 // Merge from each provider in their order of priority. |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 201 // Invoke all the callbacks if a refresh has just fully completed. | 197 // Invoke all the callbacks if a refresh has just fully completed. |
| 202 if (refresh_pending_.empty() && !refresh_callbacks_.empty()) { | 198 if (refresh_pending_.empty() && !refresh_callbacks_.empty()) { |
| 203 std::vector<base::Closure> callbacks; | 199 std::vector<base::Closure> callbacks; |
| 204 callbacks.swap(refresh_callbacks_); | 200 callbacks.swap(refresh_callbacks_); |
| 205 for (size_t i = 0; i < callbacks.size(); ++i) | 201 for (size_t i = 0; i < callbacks.size(); ++i) |
| 206 callbacks[i].Run(); | 202 callbacks[i].Run(); |
| 207 } | 203 } |
| 208 } | 204 } |
| 209 | 205 |
| 210 } // namespace policy | 206 } // namespace policy |
| OLD | NEW |