OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef CHROME_BROWSER_POLICY_ASYNCHRONOUS_POLICY_LOADER_H_ |
| 6 #define CHROME_BROWSER_POLICY_ASYNCHRONOUS_POLICY_LOADER_H_ |
| 7 #pragma once |
| 8 |
| 9 #include "base/message_loop.h" |
| 10 #include "base/ref_counted.h" |
| 11 #include "base/values.h" |
| 12 #include "chrome/browser/policy/asynchronous_policy_provider.h" |
| 13 |
| 14 namespace policy { |
| 15 |
| 16 class ConfigurationPolicyProvider; |
| 17 |
| 18 // Used by the implementation of asynchronous policy provider to manage the |
| 19 // tasks on the file thread that do the heavy lifting of loading policies. |
| 20 class AsynchronousPolicyLoader |
| 21 : public base::RefCountedThreadSafe<AsynchronousPolicyLoader> { |
| 22 public: |
| 23 explicit AsynchronousPolicyLoader( |
| 24 AsynchronousPolicyProvider::Delegate* delegate); |
| 25 |
| 26 // Triggers initial policy load. |
| 27 virtual void Init(); |
| 28 |
| 29 // Reloads policy, sending notification of changes if necessary. Must be |
| 30 // called on the file thread. |
| 31 virtual void Reload(); |
| 32 |
| 33 // Stops any pending reload tasks. |
| 34 virtual void Stop(); |
| 35 |
| 36 // Associates a provider with the loader to allow the loader to notify the |
| 37 // provider when policy changes. |
| 38 void SetProvider(AsynchronousPolicyProvider* provider); |
| 39 |
| 40 const DictionaryValue* policy() const { return policy_.get(); } |
| 41 |
| 42 protected: |
| 43 friend class UpdatePolicyTask; |
| 44 |
| 45 // AsynchronousPolicyLoader objects should only be deleted by |
| 46 // RefCountedThreadSafe. |
| 47 friend class base::RefCountedThreadSafe<AsynchronousPolicyLoader>; |
| 48 virtual ~AsynchronousPolicyLoader() {} |
| 49 |
| 50 // Schedules a call to UpdatePolicy on |origin_loop_|. |
| 51 void PostUpdatePolicyTask(DictionaryValue* new_policy); |
| 52 |
| 53 // Replaces the existing policy to value map with a new one, sending |
| 54 // notification to the provider if there is a policy change. Must be called on |
| 55 // |origin_loop_| so that it's safe to call back into the provider, which is |
| 56 // not thread-safe. |
| 57 void UpdatePolicy(DictionaryValue* new_policy); |
| 58 |
| 59 AsynchronousPolicyProvider::Delegate* delegate() { |
| 60 return delegate_.get(); |
| 61 } |
| 62 |
| 63 AsynchronousPolicyProvider* provider() { |
| 64 return provider_; |
| 65 } |
| 66 |
| 67 private: |
| 68 friend class AsynchronousPolicyLoaderTest; |
| 69 |
| 70 // Provides the low-level mechanics for loading policy. |
| 71 scoped_ptr<AsynchronousPolicyProvider::Delegate> delegate_; |
| 72 |
| 73 // Current policy. |
| 74 scoped_ptr<DictionaryValue> policy_; |
| 75 |
| 76 // The provider this loader is associated with. Access only on the thread that |
| 77 // called the constructor. See |origin_loop_| below. |
| 78 AsynchronousPolicyProvider* provider_; |
| 79 |
| 80 // The message loop on which this object was constructed. Recorded so that |
| 81 // it's possible to call back into the non thread safe provider to fire the |
| 82 // notification. |
| 83 MessageLoop* origin_loop_; |
| 84 |
| 85 DISALLOW_COPY_AND_ASSIGN(AsynchronousPolicyLoader); |
| 86 }; |
| 87 |
| 88 } // namespace policy |
| 89 |
| 90 #endif // CHROME_BROWSER_POLICY_ASYNCHRONOUS_POLICY_LOADER_H_ |
OLD | NEW |