OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 COMPONENTS_POLICY_CORE_COMMON_ASYNC_POLICY_PROVIDER_H_ | 5 #ifndef COMPONENTS_POLICY_CORE_COMMON_ASYNC_POLICY_PROVIDER_H_ |
6 #define COMPONENTS_POLICY_CORE_COMMON_ASYNC_POLICY_PROVIDER_H_ | 6 #define COMPONENTS_POLICY_CORE_COMMON_ASYNC_POLICY_PROVIDER_H_ |
7 | 7 |
8 #include "base/cancelable_callback.h" | 8 #include "base/cancelable_callback.h" |
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/scoped_ptr.h" |
11 #include "base/memory/weak_ptr.h" | 11 #include "base/memory/weak_ptr.h" |
12 #include "base/threading/non_thread_safe.h" | 12 #include "base/threading/non_thread_safe.h" |
13 #include "components/policy/core/common/configuration_policy_provider.h" | 13 #include "components/policy/core/common/configuration_policy_provider.h" |
14 #include "components/policy/policy_export.h" | 14 #include "components/policy/policy_export.h" |
15 | 15 |
16 namespace base { | 16 namespace base { |
17 class MessageLoopProxy; | 17 class SingleThreadTaskRunner; |
18 } | 18 } |
19 | 19 |
20 namespace policy { | 20 namespace policy { |
21 | 21 |
22 class AsyncPolicyLoader; | 22 class AsyncPolicyLoader; |
23 class PolicyBundle; | 23 class PolicyBundle; |
24 class SchemaRegistry; | 24 class SchemaRegistry; |
25 | 25 |
26 // A policy provider that loads its policies asynchronously on a background | 26 // A policy provider that loads its policies asynchronously on a background |
27 // thread. Platform-specific providers are created by passing an implementation | 27 // thread. Platform-specific providers are created by passing an implementation |
(...skipping 15 matching lines...) Expand all Loading... |
43 | 43 |
44 private: | 44 private: |
45 // Helper for RefreshPolicies(). | 45 // Helper for RefreshPolicies(). |
46 void ReloadAfterRefreshSync(); | 46 void ReloadAfterRefreshSync(); |
47 | 47 |
48 // Invoked with the latest bundle loaded by the |loader_|. | 48 // Invoked with the latest bundle loaded by the |loader_|. |
49 void OnLoaderReloaded(scoped_ptr<PolicyBundle> bundle); | 49 void OnLoaderReloaded(scoped_ptr<PolicyBundle> bundle); |
50 | 50 |
51 // Callback passed to the loader that it uses to pass back the current policy | 51 // Callback passed to the loader that it uses to pass back the current policy |
52 // bundle to the provider. This is invoked on the background thread and | 52 // bundle to the provider. This is invoked on the background thread and |
53 // forwards to OnLoaderReloaded() on the loop that owns the provider, | 53 // forwards to OnLoaderReloaded() on the runner that owns the provider, |
54 // if |weak_this| is still valid. | 54 // if |weak_this| is still valid. |
55 static void LoaderUpdateCallback(scoped_refptr<base::MessageLoopProxy> loop, | 55 static void LoaderUpdateCallback( |
56 base::WeakPtr<AsyncPolicyProvider> weak_this, | 56 scoped_refptr<base::SingleThreadTaskRunner> runner, |
57 scoped_ptr<PolicyBundle> bundle); | 57 base::WeakPtr<AsyncPolicyProvider> weak_this, |
| 58 scoped_ptr<PolicyBundle> bundle); |
58 | 59 |
59 // The |loader_| that does the platform-specific policy loading. It lives | 60 // The |loader_| that does the platform-specific policy loading. It lives |
60 // on the background thread but is owned by |this|. | 61 // on the background thread but is owned by |this|. |
61 scoped_ptr<AsyncPolicyLoader> loader_; | 62 scoped_ptr<AsyncPolicyLoader> loader_; |
62 | 63 |
63 // Callback used to synchronize RefreshPolicies() calls with the background | 64 // Callback used to synchronize RefreshPolicies() calls with the background |
64 // thread. See the implementation for the details. | 65 // thread. See the implementation for the details. |
65 base::CancelableClosure refresh_callback_; | 66 base::CancelableClosure refresh_callback_; |
66 | 67 |
67 // Used to get a WeakPtr to |this| for the update callback given to the | 68 // Used to get a WeakPtr to |this| for the update callback given to the |
68 // loader. | 69 // loader. |
69 base::WeakPtrFactory<AsyncPolicyProvider> weak_factory_; | 70 base::WeakPtrFactory<AsyncPolicyProvider> weak_factory_; |
70 | 71 |
71 DISALLOW_COPY_AND_ASSIGN(AsyncPolicyProvider); | 72 DISALLOW_COPY_AND_ASSIGN(AsyncPolicyProvider); |
72 }; | 73 }; |
73 | 74 |
74 } // namespace policy | 75 } // namespace policy |
75 | 76 |
76 #endif // COMPONENTS_POLICY_CORE_COMMON_ASYNC_POLICY_PROVIDER_H_ | 77 #endif // COMPONENTS_POLICY_CORE_COMMON_ASYNC_POLICY_PROVIDER_H_ |
OLD | NEW |