Chromium Code Reviews| 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 #ifndef CHROME_BROWSER_POLICY_ASYNCHRONOUS_POLICY_PROVIDER_H_ | 5 #ifndef CHROME_BROWSER_POLICY_ASYNCHRONOUS_POLICY_PROVIDER_H_ |
| 6 #define CHROME_BROWSER_POLICY_ASYNCHRONOUS_POLICY_PROVIDER_H_ | 6 #define CHROME_BROWSER_POLICY_ASYNCHRONOUS_POLICY_PROVIDER_H_ |
| 7 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 #include "base/memory/ref_counted.h" | 9 #include "base/memory/ref_counted.h" |
| 10 #include "base/memory/weak_ptr.h" | 10 #include "base/memory/weak_ptr.h" |
| 11 #include "base/threading/non_thread_safe.h" | 11 #include "base/threading/non_thread_safe.h" |
| 12 #include "chrome/browser/policy/configuration_policy_provider.h" | 12 #include "chrome/browser/policy/configuration_policy_provider.h" |
| 13 #include "chrome/browser/policy/policy_map.h" | |
| 13 | 14 |
| 14 namespace policy { | 15 namespace policy { |
| 15 | 16 |
| 16 class AsynchronousPolicyLoader; | 17 class AsynchronousPolicyLoader; |
| 17 | 18 |
| 18 // Policy provider that loads policy asynchronously. Providers should subclass | 19 // Policy provider that loads policy asynchronously. Providers should subclass |
| 19 // from this class if loading the policy requires disk access or must for some | 20 // from this class if loading the policy requires disk access or must for some |
| 20 // other reason be performed on the file thread. The actual logic for loading | 21 // other reason be performed on the file thread. The actual logic for loading |
| 21 // policy is handled by a delegate passed at construction time. | 22 // policy is handled by a delegate passed at construction time. |
| 22 class AsynchronousPolicyProvider | 23 class AsynchronousPolicyProvider |
| 23 : public ConfigurationPolicyProvider, | 24 : public ConfigurationPolicyProvider, |
| 24 public base::NonThreadSafe { | 25 public base::NonThreadSafe { |
| 25 public: | 26 public: |
| 26 // Must be implemented by subclasses of the asynchronous policy provider to | 27 // Must be implemented by subclasses of the asynchronous policy provider to |
| 27 // provide the implementation details of how policy is loaded. | 28 // provide the implementation details of how policy is loaded. |
| 28 class Delegate { | 29 class Delegate { |
| 29 public: | 30 public: |
| 30 virtual ~Delegate() {} | 31 virtual ~Delegate() {} |
| 31 | 32 |
| 32 virtual DictionaryValue* Load() = 0; | 33 virtual DictionaryValue* Load() = 0; |
| 33 }; | 34 }; |
| 34 | 35 |
| 35 // Assumes ownership of |loader|. | 36 // Assumes ownership of |loader|. |
| 36 AsynchronousPolicyProvider( | 37 AsynchronousPolicyProvider( |
| 37 const PolicyDefinitionList* policy_list, | 38 const PolicyDefinitionList* policy_list, |
| 39 PolicyLevel level, | |
| 40 PolicyScope scope, | |
| 38 scoped_refptr<AsynchronousPolicyLoader> loader); | 41 scoped_refptr<AsynchronousPolicyLoader> loader); |
| 39 virtual ~AsynchronousPolicyProvider(); | 42 virtual ~AsynchronousPolicyProvider(); |
| 40 | 43 |
| 41 // ConfigurationPolicyProvider implementation. | 44 // ConfigurationPolicyProvider implementation. |
| 42 virtual bool ProvideInternal(PolicyMap* map) OVERRIDE; | 45 virtual bool ProvideInternal(PolicyMap* map) OVERRIDE; |
| 43 virtual void RefreshPolicies() OVERRIDE; | 46 virtual void RefreshPolicies() OVERRIDE; |
| 44 | 47 |
| 45 private: | 48 private: |
| 46 // Used to trigger a Reload on |loader| on the FILE thread. | 49 // Used to trigger a Reload on |loader| on the FILE thread. |
| 47 static void PostReloadOnFileThread(AsynchronousPolicyLoader* loader); | 50 static void PostReloadOnFileThread(AsynchronousPolicyLoader* loader); |
| 48 | 51 |
| 49 // Used to notify UI that a reload task has been submitted. | 52 // Used to notify UI that a reload task has been submitted. |
| 50 void OnReloadPosted(); | 53 void OnReloadPosted(); |
| 51 | 54 |
| 52 // Callback from the loader. This is invoked whenever the loader has completed | 55 // Callback from the loader. This is invoked whenever the loader has completed |
| 53 // a reload of the policies. | 56 // a reload of the policies. |
| 54 void OnLoaderReloaded(); | 57 void OnLoaderReloaded(); |
| 55 | 58 |
| 59 // The policy level and scope for policies loaded through this provider. | |
| 60 PolicyLevel level_; | |
| 61 PolicyScope scope_; | |
|
Mattias Nissler (ping if slow)
2012/01/16 18:23:33
having the scope per-provider here might not be ap
Joao da Silva
2012/01/17 13:09:29
This is meant to be removed once all the providers
| |
| 62 | |
| 56 // The loader object used internally. | 63 // The loader object used internally. |
| 57 scoped_refptr<AsynchronousPolicyLoader> loader_; | 64 scoped_refptr<AsynchronousPolicyLoader> loader_; |
| 58 | 65 |
| 59 // Number of refreshes requested whose reload is still pending. Used to only | 66 // Number of refreshes requested whose reload is still pending. Used to only |
| 60 // fire notifications when all pending refreshes are done. | 67 // fire notifications when all pending refreshes are done. |
| 61 int pending_refreshes_; | 68 int pending_refreshes_; |
| 62 | 69 |
| 63 // Used to post tasks to self on UI. | 70 // Used to post tasks to self on UI. |
| 64 base::WeakPtrFactory<AsynchronousPolicyProvider> weak_ptr_factory_; | 71 base::WeakPtrFactory<AsynchronousPolicyProvider> weak_ptr_factory_; |
| 65 | 72 |
| 66 DISALLOW_COPY_AND_ASSIGN(AsynchronousPolicyProvider); | 73 DISALLOW_COPY_AND_ASSIGN(AsynchronousPolicyProvider); |
| 67 }; | 74 }; |
| 68 | 75 |
| 69 } // namespace policy | 76 } // namespace policy |
| 70 | 77 |
| 71 #endif // CHROME_BROWSER_POLICY_ASYNCHRONOUS_POLICY_PROVIDER_H_ | 78 #endif // CHROME_BROWSER_POLICY_ASYNCHRONOUS_POLICY_PROVIDER_H_ |
| OLD | NEW |