Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(591)

Side by Side Diff: chrome/browser/policy/configuration_policy_provider.cc

Issue 9111022: Removed ConfigurationPolicyType and extended PolicyMap. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebased Created 8 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
61 63
62 void ConfigurationPolicyProvider::OverridePolicies(PolicyMap* policies) { 64 void ConfigurationPolicyProvider::OverridePolicies(PolicyMap* policies) {
63 if (policies) 65 if (policies)
64 FixDeprecatedPolicies(policies); 66 FixDeprecatedPolicies(policies);
65 override_policies_.reset(policies); 67 override_policies_.reset(policies);
66 NotifyPolicyUpdated(); 68 NotifyPolicyUpdated();
67 } 69 }
68 70
69 #endif 71 #endif
70 72
71 void ConfigurationPolicyProvider::NotifyPolicyUpdated() {
72 FOR_EACH_OBSERVER(ConfigurationPolicyProvider::Observer,
73 observer_list_,
74 OnUpdatePolicy(this));
75 }
76
77 // static 73 // static
78 void ConfigurationPolicyProvider::FixDeprecatedPolicies(PolicyMap* policies) { 74 void ConfigurationPolicyProvider::FixDeprecatedPolicies(PolicyMap* policies) {
79 // Proxy settings have been configured by 5 policies that didn't mix well 75 // 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 76 // 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 77 // policy sources. The proxy settings will eventually be configured by a
82 // single Dictionary policy when all providers have support for that. For 78 // single Dictionary policy when all providers have support for that. For
83 // now, the individual policies are mapped here to a single Dictionary policy 79 // now, the individual policies are mapped here to a single Dictionary policy
84 // that the rest of the policy machinery uses. 80 // that the rest of the policy machinery uses.
81
82 // The highest (level, scope) pair for an existing proxy policy is determined
83 // first, and then only policies with those exact attributes are merged.
84 PolicyMap::Entry current_priority; // Defaults to the lowest priority.
85 scoped_ptr<DictionaryValue> proxy_settings(new DictionaryValue); 85 scoped_ptr<DictionaryValue> proxy_settings(new DictionaryValue);
86 for (size_t i = 0; i < arraysize(kProxyPolicies); ++i) { 86 for (size_t i = 0; i < arraysize(kProxyPolicies); ++i) {
87 const Value* value = policies->Get(kProxyPolicies[i]); 87 const PolicyMap::Entry* entry = policies->Get(kProxyPolicies[i]);
88 if (value) { 88 if (entry) {
89 proxy_settings->Set(GetPolicyName(kProxyPolicies[i]), value->DeepCopy()); 89 if (entry->has_higher_priority_than(current_priority)) {
90 proxy_settings->Clear();
91 current_priority = *entry;
92 }
93 if (!entry->has_higher_priority_than(current_priority) &&
94 !current_priority.has_higher_priority_than(*entry)) {
95 proxy_settings->Set(kProxyPolicies[i], entry->value->DeepCopy());
96 }
90 policies->Erase(kProxyPolicies[i]); 97 policies->Erase(kProxyPolicies[i]);
91 } 98 }
92 } 99 }
93 if (!proxy_settings->empty() && !policies->Get(kPolicyProxySettings)) 100 if (!proxy_settings->empty() && !policies->Get(key::kProxySettings)) {
94 policies->Set(kPolicyProxySettings, proxy_settings.release()); 101 policies->Set(key::kProxySettings,
102 current_priority.level,
103 current_priority.scope,
104 proxy_settings.release());
105 }
106 }
107
108 void ConfigurationPolicyProvider::NotifyPolicyUpdated() {
109 FOR_EACH_OBSERVER(ConfigurationPolicyProvider::Observer,
110 observer_list_,
111 OnUpdatePolicy(this));
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
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
OLDNEW
« no previous file with comments | « chrome/browser/policy/configuration_policy_provider.h ('k') | chrome/browser/policy/configuration_policy_provider_mac.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698