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 "components/policy/core/common/policy_service_impl.h" | 5 #include "components/policy/core/common/policy_service_impl.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include <algorithm> | 9 #include <algorithm> |
| 10 #include <utility> |
10 | 11 |
11 #include "base/bind.h" | 12 #include "base/bind.h" |
12 #include "base/location.h" | 13 #include "base/location.h" |
13 #include "base/macros.h" | 14 #include "base/macros.h" |
14 #include "base/single_thread_task_runner.h" | 15 #include "base/single_thread_task_runner.h" |
15 #include "base/stl_util.h" | 16 #include "base/stl_util.h" |
16 #include "base/thread_task_runner_handle.h" | 17 #include "base/thread_task_runner_handle.h" |
17 #include "base/values.h" | 18 #include "base/values.h" |
18 #include "components/policy/core/common/policy_bundle.h" | 19 #include "components/policy/core/common/policy_bundle.h" |
19 #include "components/policy/core/common/policy_map.h" | 20 #include "components/policy/core/common/policy_map.h" |
(...skipping 26 matching lines...) Expand all Loading... |
46 // first, and then only policies with those exact attributes are merged. | 47 // first, and then only policies with those exact attributes are merged. |
47 PolicyMap::Entry current_priority; // Defaults to the lowest priority. | 48 PolicyMap::Entry current_priority; // Defaults to the lowest priority. |
48 PolicySource inherited_source = POLICY_SOURCE_ENTERPRISE_DEFAULT; | 49 PolicySource inherited_source = POLICY_SOURCE_ENTERPRISE_DEFAULT; |
49 std::unique_ptr<base::DictionaryValue> proxy_settings( | 50 std::unique_ptr<base::DictionaryValue> proxy_settings( |
50 new base::DictionaryValue); | 51 new base::DictionaryValue); |
51 for (size_t i = 0; i < arraysize(kProxyPolicies); ++i) { | 52 for (size_t i = 0; i < arraysize(kProxyPolicies); ++i) { |
52 const PolicyMap::Entry* entry = policies->Get(kProxyPolicies[i]); | 53 const PolicyMap::Entry* entry = policies->Get(kProxyPolicies[i]); |
53 if (entry) { | 54 if (entry) { |
54 if (entry->has_higher_priority_than(current_priority)) { | 55 if (entry->has_higher_priority_than(current_priority)) { |
55 proxy_settings->Clear(); | 56 proxy_settings->Clear(); |
56 current_priority = *entry; | 57 current_priority = entry->DeepCopy(); |
57 if (entry->source > inherited_source) // Higher priority? | 58 if (entry->source > inherited_source) // Higher priority? |
58 inherited_source = entry->source; | 59 inherited_source = entry->source; |
59 } | 60 } |
60 if (!entry->has_higher_priority_than(current_priority) && | 61 if (!entry->has_higher_priority_than(current_priority) && |
61 !current_priority.has_higher_priority_than(*entry)) { | 62 !current_priority.has_higher_priority_than(*entry)) { |
62 proxy_settings->Set(kProxyPolicies[i], entry->value->DeepCopy()); | 63 proxy_settings->Set(kProxyPolicies[i], entry->value->CreateDeepCopy()); |
63 } | 64 } |
64 policies->Erase(kProxyPolicies[i]); | 65 policies->Erase(kProxyPolicies[i]); |
65 } | 66 } |
66 } | 67 } |
67 // Sets the new |proxy_settings| if kProxySettings isn't set yet, or if the | 68 // Sets the new |proxy_settings| if kProxySettings isn't set yet, or if the |
68 // new priority is higher. | 69 // new priority is higher. |
69 const PolicyMap::Entry* existing = policies->Get(key::kProxySettings); | 70 const PolicyMap::Entry* existing = policies->Get(key::kProxySettings); |
70 if (!proxy_settings->empty() && | 71 if (!proxy_settings->empty() && |
71 (!existing || current_priority.has_higher_priority_than(*existing))) { | 72 (!existing || current_priority.has_higher_priority_than(*existing))) { |
72 policies->Set(key::kProxySettings, | 73 policies->Set(key::kProxySettings, current_priority.level, |
73 current_priority.level, | 74 current_priority.scope, inherited_source, |
74 current_priority.scope, | 75 std::move(proxy_settings), nullptr); |
75 inherited_source, | |
76 proxy_settings.release(), | |
77 NULL); | |
78 } | 76 } |
79 } | 77 } |
80 | 78 |
81 } // namespace | 79 } // namespace |
82 | 80 |
83 PolicyServiceImpl::PolicyServiceImpl(const Providers& providers) | 81 PolicyServiceImpl::PolicyServiceImpl(const Providers& providers) |
84 : update_task_ptr_factory_(this) { | 82 : update_task_ptr_factory_(this) { |
85 for (int domain = 0; domain < POLICY_DOMAIN_SIZE; ++domain) | 83 for (int domain = 0; domain < POLICY_DOMAIN_SIZE; ++domain) |
86 initialization_complete_[domain] = true; | 84 initialization_complete_[domain] = true; |
87 providers_ = providers; | 85 providers_ = providers; |
(...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
282 if (refresh_pending_.empty() && !refresh_callbacks_.empty()) { | 280 if (refresh_pending_.empty() && !refresh_callbacks_.empty()) { |
283 std::vector<base::Closure> callbacks; | 281 std::vector<base::Closure> callbacks; |
284 callbacks.swap(refresh_callbacks_); | 282 callbacks.swap(refresh_callbacks_); |
285 std::vector<base::Closure>::iterator it; | 283 std::vector<base::Closure>::iterator it; |
286 for (it = callbacks.begin(); it != callbacks.end(); ++it) | 284 for (it = callbacks.begin(); it != callbacks.end(); ++it) |
287 it->Run(); | 285 it->Run(); |
288 } | 286 } |
289 } | 287 } |
290 | 288 |
291 } // namespace policy | 289 } // namespace policy |
OLD | NEW |