Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/policy/configuration_policy_provider.h" | 5 #include "chrome/browser/policy/configuration_policy_provider.h" |
| 6 | 6 |
| 7 #include <algorithm> | |
| 8 | |
| 7 #include "chrome/browser/policy/policy_map.h" | 9 #include "chrome/browser/policy/policy_map.h" |
| 8 #include "policy/policy_constants.h" | 10 #include "policy/policy_constants.h" |
| 9 | 11 |
| 10 namespace policy { | 12 namespace policy { |
| 11 | 13 |
| 12 namespace { | 14 namespace { |
| 13 | 15 |
| 14 ConfigurationPolicyType kProxyPolicies[] = { | 16 const char* kProxyPolicies[] = { |
| 15 kPolicyProxyMode, | 17 key::kProxyMode, |
| 16 kPolicyProxyServerMode, | 18 key::kProxyServerMode, |
| 17 kPolicyProxyServer, | 19 key::kProxyServer, |
| 18 kPolicyProxyPacUrl, | 20 key::kProxyPacUrl, |
| 19 kPolicyProxyBypassList, | 21 key::kProxyBypassList, |
| 20 }; | 22 }; |
| 21 | 23 |
| 22 } // namespace | 24 } // namespace |
| 23 | 25 |
| 24 ConfigurationPolicyProvider::Observer::~Observer() {} | 26 ConfigurationPolicyProvider::Observer::~Observer() {} |
| 25 | 27 |
| 26 void ConfigurationPolicyProvider::Observer::OnProviderGoingAway( | 28 void ConfigurationPolicyProvider::Observer::OnProviderGoingAway( |
| 27 ConfigurationPolicyProvider* provider) {} | 29 ConfigurationPolicyProvider* provider) {} |
| 28 | 30 |
| 29 // Class ConfigurationPolicyProvider. | 31 // Class ConfigurationPolicyProvider. |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 75 } | 77 } |
| 76 | 78 |
| 77 // static | 79 // static |
| 78 void ConfigurationPolicyProvider::FixDeprecatedPolicies(PolicyMap* policies) { | 80 void ConfigurationPolicyProvider::FixDeprecatedPolicies(PolicyMap* policies) { |
| 79 // Proxy settings have been configured by 5 policies that didn't mix well | 81 // Proxy settings have been configured by 5 policies that didn't mix well |
| 80 // together, and maps of policies had to take this into account when merging | 82 // together, and maps of policies had to take this into account when merging |
| 81 // policy sources. The proxy settings will eventually be configured by a | 83 // policy sources. The proxy settings will eventually be configured by a |
| 82 // single Dictionary policy when all providers have support for that. For | 84 // single Dictionary policy when all providers have support for that. For |
| 83 // now, the individual policies are mapped here to a single Dictionary policy | 85 // now, the individual policies are mapped here to a single Dictionary policy |
| 84 // that the rest of the policy machinery uses. | 86 // that the rest of the policy machinery uses. |
| 87 PolicyLevel level = POLICY_LEVEL_RECOMMENDED; | |
| 88 PolicyScope scope = POLICY_SCOPE_USER; | |
| 85 scoped_ptr<DictionaryValue> proxy_settings(new DictionaryValue); | 89 scoped_ptr<DictionaryValue> proxy_settings(new DictionaryValue); |
| 86 for (size_t i = 0; i < arraysize(kProxyPolicies); ++i) { | 90 for (size_t i = 0; i < arraysize(kProxyPolicies); ++i) { |
| 87 const Value* value = policies->Get(kProxyPolicies[i]); | 91 const PolicyMap::Entry* entry = policies->Get(kProxyPolicies[i]); |
| 88 if (value) { | 92 if (entry) { |
| 89 proxy_settings->Set(GetPolicyName(kProxyPolicies[i]), value->DeepCopy()); | 93 // The level and scope of the merged policy is the highest of any of the |
| 94 // individual deprecated policies. | |
|
Mattias Nissler (ping if slow)
2012/01/18 15:07:07
I think this is actually incorrect. Assume you hav
Joao da Silva
2012/01/18 16:49:29
Thanks for catching this, that is exactly what sho
| |
| 95 level = std::max(level, entry->level); | |
| 96 scope = std::max(scope, entry->scope); | |
| 97 proxy_settings->Set(kProxyPolicies[i], entry->value->DeepCopy()); | |
| 90 policies->Erase(kProxyPolicies[i]); | 98 policies->Erase(kProxyPolicies[i]); |
| 91 } | 99 } |
| 92 } | 100 } |
| 93 if (!proxy_settings->empty() && !policies->Get(kPolicyProxySettings)) | 101 if (!proxy_settings->empty() && !policies->Get(key::kProxySettings)) |
| 94 policies->Set(kPolicyProxySettings, proxy_settings.release()); | 102 policies->Set(key::kProxySettings, level, scope, proxy_settings.release()); |
| 95 } | 103 } |
| 96 | 104 |
| 97 void ConfigurationPolicyProvider::AddObserver(Observer* observer) { | 105 void ConfigurationPolicyProvider::AddObserver(Observer* observer) { |
| 98 observer_list_.AddObserver(observer); | 106 observer_list_.AddObserver(observer); |
| 99 } | 107 } |
| 100 | 108 |
| 101 void ConfigurationPolicyProvider::RemoveObserver(Observer* observer) { | 109 void ConfigurationPolicyProvider::RemoveObserver(Observer* observer) { |
| 102 observer_list_.RemoveObserver(observer); | 110 observer_list_.RemoveObserver(observer); |
| 103 } | 111 } |
| 104 | 112 |
| (...skipping 22 matching lines...) Expand all Loading... | |
| 127 | 135 |
| 128 void ConfigurationPolicyObserverRegistrar::OnProviderGoingAway( | 136 void ConfigurationPolicyObserverRegistrar::OnProviderGoingAway( |
| 129 ConfigurationPolicyProvider* provider) { | 137 ConfigurationPolicyProvider* provider) { |
| 130 DCHECK_EQ(provider_, provider); | 138 DCHECK_EQ(provider_, provider); |
| 131 observer_->OnProviderGoingAway(provider_); | 139 observer_->OnProviderGoingAway(provider_); |
| 132 provider_->RemoveObserver(this); | 140 provider_->RemoveObserver(this); |
| 133 provider_ = NULL; | 141 provider_ = NULL; |
| 134 } | 142 } |
| 135 | 143 |
| 136 } // namespace policy | 144 } // namespace policy |
| OLD | NEW |