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

Side by Side Diff: components/policy/core/common/policy_service_impl.cc

Issue 1350913006: Revert of Add source column to chrome://policy showing the origins of policies. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 3 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
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 "components/policy/core/common/policy_service_impl.h" 5 #include "components/policy/core/common/policy_service_impl.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/location.h" 10 #include "base/location.h"
11 #include "base/single_thread_task_runner.h" 11 #include "base/single_thread_task_runner.h"
12 #include "base/stl_util.h" 12 #include "base/stl_util.h"
13 #include "base/thread_task_runner_handle.h" 13 #include "base/thread_task_runner_handle.h"
14 #include "base/values.h" 14 #include "base/values.h"
15 #include "components/policy/core/common/policy_bundle.h" 15 #include "components/policy/core/common/policy_bundle.h"
16 #include "components/policy/core/common/policy_map.h" 16 #include "components/policy/core/common/policy_map.h"
17 #include "components/policy/core/common/policy_types.h"
18 #include "policy/policy_constants.h" 17 #include "policy/policy_constants.h"
19 18
20 namespace policy { 19 namespace policy {
21 20
22 typedef PolicyServiceImpl::Providers::const_iterator Iterator; 21 typedef PolicyServiceImpl::Providers::const_iterator Iterator;
23 22
24 namespace { 23 namespace {
25 24
26 const char* kProxyPolicies[] = { 25 const char* kProxyPolicies[] = {
27 key::kProxyMode, 26 key::kProxyMode,
28 key::kProxyServerMode, 27 key::kProxyServerMode,
29 key::kProxyServer, 28 key::kProxyServer,
30 key::kProxyPacUrl, 29 key::kProxyPacUrl,
31 key::kProxyBypassList, 30 key::kProxyBypassList,
32 }; 31 };
33 32
34 void FixDeprecatedPolicies(PolicyMap* policies) { 33 void FixDeprecatedPolicies(PolicyMap* policies) {
35 // Proxy settings have been configured by 5 policies that didn't mix well 34 // Proxy settings have been configured by 5 policies that didn't mix well
36 // together, and maps of policies had to take this into account when merging 35 // together, and maps of policies had to take this into account when merging
37 // policy sources. The proxy settings will eventually be configured by a 36 // policy sources. The proxy settings will eventually be configured by a
38 // single Dictionary policy when all providers have support for that. For 37 // single Dictionary policy when all providers have support for that. For
39 // now, the individual policies are mapped here to a single Dictionary policy 38 // now, the individual policies are mapped here to a single Dictionary policy
40 // that the rest of the policy machinery uses. 39 // that the rest of the policy machinery uses.
41 40
42 // The highest (level, scope) pair for an existing proxy policy is determined 41 // The highest (level, scope) pair for an existing proxy policy is determined
43 // first, and then only policies with those exact attributes are merged. 42 // first, and then only policies with those exact attributes are merged.
44 PolicyMap::Entry current_priority; // Defaults to the lowest priority. 43 PolicyMap::Entry current_priority; // Defaults to the lowest priority.
45 PolicySource inherited_source = POLICY_SOURCE_ENTERPRISE_DEFAULT;
46 scoped_ptr<base::DictionaryValue> proxy_settings(new base::DictionaryValue); 44 scoped_ptr<base::DictionaryValue> proxy_settings(new base::DictionaryValue);
47 for (size_t i = 0; i < arraysize(kProxyPolicies); ++i) { 45 for (size_t i = 0; i < arraysize(kProxyPolicies); ++i) {
48 const PolicyMap::Entry* entry = policies->Get(kProxyPolicies[i]); 46 const PolicyMap::Entry* entry = policies->Get(kProxyPolicies[i]);
49 if (entry) { 47 if (entry) {
50 if (entry->has_higher_priority_than(current_priority)) { 48 if (entry->has_higher_priority_than(current_priority)) {
51 proxy_settings->Clear(); 49 proxy_settings->Clear();
52 current_priority = *entry; 50 current_priority = *entry;
53 if (entry->source > inherited_source) // Higher priority?
54 inherited_source = entry->source;
55 } 51 }
56 if (!entry->has_higher_priority_than(current_priority) && 52 if (!entry->has_higher_priority_than(current_priority) &&
57 !current_priority.has_higher_priority_than(*entry)) { 53 !current_priority.has_higher_priority_than(*entry)) {
58 proxy_settings->Set(kProxyPolicies[i], entry->value->DeepCopy()); 54 proxy_settings->Set(kProxyPolicies[i], entry->value->DeepCopy());
59 } 55 }
60 policies->Erase(kProxyPolicies[i]); 56 policies->Erase(kProxyPolicies[i]);
61 } 57 }
62 } 58 }
63 // Sets the new |proxy_settings| if kProxySettings isn't set yet, or if the 59 // Sets the new |proxy_settings| if kProxySettings isn't set yet, or if the
64 // new priority is higher. 60 // new priority is higher.
65 const PolicyMap::Entry* existing = policies->Get(key::kProxySettings); 61 const PolicyMap::Entry* existing = policies->Get(key::kProxySettings);
66 if (!proxy_settings->empty() && 62 if (!proxy_settings->empty() &&
67 (!existing || current_priority.has_higher_priority_than(*existing))) { 63 (!existing || current_priority.has_higher_priority_than(*existing))) {
68 policies->Set(key::kProxySettings, 64 policies->Set(key::kProxySettings,
69 current_priority.level, 65 current_priority.level,
70 current_priority.scope, 66 current_priority.scope,
71 inherited_source,
72 proxy_settings.release(), 67 proxy_settings.release(),
73 NULL); 68 NULL);
74 } 69 }
75 } 70 }
76 71
77 } // namespace 72 } // namespace
78 73
79 PolicyServiceImpl::PolicyServiceImpl(const Providers& providers) 74 PolicyServiceImpl::PolicyServiceImpl(const Providers& providers)
80 : update_task_ptr_factory_(this) { 75 : update_task_ptr_factory_(this) {
81 for (int domain = 0; domain < POLICY_DOMAIN_SIZE; ++domain) 76 for (int domain = 0; domain < POLICY_DOMAIN_SIZE; ++domain)
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after
278 if (refresh_pending_.empty() && !refresh_callbacks_.empty()) { 273 if (refresh_pending_.empty() && !refresh_callbacks_.empty()) {
279 std::vector<base::Closure> callbacks; 274 std::vector<base::Closure> callbacks;
280 callbacks.swap(refresh_callbacks_); 275 callbacks.swap(refresh_callbacks_);
281 std::vector<base::Closure>::iterator it; 276 std::vector<base::Closure>::iterator it;
282 for (it = callbacks.begin(); it != callbacks.end(); ++it) 277 for (it = callbacks.begin(); it != callbacks.end(); ++it)
283 it->Run(); 278 it->Run();
284 } 279 }
285 } 280 }
286 281
287 } // namespace policy 282 } // namespace policy
OLDNEW
« no previous file with comments | « components/policy/core/common/policy_map_unittest.cc ('k') | components/policy/core/common/policy_service_impl_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698