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

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

Issue 6979011: Move user cloud policy to BrowserProcess. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Addressed comments by mnissler. Created 9 years, 6 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.cc
diff --git a/chrome/browser/policy/cloud_policy_provider.cc b/chrome/browser/policy/cloud_policy_provider.cc
new file mode 100644
index 0000000000000000000000000000000000000000..f7e0740733e0eae71bc40ff1b34fea17aac1977e
--- /dev/null
+++ b/chrome/browser/policy/cloud_policy_provider.cc
@@ -0,0 +1,145 @@
+// 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.
+
+#include "chrome/browser/policy/cloud_policy_provider.h"
+
+#include <set>
+
+#include "base/values.h"
+#include "chrome/browser/policy/configuration_policy_pref_store.h"
+#include "chrome/browser/policy/policy_notifier.h"
+
+namespace policy {
+
+CloudPolicyProvider::CloudPolicyProvider(
+ const ConfigurationPolicyProvider::PolicyDefinitionList* policy_list,
+ CloudPolicyCacheBase::PolicyLevel level)
+ : ConfigurationPolicyProvider(policy_list),
+ level_(level) {}
+
+CloudPolicyProvider::~CloudPolicyProvider() {
+ for (ListType::iterator i = caches_.begin(); i != caches_.end(); ++i)
+ (*i)->RemoveObserver(this);
+
+ FOR_EACH_OBSERVER(ConfigurationPolicyProvider::Observer,
+ observer_list_, OnProviderGoingAway());
+}
+
+bool CloudPolicyProvider::Provide(ConfigurationPolicyStoreInterface* store) {
+ ApplyPolicyMap(&combined_, store);
+ return true;
+}
+
+bool CloudPolicyProvider::IsInitializationComplete() const {
+ for (ListType::const_iterator i = caches_.begin(); i != caches_.end(); ++i) {
+ if ((*i)->initialization_complete()) {
+ return true;
+ }
+ }
+ return false;
+}
+
+void CloudPolicyProvider::AddObserver(
+ ConfigurationPolicyProvider::Observer* observer) {
+ observer_list_.AddObserver(observer);
+}
+
+void CloudPolicyProvider::RemoveObserver(
+ ConfigurationPolicyProvider::Observer* observer) {
+ observer_list_.RemoveObserver(observer);
+}
+
+void CloudPolicyProvider::OnCacheUpdate(CloudPolicyCacheBase* cache) {
+ RecombineCachesAndMaybeTriggerUpdate();
+}
+
+void CloudPolicyProvider::OnCacheGoingAway(CloudPolicyCacheBase* cache) {
+ cache->RemoveObserver(this);
+ for (ListType::iterator i = caches_.begin(); i != caches_.end(); ++i) {
+ if (*i == cache) {
+ caches_.erase(i);
+ break;
+ }
+ }
+
+ RecombineCachesAndMaybeTriggerUpdate();
+}
+
+void CloudPolicyProvider::AppendCache(CloudPolicyCacheBase* cache) {
+ cache->AddObserver(this);
+ caches_.push_back(cache);
+ RecombineCachesAndMaybeTriggerUpdate();
+}
+
+void CloudPolicyProvider::PrependCache(CloudPolicyCacheBase* cache) {
+ cache->AddObserver(this);
+ caches_.insert(caches_.begin(), cache);
+ RecombineCachesAndMaybeTriggerUpdate();
+}
+
+// static
+ConfigurationPolicyType CloudPolicyProvider::proxy_policies[] = {
+ kPolicyProxyMode,
+ kPolicyProxyServerMode,
+ kPolicyProxyServer,
+ kPolicyProxyPacUrl,
+ kPolicyProxyBypassList };
+
+// static
+bool CloudPolicyProvider::is_proxy_policy(ConfigurationPolicyType policy) {
+ const unsigned int n = arraysize(proxy_policies);
+ for (unsigned int i = 0; i < n; ++i)
+ if (proxy_policies[i] == policy)
+ return true;
+ return false;
+}
+
+// static
+unsigned int CloudPolicyProvider::proxy_policy_count() {
+ return arraysize(CloudPolicyProvider::proxy_policies);
+}
+
+void CloudPolicyProvider::CombineTwoPolicyMaps(const PolicyMap& base,
+ const PolicyMap& overlay,
+ PolicyMap* out_map) {
+ bool added_proxy_policy = false;
+ out_map->Clear();
+
+ for (PolicyMap::const_iterator i = base.begin(); i != base.end(); ++i) {
+ out_map->Set(i->first, i->second->DeepCopy());
+ added_proxy_policy = added_proxy_policy || is_proxy_policy(i->first);
+ }
+
+ // Add every entry of |overlay| which has not been added by |base|. Only add
+ // proxy policies if none of them was added by |base|.
+ for (PolicyMap::const_iterator i = overlay.begin(); i != overlay.end(); ++i) {
+ if (is_proxy_policy(i->first)) {
+ if (!added_proxy_policy) {
+ out_map->Set(i->first, i->second->DeepCopy());
+ }
+ } else if (!out_map->Get(i->first)) {
+ out_map->Set(i->first, i->second->DeepCopy());
+ }
+ }
+}
+
+void CloudPolicyProvider::RecombineCachesAndMaybeTriggerUpdate() {
+ PolicyMap newly_combined;
+ for (ListType::iterator i = caches_.begin(); i != caches_.end(); ++i) {
+ if (!(*i)->initialization_complete())
+ continue;
+ PolicyMap tmp_map;
+ CombineTwoPolicyMaps(newly_combined, *(*i)->policy(level_), &tmp_map);
+ newly_combined.Swap(&tmp_map);
+ }
+ if (newly_combined.Equals(combined_))
+ return;
+
+ // Trigger a notification if there was a change.
+ combined_.Swap(&newly_combined);
+ FOR_EACH_OBSERVER(ConfigurationPolicyProvider::Observer,
+ observer_list_, OnUpdatePolicy());
+}
+
+} // namespace policy
« no previous file with comments | « chrome/browser/policy/cloud_policy_provider.h ('k') | chrome/browser/policy/cloud_policy_provider_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698