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
3 // found in the LICENSE file.
5 #include "chrome/browser/policy/configuration_policy_provider.h"
7 #include "base/callback.h"
8 #include "chrome/browser/policy/external_data_fetcher.h"
9 #include "chrome/browser/policy/policy_domain_descriptor.h"
10 #include "chrome/browser/policy/policy_map.h"
11 #include "policy/policy_constants.h"
17 const char* kProxyPolicies[] = {
19 key::kProxyServerMode,
22 key::kProxyBypassList,
25 // Helper that converts deprecated chrome policies into their corresponding
27 void FixDeprecatedPolicies(PolicyMap* policies) {
28 // Proxy settings have been configured by 5 policies that didn't mix well
29 // together, and maps of policies had to take this into account when merging
30 // policy sources. The proxy settings will eventually be configured by a
31 // single Dictionary policy when all providers have support for that. For
32 // now, the individual policies are mapped here to a single Dictionary policy
33 // that the rest of the policy machinery uses.
35 // The highest (level, scope) pair for an existing proxy policy is determined
36 // first, and then only policies with those exact attributes are merged.
37 PolicyMap::Entry current_priority; // Defaults to the lowest priority.
38 scoped_ptr<DictionaryValue> proxy_settings(new DictionaryValue);
39 for (size_t i = 0; i < arraysize(kProxyPolicies); ++i) {
40 const PolicyMap::Entry* entry = policies->Get(kProxyPolicies[i]);
42 if (entry->has_higher_priority_than(current_priority)) {
43 proxy_settings->Clear();
44 current_priority = *entry;
46 if (!entry->has_higher_priority_than(current_priority) &&
47 !current_priority.has_higher_priority_than(*entry)) {
48 proxy_settings->Set(kProxyPolicies[i], entry->value->DeepCopy());
50 policies->Erase(kProxyPolicies[i]);
53 // Sets the new |proxy_settings| if kProxySettings isn't set yet, or if the
54 // new priority is higher.
55 const PolicyMap::Entry* existing = policies->Get(key::kProxySettings);
56 if (!proxy_settings->empty() &&
57 (!existing || current_priority.has_higher_priority_than(*existing))) {
58 policies->Set(key::kProxySettings,
59 current_priority.level,
60 current_priority.scope,
61 proxy_settings.release(),
68 ConfigurationPolicyProvider::Observer::~Observer() {}
70 ConfigurationPolicyProvider::ConfigurationPolicyProvider()
71 : did_shutdown_(false) {}
73 ConfigurationPolicyProvider::~ConfigurationPolicyProvider() {
74 DCHECK(did_shutdown_);
77 void ConfigurationPolicyProvider::Init() {}
79 void ConfigurationPolicyProvider::Shutdown() {
83 bool ConfigurationPolicyProvider::IsInitializationComplete(
84 PolicyDomain domain) const {
88 void ConfigurationPolicyProvider::UpdatePolicy(
89 scoped_ptr<PolicyBundle> bundle) {
91 policy_bundle_.Swap(bundle.get());
93 policy_bundle_.Clear();
94 FixDeprecatedPolicies(&policy_bundle_.Get(
95 PolicyNamespace(POLICY_DOMAIN_CHROME, std::string())));
96 FOR_EACH_OBSERVER(ConfigurationPolicyProvider::Observer,
98 OnUpdatePolicy(this));
101 void ConfigurationPolicyProvider::AddObserver(Observer* observer) {
102 observer_list_.AddObserver(observer);
105 void ConfigurationPolicyProvider::RemoveObserver(Observer* observer) {
106 observer_list_.RemoveObserver(observer);
109 void ConfigurationPolicyProvider::RegisterPolicyDomain(
110 scoped_refptr<const PolicyDomainDescriptor> descriptor) {}
112 } // namespace policy