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

Side by Side Diff: components/url_matcher/url_matcher_factory.cc

Issue 1917673002: Convert //components/[u-z]* from scoped_ptr to std::unique_ptr (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 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/url_matcher/url_matcher_factory.h" 5 #include "components/url_matcher/url_matcher_factory.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <cctype> 8 #include <cctype>
9 #include <utility> 9 #include <utility>
10 10
11 #include "base/lazy_instance.h" 11 #include "base/lazy_instance.h"
12 #include "base/logging.h" 12 #include "base/logging.h"
13 #include "base/macros.h" 13 #include "base/macros.h"
14 #include "base/memory/ptr_util.h"
14 #include "base/strings/stringprintf.h" 15 #include "base/strings/stringprintf.h"
15 #include "base/values.h" 16 #include "base/values.h"
16 #include "components/url_matcher/url_matcher_constants.h" 17 #include "components/url_matcher/url_matcher_constants.h"
17 #include "components/url_matcher/url_matcher_helpers.h" 18 #include "components/url_matcher/url_matcher_helpers.h"
18 #include "third_party/re2/src/re2/re2.h" 19 #include "third_party/re2/src/re2/re2.h"
19 20
20 namespace url_matcher { 21 namespace url_matcher {
21 22
22 namespace helpers = url_matcher_helpers; 23 namespace helpers = url_matcher_helpers;
23 namespace keys = url_matcher_constants; 24 namespace keys = url_matcher_constants;
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
102 103
103 } // namespace 104 } // namespace
104 105
105 // static 106 // static
106 scoped_refptr<URLMatcherConditionSet> 107 scoped_refptr<URLMatcherConditionSet>
107 URLMatcherFactory::CreateFromURLFilterDictionary( 108 URLMatcherFactory::CreateFromURLFilterDictionary(
108 URLMatcherConditionFactory* url_matcher_condition_factory, 109 URLMatcherConditionFactory* url_matcher_condition_factory,
109 const base::DictionaryValue* url_filter_dict, 110 const base::DictionaryValue* url_filter_dict,
110 URLMatcherConditionSet::ID id, 111 URLMatcherConditionSet::ID id,
111 std::string* error) { 112 std::string* error) {
112 scoped_ptr<URLMatcherSchemeFilter> url_matcher_schema_filter; 113 std::unique_ptr<URLMatcherSchemeFilter> url_matcher_schema_filter;
113 scoped_ptr<URLMatcherPortFilter> url_matcher_port_filter; 114 std::unique_ptr<URLMatcherPortFilter> url_matcher_port_filter;
114 URLMatcherConditionSet::Conditions url_matcher_conditions; 115 URLMatcherConditionSet::Conditions url_matcher_conditions;
115 116
116 for (base::DictionaryValue::Iterator iter(*url_filter_dict); 117 for (base::DictionaryValue::Iterator iter(*url_filter_dict);
117 !iter.IsAtEnd(); iter.Advance()) { 118 !iter.IsAtEnd(); iter.Advance()) {
118 const std::string& condition_attribute_name = iter.key(); 119 const std::string& condition_attribute_name = iter.key();
119 const base::Value& condition_attribute_value = iter.value(); 120 const base::Value& condition_attribute_value = iter.value();
120 if (IsURLMatcherConditionAttribute(condition_attribute_name)) { 121 if (IsURLMatcherConditionAttribute(condition_attribute_name)) {
121 // Handle {host, path, ...}{Prefix, Suffix, Contains, Equals}. 122 // Handle {host, path, ...}{Prefix, Suffix, Contains, Equals}.
122 URLMatcherCondition url_matcher_condition = 123 URLMatcherCondition url_matcher_condition =
123 CreateURLMatcherCondition( 124 CreateURLMatcherCondition(
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
211 *error = base::StringPrintf( 212 *error = base::StringPrintf(
212 kUnparseableRegexString, str_value.c_str(), regex.error().c_str()); 213 kUnparseableRegexString, str_value.c_str(), regex.error().c_str());
213 return URLMatcherCondition(); 214 return URLMatcherCondition();
214 } 215 }
215 } 216 }
216 return g_url_matcher_condition_factory_methods.Get().Call( 217 return g_url_matcher_condition_factory_methods.Get().Call(
217 url_matcher_condition_factory, condition_attribute_name, str_value); 218 url_matcher_condition_factory, condition_attribute_name, str_value);
218 } 219 }
219 220
220 // static 221 // static
221 scoped_ptr<URLMatcherSchemeFilter> URLMatcherFactory::CreateURLMatcherScheme( 222 std::unique_ptr<URLMatcherSchemeFilter>
222 const base::Value* value, 223 URLMatcherFactory::CreateURLMatcherScheme(const base::Value* value,
223 std::string* error) { 224 std::string* error) {
224 std::vector<std::string> schemas; 225 std::vector<std::string> schemas;
225 if (!helpers::GetAsStringVector(value, &schemas)) { 226 if (!helpers::GetAsStringVector(value, &schemas)) {
226 *error = base::StringPrintf(kVectorOfStringsExpected, keys::kSchemesKey); 227 *error = base::StringPrintf(kVectorOfStringsExpected, keys::kSchemesKey);
227 return scoped_ptr<URLMatcherSchemeFilter>(); 228 return nullptr;
228 } 229 }
229 for (std::vector<std::string>::const_iterator it = schemas.begin(); 230 for (std::vector<std::string>::const_iterator it = schemas.begin();
230 it != schemas.end(); ++it) { 231 it != schemas.end(); ++it) {
231 if (ContainsUpperCase(*it)) { 232 if (ContainsUpperCase(*it)) {
232 *error = base::StringPrintf(kLowerCaseExpected, "Scheme"); 233 *error = base::StringPrintf(kLowerCaseExpected, "Scheme");
233 return scoped_ptr<URLMatcherSchemeFilter>(); 234 return nullptr;
234 } 235 }
235 } 236 }
236 return scoped_ptr<URLMatcherSchemeFilter>( 237 return base::WrapUnique(new URLMatcherSchemeFilter(schemas));
237 new URLMatcherSchemeFilter(schemas));
238 } 238 }
239 239
240 // static 240 // static
241 scoped_ptr<URLMatcherPortFilter> URLMatcherFactory::CreateURLMatcherPorts( 241 std::unique_ptr<URLMatcherPortFilter> URLMatcherFactory::CreateURLMatcherPorts(
242 const base::Value* value, 242 const base::Value* value,
243 std::string* error) { 243 std::string* error) {
244 std::vector<URLMatcherPortFilter::Range> ranges; 244 std::vector<URLMatcherPortFilter::Range> ranges;
245 const base::ListValue* value_list = NULL; 245 const base::ListValue* value_list = NULL;
246 if (!value->GetAsList(&value_list)) { 246 if (!value->GetAsList(&value_list)) {
247 *error = kInvalidPortRanges; 247 *error = kInvalidPortRanges;
248 return scoped_ptr<URLMatcherPortFilter>(); 248 return nullptr;
249 } 249 }
250 250
251 for (base::ListValue::const_iterator i = value_list->begin(); 251 for (base::ListValue::const_iterator i = value_list->begin();
252 i != value_list->end(); ++i) { 252 i != value_list->end(); ++i) {
253 base::Value* entry = *i; 253 base::Value* entry = *i;
254 int port = 0; 254 int port = 0;
255 base::ListValue* range = NULL; 255 base::ListValue* range = NULL;
256 if (entry->GetAsInteger(&port)) { 256 if (entry->GetAsInteger(&port)) {
257 ranges.push_back(URLMatcherPortFilter::CreateRange(port)); 257 ranges.push_back(URLMatcherPortFilter::CreateRange(port));
258 } else if (entry->GetAsList(&range)) { 258 } else if (entry->GetAsList(&range)) {
259 int from = 0, to = 0; 259 int from = 0, to = 0;
260 if (range->GetSize() != 2u || 260 if (range->GetSize() != 2u ||
261 !range->GetInteger(0, &from) || 261 !range->GetInteger(0, &from) ||
262 !range->GetInteger(1, &to)) { 262 !range->GetInteger(1, &to)) {
263 *error = kInvalidPortRanges; 263 *error = kInvalidPortRanges;
264 return scoped_ptr<URLMatcherPortFilter>(); 264 return nullptr;
265 } 265 }
266 ranges.push_back(URLMatcherPortFilter::CreateRange(from, to)); 266 ranges.push_back(URLMatcherPortFilter::CreateRange(from, to));
267 } else { 267 } else {
268 *error = kInvalidPortRanges; 268 *error = kInvalidPortRanges;
269 return scoped_ptr<URLMatcherPortFilter>(); 269 return nullptr;
270 } 270 }
271 } 271 }
272 272
273 return scoped_ptr<URLMatcherPortFilter>(new URLMatcherPortFilter(ranges)); 273 return base::WrapUnique(new URLMatcherPortFilter(ranges));
274 } 274 }
275 275
276 } // namespace url_matcher 276 } // namespace url_matcher
OLDNEW
« no previous file with comments | « components/url_matcher/url_matcher_factory.h ('k') | components/url_matcher/url_matcher_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698