Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1757)

Side by Side Diff: components/previews/previews_black_list_item.h

Issue 2335023002: Adding a previews IO-thread blacklist (Closed)
Patch Set: updated comments Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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 struct TimeOptOut {
tbansal1 2016/09/13 23:52:45 comments please.
RyanSturm 2016/09/14 16:44:30 Done.
38 base::Time entry_time;
39 bool opt_out;
40 };
41
42 // Adds a new navigation and returns the base::Time that the event was
43 // recorded.
44 void AddPreviewNavigation(bool opt_out, const base::Time& entry_time);
45
46 // Whether the host name corresponding to |this| should be disallowed from
47 // showing previews.
48 bool IsBlackListed(const base::Time& now) const;
49
50 private:
51 // The amount of entries to store to determine preview eligibility.
52 const int stored_history_length_;
53 // The number opt outs in recent history that will trigger blacklisting.
54 const int opt_out_black_list_threshold_;
55 // The amount of time to black list a domain after the most recent opt out.
56 const base::TimeDelta black_list_duration_;
57
58 // The |stored_history_length_| most recent preivews navigation. Is maintained
59 // as a sorted vector.
60 std::list<TimeOptOut> opt_out_history_;
61
62 // Time of the most recent opt out.
63 base::Optional<base::Time> most_recent_opt_out_time_;
64
65 // The total number of opt outs currently in |opt_out_history_|.
66 int total_opt_out_;
67 };
68
69 typedef std::map<std::string, std::unique_ptr<PreviewsBlackListItem>>
70 BlackListItemMap;
71
72 } // namespace previews
73
74 #endif // COMPONENTS_PREVIEWS_PREVIEWS_BLACK_LIST_ITEM_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698