Index: url/origin_filter.h |
diff --git a/url/origin_filter.h b/url/origin_filter.h |
new file mode 100644 |
index 0000000000000000000000000000000000000000..cd1eb243f1fb638ec8e07008339c6acb5adecd3f |
--- /dev/null |
+++ b/url/origin_filter.h |
@@ -0,0 +1,65 @@ |
+// Copyright 2016 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#ifndef URL_ORIGIN_FILTER_H_ |
+#define URL_ORIGIN_FILTER_H_ |
+ |
+#include <ostream> |
+#include <set> |
+#include <vector> |
+ |
+#include "url/gurl.h" |
+#include "url/origin.h" |
+ |
+namespace url { |
+ |
+// A utility class to filter browsing data over origins. |
+// Unique origins are ignored. |
+class URL_EXPORT OriginFilter { |
+ public: |
+ // A filter that only matches |origins|. |
+ static scoped_ptr<OriginFilter> AsWhitelist( |
+ const std::vector<Origin>& origins); |
+ |
+ // A filter that matches everything except |origins|. |
+ static scoped_ptr<OriginFilter> AsBlacklist( |
+ const std::vector<Origin>& origins); |
+ |
+ // An empty filter that matches everything. Equivalent to an empty blacklist. |
+ static scoped_ptr<OriginFilter> Empty(); |
+ |
+ ~OriginFilter(); |
+ |
+ // True if the origin of |url| is in the whitelist, or isn't in the blacklist. |
+ bool MatchesURL(const GURL& url) const; |
+ |
+ // True if any origin [scheme, host, port], such that |url| has the same |
+ // scheme and port, and |url|'s host is the same or a subdomain of that host, |
+ // is in the whitelist, or isn't in the blacklist. |
+ bool MatchesURLWithSubdomains(const GURL& url) const; |
+ |
+ // Whether two filters match the same origins. |
+ bool operator==(const OriginFilter& other) const; |
brettw
2016/02/01 22:48:25
Why do we need to do this comparison?
msramek
2016/02/05 17:16:35
It was used in a gmock matcher. The test that used
|
+ bool operator!=(const OriginFilter& other) const; |
+ |
+ private: |
+ URL_EXPORT friend std::ostream& operator<<(std::ostream& out, |
+ const OriginFilter& filter); |
+ |
+ OriginFilter(const std::vector<Origin>& origins, bool whitelist_mode); |
+ |
+ // The list of origins and whether they should be interpreted as a whitelist |
+ // or blacklist. |
+ std::set<Origin> origin_list_; |
+ bool whitelist_mode_; |
+ |
+ DISALLOW_COPY_AND_ASSIGN(OriginFilter); |
+}; |
+ |
+URL_EXPORT std::ostream& operator<<( |
+ std::ostream& out, const OriginFilter& filter); |
+ |
+} // namespace url |
+ |
+#endif // URL_ORIGIN_FILTER_H_ |