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

Side by Side Diff: components/policy/core/common/schema.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 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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/schema.h" 5 #include "components/policy/core/common/schema.h"
6 6
7 #include <limits.h> 7 #include <limits.h>
8 #include <stddef.h> 8 #include <stddef.h>
9 9
10 #include <algorithm> 10 #include <algorithm>
11 #include <climits> 11 #include <climits>
12 #include <map> 12 #include <map>
13 #include <memory>
13 #include <utility> 14 #include <utility>
14 15
15 #include "base/compiler_specific.h" 16 #include "base/compiler_specific.h"
16 #include "base/logging.h" 17 #include "base/logging.h"
17 #include "base/macros.h" 18 #include "base/macros.h"
18 #include "base/memory/scoped_ptr.h"
19 #include "base/stl_util.h" 19 #include "base/stl_util.h"
20 #include "base/strings/stringprintf.h" 20 #include "base/strings/stringprintf.h"
21 #include "components/json_schema/json_schema_constants.h" 21 #include "components/json_schema/json_schema_constants.h"
22 #include "components/json_schema/json_schema_validator.h" 22 #include "components/json_schema/json_schema_validator.h"
23 #include "components/policy/core/common/schema_internal.h" 23 #include "components/policy/core/common/schema_internal.h"
24 #include "third_party/re2/src/re2/re2.h" 24 #include "third_party/re2/src/re2/re2.h"
25 25
26 namespace schema = json_schema_constants; 26 namespace schema = json_schema_constants;
27 27
28 namespace policy { 28 namespace policy {
(...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after
243 243
244 // Assigns the IDs in |id_map| to the pending references in the 244 // Assigns the IDs in |id_map| to the pending references in the
245 // |reference_list|. If an ID is missing then |error| is set and false is 245 // |reference_list|. If an ID is missing then |error| is set and false is
246 // returned; otherwise returns true. 246 // returned; otherwise returns true.
247 static bool ResolveReferences(const IdMap& id_map, 247 static bool ResolveReferences(const IdMap& id_map,
248 const ReferenceList& reference_list, 248 const ReferenceList& reference_list,
249 std::string* error); 249 std::string* error);
250 250
251 // Cache for CompileRegex(), will memorize return value of every call to 251 // Cache for CompileRegex(), will memorize return value of every call to
252 // CompileRegex() and return results directly next time. 252 // CompileRegex() and return results directly next time.
253 mutable std::map<std::string, scoped_ptr<re2::RE2>> regex_cache_; 253 mutable std::map<std::string, std::unique_ptr<re2::RE2>> regex_cache_;
254 254
255 SchemaData schema_data_; 255 SchemaData schema_data_;
256 std::vector<std::string> strings_; 256 std::vector<std::string> strings_;
257 std::vector<SchemaNode> schema_nodes_; 257 std::vector<SchemaNode> schema_nodes_;
258 std::vector<PropertyNode> property_nodes_; 258 std::vector<PropertyNode> property_nodes_;
259 std::vector<PropertiesNode> properties_nodes_; 259 std::vector<PropertiesNode> properties_nodes_;
260 std::vector<RestrictionNode> restriction_nodes_; 260 std::vector<RestrictionNode> restriction_nodes_;
261 std::vector<int> int_enums_; 261 std::vector<int> int_enums_;
262 std::vector<const char*> string_enums_; 262 std::vector<const char*> string_enums_;
263 263
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
340 data->restriction_nodes = storage->restriction_nodes_.data(); 340 data->restriction_nodes = storage->restriction_nodes_.data();
341 data->int_enums = storage->int_enums_.data(); 341 data->int_enums = storage->int_enums_.data();
342 data->string_enums = storage->string_enums_.data(); 342 data->string_enums = storage->string_enums_.data();
343 return storage; 343 return storage;
344 } 344 }
345 345
346 re2::RE2* Schema::InternalStorage::CompileRegex( 346 re2::RE2* Schema::InternalStorage::CompileRegex(
347 const std::string& pattern) const { 347 const std::string& pattern) const {
348 auto it = regex_cache_.find(pattern); 348 auto it = regex_cache_.find(pattern);
349 if (it == regex_cache_.end()) { 349 if (it == regex_cache_.end()) {
350 scoped_ptr<re2::RE2> compiled(new re2::RE2(pattern)); 350 std::unique_ptr<re2::RE2> compiled(new re2::RE2(pattern));
351 re2::RE2* compiled_ptr = compiled.get(); 351 re2::RE2* compiled_ptr = compiled.get();
352 regex_cache_.insert(std::make_pair(pattern, std::move(compiled))); 352 regex_cache_.insert(std::make_pair(pattern, std::move(compiled)));
353 return compiled_ptr; 353 return compiled_ptr;
354 } 354 }
355 return it->second.get(); 355 return it->second.get();
356 } 356 }
357 357
358 // static 358 // static
359 void Schema::InternalStorage::DetermineStorageSizes( 359 void Schema::InternalStorage::DetermineStorageSizes(
360 const base::DictionaryValue& schema, 360 const base::DictionaryValue& schema,
(...skipping 587 matching lines...) Expand 10 before | Expand all | Expand 10 after
948 return true; 948 return true;
949 } 949 }
950 950
951 return Validate(*value, strategy, error_path, error); 951 return Validate(*value, strategy, error_path, error);
952 } 952 }
953 953
954 // static 954 // static
955 Schema Schema::Parse(const std::string& content, std::string* error) { 955 Schema Schema::Parse(const std::string& content, std::string* error) {
956 // Validate as a generic JSON schema, and ignore unknown attributes; they 956 // Validate as a generic JSON schema, and ignore unknown attributes; they
957 // may become used in a future version of the schema format. 957 // may become used in a future version of the schema format.
958 scoped_ptr<base::DictionaryValue> dict = JSONSchemaValidator::IsValidSchema( 958 std::unique_ptr<base::DictionaryValue> dict =
959 content, JSONSchemaValidator::OPTIONS_IGNORE_UNKNOWN_ATTRIBUTES, error); 959 JSONSchemaValidator::IsValidSchema(
960 content, JSONSchemaValidator::OPTIONS_IGNORE_UNKNOWN_ATTRIBUTES,
961 error);
960 if (!dict) 962 if (!dict)
961 return Schema(); 963 return Schema();
962 964
963 // Validate the main type. 965 // Validate the main type.
964 std::string string_value; 966 std::string string_value;
965 if (!dict->GetString(schema::kType, &string_value) || 967 if (!dict->GetString(schema::kType, &string_value) ||
966 string_value != schema::kObject) { 968 string_value != schema::kObject) {
967 *error = 969 *error =
968 "The main schema must have a type attribute with \"object\" value."; 970 "The main schema must have a type attribute with \"object\" value.";
969 return Schema(); 971 return Schema();
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after
1103 return false; 1105 return false;
1104 } else { 1106 } else {
1105 int index = rnode->string_pattern_restriction.pattern_index; 1107 int index = rnode->string_pattern_restriction.pattern_index;
1106 DCHECK(index == rnode->string_pattern_restriction.pattern_index_backup); 1108 DCHECK(index == rnode->string_pattern_restriction.pattern_index_backup);
1107 re2::RE2* regex = storage_->CompileRegex(*storage_->string_enums(index)); 1109 re2::RE2* regex = storage_->CompileRegex(*storage_->string_enums(index));
1108 return re2::RE2::PartialMatch(str, *regex); 1110 return re2::RE2::PartialMatch(str, *regex);
1109 } 1111 }
1110 } 1112 }
1111 1113
1112 } // namespace policy 1114 } // namespace policy
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698