| 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 <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "chrome/browser/policy/policy_map.h" | 9 #include "chrome/browser/policy/policy_map.h" |
| 10 #include "policy/policy_constants.h" | 10 #include "policy/policy_constants.h" |
| 11 | 11 |
| 12 namespace policy { | 12 namespace policy { |
| 13 | 13 |
| 14 namespace { | 14 namespace { |
| 15 | 15 |
| 16 const char* kProxyPolicies[] = { | 16 const char* kProxyPolicies[] = { |
| 17 key::kProxyMode, | 17 key::kProxyMode, |
| 18 key::kProxyServerMode, | 18 key::kProxyServerMode, |
| 19 key::kProxyServer, | 19 key::kProxyServer, |
| 20 key::kProxyPacUrl, | 20 key::kProxyPacUrl, |
| 21 key::kProxyBypassList, | 21 key::kProxyBypassList, |
| 22 }; | 22 }; |
| 23 | 23 |
| 24 } // namespace | 24 // Helper that converts deprecated chrome policies into their corresponding |
| 25 | 25 // actual policies. |
| 26 ConfigurationPolicyProvider::Observer::~Observer() {} | 26 void FixDeprecatedPolicies(PolicyMap* policies) { |
| 27 | |
| 28 void ConfigurationPolicyProvider::Observer::OnProviderGoingAway( | |
| 29 ConfigurationPolicyProvider* provider) {} | |
| 30 | |
| 31 // Class ConfigurationPolicyProvider. | |
| 32 | |
| 33 ConfigurationPolicyProvider::ConfigurationPolicyProvider( | |
| 34 const PolicyDefinitionList* policy_list) | |
| 35 : policy_definition_list_(policy_list) { | |
| 36 } | |
| 37 | |
| 38 ConfigurationPolicyProvider::~ConfigurationPolicyProvider() { | |
| 39 FOR_EACH_OBSERVER(ConfigurationPolicyProvider::Observer, | |
| 40 observer_list_, | |
| 41 OnProviderGoingAway(this)); | |
| 42 } | |
| 43 | |
| 44 bool ConfigurationPolicyProvider::Provide(PolicyMap* result) { | |
| 45 result->CopyFrom(policy_bundle_.Get(POLICY_DOMAIN_CHROME, std::string())); | |
| 46 return true; | |
| 47 } | |
| 48 | |
| 49 bool ConfigurationPolicyProvider::IsInitializationComplete() const { | |
| 50 return true; | |
| 51 } | |
| 52 | |
| 53 // static | |
| 54 void ConfigurationPolicyProvider::FixDeprecatedPolicies(PolicyMap* policies) { | |
| 55 // Proxy settings have been configured by 5 policies that didn't mix well | 27 // Proxy settings have been configured by 5 policies that didn't mix well |
| 56 // together, and maps of policies had to take this into account when merging | 28 // together, and maps of policies had to take this into account when merging |
| 57 // policy sources. The proxy settings will eventually be configured by a | 29 // policy sources. The proxy settings will eventually be configured by a |
| 58 // single Dictionary policy when all providers have support for that. For | 30 // single Dictionary policy when all providers have support for that. For |
| 59 // now, the individual policies are mapped here to a single Dictionary policy | 31 // now, the individual policies are mapped here to a single Dictionary policy |
| 60 // that the rest of the policy machinery uses. | 32 // that the rest of the policy machinery uses. |
| 61 | 33 |
| 62 // The highest (level, scope) pair for an existing proxy policy is determined | 34 // The highest (level, scope) pair for an existing proxy policy is determined |
| 63 // first, and then only policies with those exact attributes are merged. | 35 // first, and then only policies with those exact attributes are merged. |
| 64 PolicyMap::Entry current_priority; // Defaults to the lowest priority. | 36 PolicyMap::Entry current_priority; // Defaults to the lowest priority. |
| (...skipping 17 matching lines...) Expand all Loading... |
| 82 const PolicyMap::Entry* existing = policies->Get(key::kProxySettings); | 54 const PolicyMap::Entry* existing = policies->Get(key::kProxySettings); |
| 83 if (!proxy_settings->empty() && | 55 if (!proxy_settings->empty() && |
| 84 (!existing || current_priority.has_higher_priority_than(*existing))) { | 56 (!existing || current_priority.has_higher_priority_than(*existing))) { |
| 85 policies->Set(key::kProxySettings, | 57 policies->Set(key::kProxySettings, |
| 86 current_priority.level, | 58 current_priority.level, |
| 87 current_priority.scope, | 59 current_priority.scope, |
| 88 proxy_settings.release()); | 60 proxy_settings.release()); |
| 89 } | 61 } |
| 90 } | 62 } |
| 91 | 63 |
| 64 } // namespace |
| 65 |
| 66 ConfigurationPolicyProvider::Observer::~Observer() {} |
| 67 |
| 68 void ConfigurationPolicyProvider::Observer::OnProviderGoingAway( |
| 69 ConfigurationPolicyProvider* provider) {} |
| 70 |
| 71 ConfigurationPolicyProvider::ConfigurationPolicyProvider( |
| 72 const PolicyDefinitionList* policy_list) |
| 73 : policy_definition_list_(policy_list) { |
| 74 } |
| 75 |
| 76 ConfigurationPolicyProvider::~ConfigurationPolicyProvider() { |
| 77 FOR_EACH_OBSERVER(ConfigurationPolicyProvider::Observer, |
| 78 observer_list_, |
| 79 OnProviderGoingAway(this)); |
| 80 } |
| 81 |
| 82 bool ConfigurationPolicyProvider::IsInitializationComplete() const { |
| 83 return true; |
| 84 } |
| 85 |
| 92 void ConfigurationPolicyProvider::UpdatePolicy( | 86 void ConfigurationPolicyProvider::UpdatePolicy( |
| 93 scoped_ptr<PolicyBundle> bundle) { | 87 scoped_ptr<PolicyBundle> bundle) { |
| 94 policy_bundle_.Swap(bundle.get()); | 88 if (bundle.get()) |
| 89 policy_bundle_.Swap(bundle.get()); |
| 90 else |
| 91 policy_bundle_.Clear(); |
| 95 FixDeprecatedPolicies( | 92 FixDeprecatedPolicies( |
| 96 &policy_bundle_.Get(POLICY_DOMAIN_CHROME, std::string())); | 93 &policy_bundle_.Get(POLICY_DOMAIN_CHROME, std::string())); |
| 97 FOR_EACH_OBSERVER(ConfigurationPolicyProvider::Observer, | 94 FOR_EACH_OBSERVER(ConfigurationPolicyProvider::Observer, |
| 98 observer_list_, | 95 observer_list_, |
| 99 OnUpdatePolicy(this)); | 96 OnUpdatePolicy(this)); |
| 100 } | 97 } |
| 101 | 98 |
| 102 void ConfigurationPolicyProvider::AddObserver(Observer* observer) { | 99 void ConfigurationPolicyProvider::AddObserver(Observer* observer) { |
| 103 observer_list_.AddObserver(observer); | 100 observer_list_.AddObserver(observer); |
| 104 } | 101 } |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 143 // be set to NULL. So we set |observer_| to NULL instead to signal that | 140 // be set to NULL. So we set |observer_| to NULL instead to signal that |
| 144 // we're not observing the provider anymore. | 141 // we're not observing the provider anymore. |
| 145 ConfigurationPolicyProvider::Observer* observer = observer_; | 142 ConfigurationPolicyProvider::Observer* observer = observer_; |
| 146 observer_ = NULL; | 143 observer_ = NULL; |
| 147 provider_->RemoveObserver(this); | 144 provider_->RemoveObserver(this); |
| 148 | 145 |
| 149 observer->OnProviderGoingAway(provider); | 146 observer->OnProviderGoingAway(provider); |
| 150 } | 147 } |
| 151 | 148 |
| 152 } // namespace policy | 149 } // namespace policy |
| OLD | NEW |