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

Side by Side Diff: chrome/common/extensions/matcher/url_matcher.cc

Issue 10692158: Refactor URLBlacklistManager to use URLMatcher. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: joao Created 8 years, 5 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 | Annotate | Revision Log
OLDNEW
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/common/extensions/matcher/url_matcher.h" 5 #include "chrome/common/extensions/matcher/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 241 matching lines...) Expand 10 before | Expand all | Expand 10 after
252 } 252 }
253 253
254 URLMatcherCondition URLMatcherConditionFactory::CreatePathPrefixCondition( 254 URLMatcherCondition URLMatcherConditionFactory::CreatePathPrefixCondition(
255 const std::string& prefix) { 255 const std::string& prefix) {
256 return CreateCondition(URLMatcherCondition::PATH_PREFIX, 256 return CreateCondition(URLMatcherCondition::PATH_PREFIX,
257 kEndOfDomain + prefix); 257 kEndOfDomain + prefix);
258 } 258 }
259 259
260 URLMatcherCondition URLMatcherConditionFactory::CreatePathSuffixCondition( 260 URLMatcherCondition URLMatcherConditionFactory::CreatePathSuffixCondition(
261 const std::string& suffix) { 261 const std::string& suffix) {
262 return CreateCondition(URLMatcherCondition::HOST_SUFFIX, suffix + kEndOfPath); 262 return CreateCondition(URLMatcherCondition::PATH_SUFFIX, suffix + kEndOfPath);
263 } 263 }
264 264
265 URLMatcherCondition URLMatcherConditionFactory::CreatePathContainsCondition( 265 URLMatcherCondition URLMatcherConditionFactory::CreatePathContainsCondition(
266 const std::string& str) { 266 const std::string& str) {
267 return CreateCondition(URLMatcherCondition::PATH_CONTAINS, str); 267 return CreateCondition(URLMatcherCondition::PATH_CONTAINS, str);
268 } 268 }
269 269
270 URLMatcherCondition URLMatcherConditionFactory::CreatePathEqualsCondition( 270 URLMatcherCondition URLMatcherConditionFactory::CreatePathEqualsCondition(
271 const std::string& str) { 271 const std::string& str) {
272 return CreateCondition(URLMatcherCondition::PATH_EQUALS, 272 return CreateCondition(URLMatcherCondition::PATH_EQUALS,
(...skipping 23 matching lines...) Expand all
296 } 296 }
297 297
298 URLMatcherCondition 298 URLMatcherCondition
299 URLMatcherConditionFactory::CreateHostSuffixPathPrefixCondition( 299 URLMatcherConditionFactory::CreateHostSuffixPathPrefixCondition(
300 const std::string& host_suffix, 300 const std::string& host_suffix,
301 const std::string& path_prefix) { 301 const std::string& path_prefix) {
302 return CreateCondition(URLMatcherCondition::HOST_SUFFIX_PATH_PREFIX, 302 return CreateCondition(URLMatcherCondition::HOST_SUFFIX_PATH_PREFIX,
303 host_suffix + kEndOfDomain + path_prefix); 303 host_suffix + kEndOfDomain + path_prefix);
304 } 304 }
305 305
306 URLMatcherCondition
307 URLMatcherConditionFactory::CreateHostEqualsPathPrefixCondition(
308 const std::string& host,
309 const std::string& path_prefix) {
310 return CreateCondition(URLMatcherCondition::HOST_EQUALS_PATH_PREFIX,
311 kBeginningOfURL + CanonicalizeHostname(host) + kEndOfDomain +
312 path_prefix);
313 }
314
306 std::string URLMatcherConditionFactory::CanonicalizeURLForFullSearches( 315 std::string URLMatcherConditionFactory::CanonicalizeURLForFullSearches(
307 const GURL& url) { 316 const GURL& url) {
308 return kBeginningOfURL + CanonicalizeHostname(url.host()) + url.path() + 317 return kBeginningOfURL + CanonicalizeHostname(url.host()) + url.path() +
309 (url.has_query() ? "?" + url.query() : "") + kEndOfURL; 318 (url.has_query() ? "?" + url.query() : "") + kEndOfURL;
310 } 319 }
311 320
312 URLMatcherCondition URLMatcherConditionFactory::CreateURLPrefixCondition( 321 URLMatcherCondition URLMatcherConditionFactory::CreateURLPrefixCondition(
313 const std::string& prefix) { 322 const std::string& prefix) {
314 return CreateCondition(URLMatcherCondition::URL_PREFIX, 323 return CreateCondition(URLMatcherCondition::URL_PREFIX,
315 kBeginningOfURL + CanonicalizeHostname(prefix)); 324 kBeginningOfURL + CanonicalizeHostname(prefix));
316 } 325 }
317 326
318 URLMatcherCondition URLMatcherConditionFactory::CreateURLSuffixCondition( 327 URLMatcherCondition URLMatcherConditionFactory::CreateURLSuffixCondition(
319 const std::string& suffix) { 328 const std::string& suffix) {
320 return CreateCondition(URLMatcherCondition::URL_SUFFIX, suffix + kEndOfURL); 329 return CreateCondition(URLMatcherCondition::URL_SUFFIX, suffix + kEndOfURL);
321 } 330 }
322 331
323 URLMatcherCondition URLMatcherConditionFactory::CreateURLContainsCondition( 332 URLMatcherCondition URLMatcherConditionFactory::CreateURLContainsCondition(
324 const std::string& str) { 333 const std::string& str) {
325 return CreateCondition(URLMatcherCondition::URL_CONTAINS, str); 334 return CreateCondition(URLMatcherCondition::URL_CONTAINS, str);
326 } 335 }
327 336
328 URLMatcherCondition URLMatcherConditionFactory::CreateURLEqualsCondition( 337 URLMatcherCondition URLMatcherConditionFactory::CreateURLEqualsCondition(
329 const std::string& str) { 338 const std::string& str) {
330 return CreateCondition(URLMatcherCondition::QUERY_EQUALS, 339 return CreateCondition(URLMatcherCondition::URL_EQUALS,
331 kBeginningOfURL + CanonicalizeHostname(str) + kEndOfURL); 340 kBeginningOfURL + CanonicalizeHostname(str) + kEndOfURL);
332 } 341 }
333 342
334 void URLMatcherConditionFactory::ForgetUnusedPatterns( 343 void URLMatcherConditionFactory::ForgetUnusedPatterns(
335 const std::set<SubstringPattern::ID>& used_patterns) { 344 const std::set<SubstringPattern::ID>& used_patterns) {
336 PatternSingletons::iterator i = pattern_singletons_.begin(); 345 PatternSingletons::iterator i = pattern_singletons_.begin();
337 while (i != pattern_singletons_.end()) { 346 while (i != pattern_singletons_.end()) {
338 if (used_patterns.find((*i)->id()) != used_patterns.end()) { 347 if (used_patterns.find((*i)->id()) != used_patterns.end()) {
339 ++i; 348 ++i;
340 } else { 349 } else {
(...skipping 329 matching lines...) Expand 10 before | Expand all | Expand 10 after
670 } 679 }
671 680
672 void URLMatcher::UpdateInternalDatastructures() { 681 void URLMatcher::UpdateInternalDatastructures() {
673 UpdateSubstringSetMatcher(false); 682 UpdateSubstringSetMatcher(false);
674 UpdateSubstringSetMatcher(true); 683 UpdateSubstringSetMatcher(true);
675 UpdateTriggers(); 684 UpdateTriggers();
676 UpdateConditionFactory(); 685 UpdateConditionFactory();
677 } 686 }
678 687
679 } // namespace extensions 688 } // namespace extensions
OLDNEW
« no previous file with comments | « chrome/common/extensions/matcher/url_matcher.h ('k') | chrome/common/extensions/matcher/url_matcher_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698