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 19 matching lines...) Expand all Loading... |
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 size_t OptOutRecordsSizeForTesting() const; | 47 size_t OptOutRecordsSizeForTesting() const; |
48 | 48 |
49 private: | 49 private: |
50 // A previews navigation to this host is represented by time and whether the | 50 // A previews navigation to this host is represented by time and whether the |
51 // navigation was an opt out. | 51 // navigation was an opt out. |
52 struct OptOutRecord { | 52 class OptOutRecord { |
| 53 public: |
53 OptOutRecord(base::Time entry_time, bool opt_out); | 54 OptOutRecord(base::Time entry_time, bool opt_out); |
54 ~OptOutRecord() {} | 55 ~OptOutRecord(); |
55 const base::Time | 56 OptOutRecord(OptOutRecord&&); |
56 entry_time; // The time that the opt out state was determined. | 57 OptOutRecord& operator=(OptOutRecord&&); |
57 const bool opt_out; // Whether the user opt out of the preview. | 58 |
| 59 // Used to determine eviction priority. |
| 60 bool operator<(const OptOutRecord& other) const; |
| 61 |
| 62 // The time that the opt out state was determined. |
| 63 base::Time entry_time() const { return entry_time_; } |
| 64 |
| 65 // Whether the user opted out of the preview. |
| 66 bool opt_out() const { return opt_out_; } |
| 67 |
| 68 private: |
| 69 // The time that the opt out state was determined. |
| 70 base::Time entry_time_; |
| 71 // Whether the user opted out of the preview. |
| 72 bool opt_out_; |
| 73 |
| 74 DISALLOW_COPY_AND_ASSIGN(OptOutRecord); |
58 }; | 75 }; |
59 | 76 |
60 // The number of entries to store to determine preview eligibility. | 77 // The number of entries to store to determine preview eligibility. |
61 const size_t max_stored_history_length_; | 78 const size_t max_stored_history_length_; |
62 // The number opt outs in recent history that will trigger blacklisting. | 79 // The number opt outs in recent history that will trigger blacklisting. |
63 const int opt_out_black_list_threshold_; | 80 const int opt_out_black_list_threshold_; |
64 // The amount of time to black list a domain after the most recent opt out. | 81 // The amount of time to black list a domain after the most recent opt out. |
65 const base::TimeDelta max_black_list_duration_; | 82 const base::TimeDelta max_black_list_duration_; |
66 | 83 |
67 // The |max_stored_history_length_| most recent previews navigation. Is | 84 // The |max_stored_history_length_| most recent previews navigation. Is |
68 // maintained as a list sorted by entry_time (earliest to latest). | 85 // maintained as a priority queue that has high priority for items that should |
69 std::list<OptOutRecord> opt_out_records_; | 86 // be evicted (i.e., they are old). |
| 87 std::priority_queue<OptOutRecord> opt_out_records_; |
70 | 88 |
71 // Time of the most recent opt out. | 89 // Time of the most recent opt out. |
72 base::Optional<base::Time> most_recent_opt_out_time_; | 90 base::Optional<base::Time> most_recent_opt_out_time_; |
73 | 91 |
74 // The total number of opt outs currently in |opt_out_records_|. | 92 // The total number of opt outs currently in |opt_out_records_|. |
75 int total_opt_out_; | 93 int total_opt_out_; |
76 | 94 |
77 DISALLOW_COPY_AND_ASSIGN(PreviewsBlackListItem); | 95 DISALLOW_COPY_AND_ASSIGN(PreviewsBlackListItem); |
78 }; | 96 }; |
79 | 97 |
80 } // namespace previews | 98 } // namespace previews |
81 | 99 |
82 #endif // COMPONENTS_PREVIEWS_CORE_PREVIEWS_BLACK_LIST_ITEM_H_ | 100 #endif // COMPONENTS_PREVIEWS_CORE_PREVIEWS_BLACK_LIST_ITEM_H_ |
OLD | NEW |