| OLD | NEW |
| 1 // Copyright (c) 2011 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/asynchronous_policy_provider.h" | 5 #include "chrome/browser/policy/asynchronous_policy_provider.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "chrome/browser/policy/asynchronous_policy_loader.h" | 8 #include "chrome/browser/policy/asynchronous_policy_loader.h" |
| 9 #include "chrome/browser/policy/policy_map.h" | |
| 10 #include "content/public/browser/browser_thread.h" | 9 #include "content/public/browser/browser_thread.h" |
| 11 | 10 |
| 12 using content::BrowserThread; | 11 using content::BrowserThread; |
| 13 | 12 |
| 14 namespace policy { | 13 namespace policy { |
| 15 | 14 |
| 16 AsynchronousPolicyProvider::AsynchronousPolicyProvider( | 15 AsynchronousPolicyProvider::AsynchronousPolicyProvider( |
| 17 const PolicyDefinitionList* policy_list, | 16 const PolicyDefinitionList* policy_list, |
| 17 PolicyLevel level, |
| 18 PolicyScope scope, |
| 18 scoped_refptr<AsynchronousPolicyLoader> loader) | 19 scoped_refptr<AsynchronousPolicyLoader> loader) |
| 19 : ConfigurationPolicyProvider(policy_list), | 20 : ConfigurationPolicyProvider(policy_list), |
| 21 level_(level), |
| 22 scope_(scope), |
| 20 loader_(loader), | 23 loader_(loader), |
| 21 pending_refreshes_(0), | 24 pending_refreshes_(0), |
| 22 ALLOW_THIS_IN_INITIALIZER_LIST(weak_ptr_factory_(this)) { | 25 ALLOW_THIS_IN_INITIALIZER_LIST(weak_ptr_factory_(this)) { |
| 23 loader_->Init( | 26 loader_->Init( |
| 24 base::Bind(&AsynchronousPolicyProvider::OnLoaderReloaded, | 27 base::Bind(&AsynchronousPolicyProvider::OnLoaderReloaded, |
| 25 base::Unretained(this))); | 28 base::Unretained(this))); |
| 26 } | 29 } |
| 27 | 30 |
| 28 AsynchronousPolicyProvider::~AsynchronousPolicyProvider() { | 31 AsynchronousPolicyProvider::~AsynchronousPolicyProvider() { |
| 29 DCHECK(CalledOnValidThread()); | 32 DCHECK(CalledOnValidThread()); |
| 30 // |loader_| won't invoke its callback anymore after Stop(), therefore | 33 // |loader_| won't invoke its callback anymore after Stop(), therefore |
| 31 // Unretained(this) is safe in the ctor. | 34 // Unretained(this) is safe in the ctor. |
| 32 loader_->Stop(); | 35 loader_->Stop(); |
| 33 } | 36 } |
| 34 | 37 |
| 35 bool AsynchronousPolicyProvider::ProvideInternal(PolicyMap* map) { | 38 bool AsynchronousPolicyProvider::ProvideInternal(PolicyMap* map) { |
| 36 DCHECK(CalledOnValidThread()); | 39 DCHECK(CalledOnValidThread()); |
| 37 if (!loader_->policy()) | 40 if (!loader_->policy()) |
| 38 return false; | 41 return false; |
| 39 map->LoadFrom(loader_->policy(), policy_definition_list()); | 42 map->LoadFrom(loader_->policy(), policy_definition_list(), level_, scope_); |
| 40 return true; | 43 return true; |
| 41 } | 44 } |
| 42 | 45 |
| 43 void AsynchronousPolicyProvider::RefreshPolicies() { | 46 void AsynchronousPolicyProvider::RefreshPolicies() { |
| 44 DCHECK(CalledOnValidThread()); | 47 DCHECK(CalledOnValidThread()); |
| 45 pending_refreshes_++; | 48 pending_refreshes_++; |
| 46 BrowserThread::PostTaskAndReply( | 49 BrowserThread::PostTaskAndReply( |
| 47 BrowserThread::FILE, FROM_HERE, | 50 BrowserThread::FILE, FROM_HERE, |
| 48 base::Bind(&AsynchronousPolicyProvider::PostReloadOnFileThread, | 51 base::Bind(&AsynchronousPolicyProvider::PostReloadOnFileThread, |
| 49 loader_), | 52 loader_), |
| (...skipping 15 matching lines...) Expand all Loading... |
| 65 pending_refreshes_--; | 68 pending_refreshes_--; |
| 66 } | 69 } |
| 67 | 70 |
| 68 void AsynchronousPolicyProvider::OnLoaderReloaded() { | 71 void AsynchronousPolicyProvider::OnLoaderReloaded() { |
| 69 DCHECK(CalledOnValidThread()); | 72 DCHECK(CalledOnValidThread()); |
| 70 if (pending_refreshes_ == 0) | 73 if (pending_refreshes_ == 0) |
| 71 NotifyPolicyUpdated(); | 74 NotifyPolicyUpdated(); |
| 72 } | 75 } |
| 73 | 76 |
| 74 } // namespace policy | 77 } // namespace policy |
| OLD | NEW |