| 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 <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 113 refresh_pending_.erase(provider); | 113 refresh_pending_.erase(provider); |
| 114 MergeAndTriggerUpdates(); | 114 MergeAndTriggerUpdates(); |
| 115 } | 115 } |
| 116 | 116 |
| 117 void PolicyServiceImpl::NotifyNamespaceUpdated( | 117 void PolicyServiceImpl::NotifyNamespaceUpdated( |
| 118 const PolicyNamespace& ns, | 118 const PolicyNamespace& ns, |
| 119 const PolicyMap& previous, | 119 const PolicyMap& previous, |
| 120 const PolicyMap& current) { | 120 const PolicyMap& current) { |
| 121 // If running a unit test that hasn't setup a MessageLoop, don't send any | 121 // If running a unit test that hasn't setup a MessageLoop, don't send any |
| 122 // notifications. | 122 // notifications. |
| 123 if (!MessageLoop::current()) | 123 if (!base::MessageLoop::current()) |
| 124 return; | 124 return; |
| 125 | 125 |
| 126 // Don't queue up a task if we have no observers - that way Observers added | 126 // Don't queue up a task if we have no observers - that way Observers added |
| 127 // later don't get notified of changes that happened during construction time. | 127 // later don't get notified of changes that happened during construction time. |
| 128 if (observers_.find(ns.domain) == observers_.end()) | 128 if (observers_.find(ns.domain) == observers_.end()) |
| 129 return; | 129 return; |
| 130 | 130 |
| 131 // Notify Observers via a queued task, so Observers can't trigger a re-entrant | 131 // Notify Observers via a queued task, so Observers can't trigger a re-entrant |
| 132 // call to MergeAndTriggerUpdates() by modifying policy. | 132 // call to MergeAndTriggerUpdates() by modifying policy. |
| 133 scoped_ptr<PolicyChangeInfo> changes( | 133 scoped_ptr<PolicyChangeInfo> changes( |
| 134 new PolicyChangeInfo(ns, previous, current)); | 134 new PolicyChangeInfo(ns, previous, current)); |
| 135 MessageLoop::current()->PostTask( | 135 base::MessageLoop::current()->PostTask( |
| 136 FROM_HERE, | 136 FROM_HERE, |
| 137 base::Bind(&PolicyServiceImpl::NotifyNamespaceUpdatedTask, | 137 base::Bind(&PolicyServiceImpl::NotifyNamespaceUpdatedTask, |
| 138 weak_ptr_factory_.GetWeakPtr(), | 138 weak_ptr_factory_.GetWeakPtr(), |
| 139 base::Passed(&changes))); | 139 base::Passed(&changes))); |
| 140 } | 140 } |
| 141 | 141 |
| 142 void PolicyServiceImpl::NotifyNamespaceUpdatedTask( | 142 void PolicyServiceImpl::NotifyNamespaceUpdatedTask( |
| 143 scoped_ptr<PolicyChangeInfo> changes) { | 143 scoped_ptr<PolicyChangeInfo> changes) { |
| 144 ObserverMap::iterator iterator = observers_.find( | 144 ObserverMap::iterator iterator = observers_.find( |
| 145 changes->policy_namespace_.domain); | 145 changes->policy_namespace_.domain); |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 233 if (refresh_pending_.empty() && !refresh_callbacks_.empty()) { | 233 if (refresh_pending_.empty() && !refresh_callbacks_.empty()) { |
| 234 std::vector<base::Closure> callbacks; | 234 std::vector<base::Closure> callbacks; |
| 235 callbacks.swap(refresh_callbacks_); | 235 callbacks.swap(refresh_callbacks_); |
| 236 std::vector<base::Closure>::iterator it; | 236 std::vector<base::Closure>::iterator it; |
| 237 for (it = callbacks.begin(); it != callbacks.end(); ++it) | 237 for (it = callbacks.begin(); it != callbacks.end(); ++it) |
| 238 it->Run(); | 238 it->Run(); |
| 239 } | 239 } |
| 240 } | 240 } |
| 241 | 241 |
| 242 } // namespace policy | 242 } // namespace policy |
| OLD | NEW |