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.h" | 5 #include "components/url_matcher/url_matcher.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <iterator> | 8 #include <iterator> |
9 #include <utility> | 9 #include <utility> |
10 | 10 |
(...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
215 } | 215 } |
216 | 216 |
217 bool URLMatcherCondition::IsOriginAndPathRegexCondition() const { | 217 bool URLMatcherCondition::IsOriginAndPathRegexCondition() const { |
218 return IsOriginAndPathRegexCriterion(criterion_); | 218 return IsOriginAndPathRegexCriterion(criterion_); |
219 } | 219 } |
220 | 220 |
221 bool URLMatcherCondition::IsMatch( | 221 bool URLMatcherCondition::IsMatch( |
222 const std::set<StringPattern::ID>& matching_patterns, | 222 const std::set<StringPattern::ID>& matching_patterns, |
223 const GURL& url) const { | 223 const GURL& url) const { |
224 DCHECK(string_pattern_); | 224 DCHECK(string_pattern_); |
225 if (!ContainsKey(matching_patterns, string_pattern_->id())) | 225 if (!base::ContainsKey(matching_patterns, string_pattern_->id())) |
226 return false; | 226 return false; |
227 // The criteria HOST_CONTAINS, PATH_CONTAINS, QUERY_CONTAINS are based on | 227 // The criteria HOST_CONTAINS, PATH_CONTAINS, QUERY_CONTAINS are based on |
228 // a substring match on the raw URL. In case of a match, we need to verify | 228 // a substring match on the raw URL. In case of a match, we need to verify |
229 // that the match was found in the correct component of the URL. | 229 // that the match was found in the correct component of the URL. |
230 switch (criterion_) { | 230 switch (criterion_) { |
231 case HOST_CONTAINS: | 231 case HOST_CONTAINS: |
232 return url.host().find(string_pattern_->pattern()) != | 232 return url.host().find(string_pattern_->pattern()) != |
233 std::string::npos; | 233 std::string::npos; |
234 case PATH_CONTAINS: | 234 case PATH_CONTAINS: |
235 return url.path().find(string_pattern_->pattern()) != | 235 return url.path().find(string_pattern_->pattern()) != |
(...skipping 19 matching lines...) Expand all Loading... |
255 const char kQueryComponentDelimiter[] = {static_cast<char>(-4), 0}; | 255 const char kQueryComponentDelimiter[] = {static_cast<char>(-4), 0}; |
256 const char kEndOfURL[] = {static_cast<char>(-5), 0}; | 256 const char kEndOfURL[] = {static_cast<char>(-5), 0}; |
257 | 257 |
258 // The delimiter for query parameters | 258 // The delimiter for query parameters |
259 const char kQuerySeparator = '&'; | 259 const char kQuerySeparator = '&'; |
260 } // namespace | 260 } // namespace |
261 | 261 |
262 URLMatcherConditionFactory::URLMatcherConditionFactory() : id_counter_(0) {} | 262 URLMatcherConditionFactory::URLMatcherConditionFactory() : id_counter_(0) {} |
263 | 263 |
264 URLMatcherConditionFactory::~URLMatcherConditionFactory() { | 264 URLMatcherConditionFactory::~URLMatcherConditionFactory() { |
265 STLDeleteElements(&substring_pattern_singletons_); | 265 base::STLDeleteElements(&substring_pattern_singletons_); |
266 STLDeleteElements(®ex_pattern_singletons_); | 266 base::STLDeleteElements(®ex_pattern_singletons_); |
267 STLDeleteElements(&origin_and_path_regex_pattern_singletons_); | 267 base::STLDeleteElements(&origin_and_path_regex_pattern_singletons_); |
268 } | 268 } |
269 | 269 |
270 std::string URLMatcherConditionFactory::CanonicalizeURLForComponentSearches( | 270 std::string URLMatcherConditionFactory::CanonicalizeURLForComponentSearches( |
271 const GURL& url) const { | 271 const GURL& url) const { |
272 return kBeginningOfURL + CanonicalizeHostname(url.host()) + kEndOfDomain + | 272 return kBeginningOfURL + CanonicalizeHostname(url.host()) + kEndOfDomain + |
273 url.path() + kEndOfPath + | 273 url.path() + kEndOfPath + |
274 (url.has_query() ? CanonicalizeQuery(url.query(), true, true) | 274 (url.has_query() ? CanonicalizeQuery(url.query(), true, true) |
275 : std::string()) + | 275 : std::string()) + |
276 kEndOfURL; | 276 kEndOfURL; |
277 } | 277 } |
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
458 URLMatcherCondition | 458 URLMatcherCondition |
459 URLMatcherConditionFactory::CreateOriginAndPathMatchesCondition( | 459 URLMatcherConditionFactory::CreateOriginAndPathMatchesCondition( |
460 const std::string& regex) { | 460 const std::string& regex) { |
461 return CreateCondition(URLMatcherCondition::ORIGIN_AND_PATH_MATCHES, regex); | 461 return CreateCondition(URLMatcherCondition::ORIGIN_AND_PATH_MATCHES, regex); |
462 } | 462 } |
463 | 463 |
464 void URLMatcherConditionFactory::ForgetUnusedPatterns( | 464 void URLMatcherConditionFactory::ForgetUnusedPatterns( |
465 const std::set<StringPattern::ID>& used_patterns) { | 465 const std::set<StringPattern::ID>& used_patterns) { |
466 PatternSingletons::iterator i = substring_pattern_singletons_.begin(); | 466 PatternSingletons::iterator i = substring_pattern_singletons_.begin(); |
467 while (i != substring_pattern_singletons_.end()) { | 467 while (i != substring_pattern_singletons_.end()) { |
468 if (ContainsKey(used_patterns, (*i)->id())) { | 468 if (base::ContainsKey(used_patterns, (*i)->id())) { |
469 ++i; | 469 ++i; |
470 } else { | 470 } else { |
471 delete *i; | 471 delete *i; |
472 substring_pattern_singletons_.erase(i++); | 472 substring_pattern_singletons_.erase(i++); |
473 } | 473 } |
474 } | 474 } |
475 i = regex_pattern_singletons_.begin(); | 475 i = regex_pattern_singletons_.begin(); |
476 while (i != regex_pattern_singletons_.end()) { | 476 while (i != regex_pattern_singletons_.end()) { |
477 if (ContainsKey(used_patterns, (*i)->id())) { | 477 if (base::ContainsKey(used_patterns, (*i)->id())) { |
478 ++i; | 478 ++i; |
479 } else { | 479 } else { |
480 delete *i; | 480 delete *i; |
481 regex_pattern_singletons_.erase(i++); | 481 regex_pattern_singletons_.erase(i++); |
482 } | 482 } |
483 } | 483 } |
484 i = origin_and_path_regex_pattern_singletons_.begin(); | 484 i = origin_and_path_regex_pattern_singletons_.begin(); |
485 while (i != origin_and_path_regex_pattern_singletons_.end()) { | 485 while (i != origin_and_path_regex_pattern_singletons_.end()) { |
486 if (ContainsKey(used_patterns, (*i)->id())) { | 486 if (base::ContainsKey(used_patterns, (*i)->id())) { |
487 ++i; | 487 ++i; |
488 } else { | 488 } else { |
489 delete *i; | 489 delete *i; |
490 origin_and_path_regex_pattern_singletons_.erase(i++); | 490 origin_and_path_regex_pattern_singletons_.erase(i++); |
491 } | 491 } |
492 } | 492 } |
493 } | 493 } |
494 | 494 |
495 bool URLMatcherConditionFactory::IsEmpty() const { | 495 bool URLMatcherConditionFactory::IsEmpty() const { |
496 return substring_pattern_singletons_.empty() && | 496 return substring_pattern_singletons_.empty() && |
(...skipping 280 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
777 if (port_filter_.get() && !port_filter_->IsMatch(url)) | 777 if (port_filter_.get() && !port_filter_->IsMatch(url)) |
778 return false; | 778 return false; |
779 if (query_conditions_.empty()) | 779 if (query_conditions_.empty()) |
780 return true; | 780 return true; |
781 // The loop is duplicated below for performance reasons. If not all query | 781 // The loop is duplicated below for performance reasons. If not all query |
782 // elements are found, no need to verify match that is expected to take more | 782 // elements are found, no need to verify match that is expected to take more |
783 // cycles. | 783 // cycles. |
784 for (QueryConditions::const_iterator i = query_conditions_.begin(); | 784 for (QueryConditions::const_iterator i = query_conditions_.begin(); |
785 i != query_conditions_.end(); | 785 i != query_conditions_.end(); |
786 ++i) { | 786 ++i) { |
787 if (!ContainsKey(matching_patterns, i->string_pattern()->id())) | 787 if (!base::ContainsKey(matching_patterns, i->string_pattern()->id())) |
788 return false; | 788 return false; |
789 } | 789 } |
790 for (QueryConditions::const_iterator i = query_conditions_.begin(); | 790 for (QueryConditions::const_iterator i = query_conditions_.begin(); |
791 i != query_conditions_.end(); | 791 i != query_conditions_.end(); |
792 ++i) { | 792 ++i) { |
793 if (!i->IsMatch(url_for_component_searches)) | 793 if (!i->IsMatch(url_for_component_searches)) |
794 return false; | 794 return false; |
795 } | 795 } |
796 return true; | 796 return true; |
797 } | 797 } |
(...skipping 298 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1096 | 1096 |
1097 void URLMatcher::UpdateInternalDatastructures() { | 1097 void URLMatcher::UpdateInternalDatastructures() { |
1098 UpdateSubstringSetMatcher(false); | 1098 UpdateSubstringSetMatcher(false); |
1099 UpdateSubstringSetMatcher(true); | 1099 UpdateSubstringSetMatcher(true); |
1100 UpdateRegexSetMatcher(); | 1100 UpdateRegexSetMatcher(); |
1101 UpdateTriggers(); | 1101 UpdateTriggers(); |
1102 UpdateConditionFactory(); | 1102 UpdateConditionFactory(); |
1103 } | 1103 } |
1104 | 1104 |
1105 } // namespace url_matcher | 1105 } // namespace url_matcher |
OLD | NEW |