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_H_ | 5 #ifndef COMPONENTS_PREVIEWS_CORE_PREVIEWS_BLACK_LIST_H_ |
6 #define COMPONENTS_PREVIEWS_CORE_PREVIEWS_BLACK_LIST_H_ | 6 #define COMPONENTS_PREVIEWS_CORE_PREVIEWS_BLACK_LIST_H_ |
7 | 7 |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
10 #include <memory> | 10 #include <memory> |
(...skipping 12 matching lines...) Expand all Loading... |
23 | 23 |
24 class GURL; | 24 class GURL; |
25 | 25 |
26 namespace base { | 26 namespace base { |
27 class Clock; | 27 class Clock; |
28 } | 28 } |
29 | 29 |
30 namespace previews { | 30 namespace previews { |
31 class PreviewsBlackListItem; | 31 class PreviewsBlackListItem; |
32 | 32 |
| 33 enum class PreviewsEligibilityReason { |
| 34 // The preview navigation was allowed. |
| 35 ALLOWED = 0, |
| 36 // The black list was not initialized. |
| 37 BLACKLIST_UNAVAILABLE = 1, |
| 38 // The black list has not loaded from disk yet. |
| 39 BLACKLIST_DATA_NOT_LOADED = 2, |
| 40 // The user has opted out of a preview recently. |
| 41 USER_RECENTLY_OPTED_OUT = 3, |
| 42 // The user has opted out of previews often, and is no longer shown previews |
| 43 // on any host. |
| 44 USER_BLACKLISTED = 4, |
| 45 // The user has opted out of previews on a specific host often, and was not |
| 46 // not shown a previews on that host. |
| 47 HOST_BLACKLISTED = 5, |
| 48 // The network quality estimate is not available. |
| 49 NETWORK_QUALITY_UNAVAILABLE = 6, |
| 50 // The network was fast enough to not warrant previews. |
| 51 NETWORK_NOT_SLOW = 7, |
| 52 LAST = 8, |
| 53 }; |
| 54 |
33 // Manages the state of black listed domains for the previews experiment. Loads | 55 // Manages the state of black listed domains for the previews experiment. Loads |
34 // the stored black list from |opt_out_store| and manages an in memory black | 56 // the stored black list from |opt_out_store| and manages an in memory black |
35 // list on the IO thread. Updates to the black list are stored in memory and | 57 // list on the IO thread. Updates to the black list are stored in memory and |
36 // pushed to the store. Asynchronous modifications are stored in a queue and | 58 // pushed to the store. Asynchronous modifications are stored in a queue and |
37 // executed in order. Reading from the black list is always synchronous, and if | 59 // executed in order. Reading from the black list is always synchronous, and if |
38 // the black list is not currently loaded (e.g., at startup, after clearing | 60 // the black list is not currently loaded (e.g., at startup, after clearing |
39 // browsing history), domains are reported as black listed. The list stores no | 61 // browsing history), domains are reported as black listed. The list stores no |
40 // more than previews::params::MaxInMemoryHostsInBlackList hosts in-memory, | 62 // more than previews::params::MaxInMemoryHostsInBlackList hosts in-memory, |
41 // which defaults to 100. | 63 // which defaults to 100. |
42 class PreviewsBlackList { | 64 class PreviewsBlackList { |
43 public: | 65 public: |
44 // |opt_out_store| is the backing store to retrieve and store black list | 66 // |opt_out_store| is the backing store to retrieve and store black list |
45 // information, and can be null. When |opt_out_store| is null, the in-memory | 67 // information, and can be null. When |opt_out_store| is null, the in-memory |
46 // map will be immediately loaded to empty. If |opt_out_store| is non-null, | 68 // map will be immediately loaded to empty. If |opt_out_store| is non-null, |
47 // it will be used to load the in-memory map asynchronously. | 69 // it will be used to load the in-memory map asynchronously. |
48 PreviewsBlackList(std::unique_ptr<PreviewsOptOutStore> opt_out_store, | 70 PreviewsBlackList(std::unique_ptr<PreviewsOptOutStore> opt_out_store, |
49 std::unique_ptr<base::Clock> clock); | 71 std::unique_ptr<base::Clock> clock); |
50 ~PreviewsBlackList(); | 72 ~PreviewsBlackList(); |
51 | 73 |
52 // Asynchronously adds a new navigation to to the in-memory black list and | 74 // Asynchronously adds a new navigation to to the in-memory black list and |
53 // backing store. |opt_out| is whether the user opted out of the preview or | 75 // backing store. |opt_out| is whether the user opted out of the preview or |
54 // navigated away from the page without opting out. |type| is only passed to | 76 // navigated away from the page without opting out. |type| is only passed to |
55 // the backing store. If the in memory map has reached the max number of hosts | 77 // the backing store. If the in memory map has reached the max number of hosts |
56 // allowed, and |url| is a new host, a host will be evicted based on recency | 78 // allowed, and |url| is a new host, a host will be evicted based on recency |
57 // of the hosts most recent opt out. | 79 // of the hosts most recent opt out. |
58 void AddPreviewNavigation(const GURL& url, bool opt_out, PreviewsType type); | 80 void AddPreviewNavigation(const GURL& url, bool opt_out, PreviewsType type); |
59 | 81 |
60 // Synchronously determines if |host_name| should be allowed to show previews. | 82 // Synchronously determines if |host_name| should be allowed to show previews. |
61 // If the black list has loaded yet, this will always return false. |type| is | 83 // Returns the reason the blacklist disallowed the preview, or |
62 // not used to make this decision. | 84 // PreviewsEligibilityReason::ALLOWED if the preview is allowed. |
63 bool IsLoadedAndAllowed(const GURL& url, PreviewsType type) const; | 85 PreviewsEligibilityReason IsLoadedAndAllowed(const GURL& url, |
| 86 PreviewsType type) const; |
64 | 87 |
65 // Asynchronously deletes all entries in the in-memory black list. Informs | 88 // Asynchronously deletes all entries in the in-memory black list. Informs |
66 // the backing store to delete entries between |begin_time| and |end_time|, | 89 // the backing store to delete entries between |begin_time| and |end_time|, |
67 // and reloads entries into memory from the backing store. If the embedder | 90 // and reloads entries into memory from the backing store. If the embedder |
68 // passed in a null store, resets all history in the in-memory black list. | 91 // passed in a null store, resets all history in the in-memory black list. |
69 void ClearBlackList(base::Time begin_time, base::Time end_time); | 92 void ClearBlackList(base::Time begin_time, base::Time end_time); |
70 | 93 |
71 // Returns a new PreviewsBlackListItem representing |host_name|. Adds the new | 94 // Returns a new PreviewsBlackListItem representing |host_name|. Adds the new |
72 // item to |black_list_item_map|. | 95 // item to |black_list_item_map|. |
73 static PreviewsBlackListItem* GetOrCreateBlackListItemForMap( | 96 static PreviewsBlackListItem* GetOrCreateBlackListItemForMap( |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
125 base::ThreadChecker thread_checker_; | 148 base::ThreadChecker thread_checker_; |
126 | 149 |
127 base::WeakPtrFactory<PreviewsBlackList> weak_factory_; | 150 base::WeakPtrFactory<PreviewsBlackList> weak_factory_; |
128 | 151 |
129 DISALLOW_COPY_AND_ASSIGN(PreviewsBlackList); | 152 DISALLOW_COPY_AND_ASSIGN(PreviewsBlackList); |
130 }; | 153 }; |
131 | 154 |
132 } // namespace previews | 155 } // namespace previews |
133 | 156 |
134 #endif // COMPONENTS_PREVIEWS_CORE_PREVIEWS_BLACK_LIST_H_ | 157 #endif // COMPONENTS_PREVIEWS_CORE_PREVIEWS_BLACK_LIST_H_ |
OLD | NEW |