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

Side by Side Diff: extensions/browser/api/declarative_webrequest/webrequest_condition_attribute.cc

Issue 1239493005: Remove some legacy versions of StartsWith and EndsWith. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: merge Created 5 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
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 "extensions/browser/api/declarative_webrequest/webrequest_condition_att ribute.h" 5 #include "extensions/browser/api/declarative_webrequest/webrequest_condition_att ribute.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/lazy_instance.h" 9 #include "base/lazy_instance.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
(...skipping 312 matching lines...) Expand 10 before | Expand all | Expand 10 after
323 // Does |str| pass |this| StringMatchTest? 323 // Does |str| pass |this| StringMatchTest?
324 bool Matches(const std::string& str) const; 324 bool Matches(const std::string& str) const;
325 325
326 private: 326 private:
327 StringMatchTest(const std::string& data, 327 StringMatchTest(const std::string& data,
328 MatchType type, 328 MatchType type,
329 bool case_sensitive); 329 bool case_sensitive);
330 330
331 const std::string data_; 331 const std::string data_;
332 const MatchType type_; 332 const MatchType type_;
333 const bool case_sensitive_; 333 const base::CompareCase case_sensitive_;
334 DISALLOW_COPY_AND_ASSIGN(StringMatchTest); 334 DISALLOW_COPY_AND_ASSIGN(StringMatchTest);
335 }; 335 };
336 336
337 // Represents a test group -- a set of string matching tests to be applied to 337 // Represents a test group -- a set of string matching tests to be applied to
338 // both the header name and value. 338 // both the header name and value.
339 class HeaderMatchTest { 339 class HeaderMatchTest {
340 public: 340 public:
341 ~HeaderMatchTest(); 341 ~HeaderMatchTest();
342 342
343 // Gets the test group description in |tests| and creates the corresponding 343 // Gets the test group description in |tests| and creates the corresponding
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
415 return scoped_ptr<StringMatchTest>( 415 return scoped_ptr<StringMatchTest>(
416 new StringMatchTest(str, type, case_sensitive)); 416 new StringMatchTest(str, type, case_sensitive));
417 } 417 }
418 418
419 HeaderMatcher::StringMatchTest::~StringMatchTest() {} 419 HeaderMatcher::StringMatchTest::~StringMatchTest() {}
420 420
421 bool HeaderMatcher::StringMatchTest::Matches( 421 bool HeaderMatcher::StringMatchTest::Matches(
422 const std::string& str) const { 422 const std::string& str) const {
423 switch (type_) { 423 switch (type_) {
424 case kPrefix: 424 case kPrefix:
425 return base::StartsWithASCII(str, data_, case_sensitive_); 425 return base::StartsWith(str, data_, case_sensitive_);
426 case kSuffix: 426 case kSuffix:
427 return base::EndsWith(str, data_, case_sensitive_); 427 return base::EndsWith(str, data_, case_sensitive_);
428 case kEquals: 428 case kEquals:
429 return str.size() == data_.size() && 429 return str.size() == data_.size() &&
430 base::StartsWithASCII(str, data_, case_sensitive_); 430 base::StartsWith(str, data_, case_sensitive_);
431 case kContains: 431 case kContains:
432 if (!case_sensitive_) { 432 if (case_sensitive_ == base::CompareCase::INSENSITIVE_ASCII) {
433 return std::search(str.begin(), str.end(), data_.begin(), data_.end(), 433 return std::search(str.begin(), str.end(), data_.begin(), data_.end(),
434 CaseInsensitiveCompareASCII<char>()) != str.end(); 434 CaseInsensitiveCompareASCII<char>()) != str.end();
435 } else { 435 } else {
436 return str.find(data_) != std::string::npos; 436 return str.find(data_) != std::string::npos;
437 } 437 }
438 } 438 }
439 // We never get past the "switch", but the compiler worries about no return. 439 // We never get past the "switch", but the compiler worries about no return.
440 NOTREACHED(); 440 NOTREACHED();
441 return false; 441 return false;
442 } 442 }
443 443
444 HeaderMatcher::StringMatchTest::StringMatchTest(const std::string& data, 444 HeaderMatcher::StringMatchTest::StringMatchTest(const std::string& data,
445 MatchType type, 445 MatchType type,
446 bool case_sensitive) 446 bool case_sensitive)
447 : data_(data), 447 : data_(data),
448 type_(type), 448 type_(type),
449 case_sensitive_(case_sensitive) {} 449 case_sensitive_(case_sensitive ? base::CompareCase::SENSITIVE
450 : base::CompareCase::INSENSITIVE_ASCII) {}
450 451
451 // HeaderMatcher::HeaderMatchTest implementation. 452 // HeaderMatcher::HeaderMatchTest implementation.
452 453
453 HeaderMatcher::HeaderMatchTest::HeaderMatchTest( 454 HeaderMatcher::HeaderMatchTest::HeaderMatchTest(
454 ScopedVector<const StringMatchTest>* name_match, 455 ScopedVector<const StringMatchTest>* name_match,
455 ScopedVector<const StringMatchTest>* value_match) 456 ScopedVector<const StringMatchTest>* value_match)
456 : name_match_(name_match->Pass()), 457 : name_match_(name_match->Pass()),
457 value_match_(value_match->Pass()) {} 458 value_match_(value_match->Pass()) {}
458 459
459 HeaderMatcher::HeaderMatchTest::~HeaderMatchTest() {} 460 HeaderMatcher::HeaderMatchTest::~HeaderMatchTest() {}
(...skipping 409 matching lines...) Expand 10 before | Expand all | Expand 10 after
869 bool WebRequestConditionAttributeStages::Equals( 870 bool WebRequestConditionAttributeStages::Equals(
870 const WebRequestConditionAttribute* other) const { 871 const WebRequestConditionAttribute* other) const {
871 if (!WebRequestConditionAttribute::Equals(other)) 872 if (!WebRequestConditionAttribute::Equals(other))
872 return false; 873 return false;
873 const WebRequestConditionAttributeStages* casted_other = 874 const WebRequestConditionAttributeStages* casted_other =
874 static_cast<const WebRequestConditionAttributeStages*>(other); 875 static_cast<const WebRequestConditionAttributeStages*>(other);
875 return allowed_stages_ == casted_other->allowed_stages_; 876 return allowed_stages_ == casted_other->allowed_stages_;
876 } 877 }
877 878
878 } // namespace extensions 879 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698