| 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_LOADER_H_ | 5 #ifndef COMPONENTS_POLICY_CORE_COMMON_ASYNC_POLICY_LOADER_H_ |
| 6 #define COMPONENTS_POLICY_CORE_COMMON_ASYNC_POLICY_LOADER_H_ | 6 #define COMPONENTS_POLICY_CORE_COMMON_ASYNC_POLICY_LOADER_H_ |
| 7 | 7 |
| 8 #include <memory> |
| 9 |
| 8 #include "base/callback.h" | 10 #include "base/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/time/time.h" | 14 #include "base/time/time.h" |
| 14 #include "components/policy/core/common/schema_map.h" | 15 #include "components/policy/core/common/schema_map.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 SequencedTaskRunner; | 19 class SequencedTaskRunner; |
| 19 } | 20 } |
| 20 | 21 |
| 21 namespace policy { | 22 namespace policy { |
| (...skipping 15 matching lines...) Expand all Loading... |
| 37 explicit AsyncPolicyLoader( | 38 explicit AsyncPolicyLoader( |
| 38 const scoped_refptr<base::SequencedTaskRunner>& task_runner); | 39 const scoped_refptr<base::SequencedTaskRunner>& task_runner); |
| 39 virtual ~AsyncPolicyLoader(); | 40 virtual ~AsyncPolicyLoader(); |
| 40 | 41 |
| 41 // Gets a SequencedTaskRunner backed by the background thread. | 42 // Gets a SequencedTaskRunner backed by the background thread. |
| 42 base::SequencedTaskRunner* task_runner() const { return task_runner_.get(); } | 43 base::SequencedTaskRunner* task_runner() const { return task_runner_.get(); } |
| 43 | 44 |
| 44 // Returns the currently configured policies. Load() is always invoked on | 45 // Returns the currently configured policies. Load() is always invoked on |
| 45 // the background thread, except for the initial Load() at startup which is | 46 // the background thread, except for the initial Load() at startup which is |
| 46 // invoked from the thread that owns the provider. | 47 // invoked from the thread that owns the provider. |
| 47 virtual scoped_ptr<PolicyBundle> Load() = 0; | 48 virtual std::unique_ptr<PolicyBundle> Load() = 0; |
| 48 | 49 |
| 49 // Allows implementations to finalize their initialization on the background | 50 // Allows implementations to finalize their initialization on the background |
| 50 // thread (e.g. setup file watchers). | 51 // thread (e.g. setup file watchers). |
| 51 virtual void InitOnBackgroundThread() = 0; | 52 virtual void InitOnBackgroundThread() = 0; |
| 52 | 53 |
| 53 // Implementations should return the time of the last modification detected, | 54 // Implementations should return the time of the last modification detected, |
| 54 // or base::Time() if it doesn't apply, which is the default. | 55 // or base::Time() if it doesn't apply, which is the default. |
| 55 virtual base::Time LastModificationTime(); | 56 virtual base::Time LastModificationTime(); |
| 56 | 57 |
| 57 // Used by the AsyncPolicyProvider to do the initial Load(). The first load | 58 // Used by the AsyncPolicyProvider to do the initial Load(). The first load |
| 58 // is also used to initialize |last_modification_time_| and | 59 // is also used to initialize |last_modification_time_| and |
| 59 // |schema_map_|. | 60 // |schema_map_|. |
| 60 scoped_ptr<PolicyBundle> InitialLoad(const scoped_refptr<SchemaMap>& schemas); | 61 std::unique_ptr<PolicyBundle> InitialLoad( |
| 62 const scoped_refptr<SchemaMap>& schemas); |
| 61 | 63 |
| 62 // Implementations should invoke Reload() when a change is detected. This | 64 // Implementations should invoke Reload() when a change is detected. This |
| 63 // must be invoked from the background thread and will trigger a Load(), | 65 // must be invoked from the background thread and will trigger a Load(), |
| 64 // and pass the returned bundle to the provider. | 66 // and pass the returned bundle to the provider. |
| 65 // The load is immediate when |force| is true. Otherwise, the loader | 67 // The load is immediate when |force| is true. Otherwise, the loader |
| 66 // reschedules the reload until the LastModificationTime() is a couple of | 68 // reschedules the reload until the LastModificationTime() is a couple of |
| 67 // seconds in the past. This mitigates the problem of reading files that are | 69 // seconds in the past. This mitigates the problem of reading files that are |
| 68 // currently being written to, and whose contents are incomplete. | 70 // currently being written to, and whose contents are incomplete. |
| 69 // A reload is posted periodically, if it hasn't been triggered recently. This | 71 // A reload is posted periodically, if it hasn't been triggered recently. This |
| 70 // makes sure the policies are reloaded if the update events aren't triggered. | 72 // makes sure the policies are reloaded if the update events aren't triggered. |
| 71 void Reload(bool force); | 73 void Reload(bool force); |
| 72 | 74 |
| 73 const scoped_refptr<SchemaMap>& schema_map() const { return schema_map_; } | 75 const scoped_refptr<SchemaMap>& schema_map() const { return schema_map_; } |
| 74 | 76 |
| 75 private: | 77 private: |
| 76 // Allow AsyncPolicyProvider to call Init(). | 78 // Allow AsyncPolicyProvider to call Init(). |
| 77 friend class AsyncPolicyProvider; | 79 friend class AsyncPolicyProvider; |
| 78 | 80 |
| 79 typedef base::Callback<void(scoped_ptr<PolicyBundle>)> UpdateCallback; | 81 typedef base::Callback<void(std::unique_ptr<PolicyBundle>)> UpdateCallback; |
| 80 | 82 |
| 81 // Used by the AsyncPolicyProvider to install the |update_callback_|. | 83 // Used by the AsyncPolicyProvider to install the |update_callback_|. |
| 82 // Invoked on the background thread. | 84 // Invoked on the background thread. |
| 83 void Init(const UpdateCallback& update_callback); | 85 void Init(const UpdateCallback& update_callback); |
| 84 | 86 |
| 85 // Used by the AsyncPolicyProvider to reload with an updated SchemaMap. | 87 // Used by the AsyncPolicyProvider to reload with an updated SchemaMap. |
| 86 void RefreshPolicies(scoped_refptr<SchemaMap> schema_map); | 88 void RefreshPolicies(scoped_refptr<SchemaMap> schema_map); |
| 87 | 89 |
| 88 // Cancels any pending periodic reload and posts one |delay| time units from | 90 // Cancels any pending periodic reload and posts one |delay| time units from |
| 89 // now. | 91 // now. |
| (...skipping 24 matching lines...) Expand all Loading... |
| 114 | 116 |
| 115 // Used to get WeakPtrs for the periodic reload task. | 117 // Used to get WeakPtrs for the periodic reload task. |
| 116 base::WeakPtrFactory<AsyncPolicyLoader> weak_factory_; | 118 base::WeakPtrFactory<AsyncPolicyLoader> weak_factory_; |
| 117 | 119 |
| 118 DISALLOW_COPY_AND_ASSIGN(AsyncPolicyLoader); | 120 DISALLOW_COPY_AND_ASSIGN(AsyncPolicyLoader); |
| 119 }; | 121 }; |
| 120 | 122 |
| 121 } // namespace policy | 123 } // namespace policy |
| 122 | 124 |
| 123 #endif // COMPONENTS_POLICY_CORE_COMMON_ASYNC_POLICY_LOADER_H_ | 125 #endif // COMPONENTS_POLICY_CORE_COMMON_ASYNC_POLICY_LOADER_H_ |
| OLD | NEW |