OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "chrome/browser/policy/asynchronous_policy_provider.h" |
| 6 |
| 7 #include "base/task.h" |
| 8 #include "chrome/browser/browser_thread.h" |
| 9 #include "chrome/browser/policy/asynchronous_policy_loader.h" |
| 10 |
| 11 namespace { |
| 12 |
| 13 // The time interval for rechecking policy. This is our fallback in case the |
| 14 // delegate never reports a change to the ReloadObserver. |
| 15 const int kReloadIntervalMinutes = 15; |
| 16 |
| 17 } |
| 18 |
| 19 namespace policy { |
| 20 |
| 21 class TriggerReloadPolicyChangeObserver |
| 22 : public AsynchronousPolicyProvider::PolicyChangeObserver { |
| 23 public: |
| 24 TriggerReloadPolicyChangeObserver( |
| 25 scoped_refptr<AsynchronousPolicyLoader> loader) |
| 26 : AsynchronousPolicyProvider::PolicyChangeObserver(), |
| 27 loader_(loader) {} |
| 28 virtual ~TriggerReloadPolicyChangeObserver() {} |
| 29 |
| 30 virtual void OnPolicyChange() { |
| 31 if (BrowserThread::CurrentlyOn(BrowserThread::FILE)) { |
| 32 loader_->Reload(); |
| 33 } else { |
| 34 BrowserThread::PostTask( |
| 35 BrowserThread::FILE, FROM_HERE, |
| 36 NewRunnableMethod(loader_.get(), |
| 37 &AsynchronousPolicyLoader::Reload)); |
| 38 } |
| 39 } |
| 40 |
| 41 private: |
| 42 scoped_refptr<AsynchronousPolicyLoader> loader_; |
| 43 DISALLOW_COPY_AND_ASSIGN(TriggerReloadPolicyChangeObserver); |
| 44 }; |
| 45 |
| 46 AsynchronousPolicyProvider::AsynchronousPolicyProvider( |
| 47 const PolicyDefinitionList* policy_list, |
| 48 AsynchronousPolicyProvider::Delegate* delegate) |
| 49 : ConfigurationPolicyProvider(policy_list), |
| 50 delegate_(delegate) { |
| 51 loader_ = new AsynchronousPolicyLoader( |
| 52 this->AsWeakPtr(), |
| 53 delegate, |
| 54 kReloadIntervalMinutes); |
| 55 loader_->Init(); |
| 56 delegate_->Init(new TriggerReloadPolicyChangeObserver(loader_)); |
| 57 } |
| 58 |
| 59 AsynchronousPolicyProvider::~AsynchronousPolicyProvider() { |
| 60 delegate_->Stop(); |
| 61 loader_->Stop(); |
| 62 } |
| 63 |
| 64 bool AsynchronousPolicyProvider::Provide( |
| 65 ConfigurationPolicyStoreInterface* store) { |
| 66 scoped_ptr<DictionaryValue> policy(loader_->GetPolicy()); |
| 67 DCHECK(policy.get()); |
| 68 DecodePolicyValueTree(policy.get(), store); |
| 69 return true; |
| 70 } |
| 71 |
| 72 } // namespace policy |
OLD | NEW |