| OLD | NEW |
| (Empty) |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "chrome/browser/policy/policy_transformations.h" | |
| 6 | |
| 7 #include "base/memory/scoped_ptr.h" | |
| 8 #include "base/values.h" | |
| 9 #include "components/policy/core/common/policy_bundle.h" | |
| 10 #include "components/policy/core/common/policy_map.h" | |
| 11 #include "policy/policy_constants.h" | |
| 12 | |
| 13 namespace policy { | |
| 14 | |
| 15 namespace { | |
| 16 | |
| 17 const char* kProxyPolicies[] = { | |
| 18 key::kProxyMode, | |
| 19 key::kProxyServerMode, | |
| 20 key::kProxyServer, | |
| 21 key::kProxyPacUrl, | |
| 22 key::kProxyBypassList, | |
| 23 }; | |
| 24 | |
| 25 void FixDeprecatedPolicies(PolicyMap* policies) { | |
| 26 // Proxy settings have been configured by 5 policies that didn't mix well | |
| 27 // together, and maps of policies had to take this into account when merging | |
| 28 // policy sources. The proxy settings will eventually be configured by a | |
| 29 // single Dictionary policy when all providers have support for that. For | |
| 30 // now, the individual policies are mapped here to a single Dictionary policy | |
| 31 // that the rest of the policy machinery uses. | |
| 32 | |
| 33 // The highest (level, scope) pair for an existing proxy policy is determined | |
| 34 // first, and then only policies with those exact attributes are merged. | |
| 35 PolicyMap::Entry current_priority; // Defaults to the lowest priority. | |
| 36 scoped_ptr<base::DictionaryValue> proxy_settings(new base::DictionaryValue); | |
| 37 for (size_t i = 0; i < arraysize(kProxyPolicies); ++i) { | |
| 38 const PolicyMap::Entry* entry = policies->Get(kProxyPolicies[i]); | |
| 39 if (entry) { | |
| 40 if (entry->has_higher_priority_than(current_priority)) { | |
| 41 proxy_settings->Clear(); | |
| 42 current_priority = *entry; | |
| 43 } | |
| 44 if (!entry->has_higher_priority_than(current_priority) && | |
| 45 !current_priority.has_higher_priority_than(*entry)) { | |
| 46 proxy_settings->Set(kProxyPolicies[i], entry->value->DeepCopy()); | |
| 47 } | |
| 48 policies->Erase(kProxyPolicies[i]); | |
| 49 } | |
| 50 } | |
| 51 // Sets the new |proxy_settings| if kProxySettings isn't set yet, or if the | |
| 52 // new priority is higher. | |
| 53 const PolicyMap::Entry* existing = policies->Get(key::kProxySettings); | |
| 54 if (!proxy_settings->empty() && | |
| 55 (!existing || current_priority.has_higher_priority_than(*existing))) { | |
| 56 policies->Set(key::kProxySettings, | |
| 57 current_priority.level, | |
| 58 current_priority.scope, | |
| 59 proxy_settings.release(), | |
| 60 NULL); | |
| 61 } | |
| 62 } | |
| 63 | |
| 64 } // namespace | |
| 65 | |
| 66 void FixDeprecatedPolicies(PolicyBundle* bundle) { | |
| 67 FixDeprecatedPolicies( | |
| 68 &bundle->Get(PolicyNamespace(POLICY_DOMAIN_CHROME, std::string()))); | |
| 69 } | |
| 70 | |
| 71 } // namespace policy | |
| OLD | NEW |