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

Side by Side Diff: chrome/common/extensions/url_pattern_set.cc

Issue 7347011: Update URLPatternSet to contain a std::set instead of std::vector. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix windows compile errors. Created 9 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) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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/url_pattern_set.h" 5 #include "chrome/common/extensions/url_pattern_set.h"
6 6
7 #include <algorithm>
8 #include <iterator>
9
7 #include "chrome/common/extensions/url_pattern.h" 10 #include "chrome/common/extensions/url_pattern.h"
8 #include "googleurl/src/gurl.h" 11 #include "googleurl/src/gurl.h"
9 12
10 // static 13 // static
11 void URLPatternSet::CreateUnion(const URLPatternSet& set1, 14 void URLPatternSet::CreateUnion(const URLPatternSet& set1,
12 const URLPatternSet& set2, 15 const URLPatternSet& set2,
13 URLPatternSet* out) { 16 URLPatternSet* out) {
14 const URLPatternList list1 = set1.patterns();
15 const URLPatternList list2 = set2.patterns();
16
17 out->ClearPatterns(); 17 out->ClearPatterns();
18 18 std::set_union(set1.patterns_.begin(), set1.patterns_.end(),
19 for (size_t i = 0; i < list1.size(); ++i) 19 set2.patterns_.begin(), set2.patterns_.end(),
20 out->AddPattern(list1.at(i)); 20 std::inserter<std::set<URLPattern> >(
21 21 out->patterns_, out->patterns_.begin()));
22 for (size_t i = 0; i < list2.size(); ++i)
23 out->AddPattern(list2.at(i));
24 } 22 }
25 23
26 URLPatternSet::URLPatternSet() { 24 URLPatternSet::URLPatternSet() {}
27 }
28 25
29 URLPatternSet::URLPatternSet(const URLPatternSet& rhs) 26 URLPatternSet::URLPatternSet(const URLPatternSet& rhs)
30 : patterns_(rhs.patterns_) { 27 : patterns_(rhs.patterns_) {}
31 }
32 28
33 URLPatternSet::~URLPatternSet() { 29 URLPatternSet::URLPatternSet(const std::set<URLPattern>& patterns)
34 } 30 : patterns_(patterns) {}
31
32 URLPatternSet::~URLPatternSet() {}
35 33
36 URLPatternSet& URLPatternSet::operator=(const URLPatternSet& rhs) { 34 URLPatternSet& URLPatternSet::operator=(const URLPatternSet& rhs) {
37 patterns_ = rhs.patterns_; 35 patterns_ = rhs.patterns_;
38 return *this; 36 return *this;
39 } 37 }
40 38
39 bool URLPatternSet::operator==(const URLPatternSet& other) const {
40 return patterns_ == other.patterns_;
41 }
42
41 bool URLPatternSet::is_empty() const { 43 bool URLPatternSet::is_empty() const {
42 return patterns_.empty(); 44 return patterns_.empty();
43 } 45 }
44 46
45 void URLPatternSet::AddPattern(const URLPattern& pattern) { 47 void URLPatternSet::AddPattern(const URLPattern& pattern) {
46 patterns_.push_back(pattern); 48 patterns_.insert(pattern);
47 } 49 }
48 50
49 void URLPatternSet::ClearPatterns() { 51 void URLPatternSet::ClearPatterns() {
50 patterns_.clear(); 52 patterns_.clear();
51 } 53 }
52 54
53 bool URLPatternSet::MatchesURL(const GURL& url) const { 55 bool URLPatternSet::MatchesURL(const GURL& url) const {
54 for (URLPatternList::const_iterator pattern = patterns_.begin(); 56 for (URLPatternSet::const_iterator pattern = patterns_.begin();
55 pattern != patterns_.end(); ++pattern) { 57 pattern != patterns_.end(); ++pattern) {
56 if (pattern->MatchesURL(url)) 58 if (pattern->MatchesURL(url))
57 return true; 59 return true;
58 } 60 }
59 61
60 return false; 62 return false;
61 } 63 }
62 64
63 bool URLPatternSet::OverlapsWith(const URLPatternSet& other) const { 65 bool URLPatternSet::OverlapsWith(const URLPatternSet& other) const {
64 // Two extension extents overlap if there is any one URL that would match at 66 // Two extension extents overlap if there is any one URL that would match at
65 // least one pattern in each of the extents. 67 // least one pattern in each of the extents.
66 for (URLPatternList::const_iterator i = patterns_.begin(); 68 for (URLPatternSet::const_iterator i = patterns_.begin();
67 i != patterns_.end(); ++i) { 69 i != patterns_.end(); ++i) {
68 for (URLPatternList::const_iterator j = other.patterns().begin(); 70 for (URLPatternSet::const_iterator j = other.patterns().begin();
69 j != other.patterns().end(); ++j) { 71 j != other.patterns().end(); ++j) {
70 if (i->OverlapsWith(*j)) 72 if (i->OverlapsWith(*j))
71 return true; 73 return true;
72 } 74 }
73 } 75 }
74 76
75 return false; 77 return false;
76 } 78 }
OLDNEW
« no previous file with comments | « chrome/common/extensions/url_pattern_set.h ('k') | chrome/common/extensions/url_pattern_set_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698