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..6712afeb99704db95a0cf9ff80794e5fd1a630d2 |
--- /dev/null |
+++ b/chrome/browser/browsing_data/origin_filter_builder.h |
@@ -0,0 +1,72 @@ |
+// 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: |
+ enum Mode { |
+ WHITELIST, |
+ BLACKLIST |
+ }; |
+ |
+ // Constructs a filter with the given |mode| - whitelist or blacklist. |
+ explicit OriginFilterBuilder(Mode mode); |
+ |
+ ~OriginFilterBuilder(); |
+ |
+ // Adds the |origin| to the (white- or black-) list, and returns itself |
+ // for method call chaining. |
+ OriginFilterBuilder* AddOrigin(const url::Origin& origin); |
brettw
2016/02/17 20:34:24
Thanks for the update on the builder pattern, I li
msramek
2016/02/18 12:48:43
Acknowledged.
|
+ |
+ // Change the |mode| of the filter. |
+ OriginFilterBuilder* ChangeMode(Mode mode); |
Mike West
2016/02/17 15:22:10
Nit: s/ChangeMode/SetMode/
brettw
2016/02/17 20:34:24
This, plus void return value. I notice you do this
msramek
2016/02/18 12:48:43
Done. Didn't seem unusual to me, as as I have rece
|
+ |
+ // Builds a filter that matches URLs whose origins are in the whitelist, |
+ // or aren't in the blacklist. Once a filter is built, it is no longer |
+ // possible to change the builder parameters (origin list and mode). |
+ base::Callback<bool(const GURL&)> BuildSameOriginFilter(); |
+ |
+ // Build a filter that matches URLs whose origins, or origins obtained by |
+ // replacing the host with any superdomain, are listed in the whitelist, |
+ // or are not listed in the blacklist. Once a filter is built, it is no longer |
+ // possible to change the builder parameters (origin list and mode). |
Mike West
2016/02/17 15:22:10
Can you add some comments about lifetimes here and
msramek
2016/02/18 12:48:43
My original thought here was that BrowsingDataRemo
|
+ base::Callback<bool(const GURL&)> BuildDomainFilter(); |
Mike West
2016/02/17 15:22:10
HSTS calls these "congruent" and "superdomain" mat
brettw
2016/02/17 20:34:24
I've never heard of those, and I personally prefer
Mike West
2016/02/18 10:50:31
I don't feel strongly about it: if y'all are happi
msramek
2016/02/18 12:48:43
"superdomain" could be confusing, as in my mind th
|
+ |
+ // A convenience method to produce an empty blacklist, a filter that matches |
+ // everything. |
+ static base::Callback<bool(const GURL&)> BuildEmptyFilter(); |
+ |
+ 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; |
+ |
+ // The list of origins and whether they should be interpreted as a whitelist |
+ // or blacklist. |
+ std::set<url::Origin> origin_list_; |
+ Mode mode_; |
+ |
+ // Whether the filter has already been built. |
+ bool built_; |
+ |
+ DISALLOW_COPY_AND_ASSIGN(OriginFilterBuilder); |
+}; |
+ |
+#endif // CHROME_BROWSER_BROWSING_DATA_ORIGIN_FILTER_BUILDER_H_ |