Index: chrome/browser/policy/cloud_policy_provider.h |
diff --git a/chrome/browser/policy/cloud_policy_provider.h b/chrome/browser/policy/cloud_policy_provider.h |
new file mode 100644 |
index 0000000000000000000000000000000000000000..4422527f8cead6f2017f08d4f2af6a69c40ae7be |
--- /dev/null |
+++ b/chrome/browser/policy/cloud_policy_provider.h |
@@ -0,0 +1,95 @@ |
+// Copyright (c) 2011 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#ifndef CHROME_BROWSER_POLICY_CLOUD_POLICY_PROVIDER_H_ |
+#define CHROME_BROWSER_POLICY_CLOUD_POLICY_PROVIDER_H_ |
+#pragma once |
+ |
+#include "base/memory/scoped_ptr.h" |
+#include "base/memory/scoped_vector.h" |
+#include "base/observer_list.h" |
+#include "chrome/browser/policy/cloud_policy_cache_base.h" |
+#include "chrome/browser/policy/configuration_policy_provider.h" |
+#include "chrome/browser/policy/policy_map.h" |
+ |
+namespace policy { |
+ |
+// A policy provider having multiple backend caches, combining their relevant |
+// PolicyMaps and keeping the result cached. The underlying caches are kept as |
+// weak references and can be added dynamically. Also the |
+// |CloudPolicyProvider| instance listens to cache-notifications and removes |
+// the caches automatically when they go away. The order in which the caches are |
+// stored matters! The first cache is applied as is and the following caches |
+// only contribute the not-yet applied policies. There are two functions to add |
+// a new cache: |
+// PrependCache(cache): adds |cache| to the front (i.e. most important cache). |
+// 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.
|
+class CloudPolicyProvider : public ConfigurationPolicyProvider, |
+ public CloudPolicyCacheBase::Observer { |
+ public: |
+ CloudPolicyProvider(const PolicyDefinitionList* policy_list, |
+ CloudPolicyCacheBase::PolicyLevel level); |
+ virtual ~CloudPolicyProvider(); |
+ |
+ // ConfigurationPolicyProvider implementation. |
+ virtual bool Provide(ConfigurationPolicyStoreInterface* store) OVERRIDE; |
+ virtual bool IsInitializationComplete() const OVERRIDE; |
+ virtual void AddObserver(ConfigurationPolicyProvider::Observer* observer) |
+ OVERRIDE; |
+ virtual void RemoveObserver(ConfigurationPolicyProvider::Observer* observer) |
+ OVERRIDE; |
+ |
+ // CloudPolicyCacheBase::Observer implementation. |
+ virtual void OnCacheUpdate(CloudPolicyCacheBase* cache) OVERRIDE; |
+ virtual void OnCacheGoingAway(CloudPolicyCacheBase* cache) OVERRIDE; |
+ |
+ // Adds a new instance of CloudPolicyCacheBase to the end of |caches_|. |
+ // Does not take ownership of |cache| and listens to OnCacheGoingAway to |
+ // automatically remove it from |caches_|. |
+ void AppendCache(CloudPolicyCacheBase* cache); |
+ |
+ // Adds a new instance of CloudPolicyCacheBase to the beginning of |caches_|. |
+ // Does not take ownership of |cache| and listens to OnCacheGoingAway to |
+ // automatically remove it from |caches_|. |
+ void PrependCache(CloudPolicyCacheBase* cache); |
+ |
+ private: |
+ friend class CloudPolicyProviderTest; |
+ |
+ // The underlying policy caches. |
+ typedef std::vector<CloudPolicyCacheBase*> ListType; |
+ 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.
|
+ |
+ // Combines two PolicyMap and stores the result in out_map. The policies in |
+ // |base| take precedence over the policies in |overlay|. Proxy policies are |
+ // only applied in groups, that is if at least one proxy policy is present in |
+ // |base| then no proxy related policy of |overlay| will be applied. |
+ void CombineTwoPolicyMaps(const PolicyMap& base, |
+ const PolicyMap& overlay, |
+ PolicyMap* out_map); |
+ |
+ // Policy level this provider will handle. |
+ CloudPolicyCacheBase::PolicyLevel level_; |
+ |
+ // Provider observers that are registered with this provider. |
+ ObserverList<ConfigurationPolicyProvider::Observer, true> observer_list_; |
+ |
+ // Recompute |combined| from |caches_| and trigger an OnUpdatePolicy if |
+ // something changed. This is called whenever a change in one of the caches |
+ // is observed. For i=0..n-1: |caches_[i]| will contribute all its policies |
+ // except those already provided by |caches_[0]|..|caches_[i-1]|. Proxy |
+ // related policies are handled as a special case: they are only applied in |
+ // groups. |
+ void RecombineCachesAndMaybeTriggerUpdate(); |
+ |
+ // The currently valid combination of all the maps in |caches_|. Will be |
+ // applied as is on call of Provide. |
+ 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.
|
+ |
+ DISALLOW_COPY_AND_ASSIGN(CloudPolicyProvider); |
+}; |
+ |
+} // namespace policy |
+ |
+#endif // CHROME_BROWSER_POLICY_CLOUD_POLICY_PROVIDER_H_ |