OLD | NEW |
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 "chrome/browser/extensions/api/declarative/url_matcher.h" | 5 #include "chrome/browser/extensions/api/declarative/url_matcher.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <iterator> | 8 #include <iterator> |
9 | 9 |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
(...skipping 326 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
337 while (i != pattern_singletons_.end()) { | 337 while (i != pattern_singletons_.end()) { |
338 if (used_patterns.find((*i)->id()) != used_patterns.end()) { | 338 if (used_patterns.find((*i)->id()) != used_patterns.end()) { |
339 ++i; | 339 ++i; |
340 } else { | 340 } else { |
341 delete *i; | 341 delete *i; |
342 pattern_singletons_.erase(i++); | 342 pattern_singletons_.erase(i++); |
343 } | 343 } |
344 } | 344 } |
345 } | 345 } |
346 | 346 |
| 347 bool URLMatcherConditionFactory::IsEmpty() const { |
| 348 return pattern_singletons_.empty(); |
| 349 } |
| 350 |
347 URLMatcherCondition URLMatcherConditionFactory::CreateCondition( | 351 URLMatcherCondition URLMatcherConditionFactory::CreateCondition( |
348 URLMatcherCondition::Criterion criterion, | 352 URLMatcherCondition::Criterion criterion, |
349 const std::string& pattern) { | 353 const std::string& pattern) { |
350 SubstringPattern search_pattern(pattern, 0); | 354 SubstringPattern search_pattern(pattern, 0); |
351 PatternSingletons::const_iterator iter = | 355 PatternSingletons::const_iterator iter = |
352 pattern_singletons_.find(&search_pattern); | 356 pattern_singletons_.find(&search_pattern); |
353 if (iter != pattern_singletons_.end()) { | 357 if (iter != pattern_singletons_.end()) { |
354 return URLMatcherCondition(criterion, *iter); | 358 return URLMatcherCondition(criterion, *iter); |
355 } else { | 359 } else { |
356 SubstringPattern* new_pattern = | 360 SubstringPattern* new_pattern = |
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
473 for (std::set<URLMatcherConditionSet::ID>::const_iterator j = | 477 for (std::set<URLMatcherConditionSet::ID>::const_iterator j = |
474 condition_sets.begin(); j != condition_sets.end(); ++j) { | 478 condition_sets.begin(); j != condition_sets.end(); ++j) { |
475 if (url_matcher_condition_sets_[*j].IsMatch(matches, url)) | 479 if (url_matcher_condition_sets_[*j].IsMatch(matches, url)) |
476 result.insert(*j); | 480 result.insert(*j); |
477 } | 481 } |
478 } | 482 } |
479 | 483 |
480 return result; | 484 return result; |
481 } | 485 } |
482 | 486 |
| 487 bool URLMatcher::IsEmpty() const { |
| 488 return condition_factory_.IsEmpty() && |
| 489 url_matcher_condition_sets_.empty() && |
| 490 substring_match_triggers_.empty() && |
| 491 full_url_matcher_.IsEmpty() && |
| 492 url_component_matcher_.IsEmpty() && |
| 493 registered_full_url_patterns_.empty() && |
| 494 registered_url_component_patterns_.empty(); |
| 495 } |
| 496 |
483 void URLMatcher::UpdateSubstringSetMatcher(bool full_url_conditions) { | 497 void URLMatcher::UpdateSubstringSetMatcher(bool full_url_conditions) { |
484 // The purpose of |full_url_conditions| is just that we need to execute | 498 // The purpose of |full_url_conditions| is just that we need to execute |
485 // the same logic once for Full URL searches and once for URL Component | 499 // the same logic once for Full URL searches and once for URL Component |
486 // searches (see URLMatcherConditionFactory). | 500 // searches (see URLMatcherConditionFactory). |
487 | 501 |
488 // Determine which patterns need to be registered when this function | 502 // Determine which patterns need to be registered when this function |
489 // terminates. | 503 // terminates. |
490 std::set<const SubstringPattern*> new_patterns; | 504 std::set<const SubstringPattern*> new_patterns; |
491 for (URLMatcherConditionSets::const_iterator condition_set_iter = | 505 for (URLMatcherConditionSets::const_iterator condition_set_iter = |
492 url_matcher_condition_sets_.begin(); | 506 url_matcher_condition_sets_.begin(); |
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
604 } | 618 } |
605 | 619 |
606 void URLMatcher::UpdateInternalDatastructures() { | 620 void URLMatcher::UpdateInternalDatastructures() { |
607 UpdateSubstringSetMatcher(false); | 621 UpdateSubstringSetMatcher(false); |
608 UpdateSubstringSetMatcher(true); | 622 UpdateSubstringSetMatcher(true); |
609 UpdateTriggers(); | 623 UpdateTriggers(); |
610 UpdateConditionFactory(); | 624 UpdateConditionFactory(); |
611 } | 625 } |
612 | 626 |
613 } // namespace extensions | 627 } // namespace extensions |
OLD | NEW |