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

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

Issue 2335023002: Adding a previews IO-thread blacklist (Closed)
Patch Set: tbansal 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 // |opt_out_store| is the backing store to retrieve and store black list
38 // information, and can be null.
tbansal1 2016/09/14 17:00:03 May be explain how the |opt_out_store| is used? It
RyanSturm 2016/09/14 18:36:42 Done.
39 explicit PreviewsBlackList(
40 std::unique_ptr<PreviewsOptOutStore> opt_out_store);
41 ~PreviewsBlackList();
42
43 typedef base::Closure QueueClosure;
44 typedef base::Callback<void(bool)> BlackListedCallback;
45
46 // Asynchronously adds a new navigation to to the in-memory black list and
47 // backing store. |opt_out| is whether the uesr opted out of the preview or
48 // navigated away from the page by another way.
49 void AddPreviewNavigation(const std::string& host_name,
tbansal1 2016/09/14 17:00:03 Is it possible to pass GURL? So that, the conversi
RyanSturm 2016/09/14 18:36:42 Done.
50 bool opt_out,
51 PreviewsType type);
52
53 // Synchronously determines if |host_name| should be allowed to show previews.
54 // If the black list has loaded yet, this will always return false.
55 bool IsLoadedAndAllowed(const std::string& host_name);
tbansal1 2016/09/14 17:00:03 Why does this function not take PreviewsType as in
RyanSturm 2016/09/14 18:36:42 The store will track PreviewsType, but PreviewsTyp
tbansal1 2016/09/14 20:17:50 okay, please add PreviewType so that callers do no
RyanSturm 2016/09/14 21:01:03 Done.
56
57 private:
58 // Synchronously adds a new navigation to the in-memory black list. Adds a new
59 // navigation to backing store. |opt_out| is whether the uesr opted out of
60 // the preview or navigated away from the page by another way.
61 void AddPreviewNavigationSync(const std::string& host_name,
62 bool opt_out,
63 PreviewsType type);
64
65 // Returns the PreviewsBlackListItem representing |host_name|. If there is no
66 // item for |host_name|, one will be created iff |create_if_needed| is true.
67 PreviewsBlackListItem* GetBlackListItem(const std::string& host_name,
68 bool create_if_needed);
69
70 // Callback passed to the backing store when loading black list information.
71 // Moves the returned map into the in-memory black list and runs any
72 // outstanding tasks.
73 void LoadBlackListDone(std::unique_ptr<BlackListItemMap> black_list_item_map);
74
75 // Called while waiting for the black list to be loaded from the backing
76 // store.
77 // Enqueues a task to run when when loading black list information has
78 // completed. Maintains the order that tasks were called in.
79 void QueuePendingTask(QueueClosure callback);
80
81 // Map maintaining the in-memory black list.
82 std::unique_ptr<BlackListItemMap> black_list_item_map_;
83
84 // Whether the black list is done being loaded from the backing store.
85 bool loaded_;
86
87 // The backing store of the black list information.
88 std::unique_ptr<PreviewsOptOutStore> opt_out_store_;
89
90 // Callbacks to be run after loading information from the backing store has
91 // completed.
92 std::queue<QueueClosure> pending_callbacks_;
tbansal1 2016/09/14 17:00:03 Is the queue really needed? Is it possible to just
RyanSturm 2016/09/14 18:36:42 I'd rather have it. It's possible, but unlikely th
tbansal1 2016/09/14 20:17:50 You can keep them in sync by simply dropping event
RyanSturm 2016/09/14 21:01:03 Acknowledged. Seems like we might as well not drop
93
94 base::ThreadChecker thread_checker_;
95
96 base::WeakPtrFactory<PreviewsBlackList> weak_factory_;
97
98 DISALLOW_COPY_AND_ASSIGN(PreviewsBlackList);
99 };
100
101 } // namespace previews
102
103 #endif // COMPONENTS_PREVIEWS_PREVIEWS_BLACK_LIST_ITEM_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698