diff options
Diffstat (limited to 'chrome/browser/policy/policy_transformations.cc')
-rw-r--r-- | chrome/browser/policy/policy_transformations.cc | 71 |
1 files changed, 71 insertions, 0 deletions
diff --git a/chrome/browser/policy/policy_transformations.cc b/chrome/browser/policy/policy_transformations.cc new file mode 100644 index 0000000..3504e2a --- /dev/null +++ b/chrome/browser/policy/policy_transformations.cc @@ -0,0 +1,71 @@ +// Copyright 2013 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/policy_transformations.h" + +#include "base/memory/scoped_ptr.h" +#include "base/values.h" +#include "chrome/browser/policy/policy_bundle.h" +#include "chrome/browser/policy/policy_map.h" +#include "policy/policy_constants.h" + +namespace policy { + +namespace { + +const char* kProxyPolicies[] = { + key::kProxyMode, + key::kProxyServerMode, + key::kProxyServer, + key::kProxyPacUrl, + key::kProxyBypassList, +}; + +void FixDeprecatedPolicies(PolicyMap* policies) { + // Proxy settings have been configured by 5 policies that didn't mix well + // together, and maps of policies had to take this into account when merging + // policy sources. The proxy settings will eventually be configured by a + // single Dictionary policy when all providers have support for that. For + // now, the individual policies are mapped here to a single Dictionary policy + // that the rest of the policy machinery uses. + + // The highest (level, scope) pair for an existing proxy policy is determined + // first, and then only policies with those exact attributes are merged. + PolicyMap::Entry current_priority; // Defaults to the lowest priority. + scoped_ptr<base::DictionaryValue> proxy_settings(new base::DictionaryValue); + for (size_t i = 0; i < arraysize(kProxyPolicies); ++i) { + const PolicyMap::Entry* entry = policies->Get(kProxyPolicies[i]); + if (entry) { + if (entry->has_higher_priority_than(current_priority)) { + proxy_settings->Clear(); + current_priority = *entry; + } + if (!entry->has_higher_priority_than(current_priority) && + !current_priority.has_higher_priority_than(*entry)) { + proxy_settings->Set(kProxyPolicies[i], entry->value->DeepCopy()); + } + policies->Erase(kProxyPolicies[i]); + } + } + // Sets the new |proxy_settings| if kProxySettings isn't set yet, or if the + // new priority is higher. + const PolicyMap::Entry* existing = policies->Get(key::kProxySettings); + if (!proxy_settings->empty() && + (!existing || current_priority.has_higher_priority_than(*existing))) { + policies->Set(key::kProxySettings, + current_priority.level, + current_priority.scope, + proxy_settings.release(), + NULL); + } +} + +} // namespace + +void FixDeprecatedPolicies(PolicyBundle* bundle) { + FixDeprecatedPolicies( + &bundle->Get(PolicyNamespace(POLICY_DOMAIN_CHROME, std::string()))); +} + +} // namespace policy |