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

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

Issue 6979011: Move user cloud policy to BrowserProcess. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Addressed comments by mnissler. Added unittest. Created 9 years, 7 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
new file mode 100644
index 0000000000000000000000000000000000000000..1034dd3d97120850bbf61861d4e9a959c2232166
--- /dev/null
+++ b/chrome/browser/policy/cloud_policy_provider.h
@@ -0,0 +1,150 @@
+// 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 thin wrapper around CloudPolicyCacheBase. Proxies the notifications and
+// delegates the actions to the underlying |cache_|. Also exposes the PolicyMap
+// of |cache_|.
+// The |cache_| is kept as a weak reference and can be exchanged at any point
+// destroying the CloudPolicyProvider instance.
Mattias Nissler (ping if slow) 2011/05/31 14:14:19 destroying is not exactly exchanging the |cache_|
sfeuz 2011/06/03 08:30:35 I meant to write "[...] at any point WITHOUT destr
+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() OVERRIDE;
+ virtual void OnCacheGoingAway() OVERRIDE;
+
+ // Exposes |policy_map| of the underlying |cache_|.
+ PolicyMap* policy_map();
Mattias Nissler (ping if slow) 2011/05/31 14:14:19 It feels wrong that you both expose the policy map
Joao da Silva 2011/05/31 14:50:23 Should this be const?
sfeuz 2011/06/03 08:30:35 Done. As we discussed offline.
+
+ // Sets another backend.
+ void set_cache(CloudPolicyCacheBase* cache);
+
+ private:
+ // The underlying policy cache. Can be NULL if currently none is present.
+ CloudPolicyCacheBase* cache_;
+ // Policy level this provider will handle.
+ CloudPolicyCacheBase::PolicyLevel level_;
+
+ // Provider observers that are registered with this provider.
+ ObserverList<ConfigurationPolicyProvider::Observer, true> observer_list_;
+
+ DISALLOW_COPY_AND_ASSIGN(CloudPolicyProvider);
+};
+
+// Combines multiple CloudPolicyProviders and applies them in the given order.
+class CombiningCloudPolicyProvider : public ConfigurationPolicyProvider {
+ public:
+ explicit CombiningCloudPolicyProvider(
+ const PolicyDefinitionList* policy_list);
+ virtual ~CombiningCloudPolicyProvider();
+
+ // ConfigurationPolicyProvider implementation.
+ // Applies policy by applying the policies of the underlying
+ // CloudPolicyProviders in |cloud_policy_providers_| in the
+ // order they appear there. Early elements in |cloud_policy_providers_| take
+ // precedence. Handles special case for Proxy policy by marking all
+ // Proxy-related policies as applied as soon as one of them is applied.
+ // Returns true if we could apply at least one policy.
Mattias Nissler (ping if slow) 2011/05/31 14:14:19 That seems wrong. It's totally OK for no policy to
sfeuz 2011/06/03 08:30:35 I agree. Just returning true is probably the right
+ bool Provide(ConfigurationPolicyStoreInterface* store) OVERRIDE;
Mattias Nissler (ping if slow) 2011/05/31 14:14:19 virtual
sfeuz 2011/06/03 08:30:35 Done.
+
+ // Returns true if at least one CloudPolicyProvider in
+ // |cloud_policy_providers_| is initialized.
+ bool IsInitializationComplete() const OVERRIDE;
Mattias Nissler (ping if slow) 2011/05/31 14:14:19 virtual
Joao da Silva 2011/05/31 14:50:23 I'm not sure this is the correct behavior, instead
sfeuz 2011/06/03 08:30:35 Done.
sfeuz 2011/06/03 08:30:35 I now believe the correct behaviour is to always r
+ void AddObserver(ConfigurationPolicyProvider::Observer* observer) OVERRIDE;
Mattias Nissler (ping if slow) 2011/05/31 14:14:19 virtual
sfeuz 2011/06/03 08:30:35 Done.
+ void RemoveObserver(ConfigurationPolicyProvider::Observer* observer) OVERRIDE;
Mattias Nissler (ping if slow) 2011/05/31 14:14:19 virtual
sfeuz 2011/06/03 08:30:35 Done.
+
+ // Callbacks for CloudPolicyProviderWithObserver.
+ void OnUpdatePolicy(CloudPolicyProvider* cloud_policy_provider);
+ void OnProviderGoingAway(CloudPolicyProvider* cloud_policy_provider);
+
+ // Adds a new CloudPolicyProvider to the end of |cloud_policy_providers_|.
+ // Does not take ownership of |cloud_policy_provider|.
+ void AddCloudPolicyProvider(CloudPolicyProvider* cloud_policy_provider);
+
+ private:
+ // Wrapper around a CloudPolicyProvider to include the source in the
+ // callbacks. We need that to figure out which element in
+ // |cloud_policy_providers_| to remove if a CloudPolicyProvider calls
+ // OnProviderGoingAway.
Mattias Nissler (ping if slow) 2011/05/31 14:14:19 It seems like a adding an appropriate parameter to
sfeuz 2011/06/03 08:30:35 Added the parameter to the cache observer interfac
+ class CloudPolicyProviderWithObserver :
+ public ConfigurationPolicyProvider::Observer {
+ public:
+ CloudPolicyProviderWithObserver(
+ CombiningCloudPolicyProvider* combining_cloud_policy_provider,
+ CloudPolicyProvider* cloud_policy_provider) :
+ combining_cloud_policy_provider_(combining_cloud_policy_provider),
+ cloud_policy_provider_(cloud_policy_provider) {
+ DCHECK(combining_cloud_policy_provider_ && cloud_policy_provider_);
+ cloud_policy_provider_->AddObserver(this);
+ }
+ ~CloudPolicyProviderWithObserver() {
+ if (cloud_policy_provider_) {
+ cloud_policy_provider_->RemoveObserver(this);
+ cloud_policy_provider_ = NULL;
+ }
+ }
+ virtual void OnUpdatePolicy() {
+ combining_cloud_policy_provider_->OnUpdatePolicy(
+ cloud_policy_provider_);
+ }
+ virtual void OnProviderGoingAway() {
+ combining_cloud_policy_provider_->OnProviderGoingAway(
+ cloud_policy_provider_);
+ // Normally our dtor is called on removal from |cloud_policy_providers_|,
+ // but just in case we are still active remove us as Observer.
+ if (cloud_policy_provider_) {
+ cloud_policy_provider_->RemoveObserver(this);
+ cloud_policy_provider_ = NULL;
+ }
+ }
+ CloudPolicyProvider* cloud_policy_provider() const {
+ return cloud_policy_provider_;
+ }
+
+ private:
+ CombiningCloudPolicyProvider* combining_cloud_policy_provider_;
+ CloudPolicyProvider* cloud_policy_provider_;
+
+ DISALLOW_COPY_AND_ASSIGN(CloudPolicyProviderWithObserver);
+ };
+
+ // CloudPolicyProviders which are combined by this instance of
+ // CombiningCoudPolicyProvider. Order dependant.
Mattias Nissler (ping if slow) 2011/05/31 14:14:19 "Order dependant" conveys to me: There is somethin
sfeuz 2011/06/03 08:30:35 Was explained in Provide.
+ typedef ScopedVector<CloudPolicyProviderWithObserver> ListType;
+ ListType cloud_policy_providers_;
+
+ // Provider observers that are registered with this provider.
+ ObserverList<ConfigurationPolicyProvider::Observer, true> observer_list_;
+
+ DISALLOW_COPY_AND_ASSIGN(CombiningCloudPolicyProvider);
+};
+
+} // namespace policy
+
+#endif // CHROME_BROWSER_POLICY_CLOUD_POLICY_PROVIDER_H_

Powered by Google App Engine
This is Rietveld 408576698