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

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

Issue 2000803003: Use std::unique_ptr for base::DictionaryValue and base::ListValue's internal store. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: More fixes Created 4 years, 7 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
« no previous file with comments | « dbus/values_util.cc ('k') | extensions/browser/api/device_permissions_manager.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 <stddef.h> 7 #include <stddef.h>
8 8
9 #include <algorithm> 9 #include <algorithm>
10 #include <utility> 10 #include <utility>
(...skipping 302 matching lines...) Expand 10 before | Expand all | Expand 10 after
313 bool TestNameValue(const std::string& name, const std::string& value) const; 313 bool TestNameValue(const std::string& name, const std::string& value) const;
314 314
315 private: 315 private:
316 // Represents a single string-matching test. 316 // Represents a single string-matching test.
317 class StringMatchTest { 317 class StringMatchTest {
318 public: 318 public:
319 enum MatchType { kPrefix, kSuffix, kEquals, kContains }; 319 enum MatchType { kPrefix, kSuffix, kEquals, kContains };
320 320
321 // |data| is the pattern to be matched in the position given by |type|. 321 // |data| is the pattern to be matched in the position given by |type|.
322 // Note that |data| must point to a StringValue object. 322 // Note that |data| must point to a StringValue object.
323 static std::unique_ptr<StringMatchTest> Create(const base::Value* data, 323 static std::unique_ptr<StringMatchTest> Create(const base::Value& data,
324 MatchType type, 324 MatchType type,
325 bool case_sensitive); 325 bool case_sensitive);
326 ~StringMatchTest(); 326 ~StringMatchTest();
327 327
328 // Does |str| pass |this| StringMatchTest? 328 // Does |str| pass |this| StringMatchTest?
329 bool Matches(const std::string& str) const; 329 bool Matches(const std::string& str) const;
330 330
331 private: 331 private:
332 StringMatchTest(const std::string& data, 332 StringMatchTest(const std::string& data,
333 MatchType type, 333 MatchType type,
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
410 } 410 }
411 411
412 HeaderMatcher::HeaderMatcher( 412 HeaderMatcher::HeaderMatcher(
413 std::vector<std::unique_ptr<const HeaderMatchTest>> tests) 413 std::vector<std::unique_ptr<const HeaderMatchTest>> tests)
414 : tests_(std::move(tests)) {} 414 : tests_(std::move(tests)) {}
415 415
416 // HeaderMatcher::StringMatchTest implementation. 416 // HeaderMatcher::StringMatchTest implementation.
417 417
418 // static 418 // static
419 std::unique_ptr<HeaderMatcher::StringMatchTest> 419 std::unique_ptr<HeaderMatcher::StringMatchTest>
420 HeaderMatcher::StringMatchTest::Create(const base::Value* data, 420 HeaderMatcher::StringMatchTest::Create(const base::Value& data,
421 MatchType type, 421 MatchType type,
422 bool case_sensitive) { 422 bool case_sensitive) {
423 std::string str; 423 std::string str;
424 CHECK(data->GetAsString(&str)); 424 CHECK(data.GetAsString(&str));
425 return std::unique_ptr<StringMatchTest>( 425 return base::WrapUnique(new StringMatchTest(str, type, case_sensitive));
426 new StringMatchTest(str, type, case_sensitive));
427 } 426 }
428 427
429 HeaderMatcher::StringMatchTest::~StringMatchTest() {} 428 HeaderMatcher::StringMatchTest::~StringMatchTest() {}
430 429
431 bool HeaderMatcher::StringMatchTest::Matches( 430 bool HeaderMatcher::StringMatchTest::Matches(
432 const std::string& str) const { 431 const std::string& str) const {
433 switch (type_) { 432 switch (type_) {
434 case kPrefix: 433 case kPrefix:
435 return base::StartsWith(str, data_, case_sensitive_); 434 return base::StartsWith(str, data_, case_sensitive_);
436 case kSuffix: 435 case kSuffix:
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
504 return std::unique_ptr<const HeaderMatchTest>(); 503 return std::unique_ptr<const HeaderMatchTest>();
505 } 504 }
506 const base::Value* content = &it.value(); 505 const base::Value* content = &it.value();
507 506
508 std::vector<std::unique_ptr<const StringMatchTest>>* tests = 507 std::vector<std::unique_ptr<const StringMatchTest>>* tests =
509 is_name ? &name_match : &value_match; 508 is_name ? &name_match : &value_match;
510 switch (content->GetType()) { 509 switch (content->GetType()) {
511 case base::Value::TYPE_LIST: { 510 case base::Value::TYPE_LIST: {
512 const base::ListValue* list = NULL; 511 const base::ListValue* list = NULL;
513 CHECK(content->GetAsList(&list)); 512 CHECK(content->GetAsList(&list));
514 for (base::ListValue::const_iterator it = list->begin(); 513 for (const auto& it : *list) {
515 it != list->end(); ++it) { 514 tests->push_back(StringMatchTest::Create(*it, match_type, !is_name));
516 tests->push_back(base::WrapUnique(
517 StringMatchTest::Create(*it, match_type, !is_name).release()));
518 } 515 }
519 break; 516 break;
520 } 517 }
521 case base::Value::TYPE_STRING: { 518 case base::Value::TYPE_STRING: {
522 tests->push_back(base::WrapUnique( 519 tests->push_back(
523 StringMatchTest::Create(content, match_type, !is_name).release())); 520 StringMatchTest::Create(*content, match_type, !is_name));
524 break; 521 break;
525 } 522 }
526 default: { 523 default: {
527 NOTREACHED(); // JSON schema type checking should prevent this. 524 NOTREACHED(); // JSON schema type checking should prevent this.
528 return std::unique_ptr<const HeaderMatchTest>(); 525 return std::unique_ptr<const HeaderMatchTest>();
529 } 526 }
530 } 527 }
531 } 528 }
532 529
533 return std::unique_ptr<const HeaderMatchTest>( 530 return std::unique_ptr<const HeaderMatchTest>(
(...skipping 344 matching lines...) Expand 10 before | Expand all | Expand 10 after
878 bool WebRequestConditionAttributeStages::Equals( 875 bool WebRequestConditionAttributeStages::Equals(
879 const WebRequestConditionAttribute* other) const { 876 const WebRequestConditionAttribute* other) const {
880 if (!WebRequestConditionAttribute::Equals(other)) 877 if (!WebRequestConditionAttribute::Equals(other))
881 return false; 878 return false;
882 const WebRequestConditionAttributeStages* casted_other = 879 const WebRequestConditionAttributeStages* casted_other =
883 static_cast<const WebRequestConditionAttributeStages*>(other); 880 static_cast<const WebRequestConditionAttributeStages*>(other);
884 return allowed_stages_ == casted_other->allowed_stages_; 881 return allowed_stages_ == casted_other->allowed_stages_;
885 } 882 }
886 883
887 } // namespace extensions 884 } // namespace extensions
OLDNEW
« no previous file with comments | « dbus/values_util.cc ('k') | extensions/browser/api/device_permissions_manager.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698