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

Side by Side Diff: components/previews/core/previews_black_list.h

Issue 2477073002: Adding UMA to track previews opt outs and blacklist eligibility (Closed)
Patch Set: rebase Created 4 years, 1 month 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
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
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 {
tbansal1 2016/11/08 00:30:52 nit: Is there a reason to use this style of commen
RyanSturm 2016/11/08 22:22:29 Done.
34 ALLOWED = 0, // The preview navigation was allowed.
35 BLACKLIST_UNAVAILABLE = 1, // The black list was not initialized.
36 BLACKLIST_DATA_NOT_LOADED =
37 2, // The black list has not loaded from disk yet.
38 USER_RECENTLY_OPTED_OUT = 3, // The user has opted out of a preview
39 // recently.
40 USER_BLACKLISTED = 4, // The user has opted out of previews often, and is no
41 // longer shown previews on any host.
42 HOST_BLACKLISTED = 5, // The user has opted out of previews on a specific
43 // host often, and was not not shown a previews on that
44 // host.
45 NETWORK_QUALITY_UNAVAILABLE =
46 6, // the network quality estimate is not available.
47 NETWORK_NOT_SLOW = 7, // The network was fast enough to not warrant previews.
48 LAST = 8,
49 };
50
33 // Manages the state of black listed domains for the previews experiment. Loads 51 // 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 52 // 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 53 // 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 54 // 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 55 // 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 56 // 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 57 // browsing history), domains are reported as black listed. The list stores no
40 // more than previews::params::MaxInMemoryHostsInBlackList hosts in-memory, 58 // more than previews::params::MaxInMemoryHostsInBlackList hosts in-memory,
41 // which defaults to 100. 59 // which defaults to 100.
42 class PreviewsBlackList { 60 class PreviewsBlackList {
43 public: 61 public:
44 // |opt_out_store| is the backing store to retrieve and store black list 62 // |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 63 // 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, 64 // 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. 65 // it will be used to load the in-memory map asynchronously.
48 PreviewsBlackList(std::unique_ptr<PreviewsOptOutStore> opt_out_store, 66 PreviewsBlackList(std::unique_ptr<PreviewsOptOutStore> opt_out_store,
49 std::unique_ptr<base::Clock> clock); 67 std::unique_ptr<base::Clock> clock);
50 ~PreviewsBlackList(); 68 ~PreviewsBlackList();
51 69
52 // Asynchronously adds a new navigation to to the in-memory black list and 70 // 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 71 // 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 72 // 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 73 // 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 74 // allowed, and |url| is a new host, a host will be evicted based on recency
57 // of the hosts most recent opt out. 75 // of the hosts most recent opt out.
58 void AddPreviewNavigation(const GURL& url, bool opt_out, PreviewsType type); 76 void AddPreviewNavigation(const GURL& url, bool opt_out, PreviewsType type);
59 77
60 // Synchronously determines if |host_name| should be allowed to show previews. 78 // 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 79 // Returns the reason the blacklist disallowed the preview, or
62 // not used to make this decision. 80 // PreviewsEligibilityReason::ALLOWED if the preview is allowed.
63 bool IsLoadedAndAllowed(const GURL& url, PreviewsType type) const; 81 PreviewsEligibilityReason IsLoadedAndAllowed(const GURL& url,
82 PreviewsType type) const;
64 83
65 // Asynchronously deletes all entries in the in-memory black list. Informs 84 // Asynchronously deletes all entries in the in-memory black list. Informs
66 // the backing store to delete entries between |begin_time| and |end_time|, 85 // 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 86 // 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. 87 // 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); 88 void ClearBlackList(base::Time begin_time, base::Time end_time);
70 89
71 // Returns a new PreviewsBlackListItem representing |host_name|. Adds the new 90 // Returns a new PreviewsBlackListItem representing |host_name|. Adds the new
72 // item to |black_list_item_map|. 91 // item to |black_list_item_map|.
73 static PreviewsBlackListItem* GetOrCreateBlackListItemForMap( 92 static PreviewsBlackListItem* GetOrCreateBlackListItemForMap(
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
125 base::ThreadChecker thread_checker_; 144 base::ThreadChecker thread_checker_;
126 145
127 base::WeakPtrFactory<PreviewsBlackList> weak_factory_; 146 base::WeakPtrFactory<PreviewsBlackList> weak_factory_;
128 147
129 DISALLOW_COPY_AND_ASSIGN(PreviewsBlackList); 148 DISALLOW_COPY_AND_ASSIGN(PreviewsBlackList);
130 }; 149 };
131 150
132 } // namespace previews 151 } // namespace previews
133 152
134 #endif // COMPONENTS_PREVIEWS_CORE_PREVIEWS_BLACK_LIST_H_ 153 #endif // COMPONENTS_PREVIEWS_CORE_PREVIEWS_BLACK_LIST_H_
OLDNEW
« no previous file with comments | « no previous file | components/previews/core/previews_black_list.cc » ('j') | components/previews/core/previews_black_list.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698