| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 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 | 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_CLOUD_POLICY_PROVIDER_IMPL_H_ | 5 #ifndef CHROME_BROWSER_POLICY_CLOUD_POLICY_PROVIDER_IMPL_H_ |
| 6 #define CHROME_BROWSER_POLICY_CLOUD_POLICY_PROVIDER_IMPL_H_ | 6 #define CHROME_BROWSER_POLICY_CLOUD_POLICY_PROVIDER_IMPL_H_ |
| 7 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| 11 #include "chrome/browser/policy/cloud_policy_cache_base.h" | 11 #include "chrome/browser/policy/cloud_policy_cache_base.h" |
| 12 #include "chrome/browser/policy/cloud_policy_provider.h" | 12 #include "chrome/browser/policy/cloud_policy_provider.h" |
| 13 #include "chrome/browser/policy/policy_map.h" | 13 #include "chrome/browser/policy/policy_map.h" |
| 14 | 14 |
| 15 namespace policy { | 15 namespace policy { |
| 16 | 16 |
| 17 class BrowserPolicyConnector; |
| 18 |
| 17 class CloudPolicyProviderImpl : public CloudPolicyProvider, | 19 class CloudPolicyProviderImpl : public CloudPolicyProvider, |
| 18 public CloudPolicyCacheBase::Observer { | 20 public CloudPolicyCacheBase::Observer { |
| 19 public: | 21 public: |
| 20 CloudPolicyProviderImpl(const PolicyDefinitionList* policy_list, | 22 CloudPolicyProviderImpl(BrowserPolicyConnector* browser_policy_connector, |
| 23 const PolicyDefinitionList* policy_list, |
| 21 CloudPolicyCacheBase::PolicyLevel level); | 24 CloudPolicyCacheBase::PolicyLevel level); |
| 22 virtual ~CloudPolicyProviderImpl(); | 25 virtual ~CloudPolicyProviderImpl(); |
| 23 | 26 |
| 24 // ConfigurationPolicyProvider implementation. | 27 // ConfigurationPolicyProvider implementation. |
| 25 virtual bool ProvideInternal(PolicyMap* result) OVERRIDE; | 28 virtual bool ProvideInternal(PolicyMap* result) OVERRIDE; |
| 26 virtual bool IsInitializationComplete() const OVERRIDE; | 29 virtual bool IsInitializationComplete() const OVERRIDE; |
| 30 virtual void RefreshPolicies() OVERRIDE; |
| 27 | 31 |
| 28 // CloudPolicyCacheBase::Observer implementation. | 32 // CloudPolicyCacheBase::Observer implementation. |
| 29 virtual void OnCacheUpdate(CloudPolicyCacheBase* cache) OVERRIDE; | 33 virtual void OnCacheUpdate(CloudPolicyCacheBase* cache) OVERRIDE; |
| 30 virtual void OnCacheGoingAway(CloudPolicyCacheBase* cache) OVERRIDE; | 34 virtual void OnCacheGoingAway(CloudPolicyCacheBase* cache) OVERRIDE; |
| 31 virtual void AppendCache(CloudPolicyCacheBase* cache) OVERRIDE; | 35 virtual void AppendCache(CloudPolicyCacheBase* cache) OVERRIDE; |
| 32 virtual void PrependCache(CloudPolicyCacheBase* cache) OVERRIDE; | 36 virtual void PrependCache(CloudPolicyCacheBase* cache) OVERRIDE; |
| 33 | 37 |
| 34 private: | 38 private: |
| 35 friend class CloudPolicyProviderTest; | 39 friend class CloudPolicyProviderTest; |
| 36 | 40 |
| 37 // Combines two PolicyMap and stores the result in out_map. The policies in | 41 // Combines two PolicyMap and stores the result in out_map. The policies in |
| 38 // |base| take precedence over the policies in |overlay|. Proxy policies are | 42 // |base| take precedence over the policies in |overlay|. Proxy policies are |
| 39 // only applied in groups, that is if at least one proxy policy is present in | 43 // only applied in groups, that is if at least one proxy policy is present in |
| 40 // |base| then no proxy related policy of |overlay| will be applied. | 44 // |base| then no proxy related policy of |overlay| will be applied. |
| 41 static void CombineTwoPolicyMaps(const PolicyMap& base, | 45 static void CombineTwoPolicyMaps(const PolicyMap& base, |
| 42 const PolicyMap& overlay, | 46 const PolicyMap& overlay, |
| 43 PolicyMap* out_map); | 47 PolicyMap* out_map); |
| 44 | 48 |
| 45 // Recompute |combined_| from |caches_| and trigger an OnUpdatePolicy if | 49 // Recompute |combined_| from |caches_| and trigger an OnUpdatePolicy if |
| 46 // something changed. This is called whenever a change in one of the caches | 50 // something changed. This is called whenever a change in one of the caches |
| 47 // is observed. For i=0..n-1: |caches_[i]| will contribute all its policies | 51 // is observed. For i=0..n-1: |caches_[i]| will contribute all its policies |
| 48 // except those already provided by |caches_[0]|..|caches_[i-1]|. Proxy | 52 // except those already provided by |caches_[0]|..|caches_[i-1]|. Proxy |
| 49 // related policies are handled as a special case: they are only applied in | 53 // related policies are handled as a special case: they are only applied in |
| 50 // groups. | 54 // groups. |
| 51 void RecombineCachesAndTriggerUpdate(); | 55 void RecombineCachesAndTriggerUpdate(); |
| 52 | 56 |
| 57 // Removes |cache| from |pending_update_caches_|, if contained therein. |
| 58 void RemoveFromPending(CloudPolicyCacheBase* cache); |
| 59 |
| 60 // Weak pointer to the connector. Guaranteed to outlive |this|. |
| 61 BrowserPolicyConnector* browser_policy_connector_; |
| 62 |
| 53 // The underlying policy caches. | 63 // The underlying policy caches. |
| 54 typedef std::vector<CloudPolicyCacheBase*> ListType; | 64 typedef std::vector<CloudPolicyCacheBase*> ListType; |
| 55 ListType caches_; | 65 ListType caches_; |
| 56 | 66 |
| 67 // Caches with pending updates. Used by RefreshPolicies to determine if a |
| 68 // refresh has fully completed. |
| 69 ListType pending_update_caches_; |
| 70 |
| 57 // Policy level this provider will handle. | 71 // Policy level this provider will handle. |
| 58 CloudPolicyCacheBase::PolicyLevel level_; | 72 CloudPolicyCacheBase::PolicyLevel level_; |
| 59 | 73 |
| 60 // Whether all caches are fully initialized. | 74 // Whether all caches are fully initialized. |
| 61 bool initialization_complete_; | 75 bool initialization_complete_; |
| 62 | 76 |
| 63 // The currently valid combination of all the maps in |caches_|. Will be | 77 // The currently valid combination of all the maps in |caches_|. Will be |
| 64 // applied as is on call of Provide. | 78 // applied as is on call of Provide. |
| 65 PolicyMap combined_; | 79 PolicyMap combined_; |
| 66 | 80 |
| 67 DISALLOW_COPY_AND_ASSIGN(CloudPolicyProviderImpl); | 81 DISALLOW_COPY_AND_ASSIGN(CloudPolicyProviderImpl); |
| 68 }; | 82 }; |
| 69 | 83 |
| 70 } // namespace policy | 84 } // namespace policy |
| 71 | 85 |
| 72 #endif // CHROME_BROWSER_POLICY_CLOUD_POLICY_PROVIDER_IMPL_H_ | 86 #endif // CHROME_BROWSER_POLICY_CLOUD_POLICY_PROVIDER_IMPL_H_ |
| OLD | NEW |