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 // ApendCache(cache): adds |cache| to the back (i.e. least important cache). | |
Mattias Nissler (ping if slow)
2011/06/09 14:36:26
Do we actually need both of them? I would expect o
Mattias Nissler (ping if slow)
2011/06/09 14:36:26
Apend -> Append
sfeuz
2011/06/13 06:53:53
I'd like to keep both.
It is true that in the curr
sfeuz
2011/06/13 06:53:53
Done.
| |
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 // The underlying policy caches. | |
61 typedef std::vector<CloudPolicyCacheBase*> ListType; | |
62 ListType caches_; | |
Mattias Nissler (ping if slow)
2011/06/09 14:36:26
Move the declaration of this data member down to t
sfeuz
2011/06/13 06:53:53
Done.
| |
63 | |
64 // Combines two PolicyMap and stores the result in out_map. The policies in | |
65 // |base| take precedence over the policies in |overlay|. Proxy policies are | |
66 // only applied in groups, that is if at least one proxy policy is present in | |
67 // |base| then no proxy related policy of |overlay| will be applied. | |
68 void CombineTwoPolicyMaps(const PolicyMap& base, | |
69 const PolicyMap& overlay, | |
70 PolicyMap* out_map); | |
71 | |
72 // Policy level this provider will handle. | |
73 CloudPolicyCacheBase::PolicyLevel level_; | |
74 | |
75 // Provider observers that are registered with this provider. | |
76 ObserverList<ConfigurationPolicyProvider::Observer, true> observer_list_; | |
77 | |
78 // Recompute |combined| from |caches_| and trigger an OnUpdatePolicy if | |
79 // something changed. This is called whenever a change in one of the caches | |
80 // is observed. For i=0..n-1: |caches_[i]| will contribute all its policies | |
81 // except those already provided by |caches_[0]|..|caches_[i-1]|. Proxy | |
82 // related policies are handled as a special case: they are only applied in | |
83 // groups. | |
84 void RecombineCachesAndMaybeTriggerUpdate(); | |
85 | |
86 // The currently valid combination of all the maps in |caches_|. Will be | |
87 // applied as is on call of Provide. | |
88 PolicyMap combined; | |
Mattias Nissler (ping if slow)
2011/06/09 14:36:26
Missing a trailing underscore.
sfeuz
2011/06/13 06:53:53
Done.
| |
89 | |
90 DISALLOW_COPY_AND_ASSIGN(CloudPolicyProvider); | |
91 }; | |
92 | |
93 } // namespace policy | |
94 | |
95 #endif // CHROME_BROWSER_POLICY_CLOUD_POLICY_PROVIDER_H_ | |
OLD | NEW |