OLD | NEW |
---|---|
(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 class GURL; | |
22 | |
23 namespace base { | |
24 class Time; | |
25 } | |
26 | |
27 namespace previews { | |
28 class PreviewsBlackListItem; | |
29 | |
30 // Manages the state of black listed domains for the previews experiment. Loads | |
31 // the stored black list from |opt_out_store| and manages an in memory black | |
32 // list on the IO thread. Updates to the black list are stored in memory and | |
33 // pushed to the store. Asynchronous modifications are stored in a queue and | |
34 // executed in order. Reading from the black list is always synchronous, and if | |
35 // the black list is not currently loaded (e.g., at startup, after clearing | |
36 // browsing history), domains are reported as black listed. | |
37 class PreviewsBlackList { | |
38 public: | |
39 // |opt_out_store| is the backing store to retrieve and store black list | |
40 // information, and can be null. When |opt_out_store| is null, the in-memory | |
41 // map will be immeadiately loaded to empty. If |opt_out_store| is non-null, | |
42 // it will be used to load the in-memory map asynchronously. | |
43 explicit PreviewsBlackList( | |
44 std::unique_ptr<PreviewsOptOutStore> opt_out_store); | |
45 ~PreviewsBlackList(); | |
46 | |
47 // Asynchronously adds a new navigation to to the in-memory black list and | |
48 // backing store. |opt_out| is whether the user opted out of the preview or | |
49 // navigated away from the page without opting out. |type| is only passed to | |
50 // the backing store. | |
51 void AddPreviewNavigation(const GURL& url, bool opt_out, 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. |type| is | |
55 // not used to make this decision. | |
56 bool IsLoadedAndAllowed(const GURL& url, PreviewsType type); | |
57 | |
58 private: | |
59 typedef base::Closure QueueClosure; | |
60 | |
61 // Synchronous version of AddPreviewNavigation method. | |
62 void AddPreviewNavigationSync(const GURL& host_name, | |
63 bool opt_out, | |
64 PreviewsType type); | |
65 | |
66 // Returns the PreviewsBlackListItem representing |host_name|. If there is no | |
67 // item for |host_name|, one will be created iff |create_if_needed| is true. | |
68 PreviewsBlackListItem* GetBlackListItem(const std::string& host_name, | |
69 bool create_if_needed); | |
70 | |
71 // Callback passed to the backing store when loading black list information. | |
72 // Moves the returned map into the in-memory black list and runs any | |
73 // outstanding tasks. | |
74 void LoadBlackListDone(std::unique_ptr<BlackListItemMap> black_list_item_map); | |
75 | |
76 // Called while waiting for the black list to be loaded from the backing | |
77 // store. | |
78 // Enqueues a task to run when when loading black list information has | |
79 // completed. Maintains the order that tasks were called in. | |
80 void QueuePendingTask(QueueClosure callback); | |
81 | |
82 // Map maintaining the in-memory black list. | |
83 std::unique_ptr<BlackListItemMap> black_list_item_map_; | |
tbansal1
2016/09/15 16:34:25
Is there a limit on the size of the map?
RyanSturm
2016/09/19 18:07:25
Done.
| |
84 | |
85 // Whether the black list is done being loaded from the backing store. | |
86 bool loaded_; | |
87 | |
88 // The backing store of the black list information. | |
89 std::unique_ptr<PreviewsOptOutStore> opt_out_store_; | |
90 | |
91 // Callbacks to be run after loading information from the backing store has | |
92 // completed. | |
93 std::queue<QueueClosure> pending_callbacks_; | |
94 | |
95 base::ThreadChecker thread_checker_; | |
96 | |
97 base::WeakPtrFactory<PreviewsBlackList> weak_factory_; | |
98 | |
99 DISALLOW_COPY_AND_ASSIGN(PreviewsBlackList); | |
100 }; | |
101 | |
102 } // namespace previews | |
103 | |
104 #endif // COMPONENTS_PREVIEWS_PREVIEWS_BLACK_LIST_ITEM_H_ | |
OLD | NEW |