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