| OLD | NEW |
| (Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef CHROME_BROWSER_POLICY_ASYNC_POLICY_PROVIDER_H_ |
| 6 #define CHROME_BROWSER_POLICY_ASYNC_POLICY_PROVIDER_H_ |
| 7 #pragma once |
| 8 |
| 9 #include "base/cancelable_callback.h" |
| 10 #include "base/memory/ref_counted.h" |
| 11 #include "base/memory/scoped_ptr.h" |
| 12 #include "base/memory/weak_ptr.h" |
| 13 #include "base/threading/non_thread_safe.h" |
| 14 #include "chrome/browser/policy/configuration_policy_provider.h" |
| 15 |
| 16 namespace base { |
| 17 class MessageLoopProxy; |
| 18 } |
| 19 |
| 20 namespace policy { |
| 21 |
| 22 class AsyncPolicyLoader; |
| 23 class PolicyBundle; |
| 24 |
| 25 // A policy provider that loads its policies asynchronously on the FILE thread. |
| 26 // Platform-specific providers are created by passing an implementation of |
| 27 // AsyncPolicyLoader to a new AsyncPolicyProvider. |
| 28 class AsyncPolicyProvider : public ConfigurationPolicyProvider, |
| 29 public base::NonThreadSafe { |
| 30 public: |
| 31 AsyncPolicyProvider(const PolicyDefinitionList* policy_list, |
| 32 scoped_ptr<AsyncPolicyLoader> loader); |
| 33 virtual ~AsyncPolicyProvider(); |
| 34 |
| 35 // ConfigurationPolicyProvider implementation. |
| 36 virtual void RefreshPolicies() OVERRIDE; |
| 37 |
| 38 private: |
| 39 // Resumes initialization once the loops are spinning. |
| 40 void InitWithLoopsReady(); |
| 41 |
| 42 // Helper for RefreshPolicies(). |
| 43 void ReloadAfterRefreshSync(); |
| 44 |
| 45 // Invoked with the latest bundle loaded by the |loader_|. |
| 46 void OnLoaderReloaded(scoped_ptr<PolicyBundle> bundle); |
| 47 |
| 48 // Callback passed to the loader that it uses to pass back the current policy |
| 49 // bundle to the provider. This is invoked on the FILE thread and forwards |
| 50 // to OnLoaderReloaded() on the loop that owns the provider, if |weak_this| is |
| 51 // still valid. |
| 52 static void LoaderUpdateCallback(scoped_refptr<base::MessageLoopProxy> loop, |
| 53 base::WeakPtr<AsyncPolicyProvider> weak_this, |
| 54 scoped_ptr<PolicyBundle> bundle); |
| 55 |
| 56 // The |loader_| that does the platform-specific policy loading. It lives |
| 57 // on the FILE thread, and always outlives |this|. |
| 58 AsyncPolicyLoader* loader_; |
| 59 |
| 60 // Used to get a WeakPtr to |this| for the update callback given to the |
| 61 // loader. |
| 62 base::WeakPtrFactory<AsyncPolicyProvider> weak_factory_; |
| 63 |
| 64 // Callback used to synchronize RefreshPolicies() calls with the FILE thread. |
| 65 // See the implementation for the details. |
| 66 base::CancelableClosure refresh_callback_; |
| 67 |
| 68 DISALLOW_COPY_AND_ASSIGN(AsyncPolicyProvider); |
| 69 }; |
| 70 |
| 71 } // namespace policy |
| 72 |
| 73 #endif // CHROME_BROWSER_POLICY_ASYNC_POLICY_PROVIDER_H_ |
| OLD | NEW |