| 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_LOADER_H_ | 5 #ifndef CHROME_BROWSER_POLICY_ASYNCHRONOUS_POLICY_LOADER_H_ |
| 6 #define CHROME_BROWSER_POLICY_ASYNCHRONOUS_POLICY_LOADER_H_ | 6 #define CHROME_BROWSER_POLICY_ASYNCHRONOUS_POLICY_LOADER_H_ |
| 7 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 #include "base/callback.h" | 9 #include "base/callback.h" |
| 10 #include "base/memory/ref_counted.h" | 10 #include "base/memory/ref_counted.h" |
| 11 #include "base/memory/scoped_ptr.h" | 11 #include "base/memory/scoped_ptr.h" |
| 12 #include "base/memory/weak_ptr.h" | 12 #include "base/memory/weak_ptr.h" |
| 13 #include "base/time.h" | 13 #include "base/time.h" |
| 14 #include "chrome/browser/policy/asynchronous_policy_provider.h" | 14 #include "chrome/browser/policy/asynchronous_policy_provider.h" |
| 15 | 15 |
| 16 class MessageLoop; | 16 class MessageLoop; |
| 17 | 17 |
| 18 namespace policy { | 18 namespace policy { |
| 19 | 19 |
| 20 class PolicyBundle; | 20 class PolicyBundle; |
| 21 class PolicyMap; | |
| 22 | 21 |
| 23 // Used by the implementation of asynchronous policy provider to manage the | 22 // Used by the implementation of asynchronous policy provider to manage the |
| 24 // tasks on the FILE thread that do the heavy lifting of loading policies. | 23 // tasks on the FILE thread that do the heavy lifting of loading policies. |
| 25 class AsynchronousPolicyLoader | 24 class AsynchronousPolicyLoader |
| 26 : public base::RefCountedThreadSafe<AsynchronousPolicyLoader> { | 25 : public base::RefCountedThreadSafe<AsynchronousPolicyLoader> { |
| 27 public: | 26 public: |
| 28 // The type of the callback passed to Init(). | 27 // The type of the callback passed to Init(). |
| 29 typedef base::Callback<void(scoped_ptr<PolicyBundle>)> UpdateCallback; | 28 typedef base::Callback<void(scoped_ptr<PolicyBundle>)> UpdateCallback; |
| 30 | 29 |
| 31 AsynchronousPolicyLoader(AsynchronousPolicyProvider::Delegate* delegate, | 30 AsynchronousPolicyLoader(AsynchronousPolicyProvider::Delegate* delegate, |
| (...skipping 12 matching lines...) Expand all Loading... |
| 44 // Stops any pending reload tasks. Updates callbacks won't be performed | 43 // Stops any pending reload tasks. Updates callbacks won't be performed |
| 45 // anymore once the loader is stopped. | 44 // anymore once the loader is stopped. |
| 46 virtual void Stop(); | 45 virtual void Stop(); |
| 47 | 46 |
| 48 protected: | 47 protected: |
| 49 // AsynchronousPolicyLoader objects should only be deleted by | 48 // AsynchronousPolicyLoader objects should only be deleted by |
| 50 // RefCountedThreadSafe. | 49 // RefCountedThreadSafe. |
| 51 friend class base::RefCountedThreadSafe<AsynchronousPolicyLoader>; | 50 friend class base::RefCountedThreadSafe<AsynchronousPolicyLoader>; |
| 52 virtual ~AsynchronousPolicyLoader(); | 51 virtual ~AsynchronousPolicyLoader(); |
| 53 | 52 |
| 54 // Schedules a call to UpdatePolicy on |origin_loop_|. Takes ownership of | 53 // Schedules a call to UpdatePolicy on |origin_loop_|. |
| 55 // |new_policy|. | 54 void PostUpdatePolicyTask(scoped_ptr<PolicyBundle> bundle); |
| 56 void PostUpdatePolicyTask(PolicyMap* new_policy); | |
| 57 | 55 |
| 58 AsynchronousPolicyProvider::Delegate* delegate() { | 56 AsynchronousPolicyProvider::Delegate* delegate() { |
| 59 return delegate_.get(); | 57 return delegate_.get(); |
| 60 } | 58 } |
| 61 | 59 |
| 62 // Performs start operations that must be performed on the FILE thread. | 60 // Performs start operations that must be performed on the FILE thread. |
| 63 virtual void InitOnFileThread(); | 61 virtual void InitOnFileThread(); |
| 64 | 62 |
| 65 // Performs stop operations that must be performed on the FILE thread. | 63 // Performs stop operations that must be performed on the FILE thread. |
| 66 virtual void StopOnFileThread(); | 64 virtual void StopOnFileThread(); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 81 private: | 79 private: |
| 82 friend class AsynchronousPolicyLoaderTest; | 80 friend class AsynchronousPolicyLoaderTest; |
| 83 | 81 |
| 84 // Finishes loader initialization after the threading system has been fully | 82 // Finishes loader initialization after the threading system has been fully |
| 85 // intialized. | 83 // intialized. |
| 86 void InitAfterFileThreadAvailable(); | 84 void InitAfterFileThreadAvailable(); |
| 87 | 85 |
| 88 // Invokes the |update_callback_| with a new PolicyBundle that maps | 86 // Invokes the |update_callback_| with a new PolicyBundle that maps |
| 89 // the chrome namespace to |policy|. Must be called on |origin_loop_| so that | 87 // the chrome namespace to |policy|. Must be called on |origin_loop_| so that |
| 90 // it's safe to invoke |update_callback_|. | 88 // it's safe to invoke |update_callback_|. |
| 91 void UpdatePolicy(scoped_ptr<PolicyMap> policy); | 89 void UpdatePolicy(scoped_ptr<PolicyBundle> policy); |
| 92 | 90 |
| 93 // Provides the low-level mechanics for loading policy. | 91 // Provides the low-level mechanics for loading policy. |
| 94 scoped_ptr<AsynchronousPolicyProvider::Delegate> delegate_; | 92 scoped_ptr<AsynchronousPolicyProvider::Delegate> delegate_; |
| 95 | 93 |
| 96 // Used to create and invalidate WeakPtrs on the FILE thread. These are only | 94 // Used to create and invalidate WeakPtrs on the FILE thread. These are only |
| 97 // used to post reload tasks that can be cancelled. | 95 // used to post reload tasks that can be cancelled. |
| 98 base::WeakPtrFactory<AsynchronousPolicyLoader> weak_ptr_factory_; | 96 base::WeakPtrFactory<AsynchronousPolicyLoader> weak_ptr_factory_; |
| 99 | 97 |
| 100 // The interval at which a policy reload will be triggered as a fallback. | 98 // The interval at which a policy reload will be triggered as a fallback. |
| 101 const base::TimeDelta reload_interval_; | 99 const base::TimeDelta reload_interval_; |
| 102 | 100 |
| 103 // The message loop on which this object was constructed. Recorded so that | 101 // The message loop on which this object was constructed. Recorded so that |
| 104 // it's possible to call back into the non thread safe provider to fire the | 102 // it's possible to call back into the non thread safe provider to fire the |
| 105 // notification. | 103 // notification. |
| 106 MessageLoop* origin_loop_; | 104 MessageLoop* origin_loop_; |
| 107 | 105 |
| 108 // True if Stop has been called. | 106 // True if Stop has been called. |
| 109 bool stopped_; | 107 bool stopped_; |
| 110 | 108 |
| 111 // Callback to invoke on policy updates. | 109 // Callback to invoke on policy updates. |
| 112 UpdateCallback update_callback_; | 110 UpdateCallback update_callback_; |
| 113 | 111 |
| 114 DISALLOW_COPY_AND_ASSIGN(AsynchronousPolicyLoader); | 112 DISALLOW_COPY_AND_ASSIGN(AsynchronousPolicyLoader); |
| 115 }; | 113 }; |
| 116 | 114 |
| 117 } // namespace policy | 115 } // namespace policy |
| 118 | 116 |
| 119 #endif // CHROME_BROWSER_POLICY_ASYNCHRONOUS_POLICY_LOADER_H_ | 117 #endif // CHROME_BROWSER_POLICY_ASYNCHRONOUS_POLICY_LOADER_H_ |
| OLD | NEW |