Index: components/subresource_filter/core/common/url_pattern.h |
diff --git a/components/subresource_filter/core/common/url_pattern.h b/components/subresource_filter/core/common/url_pattern.h |
index f49b5ea610bbaa26a9bfeb98187a23762cdc9f1c..d2a22756c20444deb98a41ac90bcd08929186b10 100644 |
--- a/components/subresource_filter/core/common/url_pattern.h |
+++ b/components/subresource_filter/core/common/url_pattern.h |
@@ -5,10 +5,14 @@ |
#ifndef COMPONENTS_SUBRESOURCE_FILTER_CORE_COMMON_URL_PATTERN_H_ |
#define COMPONENTS_SUBRESOURCE_FILTER_CORE_COMMON_URL_PATTERN_H_ |
+#include <iosfwd> |
+ |
#include "base/macros.h" |
#include "base/strings/string_piece.h" |
#include "components/subresource_filter/core/common/proto/rules.pb.h" |
+class GURL; |
+ |
namespace subresource_filter { |
namespace flat { |
@@ -17,7 +21,8 @@ struct UrlRule; // The FlatBuffers version of UrlRule. |
// The structure used to mirror a URL pattern regardless of the representation |
engedy
2017/04/05 10:55:11
nit: Should update this comment now that there is
pkalinnikov
2017/04/05 13:29:21
Done.
|
// of the UrlRule that owns it. |
-struct UrlPattern { |
+class UrlPattern { |
+ public: |
UrlPattern(); |
// Creates a |url_pattern| of a certain |type|. |
@@ -36,18 +41,34 @@ struct UrlPattern { |
~UrlPattern(); |
- proto::UrlPatternType type = proto::URL_PATTERN_TYPE_UNSPECIFIED; |
- base::StringPiece url_pattern; |
+ proto::UrlPatternType type() const { return type_; } |
+ base::StringPiece url_pattern() const { return url_pattern_; } |
+ proto::AnchorType anchor_left() const { return anchor_left_; } |
+ proto::AnchorType anchor_right() const { return anchor_right_; } |
+ bool match_case() const { return match_case_; } |
- proto::AnchorType anchor_left = proto::ANCHOR_TYPE_NONE; |
- proto::AnchorType anchor_right = proto::ANCHOR_TYPE_NONE; |
- |
- bool match_case = false; |
+ // Returns whether the |url| matches the URL |pattern|. Requires the type of |
+ // |this| pattern to be either SUBSTRING or WILDCARDED. |
+ // TODO(pkalinnikov): Outline algorithms implemented in this method. |
engedy
2017/04/05 10:55:11
nit: Can we resolve this in this CL?
pkalinnikov
2017/04/05 13:29:22
Done.
|
+ bool MatchesUrl(const GURL& url) const; |
private: |
+ // TODO(pkalinnikov): Store flat:: types instead of proto::, in order to avoid |
+ // convertions in IndexedRuleset. |
engedy
2017/04/05 10:55:11
typo: conversions
pkalinnikov
2017/04/05 13:29:22
Done.
|
+ proto::UrlPatternType type_ = proto::URL_PATTERN_TYPE_UNSPECIFIED; |
+ base::StringPiece url_pattern_; |
+ |
+ proto::AnchorType anchor_left_ = proto::ANCHOR_TYPE_NONE; |
+ proto::AnchorType anchor_right_ = proto::ANCHOR_TYPE_NONE; |
+ |
+ bool match_case_ = false; |
+ |
DISALLOW_COPY_AND_ASSIGN(UrlPattern); |
}; |
+// Stream operator so UrlPattern can be used in testing assertions. |
engedy
2017/04/05 10:55:11
nit: It can be used in GTest assertions without th
pkalinnikov
2017/04/05 13:29:22
Done.
|
+std::ostream& operator<<(std::ostream& out, const UrlPattern& pattern); |
+ |
} // namespace subresource_filter |
#endif // COMPONENTS_SUBRESOURCE_FILTER_CORE_COMMON_URL_PATTERN_H_ |