| 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_CLOUD_POLICY_PROVIDER_H_ | |
| 6 #define CHROME_BROWSER_POLICY_CLOUD_POLICY_PROVIDER_H_ | |
| 7 | |
| 8 #include <set> | |
| 9 | |
| 10 #include "base/basictypes.h" | |
| 11 #include "chrome/browser/policy/cloud_policy_cache_base.h" | |
| 12 #include "chrome/browser/policy/configuration_policy_provider.h" | |
| 13 | |
| 14 namespace policy { | |
| 15 | |
| 16 class BrowserPolicyConnector; | |
| 17 | |
| 18 // A policy provider that merges the policies contained in the caches it | |
| 19 // observes. The caches receive their policies by fetching them from the cloud, | |
| 20 // through the CloudPolicyController. | |
| 21 class CloudPolicyProvider : public ConfigurationPolicyProvider, | |
| 22 public CloudPolicyCacheBase::Observer { | |
| 23 public: | |
| 24 explicit CloudPolicyProvider(BrowserPolicyConnector* connector); | |
| 25 virtual ~CloudPolicyProvider(); | |
| 26 | |
| 27 // Sets the user policy cache. This must be invoked only once, and |cache| | |
| 28 // must not be NULL. |cache| must be valid until Shutdown() has been called. | |
| 29 void SetUserPolicyCache(CloudPolicyCacheBase* cache); | |
| 30 | |
| 31 #if defined(OS_CHROMEOS) | |
| 32 // Sets the device policy cache. This must be invoked only once, and |cache| | |
| 33 // must not be NULL. |cache| must be valid until Shutdown() has been called. | |
| 34 void SetDevicePolicyCache(CloudPolicyCacheBase* cache); | |
| 35 #endif | |
| 36 | |
| 37 // ConfigurationPolicyProvider implementation. | |
| 38 virtual void Shutdown() OVERRIDE; | |
| 39 virtual bool IsInitializationComplete() const OVERRIDE; | |
| 40 virtual void RefreshPolicies() OVERRIDE; | |
| 41 | |
| 42 // CloudPolicyCacheBase::Observer implementation. | |
| 43 virtual void OnCacheUpdate(CloudPolicyCacheBase* cache) OVERRIDE; | |
| 44 | |
| 45 private: | |
| 46 // Indices of the known caches in |caches_|. | |
| 47 enum { | |
| 48 CACHE_USER, | |
| 49 #if defined(OS_CHROMEOS) | |
| 50 CACHE_DEVICE, | |
| 51 #endif | |
| 52 CACHE_SIZE, | |
| 53 }; | |
| 54 | |
| 55 // Merges policies from both caches, and triggers a notification if ready. | |
| 56 void Merge(); | |
| 57 | |
| 58 // The device and user policy caches, whose policies are provided by |this|. | |
| 59 // Both are initially NULL, and the provider only becomes initialized once | |
| 60 // all the caches are available and ready. | |
| 61 CloudPolicyCacheBase* caches_[CACHE_SIZE]; | |
| 62 | |
| 63 // Weak pointer to the connector. Guaranteed to outlive |this|. | |
| 64 BrowserPolicyConnector* browser_policy_connector_; | |
| 65 | |
| 66 // Whether all caches are present and fully initialized. | |
| 67 bool initialization_complete_; | |
| 68 | |
| 69 // Used to determine when updates due to a RefreshPolicies() call have been | |
| 70 // completed. | |
| 71 std::set<const CloudPolicyCacheBase*> pending_updates_; | |
| 72 | |
| 73 DISALLOW_COPY_AND_ASSIGN(CloudPolicyProvider); | |
| 74 }; | |
| 75 | |
| 76 } // namespace policy | |
| 77 | |
| 78 #endif // CHROME_BROWSER_POLICY_CLOUD_POLICY_PROVIDER_H_ | |
| OLD | NEW |