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 |
| 41 typedef std::vector<CloudPolicyCacheBase*> ListType; |
| 42 |
37 // Combines two PolicyMap and stores the result in out_map. The policies in | 43 // 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 | 44 // |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 | 45 // 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. | 46 // |base| then no proxy related policy of |overlay| will be applied. |
41 static void CombineTwoPolicyMaps(const PolicyMap& base, | 47 static void CombineTwoPolicyMaps(const PolicyMap& base, |
42 const PolicyMap& overlay, | 48 const PolicyMap& overlay, |
43 PolicyMap* out_map); | 49 PolicyMap* out_map); |
44 | 50 |
45 // Recompute |combined_| from |caches_| and trigger an OnUpdatePolicy if | 51 // Recompute |combined_| from |caches_| and trigger an OnUpdatePolicy if |
46 // something changed. This is called whenever a change in one of the caches | 52 // 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 | 53 // 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 | 54 // 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 | 55 // related policies are handled as a special case: they are only applied in |
50 // groups. | 56 // groups. |
51 void RecombineCachesAndTriggerUpdate(); | 57 void RecombineCachesAndTriggerUpdate(); |
52 | 58 |
| 59 // Removes |cache| from |caches|, if contained therein. |
| 60 static void RemoveCache(CloudPolicyCacheBase* cache, ListType* caches); |
| 61 |
| 62 // Weak pointer to the connector. Guaranteed to outlive |this|. |
| 63 BrowserPolicyConnector* browser_policy_connector_; |
| 64 |
53 // The underlying policy caches. | 65 // The underlying policy caches. |
54 typedef std::vector<CloudPolicyCacheBase*> ListType; | |
55 ListType caches_; | 66 ListType caches_; |
56 | 67 |
| 68 // Caches with pending updates. Used by RefreshPolicies to determine if a |
| 69 // refresh has fully completed. |
| 70 ListType pending_update_caches_; |
| 71 |
57 // Policy level this provider will handle. | 72 // Policy level this provider will handle. |
58 CloudPolicyCacheBase::PolicyLevel level_; | 73 CloudPolicyCacheBase::PolicyLevel level_; |
59 | 74 |
60 // Whether all caches are fully initialized. | 75 // Whether all caches are fully initialized. |
61 bool initialization_complete_; | 76 bool initialization_complete_; |
62 | 77 |
63 // The currently valid combination of all the maps in |caches_|. Will be | 78 // The currently valid combination of all the maps in |caches_|. Will be |
64 // applied as is on call of Provide. | 79 // applied as is on call of Provide. |
65 PolicyMap combined_; | 80 PolicyMap combined_; |
66 | 81 |
67 DISALLOW_COPY_AND_ASSIGN(CloudPolicyProviderImpl); | 82 DISALLOW_COPY_AND_ASSIGN(CloudPolicyProviderImpl); |
68 }; | 83 }; |
69 | 84 |
70 } // namespace policy | 85 } // namespace policy |
71 | 86 |
72 #endif // CHROME_BROWSER_POLICY_CLOUD_POLICY_PROVIDER_IMPL_H_ | 87 #endif // CHROME_BROWSER_POLICY_CLOUD_POLICY_PROVIDER_IMPL_H_ |
OLD | NEW |