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 | |
| 88 // The highest (level, scope) pair for an existing proxy policy is determined | |
| 89 // first, and then only policies with those exact attributes are merged. | |
| 90 PolicyMap::Entry current_priority; // Defaults to the lowest priority. | |
| 85 scoped_ptr<DictionaryValue> proxy_settings(new DictionaryValue); | 91 scoped_ptr<DictionaryValue> proxy_settings(new DictionaryValue); |
| 86 for (size_t i = 0; i < arraysize(kProxyPolicies); ++i) { | 92 for (size_t i = 0; i < arraysize(kProxyPolicies); ++i) { |
| 87 const Value* value = policies->Get(kProxyPolicies[i]); | 93 const PolicyMap::Entry* entry = policies->Get(kProxyPolicies[i]); |
| 88 if (value) { | 94 if (entry) { |
| 89 proxy_settings->Set(GetPolicyName(kProxyPolicies[i]), value->DeepCopy()); | 95 if (entry->has_higher_priority_than(current_priority)) { |
| 90 policies->Erase(kProxyPolicies[i]); | 96 proxy_settings->Clear(); |
| 97 current_priority = *entry; | |
| 98 } | |
| 99 if (!entry->has_higher_priority_than(current_priority) && | |
| 100 !current_priority.has_higher_priority_than(*entry)) | |
|
Mattias Nissler (ping if slow)
2012/01/19 12:58:36
need curlies.
Joao da Silva
2012/01/19 16:21:41
Done.
| |
| 101 proxy_settings->Set(kProxyPolicies[i], entry->value->DeepCopy()); | |
| 91 } | 102 } |
| 92 } | 103 } |
| 93 if (!proxy_settings->empty() && !policies->Get(kPolicyProxySettings)) | 104 if (!proxy_settings->empty() && !policies->Get(key::kProxySettings)) { |
| 94 policies->Set(kPolicyProxySettings, proxy_settings.release()); | 105 policies->Set(key::kProxySettings, |
| 106 current_priority.level, | |
| 107 current_priority.scope, | |
| 108 proxy_settings.release()); | |
| 109 for (size_t i = 0; i < arraysize(kProxyPolicies); ++i) | |
| 110 policies->Erase(kProxyPolicies[i]); | |
|
Mattias Nissler (ping if slow)
2012/01/19 12:58:36
Shouldn't we be doing this unconditionally?
Joao da Silva
2012/01/19 16:21:41
Yes. The only case where it matters is when there
| |
| 111 } | |
| 95 } | 112 } |
| 96 | 113 |
| 97 void ConfigurationPolicyProvider::AddObserver(Observer* observer) { | 114 void ConfigurationPolicyProvider::AddObserver(Observer* observer) { |
| 98 observer_list_.AddObserver(observer); | 115 observer_list_.AddObserver(observer); |
| 99 } | 116 } |
| 100 | 117 |
| 101 void ConfigurationPolicyProvider::RemoveObserver(Observer* observer) { | 118 void ConfigurationPolicyProvider::RemoveObserver(Observer* observer) { |
| 102 observer_list_.RemoveObserver(observer); | 119 observer_list_.RemoveObserver(observer); |
| 103 } | 120 } |
| 104 | 121 |
| (...skipping 22 matching lines...) Expand all Loading... | |
| 127 | 144 |
| 128 void ConfigurationPolicyObserverRegistrar::OnProviderGoingAway( | 145 void ConfigurationPolicyObserverRegistrar::OnProviderGoingAway( |
| 129 ConfigurationPolicyProvider* provider) { | 146 ConfigurationPolicyProvider* provider) { |
| 130 DCHECK_EQ(provider_, provider); | 147 DCHECK_EQ(provider_, provider); |
| 131 observer_->OnProviderGoingAway(provider_); | 148 observer_->OnProviderGoingAway(provider_); |
| 132 provider_->RemoveObserver(this); | 149 provider_->RemoveObserver(this); |
| 133 provider_ = NULL; | 150 provider_ = NULL; |
| 134 } | 151 } |
| 135 | 152 |
| 136 } // namespace policy | 153 } // namespace policy |
| OLD | NEW |