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..0864bbea8e1b138dcc9e9915877803d67296d4fe |
--- /dev/null |
+++ b/chrome/browser/browsing_data/origin_filter_builder.h |
@@ -0,0 +1,68 @@ |
+// 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); |
+ |
+ // Change the |mode| of the filter. |
+ OriginFilterBuilder* ChangeMode(Mode mode); |
+ |
+ // 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). |
+ base::Callback<bool(const GURL&)> BuildDomainFilter(); |
+ |
+ 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_ |