| OLD | NEW |
| 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 #ifndef CHROME_COMMON_EXTENSIONS_URL_PATTERN_SET_H_ | 5 #ifndef CHROME_COMMON_EXTENSIONS_URL_PATTERN_SET_H_ |
| 6 #define CHROME_COMMON_EXTENSIONS_URL_PATTERN_SET_H_ | 6 #define CHROME_COMMON_EXTENSIONS_URL_PATTERN_SET_H_ |
| 7 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 #include <vector> | 9 #include <set> |
| 10 | 10 |
| 11 #include "chrome/common/extensions/url_pattern.h" | 11 #include "chrome/common/extensions/url_pattern.h" |
| 12 | 12 |
| 13 class GURL; | 13 class GURL; |
| 14 | 14 |
| 15 // Represents the set of URLs an extension uses for web content. | 15 // Represents the set of URLs an extension uses for web content. |
| 16 class URLPatternSet { | 16 class URLPatternSet { |
| 17 public: | 17 public: |
| 18 typedef std::set<URLPattern>::const_iterator const_iterator; |
| 19 typedef std::set<URLPattern>::iterator iterator; |
| 20 |
| 18 // Clears |out| and populates the set with the union of |set1| and |set2|. | 21 // Clears |out| and populates the set with the union of |set1| and |set2|. |
| 19 // NOTE: this does not discard duplicates. | |
| 20 static void CreateUnion(const URLPatternSet& set1, | 22 static void CreateUnion(const URLPatternSet& set1, |
| 21 const URLPatternSet& set2, | 23 const URLPatternSet& set2, |
| 22 URLPatternSet* out); | 24 URLPatternSet* out); |
| 23 | 25 |
| 24 URLPatternSet(); | 26 URLPatternSet(); |
| 25 URLPatternSet(const URLPatternSet& rhs); | 27 URLPatternSet(const URLPatternSet& rhs); |
| 28 explicit URLPatternSet(const std::set<URLPattern>& patterns); |
| 26 ~URLPatternSet(); | 29 ~URLPatternSet(); |
| 30 |
| 27 URLPatternSet& operator=(const URLPatternSet& rhs); | 31 URLPatternSet& operator=(const URLPatternSet& rhs); |
| 32 bool operator==(const URLPatternSet& rhs) const; |
| 28 | 33 |
| 29 bool is_empty() const; | 34 bool is_empty() const; |
| 35 const std::set<URLPattern>& patterns() const { return patterns_; } |
| 36 const_iterator begin() const { return patterns_.begin(); } |
| 37 const_iterator end() const { return patterns_.end(); } |
| 30 | 38 |
| 31 const URLPatternList& patterns() const { return patterns_; } | |
| 32 void AddPattern(const URLPattern& pattern); | 39 void AddPattern(const URLPattern& pattern); |
| 33 void ClearPatterns(); | 40 void ClearPatterns(); |
| 34 | 41 |
| 35 // Test if the extent contains a URL. | 42 // Test if the extent contains a URL. |
| 36 bool MatchesURL(const GURL& url) const; | 43 bool MatchesURL(const GURL& url) const; |
| 37 | 44 |
| 38 // Returns true if there is a single URL that would be in two extents. | 45 // Returns true if there is a single URL that would be in two extents. |
| 39 bool OverlapsWith(const URLPatternSet& other) const; | 46 bool OverlapsWith(const URLPatternSet& other) const; |
| 40 | 47 |
| 41 private: | 48 private: |
| 42 // The list of URL patterns that comprise the extent. | 49 // The list of URL patterns that comprise the extent. |
| 43 URLPatternList patterns_; | 50 std::set<URLPattern> patterns_; |
| 44 }; | 51 }; |
| 45 | 52 |
| 46 #endif // CHROME_COMMON_EXTENSIONS_URL_PATTERN_SET_H_ | 53 #endif // CHROME_COMMON_EXTENSIONS_URL_PATTERN_SET_H_ |
| OLD | NEW |