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

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

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