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 <memory> |
| 9 |
8 #include "base/cancelable_callback.h" | 10 #include "base/cancelable_callback.h" |
9 #include "base/macros.h" | 11 #include "base/macros.h" |
10 #include "base/memory/ref_counted.h" | 12 #include "base/memory/ref_counted.h" |
11 #include "base/memory/scoped_ptr.h" | |
12 #include "base/memory/weak_ptr.h" | 13 #include "base/memory/weak_ptr.h" |
13 #include "base/threading/non_thread_safe.h" | 14 #include "base/threading/non_thread_safe.h" |
14 #include "components/policy/core/common/configuration_policy_provider.h" | 15 #include "components/policy/core/common/configuration_policy_provider.h" |
15 #include "components/policy/policy_export.h" | 16 #include "components/policy/policy_export.h" |
16 | 17 |
17 namespace base { | 18 namespace base { |
18 class SingleThreadTaskRunner; | 19 class SingleThreadTaskRunner; |
19 } | 20 } |
20 | 21 |
21 namespace policy { | 22 namespace policy { |
22 | 23 |
23 class AsyncPolicyLoader; | 24 class AsyncPolicyLoader; |
24 class PolicyBundle; | 25 class PolicyBundle; |
25 class SchemaRegistry; | 26 class SchemaRegistry; |
26 | 27 |
27 // A policy provider that loads its policies asynchronously on a background | 28 // A policy provider that loads its policies asynchronously on a background |
28 // thread. Platform-specific providers are created by passing an implementation | 29 // thread. Platform-specific providers are created by passing an implementation |
29 // of AsyncPolicyLoader to a new AsyncPolicyProvider. | 30 // of AsyncPolicyLoader to a new AsyncPolicyProvider. |
30 class POLICY_EXPORT AsyncPolicyProvider : public ConfigurationPolicyProvider, | 31 class POLICY_EXPORT AsyncPolicyProvider : public ConfigurationPolicyProvider, |
31 public base::NonThreadSafe { | 32 public base::NonThreadSafe { |
32 public: | 33 public: |
33 // The AsyncPolicyProvider does a synchronous load in its constructor, and | 34 // The AsyncPolicyProvider does a synchronous load in its constructor, and |
34 // therefore it needs the |registry| at construction time. The same |registry| | 35 // therefore it needs the |registry| at construction time. The same |registry| |
35 // should be passed later to Init(). | 36 // should be passed later to Init(). |
36 AsyncPolicyProvider(SchemaRegistry* registry, | 37 AsyncPolicyProvider(SchemaRegistry* registry, |
37 scoped_ptr<AsyncPolicyLoader> loader); | 38 std::unique_ptr<AsyncPolicyLoader> loader); |
38 ~AsyncPolicyProvider() override; | 39 ~AsyncPolicyProvider() override; |
39 | 40 |
40 // ConfigurationPolicyProvider implementation. | 41 // ConfigurationPolicyProvider implementation. |
41 void Init(SchemaRegistry* registry) override; | 42 void Init(SchemaRegistry* registry) override; |
42 void Shutdown() override; | 43 void Shutdown() override; |
43 void RefreshPolicies() override; | 44 void RefreshPolicies() override; |
44 | 45 |
45 private: | 46 private: |
46 // Helper for RefreshPolicies(). | 47 // Helper for RefreshPolicies(). |
47 void ReloadAfterRefreshSync(); | 48 void ReloadAfterRefreshSync(); |
48 | 49 |
49 // Invoked with the latest bundle loaded by the |loader_|. | 50 // Invoked with the latest bundle loaded by the |loader_|. |
50 void OnLoaderReloaded(scoped_ptr<PolicyBundle> bundle); | 51 void OnLoaderReloaded(std::unique_ptr<PolicyBundle> bundle); |
51 | 52 |
52 // Callback passed to the loader that it uses to pass back the current policy | 53 // Callback passed to the loader that it uses to pass back the current policy |
53 // bundle to the provider. This is invoked on the background thread and | 54 // bundle to the provider. This is invoked on the background thread and |
54 // forwards to OnLoaderReloaded() on the runner that owns the provider, | 55 // forwards to OnLoaderReloaded() on the runner that owns the provider, |
55 // if |weak_this| is still valid. | 56 // if |weak_this| is still valid. |
56 static void LoaderUpdateCallback( | 57 static void LoaderUpdateCallback( |
57 scoped_refptr<base::SingleThreadTaskRunner> runner, | 58 scoped_refptr<base::SingleThreadTaskRunner> runner, |
58 base::WeakPtr<AsyncPolicyProvider> weak_this, | 59 base::WeakPtr<AsyncPolicyProvider> weak_this, |
59 scoped_ptr<PolicyBundle> bundle); | 60 std::unique_ptr<PolicyBundle> bundle); |
60 | 61 |
61 // The |loader_| that does the platform-specific policy loading. It lives | 62 // The |loader_| that does the platform-specific policy loading. It lives |
62 // on the background thread but is owned by |this|. | 63 // on the background thread but is owned by |this|. |
63 scoped_ptr<AsyncPolicyLoader> loader_; | 64 std::unique_ptr<AsyncPolicyLoader> loader_; |
64 | 65 |
65 // Callback used to synchronize RefreshPolicies() calls with the background | 66 // Callback used to synchronize RefreshPolicies() calls with the background |
66 // thread. See the implementation for the details. | 67 // thread. See the implementation for the details. |
67 base::CancelableClosure refresh_callback_; | 68 base::CancelableClosure refresh_callback_; |
68 | 69 |
69 // Used to get a WeakPtr to |this| for the update callback given to the | 70 // Used to get a WeakPtr to |this| for the update callback given to the |
70 // loader. | 71 // loader. |
71 base::WeakPtrFactory<AsyncPolicyProvider> weak_factory_; | 72 base::WeakPtrFactory<AsyncPolicyProvider> weak_factory_; |
72 | 73 |
73 DISALLOW_COPY_AND_ASSIGN(AsyncPolicyProvider); | 74 DISALLOW_COPY_AND_ASSIGN(AsyncPolicyProvider); |
74 }; | 75 }; |
75 | 76 |
76 } // namespace policy | 77 } // namespace policy |
77 | 78 |
78 #endif // COMPONENTS_POLICY_CORE_COMMON_ASYNC_POLICY_PROVIDER_H_ | 79 #endif // COMPONENTS_POLICY_CORE_COMMON_ASYNC_POLICY_PROVIDER_H_ |
OLD | NEW |