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

Side by Side Diff: components/policy/core/common/policy_loader_win.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: another-fix 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) 2014 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2014 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_loader_win.h" 5 #include "components/policy/core/common/policy_loader_win.h"
6 6
7 #include <windows.h> 7 #include <windows.h>
8 #include <lm.h> // For limits. 8 #include <lm.h> // For limits.
9 #include <ntdsapi.h> // For Ds[Un]Bind 9 #include <ntdsapi.h> // For Ds[Un]Bind
10 #include <rpc.h> // For struct GUID 10 #include <rpc.h> // For struct GUID
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after
141 141
142 int invalid_policies = 0; 142 int invalid_policies = 0;
143 const PolicyMap::Entry* map_entry = 143 const PolicyMap::Entry* map_entry =
144 policy->Get(key::kExtensionInstallForcelist); 144 policy->Get(key::kExtensionInstallForcelist);
145 if (map_entry && map_entry->value) { 145 if (map_entry && map_entry->value) {
146 const base::ListValue* policy_list_value = NULL; 146 const base::ListValue* policy_list_value = NULL;
147 if (!map_entry->value->GetAsList(&policy_list_value)) 147 if (!map_entry->value->GetAsList(&policy_list_value))
148 return; 148 return;
149 149
150 std::unique_ptr<base::ListValue> filtered_values(new base::ListValue); 150 std::unique_ptr<base::ListValue> filtered_values(new base::ListValue);
151 for (base::ListValue::const_iterator list_entry(policy_list_value->begin()); 151 for (const auto& list_entry : *policy_list_value) {
152 list_entry != policy_list_value->end(); ++list_entry) {
153 std::string entry; 152 std::string entry;
154 if (!(*list_entry)->GetAsString(&entry)) 153 if (!list_entry->GetAsString(&entry))
155 continue; 154 continue;
156 size_t pos = entry.find(';'); 155 size_t pos = entry.find(';');
157 if (pos == std::string::npos) 156 if (pos == std::string::npos)
158 continue; 157 continue;
159 // Only allow custom update urls in enterprise environments. 158 // Only allow custom update urls in enterprise environments.
160 if (!base::LowerCaseEqualsASCII(entry.substr(pos), 159 if (!base::LowerCaseEqualsASCII(entry.substr(pos),
161 kExpectedWebStoreUrl)) { 160 kExpectedWebStoreUrl)) {
162 entry = kBlockedExtensionPrefix + entry; 161 entry = kBlockedExtensionPrefix + entry;
163 invalid_policies++; 162 invalid_policies++;
164 } 163 }
165 164
166 filtered_values->AppendString(entry); 165 filtered_values->AppendString(entry);
167 } 166 }
168 if (invalid_policies) { 167 if (invalid_policies) {
169 policy->Set(key::kExtensionInstallForcelist, 168 PolicyMap::Entry filtered_entry = map_entry->DeepCopy();
170 map_entry->level, map_entry->scope, map_entry->source, 169 filtered_entry.value = std::move(filtered_values);
171 filtered_values.release(), 170 policy->Set(key::kExtensionInstallForcelist, std::move(filtered_entry));
172 map_entry->external_data_fetcher);
173 171
174 const PolicyDetails* details = GetChromePolicyDetails( 172 const PolicyDetails* details = GetChromePolicyDetails(
175 key::kExtensionInstallForcelist); 173 key::kExtensionInstallForcelist);
176 UMA_HISTOGRAM_SPARSE_SLOWLY("EnterpriseCheck.InvalidPolicies", 174 UMA_HISTOGRAM_SPARSE_SLOWLY("EnterpriseCheck.InvalidPolicies",
177 details->id); 175 details->id);
178 } 176 }
179 } 177 }
180 178
181 for (size_t i = 0; i < arraysize(kInsecurePolicies); ++i) { 179 for (size_t i = 0; i < arraysize(kInsecurePolicies); ++i) {
182 if (policy->Get(kInsecurePolicies[i])) { 180 if (policy->Get(kInsecurePolicies[i])) {
(...skipping 500 matching lines...) Expand 10 before | Expand all | Expand 10 after
683 681
684 void PolicyLoaderWin::OnObjectSignaled(HANDLE object) { 682 void PolicyLoaderWin::OnObjectSignaled(HANDLE object) {
685 DCHECK(object == user_policy_changed_event_.handle() || 683 DCHECK(object == user_policy_changed_event_.handle() ||
686 object == machine_policy_changed_event_.handle()) 684 object == machine_policy_changed_event_.handle())
687 << "unexpected object signaled policy reload, obj = " 685 << "unexpected object signaled policy reload, obj = "
688 << std::showbase << std::hex << object; 686 << std::showbase << std::hex << object;
689 Reload(false); 687 Reload(false);
690 } 688 }
691 689
692 } // namespace policy 690 } // namespace policy
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698