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> | 8 #include <memory> |
9 | 9 |
10 #include "base/cancelable_callback.h" | 10 #include "base/cancelable_callback.h" |
11 #include "base/macros.h" | 11 #include "base/macros.h" |
12 #include "base/memory/ref_counted.h" | 12 #include "base/memory/ref_counted.h" |
13 #include "base/memory/weak_ptr.h" | 13 #include "base/memory/weak_ptr.h" |
14 #include "base/threading/non_thread_safe.h" | 14 #include "base/sequence_checker.h" |
15 #include "components/policy/core/common/configuration_policy_provider.h" | 15 #include "components/policy/core/common/configuration_policy_provider.h" |
16 #include "components/policy/policy_export.h" | 16 #include "components/policy/policy_export.h" |
17 | 17 |
18 namespace base { | 18 namespace base { |
19 class SingleThreadTaskRunner; | 19 class SingleThreadTaskRunner; |
20 } | 20 } |
21 | 21 |
22 namespace policy { | 22 namespace policy { |
23 | 23 |
24 class AsyncPolicyLoader; | 24 class AsyncPolicyLoader; |
25 class PolicyBundle; | 25 class PolicyBundle; |
26 class SchemaRegistry; | 26 class SchemaRegistry; |
27 | 27 |
28 // A policy provider that loads its policies asynchronously on a background | 28 // A policy provider that loads its policies asynchronously on a background |
29 // thread. Platform-specific providers are created by passing an implementation | 29 // thread. Platform-specific providers are created by passing an implementation |
30 // of AsyncPolicyLoader to a new AsyncPolicyProvider. | 30 // of AsyncPolicyLoader to a new AsyncPolicyProvider. |
31 class POLICY_EXPORT AsyncPolicyProvider : public ConfigurationPolicyProvider, | 31 class POLICY_EXPORT AsyncPolicyProvider : public ConfigurationPolicyProvider { |
32 public base::NonThreadSafe { | |
33 public: | 32 public: |
34 // The AsyncPolicyProvider does a synchronous load in its constructor, and | 33 // The AsyncPolicyProvider does a synchronous load in its constructor, and |
35 // therefore it needs the |registry| at construction time. The same |registry| | 34 // therefore it needs the |registry| at construction time. The same |registry| |
36 // should be passed later to Init(). | 35 // should be passed later to Init(). |
37 AsyncPolicyProvider(SchemaRegistry* registry, | 36 AsyncPolicyProvider(SchemaRegistry* registry, |
38 std::unique_ptr<AsyncPolicyLoader> loader); | 37 std::unique_ptr<AsyncPolicyLoader> loader); |
39 ~AsyncPolicyProvider() override; | 38 ~AsyncPolicyProvider() override; |
40 | 39 |
41 // ConfigurationPolicyProvider implementation. | 40 // ConfigurationPolicyProvider implementation. |
42 void Init(SchemaRegistry* registry) override; | 41 void Init(SchemaRegistry* registry) override; |
(...skipping 17 matching lines...) Expand all Loading... |
60 std::unique_ptr<PolicyBundle> bundle); | 59 std::unique_ptr<PolicyBundle> bundle); |
61 | 60 |
62 // The |loader_| that does the platform-specific policy loading. It lives | 61 // The |loader_| that does the platform-specific policy loading. It lives |
63 // on the background thread but is owned by |this|. | 62 // on the background thread but is owned by |this|. |
64 std::unique_ptr<AsyncPolicyLoader> loader_; | 63 std::unique_ptr<AsyncPolicyLoader> loader_; |
65 | 64 |
66 // Callback used to synchronize RefreshPolicies() calls with the background | 65 // Callback used to synchronize RefreshPolicies() calls with the background |
67 // thread. See the implementation for the details. | 66 // thread. See the implementation for the details. |
68 base::CancelableClosure refresh_callback_; | 67 base::CancelableClosure refresh_callback_; |
69 | 68 |
| 69 SEQUENCE_CHECKER(sequence_checker_); |
| 70 |
70 // Used to get a WeakPtr to |this| for the update callback given to the | 71 // Used to get a WeakPtr to |this| for the update callback given to the |
71 // loader. | 72 // loader. |
72 base::WeakPtrFactory<AsyncPolicyProvider> weak_factory_; | 73 base::WeakPtrFactory<AsyncPolicyProvider> weak_factory_; |
73 | 74 |
74 DISALLOW_COPY_AND_ASSIGN(AsyncPolicyProvider); | 75 DISALLOW_COPY_AND_ASSIGN(AsyncPolicyProvider); |
75 }; | 76 }; |
76 | 77 |
77 } // namespace policy | 78 } // namespace policy |
78 | 79 |
79 #endif // COMPONENTS_POLICY_CORE_COMMON_ASYNC_POLICY_PROVIDER_H_ | 80 #endif // COMPONENTS_POLICY_CORE_COMMON_ASYNC_POLICY_PROVIDER_H_ |
OLD | NEW |