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(const int stored_history_length, | |
32 const int opt_out_black_list_threshold, | |
33 const base::TimeDelta& black_list_duration); | |
34 | |
35 ~PreviewsBlackListItem(); | |
36 | |
37 // A previews navigation to this host can be represented by time and whether | |
38 // the navigation was an opt out. | |
39 struct TimeOptOut { | |
40 base::Time entry_time; // The time that the opt out state was determined. | |
41 bool opt_out; // Whether the user opt out of the preview. | |
42 }; | |
43 | |
44 // Adds a new navigation and returns the base::Time that the event was | |
45 // recorded. | |
46 void AddPreviewNavigation(bool opt_out, const base::Time& entry_time); | |
47 | |
48 // Whether the host name corresponding to |this| should be disallowed from | |
49 // showing previews. | |
50 bool IsBlackListed(const base::Time& now) const; | |
51 | |
52 private: | |
53 // The amount of entries to store to determine preview eligibility. | |
54 const int stored_history_length_; | |
tbansal1
2016/09/14 17:17:29
can this be size_t, and same for other variables t
RyanSturm
2016/09/14 18:36:43
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_; | |
59 | |
60 // The |stored_history_length_| most recent preivews navigation. Is maintained | |
tbansal1
2016/09/14 17:17:28
typo in previews.
RyanSturm
2016/09/14 18:36:43
Done.
| |
61 // as a sorted vector. | |
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 typedef std::map<std::string, std::unique_ptr<PreviewsBlackListItem>> | |
72 BlackListItemMap; | |
tbansal1
2016/09/14 17:17:28
Why is this defined here since this is not used in
RyanSturm
2016/09/14 18:36:43
Moved to opt_out_store.h
| |
73 | |
74 } // namespace previews | |
75 | |
76 #endif // COMPONENTS_PREVIEWS_PREVIEWS_BLACK_LIST_ITEM_H_ | |
OLD | NEW |