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

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

Issue 1940153002: Use std::unique_ptr to express ownership of base::Value in PolicyMap::Entry (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: . Created 4 years, 7 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 <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 17 matching lines...) Expand all
37 void FixDeprecatedPolicies(PolicyMap* policies) { 38 void FixDeprecatedPolicies(PolicyMap* policies) {
38 // Proxy settings have been configured by 5 policies that didn't mix well 39 // Proxy settings have been configured by 5 policies that didn't mix well
39 // together, and maps of policies had to take this into account when merging 40 // together, and maps of policies had to take this into account when merging
40 // policy sources. The proxy settings will eventually be configured by a 41 // policy sources. The proxy settings will eventually be configured by a
41 // single Dictionary policy when all providers have support for that. For 42 // single Dictionary policy when all providers have support for that. For
42 // now, the individual policies are mapped here to a single Dictionary policy 43 // now, the individual policies are mapped here to a single Dictionary policy
43 // that the rest of the policy machinery uses. 44 // that the rest of the policy machinery uses.
44 45
45 // The highest (level, scope) pair for an existing proxy policy is determined 46 // The highest (level, scope) pair for an existing proxy policy is determined
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 default_priority; // Defaults to the lowest priority.
49 const PolicyMap::Entry* current_priority = &default_priority;
48 PolicySource inherited_source = POLICY_SOURCE_ENTERPRISE_DEFAULT; 50 PolicySource inherited_source = POLICY_SOURCE_ENTERPRISE_DEFAULT;
49 std::unique_ptr<base::DictionaryValue> proxy_settings( 51 std::unique_ptr<base::DictionaryValue> proxy_settings(
50 new base::DictionaryValue); 52 new base::DictionaryValue);
51 for (size_t i = 0; i < arraysize(kProxyPolicies); ++i) { 53 for (size_t i = 0; i < arraysize(kProxyPolicies); ++i) {
52 const PolicyMap::Entry* entry = policies->Get(kProxyPolicies[i]); 54 const PolicyMap::Entry* entry = policies->Get(kProxyPolicies[i]);
53 if (entry) { 55 if (entry) {
54 if (entry->has_higher_priority_than(current_priority)) { 56 if (entry->has_higher_priority_than(*current_priority)) {
55 proxy_settings->Clear(); 57 proxy_settings->Clear();
56 current_priority = *entry; 58 current_priority = entry;
57 if (entry->source > inherited_source) // Higher priority? 59 if (entry->source > inherited_source) // Higher priority?
58 inherited_source = entry->source; 60 inherited_source = entry->source;
59 } 61 }
60 if (!entry->has_higher_priority_than(current_priority) && 62 if (!entry->has_higher_priority_than(*current_priority) &&
61 !current_priority.has_higher_priority_than(*entry)) { 63 !current_priority->has_higher_priority_than(*entry)) {
62 proxy_settings->Set(kProxyPolicies[i], entry->value->DeepCopy()); 64 proxy_settings->Set(kProxyPolicies[i], entry->value->CreateDeepCopy());
63 } 65 }
64 policies->Erase(kProxyPolicies[i]); 66 policies->Erase(kProxyPolicies[i]);
65 } 67 }
66 } 68 }
67 // Sets the new |proxy_settings| if kProxySettings isn't set yet, or if the 69 // Sets the new |proxy_settings| if kProxySettings isn't set yet, or if the
68 // new priority is higher. 70 // new priority is higher.
69 const PolicyMap::Entry* existing = policies->Get(key::kProxySettings); 71 const PolicyMap::Entry* existing = policies->Get(key::kProxySettings);
70 if (!proxy_settings->empty() && 72 if (!proxy_settings->empty() &&
71 (!existing || current_priority.has_higher_priority_than(*existing))) { 73 (!existing || current_priority->has_higher_priority_than(*existing))) {
72 policies->Set(key::kProxySettings, 74 policies->Set(key::kProxySettings, current_priority->level,
73 current_priority.level, 75 current_priority->scope, inherited_source,
74 current_priority.scope, 76 std::move(proxy_settings), nullptr);
75 inherited_source,
76 proxy_settings.release(),
77 NULL);
78 } 77 }
79 } 78 }
80 79
81 } // namespace 80 } // namespace
82 81
83 PolicyServiceImpl::PolicyServiceImpl(const Providers& providers) 82 PolicyServiceImpl::PolicyServiceImpl(const Providers& providers)
84 : update_task_ptr_factory_(this) { 83 : update_task_ptr_factory_(this) {
85 for (int domain = 0; domain < POLICY_DOMAIN_SIZE; ++domain) 84 for (int domain = 0; domain < POLICY_DOMAIN_SIZE; ++domain)
86 initialization_complete_[domain] = true; 85 initialization_complete_[domain] = true;
87 providers_ = providers; 86 providers_ = providers;
(...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after
282 if (refresh_pending_.empty() && !refresh_callbacks_.empty()) { 281 if (refresh_pending_.empty() && !refresh_callbacks_.empty()) {
283 std::vector<base::Closure> callbacks; 282 std::vector<base::Closure> callbacks;
284 callbacks.swap(refresh_callbacks_); 283 callbacks.swap(refresh_callbacks_);
285 std::vector<base::Closure>::iterator it; 284 std::vector<base::Closure>::iterator it;
286 for (it = callbacks.begin(); it != callbacks.end(); ++it) 285 for (it = callbacks.begin(); it != callbacks.end(); ++it)
287 it->Run(); 286 it->Run();
288 } 287 }
289 } 288 }
290 289
291 } // namespace policy 290 } // namespace policy
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698