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

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

Issue 16703018: Rewrite scoped_ptr<T>(NULL) to use the default ctor in chrome/. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 6 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/browser/extensions/api/declarative_webrequest/webrequest_condit ion_attribute.h" 5 #include "chrome/browser/extensions/api/declarative_webrequest/webrequest_condit ion_attribute.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 361 matching lines...) Expand 10 before | Expand all | Expand 10 after
372 HeaderMatcher::~HeaderMatcher() {} 372 HeaderMatcher::~HeaderMatcher() {}
373 373
374 // static 374 // static
375 scoped_ptr<const HeaderMatcher> HeaderMatcher::Create( 375 scoped_ptr<const HeaderMatcher> HeaderMatcher::Create(
376 const base::ListValue* tests) { 376 const base::ListValue* tests) {
377 ScopedVector<const HeaderMatchTest> header_tests; 377 ScopedVector<const HeaderMatchTest> header_tests;
378 for (ListValue::const_iterator it = tests->begin(); 378 for (ListValue::const_iterator it = tests->begin();
379 it != tests->end(); ++it) { 379 it != tests->end(); ++it) {
380 const DictionaryValue* tests = NULL; 380 const DictionaryValue* tests = NULL;
381 if (!(*it)->GetAsDictionary(&tests)) 381 if (!(*it)->GetAsDictionary(&tests))
382 return scoped_ptr<const HeaderMatcher>(NULL); 382 return scoped_ptr<const HeaderMatcher>();
383 383
384 scoped_ptr<const HeaderMatchTest> header_test( 384 scoped_ptr<const HeaderMatchTest> header_test(
385 HeaderMatchTest::Create(tests)); 385 HeaderMatchTest::Create(tests));
386 if (header_test.get() == NULL) 386 if (header_test.get() == NULL)
387 return scoped_ptr<const HeaderMatcher>(NULL); 387 return scoped_ptr<const HeaderMatcher>();
388 header_tests.push_back(header_test.release()); 388 header_tests.push_back(header_test.release());
389 } 389 }
390 390
391 return scoped_ptr<const HeaderMatcher>(new HeaderMatcher(&header_tests)); 391 return scoped_ptr<const HeaderMatcher>(new HeaderMatcher(&header_tests));
392 } 392 }
393 393
394 bool HeaderMatcher::TestNameValue(const std::string& name, 394 bool HeaderMatcher::TestNameValue(const std::string& name,
395 const std::string& value) const { 395 const std::string& value) const {
396 for (size_t i = 0; i < tests_.size(); ++i) { 396 for (size_t i = 0; i < tests_.size(); ++i) {
397 if (tests_[i]->Matches(name, value)) 397 if (tests_[i]->Matches(name, value))
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
482 } else if (it.key() == keys::kValuePrefixKey) { 482 } else if (it.key() == keys::kValuePrefixKey) {
483 match_type = StringMatchTest::kPrefix; 483 match_type = StringMatchTest::kPrefix;
484 } else if (it.key() == keys::kValueSuffixKey) { 484 } else if (it.key() == keys::kValueSuffixKey) {
485 match_type = StringMatchTest::kSuffix; 485 match_type = StringMatchTest::kSuffix;
486 } else if (it.key() == keys::kValueContainsKey) { 486 } else if (it.key() == keys::kValueContainsKey) {
487 match_type = StringMatchTest::kContains; 487 match_type = StringMatchTest::kContains;
488 } else if (it.key() == keys::kValueEqualsKey) { 488 } else if (it.key() == keys::kValueEqualsKey) {
489 match_type = StringMatchTest::kEquals; 489 match_type = StringMatchTest::kEquals;
490 } else { 490 } else {
491 NOTREACHED(); // JSON schema type checking should prevent this. 491 NOTREACHED(); // JSON schema type checking should prevent this.
492 return scoped_ptr<const HeaderMatchTest>(NULL); 492 return scoped_ptr<const HeaderMatchTest>();
493 } 493 }
494 const Value* content = &it.value(); 494 const Value* content = &it.value();
495 495
496 ScopedVector<const StringMatchTest>* tests = 496 ScopedVector<const StringMatchTest>* tests =
497 is_name ? &name_match : &value_match; 497 is_name ? &name_match : &value_match;
498 switch (content->GetType()) { 498 switch (content->GetType()) {
499 case Value::TYPE_LIST: { 499 case Value::TYPE_LIST: {
500 const ListValue* list = NULL; 500 const ListValue* list = NULL;
501 CHECK(content->GetAsList(&list)); 501 CHECK(content->GetAsList(&list));
502 for (ListValue::const_iterator it = list->begin(); 502 for (ListValue::const_iterator it = list->begin();
503 it != list->end(); ++it) { 503 it != list->end(); ++it) {
504 tests->push_back( 504 tests->push_back(
505 StringMatchTest::Create(*it, match_type, !is_name).release()); 505 StringMatchTest::Create(*it, match_type, !is_name).release());
506 } 506 }
507 break; 507 break;
508 } 508 }
509 case Value::TYPE_STRING: { 509 case Value::TYPE_STRING: {
510 tests->push_back( 510 tests->push_back(
511 StringMatchTest::Create(content, match_type, !is_name).release()); 511 StringMatchTest::Create(content, match_type, !is_name).release());
512 break; 512 break;
513 } 513 }
514 default: { 514 default: {
515 NOTREACHED(); // JSON schema type checking should prevent this. 515 NOTREACHED(); // JSON schema type checking should prevent this.
516 return scoped_ptr<const HeaderMatchTest>(NULL); 516 return scoped_ptr<const HeaderMatchTest>();
517 } 517 }
518 } 518 }
519 } 519 }
520 520
521 return scoped_ptr<const HeaderMatchTest>( 521 return scoped_ptr<const HeaderMatchTest>(
522 new HeaderMatchTest(&name_match, &value_match)); 522 new HeaderMatchTest(&name_match, &value_match));
523 } 523 }
524 524
525 bool HeaderMatcher::HeaderMatchTest::Matches(const std::string& name, 525 bool HeaderMatcher::HeaderMatchTest::Matches(const std::string& name,
526 const std::string& value) const { 526 const std::string& value) const {
(...skipping 26 matching lines...) Expand all
553 553
554 namespace { 554 namespace {
555 555
556 scoped_ptr<const HeaderMatcher> PrepareHeaderMatcher( 556 scoped_ptr<const HeaderMatcher> PrepareHeaderMatcher(
557 const std::string& name, 557 const std::string& name,
558 const base::Value* value, 558 const base::Value* value,
559 std::string* error) { 559 std::string* error) {
560 const ListValue* value_as_list = NULL; 560 const ListValue* value_as_list = NULL;
561 if (!value->GetAsList(&value_as_list)) { 561 if (!value->GetAsList(&value_as_list)) {
562 *error = ErrorUtils::FormatErrorMessage(kInvalidValue, name); 562 *error = ErrorUtils::FormatErrorMessage(kInvalidValue, name);
563 return scoped_ptr<const HeaderMatcher>(NULL); 563 return scoped_ptr<const HeaderMatcher>();
564 } 564 }
565 565
566 scoped_ptr<const HeaderMatcher> header_matcher( 566 scoped_ptr<const HeaderMatcher> header_matcher(
567 HeaderMatcher::Create(value_as_list)); 567 HeaderMatcher::Create(value_as_list));
568 if (header_matcher.get() == NULL) 568 if (header_matcher.get() == NULL)
569 *error = ErrorUtils::FormatErrorMessage(kInvalidValue, name); 569 *error = ErrorUtils::FormatErrorMessage(kInvalidValue, name);
570 return header_matcher.Pass(); 570 return header_matcher.Pass();
571 } 571 }
572 572
573 } // namespace 573 } // namespace
(...skipping 293 matching lines...) Expand 10 before | Expand all | Expand 10 after
867 bool WebRequestConditionAttributeStages::Equals( 867 bool WebRequestConditionAttributeStages::Equals(
868 const WebRequestConditionAttribute* other) const { 868 const WebRequestConditionAttribute* other) const {
869 if (!WebRequestConditionAttribute::Equals(other)) 869 if (!WebRequestConditionAttribute::Equals(other))
870 return false; 870 return false;
871 const WebRequestConditionAttributeStages* casted_other = 871 const WebRequestConditionAttributeStages* casted_other =
872 static_cast<const WebRequestConditionAttributeStages*>(other); 872 static_cast<const WebRequestConditionAttributeStages*>(other);
873 return allowed_stages_ == casted_other->allowed_stages_; 873 return allowed_stages_ == casted_other->allowed_stages_;
874 } 874 }
875 875
876 } // namespace extensions 876 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698