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

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

Issue 2335023002: Adding a previews IO-thread blacklist (Closed)
Patch Set: updated comments 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_H_
6 #define COMPONENTS_PREVIEWS_PREVIEWS_BLACK_LIST_H_
7
8 #include <stdint.h>
9
10 #include <memory>
11 #include <queue>
12 #include <string>
13 #include <vector>
14
15 #include "base/callback.h"
16 #include "base/macros.h"
17 #include "base/memory/weak_ptr.h"
18 #include "base/threading/thread_checker.h"
19 #include "components/previews/previews_opt_out_store.h"
20
21 namespace base {
22 class Time;
23 }
24
25 namespace previews {
26 class PreviewsBlackListItem;
27
28 // Manages the state of black listed domains for the previews experiment. Loads
29 // the stored black list from |opt_out_store| and manages an in memory black
30 // list on the IO thread. Updates to the black list are stored in memory and
31 // pushed to the store. Asynchronous modifications are stored in a queue and
32 // executed in order. Reading from the black list is always synchronous, and if
33 // the black list is not currently loaded (e.g., at startup, after clearing
34 // browsing history), domains are reported as black listed.
35 class PreviewsBlackList {
36 public:
37 PreviewsBlackList(std::unique_ptr<PreviewsOptOutStore> opt_out_store);
tbansal1 2016/09/13 23:52:45 explicit.
RyanSturm 2016/09/14 16:44:30 Done.
38 ~PreviewsBlackList();
39
40 typedef base::Closure QueueClosure;
41 typedef base::Callback<void(bool)> BlackListedCallback;
42
43 // Asynchronously adds a new navigation to |black_list_item_map_| and
44 // |opt_out_store_|. |opt_out| is whether the uesr opted out of the preview or
45 // navigated away from the page by another way.
46 void AddPreviewNavigation(const std::string& host_name,
47 bool opt_out,
48 PreviewsType type);
49
50 // Synchronously determines if |host_name| should be allowed to show previews.
51 // If LoadBlackListDone has not been called yet, this will always return
tbansal1 2016/09/13 23:52:45 what is LoadBlackListDone?
RyanSturm 2016/09/14 16:44:30 Done.
52 // false.
53 bool IsLoadedAndAllowed(const std::string& host_name);
54
55 // Asynchronously deletes all entries in |black_list_item_map_|. Informs
56 // |opt_out_store_| to delete entries between |begin_time| and |end_time|.
tbansal1 2016/09/13 23:52:45 Generally, documentation of public functions shoul
RyanSturm 2016/09/14 16:44:30 Done.
57 // Reloads entries into memory from |opt_out_store_|. If |opt_out_store_| is
58 // null, resets all history in |black_list_item_map_|.
59 void ClearBlackList(const base::Time& begin_time, const base::Time& end_time);
60
61 private:
62 // Synchronously adds a new navigation to |black_list_item_map_|. Adds a new
63 // navigation to |opt_out_store_|. |opt_out| is whether the uesr opted out of
64 // the preview or navigated away from the page by another way.
65 void AddPreviewNavigationSync(const std::string& host_name,
66 bool opt_out,
67 PreviewsType type);
68
69 // Returns the PreviewsBlackListItem representing |host_name|. If there is no
70 // item for |host_name|, one will be created iff |create_if_needed| is true.
71 PreviewsBlackListItem* GetBlackListItem(std::string host_name,
tbansal1 2016/09/13 23:52:45 pass std::string as const ref?
RyanSturm 2016/09/14 16:44:30 Done.
72 bool create_if_needed);
73
74 // Synchronously deletes all entries in |black_list_item_map_|. Informs
75 // |opt_out_store_| to delete entries between |begin_time| and |end_time|.
76 // Reloads entries into memory from |opt_out_store_|. If |opt_out_store_| is
77 // null, resets all history in |black_list_item_map_|.
78 void ClearBlackListSync(const base::Time& begin_time,
79 const base::Time& end_time);
80
81 // Callback passed to PreviewsOptOutStore::LoadBlackList. Moves the returned
82 // map into |black_list_item_map_| and runs any outstanding
83 // |pending_callbacks_|.
84 void LoadBlackListDone(std::unique_ptr<BlackListItemMap> black_list_item_map);
85
86 // Called while waiting for the black list to be loaded from |opt_out_store_|.
87 // Enqueues a task to run when PreviewsOptOutStore::LoadBlackList has
88 // completed. Maintains the order that tasks were called in.
89 void QueuePendingTask(QueueClosure callback);
90
91 // Map maintaining the black list in memory.
92 std::unique_ptr<BlackListItemMap> black_list_item_map_;
93
94 // Whether the black list is done being loaded from |opt_out_store_|.
95 bool loaded_;
96
97 // Backing store representation of the black list.
98 std::unique_ptr<PreviewsOptOutStore> opt_out_store_;
99
100 // Callbacks to be run after PreviewsOptOutStore::LoadBlackList has completed.
101 std::queue<QueueClosure> pending_callbacks_;
102
103 base::ThreadChecker thread_checker_;
104
105 base::WeakPtrFactory<PreviewsBlackList> weak_factory_;
106
107 DISALLOW_COPY_AND_ASSIGN(PreviewsBlackList);
108 };
109
110 } // namespace previews
111
112 #endif // COMPONENTS_PREVIEWS_PREVIEWS_BLACK_LIST_ITEM_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698