Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1627)

Unified Diff: chrome/browser/policy/cloud_policy_provider.h

Issue 9911029: Refactored the CloudPolicyProvider so that it becomes initialized once and stays initialized. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Updated expectations in failing browser_tests Created 8 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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
index a9bc606ba4d26dc689557ae9529c1b4c398d7bfd..cba417e6c57502afc71a7f0e0eca7a461dd9ad48 100644
--- a/chrome/browser/policy/cloud_policy_provider.h
+++ b/chrome/browser/policy/cloud_policy_provider.h
@@ -6,39 +6,78 @@
#define CHROME_BROWSER_POLICY_CLOUD_POLICY_PROVIDER_H_
#pragma once
+#include <set>
+
#include "base/basictypes.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 {
-class CloudPolicyCacheBase;
-
-// 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).
-// AppendCache(cache): adds |cache| to the back (i.e. least important cache).
-class CloudPolicyProvider : public ConfigurationPolicyProvider {
+class BrowserPolicyConnector;
+
+// A policy provider that merges the policies contained in its policy caches.
Mattias Nissler (ping if slow) 2012/03/30 08:48:46 This sentence suggests that every policy provide h
Joao da Silva 2012/03/30 10:09:23 Done.
+// The caches receive their policies by fetching them from the cloud, through
+// the CloudPolicyController.
+class CloudPolicyProvider : public ConfigurationPolicyProvider,
+ public CloudPolicyCacheBase::Observer {
public:
- explicit CloudPolicyProvider(const PolicyDefinitionList* policy_list);
+ CloudPolicyProvider(BrowserPolicyConnector* browser_policy_connector,
+ const PolicyDefinitionList* policy_list,
+ PolicyLevel level);
virtual ~CloudPolicyProvider();
- // 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_|.
- virtual void AppendCache(CloudPolicyCacheBase* cache) = 0;
+ void SetUserPolicyCache(CloudPolicyCacheBase* cache);
+
+#if defined(OS_CHROMEOS)
+ void SetDevicePolicyCache(CloudPolicyCacheBase* cache);
+#endif
- // 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_|.
- virtual void PrependCache(CloudPolicyCacheBase* cache) = 0;
+ // ConfigurationPolicyProvider implementation.
+ virtual bool ProvideInternal(PolicyMap* result) OVERRIDE;
+ virtual bool IsInitializationComplete() const OVERRIDE;
+ virtual void RefreshPolicies() OVERRIDE;
+
+ // CloudPolicyCacheBase::Observer implementation.
+ virtual void OnCacheUpdate(CloudPolicyCacheBase* cache) OVERRIDE;
+ virtual void OnCacheGoingAway(CloudPolicyCacheBase* cache) OVERRIDE;
private:
+ // Indices of the known caches in |caches_|.
+ enum {
+ CACHE_USER,
+#if defined(OS_CHROMEOS)
+ CACHE_DEVICE,
+#endif
+ CACHE_SIZE,
+ };
+
+ // Merges policies from both caches, and triggers a notification if ready.
+ void Merge();
+
+ // The device and user policy caches, whose policies are provided by |this|.
+ // Both are initially NULL, and the provider only becomes initialized once
+ // all the caches are available and ready.
+ CloudPolicyCacheBase* caches_[CACHE_SIZE];
+
+ // Weak pointer to the connector. Guaranteed to outlive |this|.
+ BrowserPolicyConnector* browser_policy_connector_;
+
+ // The policy level published by this provider.
+ PolicyLevel level_;
+
+ // Whether all caches are present and fully initialized.
+ bool initialization_complete_;
+
+ // Used to determine when updates due to a RefreshPolicies() call have been
+ // completed.
+ std::set<const CloudPolicyCacheBase*> pending_updates_;
+
+ // The currently valid combination of the caches. ProvideInternal() fills
+ // |results| with a copy of |combined_|.
+ PolicyMap combined_;
+
DISALLOW_COPY_AND_ASSIGN(CloudPolicyProvider);
};

Powered by Google App Engine
This is Rietveld 408576698