OLD | NEW |
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 |
(...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
241 std::unique_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 nullptr; | 248 return nullptr; |
249 } | 249 } |
250 | 250 |
251 for (base::ListValue::const_iterator i = value_list->begin(); | 251 for (const auto& entry : *value_list) { |
252 i != value_list->end(); ++i) { | |
253 base::Value* entry = *i; | |
254 int port = 0; | 252 int port = 0; |
255 base::ListValue* range = NULL; | 253 base::ListValue* range = NULL; |
256 if (entry->GetAsInteger(&port)) { | 254 if (entry->GetAsInteger(&port)) { |
257 ranges.push_back(URLMatcherPortFilter::CreateRange(port)); | 255 ranges.push_back(URLMatcherPortFilter::CreateRange(port)); |
258 } else if (entry->GetAsList(&range)) { | 256 } else if (entry->GetAsList(&range)) { |
259 int from = 0, to = 0; | 257 int from = 0, to = 0; |
260 if (range->GetSize() != 2u || | 258 if (range->GetSize() != 2u || |
261 !range->GetInteger(0, &from) || | 259 !range->GetInteger(0, &from) || |
262 !range->GetInteger(1, &to)) { | 260 !range->GetInteger(1, &to)) { |
263 *error = kInvalidPortRanges; | 261 *error = kInvalidPortRanges; |
264 return nullptr; | 262 return nullptr; |
265 } | 263 } |
266 ranges.push_back(URLMatcherPortFilter::CreateRange(from, to)); | 264 ranges.push_back(URLMatcherPortFilter::CreateRange(from, to)); |
267 } else { | 265 } else { |
268 *error = kInvalidPortRanges; | 266 *error = kInvalidPortRanges; |
269 return nullptr; | 267 return nullptr; |
270 } | 268 } |
271 } | 269 } |
272 | 270 |
273 return base::WrapUnique(new URLMatcherPortFilter(ranges)); | 271 return base::WrapUnique(new URLMatcherPortFilter(ranges)); |
274 } | 272 } |
275 | 273 |
276 } // namespace url_matcher | 274 } // namespace url_matcher |
OLD | NEW |