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

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

Issue 2335023002: Adding a previews IO-thread blacklist (Closed)
Patch Set: build.gn dependency on gurl 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(size_t stored_history_length,
32 int opt_out_black_list_threshold,
33 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 {
tbansal1 2016/09/14 20:17:50 Why is this public?
RyanSturm 2016/09/14 21:01:04 Done.
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, base::Time entry_time);
47
48 // Whether the host name corresponding to |this| should be disallowed from
49 // showing previews.
50 bool IsBlackListed(base::Time now) const;
51
52 private:
53 // The amount of entries to store to determine preview eligibility.
54 const size_t stored_history_length_;
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 previews navigation. Is maintained
61 // as a sorted vector.
tbansal1 2016/09/14 20:17:50 sorted by what?
RyanSturm 2016/09/14 21:01:04 Done.
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_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698