OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #ifndef COMPONENTS_PREVIEWS_PREVIEWS_BLACK_LIST_ITEM_H_ | |
6 #define COMPONENTS_PREVIEWS_PREVIEWS_BLACK_LIST_ITEM_H_ | |
7 | |
8 #include <stdint.h> | |
9 | |
10 #include <list> | |
11 #include <map> | |
12 #include <memory> | |
13 #include <string> | |
14 | |
15 #include "base/callback.h" | |
16 #include "base/macros.h" | |
17 #include "base/optional.h" | |
18 #include "base/time/time.h" | |
19 | |
20 namespace previews { | |
21 enum class PreviewsType; | |
22 | |
23 // Stores the recent black list history for a single host. Stores | |
24 // |stored_history_length| of the most recent previews navigations. To determine | |
25 // previews eligiblity fewer than |opt_out_black_list_threshold| out of the past | |
26 // |stored_history_length| navigations must be opt outs. |black_list_duration| | |
27 // is the amount of time that elapses until the host is no longer on the black | |
28 // list. | |
29 class PreviewsBlackListItem { | |
30 public: | |
31 PreviewsBlackListItem(size_t stored_history_length, | |
32 int opt_out_black_list_threshold, | |
33 base::TimeDelta black_list_duration); | |
34 | |
35 ~PreviewsBlackListItem(); | |
36 | |
37 // Adds a new navigation and returns the base::Time that the event was | |
38 // recorded. | |
39 void AddPreviewNavigation(bool opt_out, base::Time entry_time); | |
40 | |
41 // Whether the host name corresponding to |this| should be disallowed from | |
42 // showing previews. | |
43 bool IsBlackListed(base::Time now) const; | |
44 | |
45 private: | |
46 // A previews navigation to this host can be represented by time and whether | |
47 // the navigation was an opt out. | |
48 struct TimeOptOut { | |
tbansal1
2016/09/15 16:34:25
May be call it OptOutRecord?
RyanSturm
2016/09/19 18:07:25
Done.
| |
49 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.
| |
50 bool opt_out; // Whether the user opt out of the preview. | |
51 }; | |
52 | |
53 // 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.
| |
54 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.
| |
55 // The number opt outs in recent history that will trigger blacklisting. | |
56 const int opt_out_black_list_threshold_; | |
57 // The amount of time to black list a domain after the most recent opt out. | |
58 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.
| |
59 | |
60 // The |stored_history_length_| most recent previews navigation. Is maintained | |
61 // as a list sorted by entry_time (earliest to latest). | |
62 std::list<TimeOptOut> opt_out_history_; | |
63 | |
64 // Time of the most recent opt out. | |
65 base::Optional<base::Time> most_recent_opt_out_time_; | |
66 | |
67 // The total number of opt outs currently in |opt_out_history_|. | |
68 int total_opt_out_; | |
69 }; | |
70 | |
71 } // namespace previews | |
72 | |
73 #endif // COMPONENTS_PREVIEWS_PREVIEWS_BLACK_LIST_ITEM_H_ | |
OLD | NEW |