OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2011 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 #pragma once |
| 8 |
| 9 #include "base/memory/scoped_ptr.h" |
| 10 #include "base/memory/scoped_vector.h" |
| 11 #include "base/observer_list.h" |
| 12 #include "chrome/browser/policy/cloud_policy_cache_base.h" |
| 13 #include "chrome/browser/policy/configuration_policy_provider.h" |
| 14 #include "chrome/browser/policy/policy_map.h" |
| 15 |
| 16 namespace policy { |
| 17 |
| 18 // A policy provider having multiple backend caches, combining their relevant |
| 19 // PolicyMaps and keeping the result cached. The underlying caches are kept as |
| 20 // weak references and can be added dynamically. Also the |
| 21 // |CloudPolicyProvider| instance listens to cache-notifications and removes |
| 22 // the caches automatically when they go away. The order in which the caches are |
| 23 // stored matters! The first cache is applied as is and the following caches |
| 24 // only contribute the not-yet applied policies. There are two functions to add |
| 25 // a new cache: |
| 26 // PrependCache(cache): adds |cache| to the front (i.e. most important cache). |
| 27 // AppendCache(cache): adds |cache| to the back (i.e. least important cache). |
| 28 class CloudPolicyProvider : public ConfigurationPolicyProvider, |
| 29 public CloudPolicyCacheBase::Observer { |
| 30 public: |
| 31 CloudPolicyProvider(const PolicyDefinitionList* policy_list, |
| 32 CloudPolicyCacheBase::PolicyLevel level); |
| 33 virtual ~CloudPolicyProvider(); |
| 34 |
| 35 // ConfigurationPolicyProvider implementation. |
| 36 virtual bool Provide(ConfigurationPolicyStoreInterface* store) OVERRIDE; |
| 37 virtual bool IsInitializationComplete() const OVERRIDE; |
| 38 virtual void AddObserver(ConfigurationPolicyProvider::Observer* observer) |
| 39 OVERRIDE; |
| 40 virtual void RemoveObserver(ConfigurationPolicyProvider::Observer* observer) |
| 41 OVERRIDE; |
| 42 |
| 43 // CloudPolicyCacheBase::Observer implementation. |
| 44 virtual void OnCacheUpdate(CloudPolicyCacheBase* cache) OVERRIDE; |
| 45 virtual void OnCacheGoingAway(CloudPolicyCacheBase* cache) OVERRIDE; |
| 46 |
| 47 // Adds a new instance of CloudPolicyCacheBase to the end of |caches_|. |
| 48 // Does not take ownership of |cache| and listens to OnCacheGoingAway to |
| 49 // automatically remove it from |caches_|. |
| 50 void AppendCache(CloudPolicyCacheBase* cache); |
| 51 |
| 52 // Adds a new instance of CloudPolicyCacheBase to the beginning of |caches_|. |
| 53 // Does not take ownership of |cache| and listens to OnCacheGoingAway to |
| 54 // automatically remove it from |caches_|. |
| 55 void PrependCache(CloudPolicyCacheBase* cache); |
| 56 |
| 57 private: |
| 58 friend class CloudPolicyProviderTest; |
| 59 |
| 60 // Detecting proxy-policies since they need a special handling when combining |
| 61 // policy maps. |
| 62 static ConfigurationPolicyType proxy_policies[]; |
| 63 static bool is_proxy_policy(ConfigurationPolicyType policy); |
| 64 static unsigned int proxy_policy_count(); |
| 65 // Combines two PolicyMap and stores the result in out_map. The policies in |
| 66 // |base| take precedence over the policies in |overlay|. Proxy policies are |
| 67 // only applied in groups, that is if at least one proxy policy is present in |
| 68 // |base| then no proxy related policy of |overlay| will be applied. |
| 69 void CombineTwoPolicyMaps(const PolicyMap& base, |
| 70 const PolicyMap& overlay, |
| 71 PolicyMap* out_map); |
| 72 |
| 73 // Recompute |combined_| from |caches_| and trigger an OnUpdatePolicy if |
| 74 // something changed. This is called whenever a change in one of the caches |
| 75 // is observed. For i=0..n-1: |caches_[i]| will contribute all its policies |
| 76 // except those already provided by |caches_[0]|..|caches_[i-1]|. Proxy |
| 77 // related policies are handled as a special case: they are only applied in |
| 78 // groups. |
| 79 void RecombineCachesAndMaybeTriggerUpdate(); |
| 80 |
| 81 // The underlying policy caches. |
| 82 typedef std::vector<CloudPolicyCacheBase*> ListType; |
| 83 ListType caches_; |
| 84 |
| 85 // Policy level this provider will handle. |
| 86 CloudPolicyCacheBase::PolicyLevel level_; |
| 87 |
| 88 // Provider observers that are registered with this provider. |
| 89 ObserverList<ConfigurationPolicyProvider::Observer, true> observer_list_; |
| 90 |
| 91 // The currently valid combination of all the maps in |caches_|. Will be |
| 92 // applied as is on call of Provide. |
| 93 PolicyMap combined_; |
| 94 |
| 95 DISALLOW_COPY_AND_ASSIGN(CloudPolicyProvider); |
| 96 }; |
| 97 |
| 98 } // namespace policy |
| 99 |
| 100 #endif // CHROME_BROWSER_POLICY_CLOUD_POLICY_PROVIDER_H_ |
OLD | NEW |