OLD | NEW |
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/common/url_pattern_set.h" | 5 #include "extensions/common/url_pattern_set.h" |
6 | 6 |
7 #include <algorithm> | |
8 #include <iterator> | 7 #include <iterator> |
9 | 8 |
10 #include "base/logging.h" | 9 #include "base/logging.h" |
11 #include "base/memory/linked_ptr.h" | 10 #include "base/memory/linked_ptr.h" |
12 #include "base/stl_util.h" | 11 #include "base/stl_util.h" |
13 #include "base/values.h" | 12 #include "base/values.h" |
14 #include "content/public/common/url_constants.h" | 13 #include "content/public/common/url_constants.h" |
15 #include "extensions/common/error_utils.h" | 14 #include "extensions/common/error_utils.h" |
16 #include "extensions/common/url_pattern.h" | 15 #include "extensions/common/url_pattern.h" |
17 #include "url/gurl.h" | 16 #include "url/gurl.h" |
18 | 17 |
19 namespace extensions { | 18 namespace extensions { |
20 | 19 |
21 namespace { | 20 namespace { |
22 | 21 |
23 const char kInvalidURLPatternError[] = "Invalid url pattern '*'"; | 22 const char kInvalidURLPatternError[] = "Invalid url pattern '*'"; |
24 | 23 |
25 } // namespace | 24 } // namespace |
26 | 25 |
27 // static | 26 // static |
28 void URLPatternSet::CreateDifference(const URLPatternSet& set1, | 27 void URLPatternSet::CreateDifference(const URLPatternSet& set1, |
29 const URLPatternSet& set2, | 28 const URLPatternSet& set2, |
30 URLPatternSet* out) { | 29 URLPatternSet* out) { |
31 out->ClearPatterns(); | |
32 out->patterns_ = base::STLSetDifference<std::set<URLPattern> >( | 30 out->patterns_ = base::STLSetDifference<std::set<URLPattern> >( |
33 set1.patterns_, set2.patterns_); | 31 set1.patterns_, set2.patterns_); |
34 } | 32 } |
35 | 33 |
36 // static | 34 // static |
37 void URLPatternSet::CreateIntersection(const URLPatternSet& set1, | 35 void URLPatternSet::CreateIntersection(const URLPatternSet& set1, |
38 const URLPatternSet& set2, | 36 const URLPatternSet& set2, |
39 URLPatternSet* out) { | 37 URLPatternSet* out) { |
40 out->ClearPatterns(); | 38 out->patterns_ = base::STLSetIntersection<std::set<URLPattern> >( |
41 std::set_intersection(set1.patterns_.begin(), set1.patterns_.end(), | 39 set1.patterns_, set2.patterns_); |
42 set2.patterns_.begin(), set2.patterns_.end(), | |
43 std::inserter<std::set<URLPattern> >( | |
44 out->patterns_, out->patterns_.begin())); | |
45 } | 40 } |
46 | 41 |
47 // static | 42 // static |
48 void URLPatternSet::CreateUnion(const URLPatternSet& set1, | 43 void URLPatternSet::CreateUnion(const URLPatternSet& set1, |
49 const URLPatternSet& set2, | 44 const URLPatternSet& set2, |
50 URLPatternSet* out) { | 45 URLPatternSet* out) { |
51 out->ClearPatterns(); | 46 out->patterns_ = base::STLSetUnion<std::set<URLPattern> >( |
52 std::set_union(set1.patterns_.begin(), set1.patterns_.end(), | 47 set1.patterns_, set2.patterns_); |
53 set2.patterns_.begin(), set2.patterns_.end(), | |
54 std::inserter<std::set<URLPattern> >( | |
55 out->patterns_, out->patterns_.begin())); | |
56 } | 48 } |
57 | 49 |
58 // static | 50 // static |
59 void URLPatternSet::CreateUnion(const std::vector<URLPatternSet>& sets, | 51 void URLPatternSet::CreateUnion(const std::vector<URLPatternSet>& sets, |
60 URLPatternSet* out) { | 52 URLPatternSet* out) { |
61 out->ClearPatterns(); | 53 out->ClearPatterns(); |
62 if (sets.empty()) | 54 if (sets.empty()) |
63 return; | 55 return; |
64 | 56 |
65 // N-way union algorithm is basic O(nlog(n)) merge algorithm. | 57 // N-way union algorithm is basic O(nlog(n)) merge algorithm. |
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
223 for (size_t i = 0; i < value.GetSize(); ++i) { | 215 for (size_t i = 0; i < value.GetSize(); ++i) { |
224 std::string item; | 216 std::string item; |
225 if (!value.GetString(i, &item)) | 217 if (!value.GetString(i, &item)) |
226 return false; | 218 return false; |
227 patterns.push_back(item); | 219 patterns.push_back(item); |
228 } | 220 } |
229 return Populate(patterns, valid_schemes, allow_file_access, error); | 221 return Populate(patterns, valid_schemes, allow_file_access, error); |
230 } | 222 } |
231 | 223 |
232 } // namespace extensions | 224 } // namespace extensions |
OLD | NEW |