OLD | NEW |
---|---|
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef COMPONENTS_PREVIEWS_CORE_PREVIEWS_BLACK_LIST_ITEM_H_ | 5 #ifndef COMPONENTS_PREVIEWS_CORE_PREVIEWS_BLACK_LIST_ITEM_H_ |
6 #define COMPONENTS_PREVIEWS_CORE_PREVIEWS_BLACK_LIST_ITEM_H_ | 6 #define COMPONENTS_PREVIEWS_CORE_PREVIEWS_BLACK_LIST_ITEM_H_ |
7 | 7 |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
10 #include <list> | |
11 #include <map> | 10 #include <map> |
12 #include <memory> | 11 #include <memory> |
12 #include <queue> | |
13 #include <string> | 13 #include <string> |
14 | 14 |
15 #include "base/callback.h" | 15 #include "base/callback.h" |
16 #include "base/macros.h" | 16 #include "base/macros.h" |
17 #include "base/optional.h" | 17 #include "base/optional.h" |
18 #include "base/time/time.h" | 18 #include "base/time/time.h" |
19 | 19 |
20 namespace previews { | 20 namespace previews { |
21 | 21 |
22 // Stores the recent black list history for a single host. Stores | 22 // Stores the recent black list history for a single host. Stores |
(...skipping 17 matching lines...) Expand all Loading... | |
40 // showing previews. | 40 // showing previews. |
41 bool IsBlackListed(base::Time now) const; | 41 bool IsBlackListed(base::Time now) const; |
42 | 42 |
43 base::Optional<base::Time> most_recent_opt_out_time() const { | 43 base::Optional<base::Time> most_recent_opt_out_time() const { |
44 return most_recent_opt_out_time_; | 44 return most_recent_opt_out_time_; |
45 } | 45 } |
46 | 46 |
47 private: | 47 private: |
48 // A previews navigation to this host is represented by time and whether the | 48 // A previews navigation to this host is represented by time and whether the |
49 // navigation was an opt out. | 49 // navigation was an opt out. |
50 struct OptOutRecord { | 50 class OptOutRecord { |
51 public: | |
51 OptOutRecord(base::Time entry_time, bool opt_out); | 52 OptOutRecord(base::Time entry_time, bool opt_out); |
52 ~OptOutRecord() {} | 53 ~OptOutRecord(); |
53 const base::Time | 54 OptOutRecord(OptOutRecord&&); |
54 entry_time; // The time that the opt out state was determined. | 55 OptOutRecord& operator=(OptOutRecord&&); |
55 const bool opt_out; // Whether the user opt out of the preview. | 56 |
57 // Used to determine eviction priority. | |
58 bool operator<(const OptOutRecord& other) const; | |
59 | |
60 // Whether the user opted out of the preview. | |
61 bool opt_out() const { return opt_out_; } | |
tbansal1
2016/10/25 16:15:48
nit: reverse the order of functions to match the o
RyanSturm
2016/10/25 18:15:44
Done.
| |
62 | |
63 // The time that the opt out state was determined. | |
64 base::Time entry_time() const { return entry_time_; } | |
65 | |
66 private: | |
67 // The time that the opt out state was determined. | |
68 base::Time entry_time_; | |
69 // Whether the user opted out of the preview. | |
70 bool opt_out_; | |
71 | |
72 DISALLOW_COPY_AND_ASSIGN(OptOutRecord); | |
56 }; | 73 }; |
57 | 74 |
58 // The number of entries to store to determine preview eligibility. | 75 // The number of entries to store to determine preview eligibility. |
59 const size_t max_stored_history_length_; | 76 const size_t max_stored_history_length_; |
60 // The number opt outs in recent history that will trigger blacklisting. | 77 // The number opt outs in recent history that will trigger blacklisting. |
61 const int opt_out_black_list_threshold_; | 78 const int opt_out_black_list_threshold_; |
62 // The amount of time to black list a domain after the most recent opt out. | 79 // The amount of time to black list a domain after the most recent opt out. |
63 const base::TimeDelta max_black_list_duration_; | 80 const base::TimeDelta max_black_list_duration_; |
64 | 81 |
65 // The |max_stored_history_length_| most recent previews navigation. Is | 82 // The |max_stored_history_length_| most recent previews navigation. Is |
66 // maintained as a list sorted by entry_time (earliest to latest). | 83 // maintained as a list sorted by entry_time (earliest to latest). |
tbansal1
2016/10/25 16:15:48
"sorted"
stale comment
Also, mention that top ele
RyanSturm
2016/10/25 18:15:44
Done.
| |
67 std::list<OptOutRecord> opt_out_records_; | 84 std::priority_queue<OptOutRecord> opt_out_records_; |
68 | 85 |
69 // Time of the most recent opt out. | 86 // Time of the most recent opt out. |
70 base::Optional<base::Time> most_recent_opt_out_time_; | 87 base::Optional<base::Time> most_recent_opt_out_time_; |
71 | 88 |
72 // The total number of opt outs currently in |opt_out_records_|. | 89 // The total number of opt outs currently in |opt_out_records_|. |
73 int total_opt_out_; | 90 int total_opt_out_; |
74 | 91 |
75 DISALLOW_COPY_AND_ASSIGN(PreviewsBlackListItem); | 92 DISALLOW_COPY_AND_ASSIGN(PreviewsBlackListItem); |
76 }; | 93 }; |
77 | 94 |
78 } // namespace previews | 95 } // namespace previews |
79 | 96 |
80 #endif // COMPONENTS_PREVIEWS_CORE_PREVIEWS_BLACK_LIST_ITEM_H_ | 97 #endif // COMPONENTS_PREVIEWS_CORE_PREVIEWS_BLACK_LIST_ITEM_H_ |
OLD | NEW |