Index: chrome/browser/browsing_data/origin_filter_builder.h |
diff --git a/chrome/browser/browsing_data/origin_filter_builder.h b/chrome/browser/browsing_data/origin_filter_builder.h |
new file mode 100644 |
index 0000000000000000000000000000000000000000..24d9e2df832e4d4bacab39613c1d56b2a78c0d84 |
--- /dev/null |
+++ b/chrome/browser/browsing_data/origin_filter_builder.h |
@@ -0,0 +1,61 @@ |
+// 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 CHROME_BROWSER_BROWSING_DATA_ORIGIN_FILTER_BUILDER_H_ |
+#define CHROME_BROWSER_BROWSING_DATA_ORIGIN_FILTER_BUILDER_H_ |
+ |
+#include <ostream> |
+#include <set> |
+#include <vector> |
+ |
+#include "base/callback.h" |
+#include "url/gurl.h" |
+#include "url/origin.h" |
+ |
+// A class that constructs URL deletion filters (represented as GURL->bool |
+// predicates) that match certain origins. |
+class OriginFilterBuilder { |
+ public: |
+ // A filter that only matches |origins|. |
+ static scoped_ptr<OriginFilterBuilder> AsWhitelist( |
brettw
2016/02/05 21:26:04
This API seems unusual to me. It forces heap alloc
msramek
2016/02/10 14:30:37
Done. Agreed, the builder model is quite convenien
|
+ const std::vector<url::Origin>& origins); |
+ |
+ // A filter that matches everything except |origins|. |
+ static scoped_ptr<OriginFilterBuilder> AsBlacklist( |
+ const std::vector<url::Origin>& origins); |
+ |
+ // An empty filter that matches everything. Equivalent to an empty blacklist. |
+ static scoped_ptr<OriginFilterBuilder> Empty(); |
+ |
+ ~OriginFilterBuilder(); |
+ |
+ const base::Callback<bool(const GURL& url)>& GetSameOriginFilter(); |
+ const base::Callback<bool(const GURL& url)>& GetSubdomainFilter(); |
brettw
2016/02/05 21:26:04
Did you pick "dubdomain" over "domain" for a reaso
msramek
2016/02/10 14:30:37
Done.
Ok, let's try using "domain"; I hope it won
|
+ |
+ private: |
+ // 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; |
+ |
+ OriginFilterBuilder( |
+ const std::vector<url::Origin>& origins, bool whitelist_mode); |
+ |
+ // The list of origins and whether they should be interpreted as a whitelist |
+ // or blacklist. |
+ std::set<url::Origin> origin_list_; |
+ bool whitelist_mode_; |
+ |
+ // MatchesURL and MatchesURLWithSubdomains pre-packaged as predicates |
+ // that can be passed to various browsing data backends. |
+ base::Callback<bool(const GURL& url)> matches_url_callback_; |
+ base::Callback<bool(const GURL& url)> matches_url_with_subdomains_callback_; |
+ |
+ DISALLOW_COPY_AND_ASSIGN(OriginFilterBuilder); |
+}; |
+ |
+#endif // CHROME_BROWSER_BROWSING_DATA_ORIGIN_FILTER_BUILDER_H_ |