| 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 "components/policy/core/common/policy_service_impl.h" | 5 #include "components/policy/core/common/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/message_loop/message_loop.h" | 10 #include "base/location.h" |
| 11 #include "base/single_thread_task_runner.h" |
| 11 #include "base/stl_util.h" | 12 #include "base/stl_util.h" |
| 13 #include "base/thread_task_runner_handle.h" |
| 12 #include "base/values.h" | 14 #include "base/values.h" |
| 13 #include "components/policy/core/common/policy_bundle.h" | 15 #include "components/policy/core/common/policy_bundle.h" |
| 14 #include "components/policy/core/common/policy_map.h" | 16 #include "components/policy/core/common/policy_map.h" |
| 15 #include "policy/policy_constants.h" | 17 #include "policy/policy_constants.h" |
| 16 | 18 |
| 17 namespace policy { | 19 namespace policy { |
| 18 | 20 |
| 19 typedef PolicyServiceImpl::Providers::const_iterator Iterator; | 21 typedef PolicyServiceImpl::Providers::const_iterator Iterator; |
| 20 | 22 |
| 21 namespace { | 23 namespace { |
| (...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 133 void PolicyServiceImpl::RefreshPolicies(const base::Closure& callback) { | 135 void PolicyServiceImpl::RefreshPolicies(const base::Closure& callback) { |
| 134 DCHECK(thread_checker_.CalledOnValidThread()); | 136 DCHECK(thread_checker_.CalledOnValidThread()); |
| 135 | 137 |
| 136 if (!callback.is_null()) | 138 if (!callback.is_null()) |
| 137 refresh_callbacks_.push_back(callback); | 139 refresh_callbacks_.push_back(callback); |
| 138 | 140 |
| 139 if (providers_.empty()) { | 141 if (providers_.empty()) { |
| 140 // Refresh is immediately complete if there are no providers. See the note | 142 // Refresh is immediately complete if there are no providers. See the note |
| 141 // on OnUpdatePolicy() about why this is a posted task. | 143 // on OnUpdatePolicy() about why this is a posted task. |
| 142 update_task_ptr_factory_.InvalidateWeakPtrs(); | 144 update_task_ptr_factory_.InvalidateWeakPtrs(); |
| 143 base::MessageLoop::current()->PostTask( | 145 base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 144 FROM_HERE, | 146 FROM_HERE, base::Bind(&PolicyServiceImpl::MergeAndTriggerUpdates, |
| 145 base::Bind(&PolicyServiceImpl::MergeAndTriggerUpdates, | 147 update_task_ptr_factory_.GetWeakPtr())); |
| 146 update_task_ptr_factory_.GetWeakPtr())); | |
| 147 } else { | 148 } else { |
| 148 // Some providers might invoke OnUpdatePolicy synchronously while handling | 149 // Some providers might invoke OnUpdatePolicy synchronously while handling |
| 149 // RefreshPolicies. Mark all as pending before refreshing. | 150 // RefreshPolicies. Mark all as pending before refreshing. |
| 150 for (Iterator it = providers_.begin(); it != providers_.end(); ++it) | 151 for (Iterator it = providers_.begin(); it != providers_.end(); ++it) |
| 151 refresh_pending_.insert(*it); | 152 refresh_pending_.insert(*it); |
| 152 for (Iterator it = providers_.begin(); it != providers_.end(); ++it) | 153 for (Iterator it = providers_.begin(); it != providers_.end(); ++it) |
| 153 (*it)->RefreshPolicies(); | 154 (*it)->RefreshPolicies(); |
| 154 } | 155 } |
| 155 } | 156 } |
| 156 | 157 |
| 157 void PolicyServiceImpl::OnUpdatePolicy(ConfigurationPolicyProvider* provider) { | 158 void PolicyServiceImpl::OnUpdatePolicy(ConfigurationPolicyProvider* provider) { |
| 158 DCHECK_EQ(1, std::count(providers_.begin(), providers_.end(), provider)); | 159 DCHECK_EQ(1, std::count(providers_.begin(), providers_.end(), provider)); |
| 159 refresh_pending_.erase(provider); | 160 refresh_pending_.erase(provider); |
| 160 | 161 |
| 161 // Note: a policy change may trigger further policy changes in some providers. | 162 // Note: a policy change may trigger further policy changes in some providers. |
| 162 // For example, disabling SigninAllowed would cause the CloudPolicyManager to | 163 // For example, disabling SigninAllowed would cause the CloudPolicyManager to |
| 163 // drop all its policies, which makes this method enter again for that | 164 // drop all its policies, which makes this method enter again for that |
| 164 // provider. | 165 // provider. |
| 165 // | 166 // |
| 166 // Therefore this update is posted asynchronously, to prevent reentrancy in | 167 // Therefore this update is posted asynchronously, to prevent reentrancy in |
| 167 // MergeAndTriggerUpdates. Also, cancel a pending update if there is any, | 168 // MergeAndTriggerUpdates. Also, cancel a pending update if there is any, |
| 168 // since both will produce the same PolicyBundle. | 169 // since both will produce the same PolicyBundle. |
| 169 update_task_ptr_factory_.InvalidateWeakPtrs(); | 170 update_task_ptr_factory_.InvalidateWeakPtrs(); |
| 170 base::MessageLoop::current()->PostTask( | 171 base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 171 FROM_HERE, | 172 FROM_HERE, base::Bind(&PolicyServiceImpl::MergeAndTriggerUpdates, |
| 172 base::Bind(&PolicyServiceImpl::MergeAndTriggerUpdates, | 173 update_task_ptr_factory_.GetWeakPtr())); |
| 173 update_task_ptr_factory_.GetWeakPtr())); | |
| 174 } | 174 } |
| 175 | 175 |
| 176 void PolicyServiceImpl::NotifyNamespaceUpdated( | 176 void PolicyServiceImpl::NotifyNamespaceUpdated( |
| 177 const PolicyNamespace& ns, | 177 const PolicyNamespace& ns, |
| 178 const PolicyMap& previous, | 178 const PolicyMap& previous, |
| 179 const PolicyMap& current) { | 179 const PolicyMap& current) { |
| 180 DCHECK(thread_checker_.CalledOnValidThread()); | 180 DCHECK(thread_checker_.CalledOnValidThread()); |
| 181 ObserverMap::iterator iterator = observers_.find(ns.domain); | 181 ObserverMap::iterator iterator = observers_.find(ns.domain); |
| 182 if (iterator != observers_.end()) { | 182 if (iterator != observers_.end()) { |
| 183 FOR_EACH_OBSERVER(PolicyService::Observer, | 183 FOR_EACH_OBSERVER(PolicyService::Observer, |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 273 if (refresh_pending_.empty() && !refresh_callbacks_.empty()) { | 273 if (refresh_pending_.empty() && !refresh_callbacks_.empty()) { |
| 274 std::vector<base::Closure> callbacks; | 274 std::vector<base::Closure> callbacks; |
| 275 callbacks.swap(refresh_callbacks_); | 275 callbacks.swap(refresh_callbacks_); |
| 276 std::vector<base::Closure>::iterator it; | 276 std::vector<base::Closure>::iterator it; |
| 277 for (it = callbacks.begin(); it != callbacks.end(); ++it) | 277 for (it = callbacks.begin(); it != callbacks.end(); ++it) |
| 278 it->Run(); | 278 it->Run(); |
| 279 } | 279 } |
| 280 } | 280 } |
| 281 | 281 |
| 282 } // namespace policy | 282 } // namespace policy |
| OLD | NEW |