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

Side by Side Diff: components/policy/core/browser/configuration_policy_handler.cc

Issue 1902633006: Convert //components/policy from scoped_ptr to std::unique_ptr (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address comments and use namespace alias Created 4 years, 8 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/browser/configuration_policy_handler.h" 5 #include "components/policy/core/browser/configuration_policy_handler.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8
8 #include <algorithm> 9 #include <algorithm>
9 #include <utility> 10 #include <utility>
10 11
11 #include "base/callback.h" 12 #include "base/callback.h"
12 #include "base/files/file_path.h" 13 #include "base/files/file_path.h"
13 #include "base/logging.h" 14 #include "base/logging.h"
14 #include "base/macros.h" 15 #include "base/macros.h"
16 #include "base/memory/ptr_util.h"
15 #include "base/strings/string16.h" 17 #include "base/strings/string16.h"
16 #include "base/strings/string_number_conversions.h" 18 #include "base/strings/string_number_conversions.h"
17 #include "base/strings/string_util.h" 19 #include "base/strings/string_util.h"
18 #include "components/policy/core/browser/policy_error_map.h" 20 #include "components/policy/core/browser/policy_error_map.h"
19 #include "components/policy/core/common/policy_map.h" 21 #include "components/policy/core/common/policy_map.h"
20 #include "components/prefs/pref_value_map.h" 22 #include "components/prefs/pref_value_map.h"
21 #include "grit/components_strings.h" 23 #include "grit/components_strings.h"
22 #include "url/gurl.h" 24 #include "url/gurl.h"
23 25
24 namespace policy { 26 namespace policy {
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
145 if (output) 147 if (output)
146 *output = value; 148 *output = value;
147 return true; 149 return true;
148 } 150 }
149 151
150 152
151 // StringMappingListPolicyHandler implementation ----------------------------- 153 // StringMappingListPolicyHandler implementation -----------------------------
152 154
153 StringMappingListPolicyHandler::MappingEntry::MappingEntry( 155 StringMappingListPolicyHandler::MappingEntry::MappingEntry(
154 const char* policy_value, 156 const char* policy_value,
155 scoped_ptr<base::Value> map) 157 std::unique_ptr<base::Value> map)
156 : enum_value(policy_value), mapped_value(std::move(map)) {} 158 : enum_value(policy_value), mapped_value(std::move(map)) {}
157 159
158 StringMappingListPolicyHandler::MappingEntry::~MappingEntry() {} 160 StringMappingListPolicyHandler::MappingEntry::~MappingEntry() {}
159 161
160 StringMappingListPolicyHandler::StringMappingListPolicyHandler( 162 StringMappingListPolicyHandler::StringMappingListPolicyHandler(
161 const char* policy_name, 163 const char* policy_name,
162 const char* pref_path, 164 const char* pref_path,
163 const GenerateMapCallback& callback) 165 const GenerateMapCallback& callback)
164 : TypeCheckingPolicyHandler(policy_name, base::Value::TYPE_LIST), 166 : TypeCheckingPolicyHandler(policy_name, base::Value::TYPE_LIST),
165 pref_path_(pref_path), 167 pref_path_(pref_path),
166 map_getter_(callback) {} 168 map_getter_(callback) {}
167 169
168 StringMappingListPolicyHandler::~StringMappingListPolicyHandler() {} 170 StringMappingListPolicyHandler::~StringMappingListPolicyHandler() {}
169 171
170 bool StringMappingListPolicyHandler::CheckPolicySettings( 172 bool StringMappingListPolicyHandler::CheckPolicySettings(
171 const PolicyMap& policies, 173 const PolicyMap& policies,
172 PolicyErrorMap* errors) { 174 PolicyErrorMap* errors) {
173 const base::Value* value; 175 const base::Value* value;
174 return CheckAndGetValue(policies, errors, &value) && 176 return CheckAndGetValue(policies, errors, &value) &&
175 Convert(value, NULL, errors); 177 Convert(value, NULL, errors);
176 } 178 }
177 179
178 void StringMappingListPolicyHandler::ApplyPolicySettings( 180 void StringMappingListPolicyHandler::ApplyPolicySettings(
179 const PolicyMap& policies, 181 const PolicyMap& policies,
180 PrefValueMap* prefs) { 182 PrefValueMap* prefs) {
181 if (!pref_path_) 183 if (!pref_path_)
182 return; 184 return;
183 const base::Value* value = policies.GetValue(policy_name()); 185 const base::Value* value = policies.GetValue(policy_name());
184 scoped_ptr<base::ListValue> list(new base::ListValue()); 186 std::unique_ptr<base::ListValue> list(new base::ListValue());
185 if (value && Convert(value, list.get(), NULL)) 187 if (value && Convert(value, list.get(), NULL))
186 prefs->SetValue(pref_path_, std::move(list)); 188 prefs->SetValue(pref_path_, std::move(list));
187 } 189 }
188 190
189 bool StringMappingListPolicyHandler::Convert(const base::Value* input, 191 bool StringMappingListPolicyHandler::Convert(const base::Value* input,
190 base::ListValue* output, 192 base::ListValue* output,
191 PolicyErrorMap* errors) { 193 PolicyErrorMap* errors) {
192 if (!input) 194 if (!input)
193 return true; 195 return true;
194 196
195 const base::ListValue* list_value = NULL; 197 const base::ListValue* list_value = NULL;
196 if (!input->GetAsList(&list_value)) { 198 if (!input->GetAsList(&list_value)) {
197 NOTREACHED(); 199 NOTREACHED();
198 return false; 200 return false;
199 } 201 }
200 202
201 for (base::ListValue::const_iterator entry(list_value->begin()); 203 for (base::ListValue::const_iterator entry(list_value->begin());
202 entry != list_value->end(); ++entry) { 204 entry != list_value->end(); ++entry) {
203 std::string entry_value; 205 std::string entry_value;
204 if (!(*entry)->GetAsString(&entry_value)) { 206 if (!(*entry)->GetAsString(&entry_value)) {
205 if (errors) { 207 if (errors) {
206 errors->AddError(policy_name(), 208 errors->AddError(policy_name(),
207 entry - list_value->begin(), 209 entry - list_value->begin(),
208 IDS_POLICY_TYPE_ERROR, 210 IDS_POLICY_TYPE_ERROR,
209 ValueTypeToString(base::Value::TYPE_STRING)); 211 ValueTypeToString(base::Value::TYPE_STRING));
210 } 212 }
211 continue; 213 continue;
212 } 214 }
213 215
214 scoped_ptr<base::Value> mapped_value = Map(entry_value); 216 std::unique_ptr<base::Value> mapped_value = Map(entry_value);
215 if (mapped_value) { 217 if (mapped_value) {
216 if (output) 218 if (output)
217 output->Append(mapped_value.release()); 219 output->Append(mapped_value.release());
218 } else { 220 } else {
219 if (errors) { 221 if (errors) {
220 errors->AddError(policy_name(), 222 errors->AddError(policy_name(),
221 entry - list_value->begin(), 223 entry - list_value->begin(),
222 IDS_POLICY_OUT_OF_RANGE_ERROR); 224 IDS_POLICY_OUT_OF_RANGE_ERROR);
223 } 225 }
224 } 226 }
225 } 227 }
226 228
227 return true; 229 return true;
228 } 230 }
229 231
230 scoped_ptr<base::Value> StringMappingListPolicyHandler::Map( 232 std::unique_ptr<base::Value> StringMappingListPolicyHandler::Map(
231 const std::string& entry_value) { 233 const std::string& entry_value) {
232 // Lazily generate the map of policy strings to mapped values. 234 // Lazily generate the map of policy strings to mapped values.
233 if (map_.empty()) 235 if (map_.empty())
234 map_getter_.Run(&map_); 236 map_getter_.Run(&map_);
235 237
236 scoped_ptr<base::Value> return_value; 238 std::unique_ptr<base::Value> return_value;
237 for (ScopedVector<MappingEntry>::const_iterator it = map_.begin(); 239 for (ScopedVector<MappingEntry>::const_iterator it = map_.begin();
238 it != map_.end(); ++it) { 240 it != map_.end(); ++it) {
239 const MappingEntry* mapping_entry = *it; 241 const MappingEntry* mapping_entry = *it;
240 if (mapping_entry->enum_value == entry_value) { 242 if (mapping_entry->enum_value == entry_value) {
241 return_value = make_scoped_ptr(mapping_entry->mapped_value->DeepCopy()); 243 return_value = base::WrapUnique(mapping_entry->mapped_value->DeepCopy());
242 break; 244 break;
243 } 245 }
244 } 246 }
245 return return_value; 247 return return_value;
246 } 248 }
247 249
248 // IntRangePolicyHandler implementation ---------------------------------------- 250 // IntRangePolicyHandler implementation ----------------------------------------
249 251
250 IntRangePolicyHandler::IntRangePolicyHandler(const char* policy_name, 252 IntRangePolicyHandler::IntRangePolicyHandler(const char* policy_name,
251 const char* pref_path, 253 const char* pref_path,
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
353 error_path = "(ROOT)"; 355 error_path = "(ROOT)";
354 errors->AddError(policy_name_, error_path, error); 356 errors->AddError(policy_name_, error_path, error);
355 } 357 }
356 358
357 return result; 359 return result;
358 } 360 }
359 361
360 bool SchemaValidatingPolicyHandler::CheckAndGetValue( 362 bool SchemaValidatingPolicyHandler::CheckAndGetValue(
361 const PolicyMap& policies, 363 const PolicyMap& policies,
362 PolicyErrorMap* errors, 364 PolicyErrorMap* errors,
363 scoped_ptr<base::Value>* output) { 365 std::unique_ptr<base::Value>* output) {
364 const base::Value* value = policies.GetValue(policy_name()); 366 const base::Value* value = policies.GetValue(policy_name());
365 if (!value) 367 if (!value)
366 return true; 368 return true;
367 369
368 output->reset(value->DeepCopy()); 370 output->reset(value->DeepCopy());
369 std::string error_path; 371 std::string error_path;
370 std::string error; 372 std::string error;
371 bool result = 373 bool result =
372 schema_.Normalize(output->get(), strategy_, &error_path, &error, NULL); 374 schema_.Normalize(output->get(), strategy_, &error_path, &error, NULL);
373 375
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
429 } 431 }
430 432
431 // LegacyPoliciesDeprecatingPolicyHandler implementation ----------------------- 433 // LegacyPoliciesDeprecatingPolicyHandler implementation -----------------------
432 434
433 // TODO(binjin): Add a new common base class for SchemaValidatingPolicyHandler 435 // TODO(binjin): Add a new common base class for SchemaValidatingPolicyHandler
434 // and TypeCheckingPolicyHandler representing policy handlers for a single 436 // and TypeCheckingPolicyHandler representing policy handlers for a single
435 // policy, and use it as the type of |new_policy_handler|. 437 // policy, and use it as the type of |new_policy_handler|.
436 // http://crbug.com/345299 438 // http://crbug.com/345299
437 LegacyPoliciesDeprecatingPolicyHandler::LegacyPoliciesDeprecatingPolicyHandler( 439 LegacyPoliciesDeprecatingPolicyHandler::LegacyPoliciesDeprecatingPolicyHandler(
438 ScopedVector<ConfigurationPolicyHandler> legacy_policy_handlers, 440 ScopedVector<ConfigurationPolicyHandler> legacy_policy_handlers,
439 scoped_ptr<SchemaValidatingPolicyHandler> new_policy_handler) 441 std::unique_ptr<SchemaValidatingPolicyHandler> new_policy_handler)
440 : legacy_policy_handlers_(std::move(legacy_policy_handlers)), 442 : legacy_policy_handlers_(std::move(legacy_policy_handlers)),
441 new_policy_handler_(std::move(new_policy_handler)) {} 443 new_policy_handler_(std::move(new_policy_handler)) {}
442 444
443 LegacyPoliciesDeprecatingPolicyHandler:: 445 LegacyPoliciesDeprecatingPolicyHandler::
444 ~LegacyPoliciesDeprecatingPolicyHandler() { 446 ~LegacyPoliciesDeprecatingPolicyHandler() {
445 } 447 }
446 448
447 bool LegacyPoliciesDeprecatingPolicyHandler::CheckPolicySettings( 449 bool LegacyPoliciesDeprecatingPolicyHandler::CheckPolicySettings(
448 const PolicyMap& policies, 450 const PolicyMap& policies,
449 PolicyErrorMap* errors) { 451 PolicyErrorMap* errors) {
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
484 } 486 }
485 } 487 }
486 } 488 }
487 void LegacyPoliciesDeprecatingPolicyHandler::ApplyPolicySettings( 489 void LegacyPoliciesDeprecatingPolicyHandler::ApplyPolicySettings(
488 const policy::PolicyMap& /* policies */, 490 const policy::PolicyMap& /* policies */,
489 PrefValueMap* /* prefs */) { 491 PrefValueMap* /* prefs */) {
490 NOTREACHED(); 492 NOTREACHED();
491 } 493 }
492 494
493 } // namespace policy 495 } // namespace policy
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698