Index: components/previews/previews_black_list_item.h |
diff --git a/components/previews/previews_black_list_item.h b/components/previews/previews_black_list_item.h |
new file mode 100644 |
index 0000000000000000000000000000000000000000..3ea8e448a68478ceaa315625b66877e190c4552f |
--- /dev/null |
+++ b/components/previews/previews_black_list_item.h |
@@ -0,0 +1,73 @@ |
+// 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 COMPONENTS_PREVIEWS_PREVIEWS_BLACK_LIST_ITEM_H_ |
+#define COMPONENTS_PREVIEWS_PREVIEWS_BLACK_LIST_ITEM_H_ |
+ |
+#include <stdint.h> |
+ |
+#include <list> |
+#include <map> |
+#include <memory> |
+#include <string> |
+ |
+#include "base/callback.h" |
+#include "base/macros.h" |
+#include "base/optional.h" |
+#include "base/time/time.h" |
+ |
+namespace previews { |
+enum class PreviewsType; |
+ |
+// Stores the recent black list history for a single host. Stores |
+// |stored_history_length| of the most recent previews navigations. To determine |
+// previews eligiblity fewer than |opt_out_black_list_threshold| out of the past |
+// |stored_history_length| navigations must be opt outs. |black_list_duration| |
+// is the amount of time that elapses until the host is no longer on the black |
+// list. |
+class PreviewsBlackListItem { |
+ public: |
+ PreviewsBlackListItem(size_t stored_history_length, |
+ int opt_out_black_list_threshold, |
+ base::TimeDelta black_list_duration); |
+ |
+ ~PreviewsBlackListItem(); |
+ |
+ // Adds a new navigation and returns the base::Time that the event was |
+ // recorded. |
+ void AddPreviewNavigation(bool opt_out, base::Time entry_time); |
+ |
+ // Whether the host name corresponding to |this| should be disallowed from |
+ // showing previews. |
+ bool IsBlackListed(base::Time now) const; |
+ |
+ private: |
+ // A previews navigation to this host can be represented by time and whether |
+ // the navigation was an opt out. |
+ struct TimeOptOut { |
tbansal1
2016/09/15 16:34:25
May be call it OptOutRecord?
RyanSturm
2016/09/19 18:07:25
Done.
|
+ base::Time entry_time; // The time that the opt out state was determined. |
tbansal1
2016/09/15 16:34:25
Why is entry_time needed? strictly speaking, you d
tbansal1
2016/09/15 16:34:25
can these be const members?
RyanSturm
2016/09/19 18:07:25
Talked offline about this, it is needed for the da
RyanSturm
2016/09/19 18:07:25
Done.
|
+ bool opt_out; // Whether the user opt out of the preview. |
+ }; |
+ |
+ // The amount of entries to store to determine preview eligibility. |
tbansal1
2016/09/15 16:34:25
s/amount/number/
RyanSturm
2016/09/19 18:07:25
Done.
|
+ const size_t stored_history_length_; |
tbansal1
2016/09/15 16:34:25
s/stored_history_length_/max_stored_history_length
RyanSturm
2016/09/19 18:07:25
Done.
|
+ // The number opt outs in recent history that will trigger blacklisting. |
+ const int opt_out_black_list_threshold_; |
+ // The amount of time to black list a domain after the most recent opt out. |
+ const base::TimeDelta black_list_duration_; |
tbansal1
2016/09/15 16:34:25
s/black_list_duration_/max_black_list_duration_/
RyanSturm
2016/09/19 18:07:25
Done.
|
+ |
+ // The |stored_history_length_| most recent previews navigation. Is maintained |
+ // as a list sorted by entry_time (earliest to latest). |
+ std::list<TimeOptOut> opt_out_history_; |
+ |
+ // Time of the most recent opt out. |
+ base::Optional<base::Time> most_recent_opt_out_time_; |
+ |
+ // The total number of opt outs currently in |opt_out_history_|. |
+ int total_opt_out_; |
+}; |
+ |
+} // namespace previews |
+ |
+#endif // COMPONENTS_PREVIEWS_PREVIEWS_BLACK_LIST_ITEM_H_ |