| 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 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 63 bool IsLoadedAndAllowed(const GURL& url, PreviewsType type) const; | 63 bool IsLoadedAndAllowed(const GURL& url, PreviewsType type) const; |
| 64 | 64 |
| 65 // Asynchronously deletes all entries in the in-memory black list. Informs | 65 // Asynchronously deletes all entries in the in-memory black list. Informs |
| 66 // the backing store to delete entries between |begin_time| and |end_time|, | 66 // 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 | 67 // 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. | 68 // 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); | 69 void ClearBlackList(base::Time begin_time, base::Time end_time); |
| 70 | 70 |
| 71 // Returns a new PreviewsBlackListItem representing |host_name|. Adds the new | 71 // Returns a new PreviewsBlackListItem representing |host_name|. Adds the new |
| 72 // item to |black_list_item_map|. | 72 // item to |black_list_item_map|. |
| 73 static PreviewsBlackListItem* GetOrCreateBlackListItem( | 73 static PreviewsBlackListItem* GetOrCreateBlackListItemForMap( |
| 74 BlackListItemMap* black_list_item_map, | 74 BlackListItemMap* black_list_item_map, |
| 75 const std::string& host_name); | 75 const std::string& host_name); |
| 76 | 76 |
| 77 // Returns the PreviewsBlackListItem representing |host_name| in | 77 // Returns a new PreviewsBlackListItem for the host indifferent black list |
| 78 // |black_list_item_map|. If there is no item for |host_name|, returns null. | 78 // that does not consider host name when determining eligibility. |
| 79 static PreviewsBlackListItem* GetBlackListItem( | 79 static std::unique_ptr<PreviewsBlackListItem> |
| 80 const BlackListItemMap& black_list_item_map, | 80 CreateHostIndifferentBlackListItem(); |
| 81 const std::string& host_name); | |
| 82 | 81 |
| 83 private: | 82 private: |
| 84 // Synchronous version of AddPreviewNavigation method. | 83 // Synchronous version of AddPreviewNavigation method. |
| 85 void AddPreviewNavigationSync(const GURL& host_name, | 84 void AddPreviewNavigationSync(const GURL& host_name, |
| 86 bool opt_out, | 85 bool opt_out, |
| 87 PreviewsType type); | 86 PreviewsType type); |
| 88 | 87 |
| 89 // Synchronous version of ClearBlackList method. | 88 // Synchronous version of ClearBlackList method. |
| 90 void ClearBlackListSync(base::Time begin_time, base::Time end_time); | 89 void ClearBlackListSync(base::Time begin_time, base::Time end_time); |
| 91 | 90 |
| 92 // Callback passed to the backing store when loading black list information. | 91 // Callback passed to the backing store when loading black list information. |
| 93 // Moves the returned map into the in-memory black list and runs any | 92 // Moves the |black_list_item_map| and |host_indifferent_black_list_item| into |
| 94 // outstanding tasks. | 93 // the in-memory black list and runs any outstanding tasks. |
| 95 void LoadBlackListDone(std::unique_ptr<BlackListItemMap> black_list_item_map); | 94 void LoadBlackListDone( |
| 95 std::unique_ptr<BlackListItemMap> black_list_item_map, |
| 96 std::unique_ptr<PreviewsBlackListItem> host_indifferent_black_list_item); |
| 96 | 97 |
| 97 // Called while waiting for the black list to be loaded from the backing | 98 // Called while waiting for the black list to be loaded from the backing |
| 98 // store. | 99 // store. |
| 99 // Enqueues a task to run when when loading black list information has | 100 // Enqueues a task to run when when loading black list information has |
| 100 // completed. Maintains the order that tasks were called in. | 101 // completed. Maintains the order that tasks were called in. |
| 101 void QueuePendingTask(base::Closure callback); | 102 void QueuePendingTask(base::Closure callback); |
| 102 | 103 |
| 103 // Map maintaining the in-memory black list. | 104 // Map maintaining the in-memory black list. |
| 104 std::unique_ptr<BlackListItemMap> black_list_item_map_; | 105 std::unique_ptr<BlackListItemMap> black_list_item_map_; |
| 105 | 106 |
| 107 // Host indifferent opt out history. |
| 108 std::unique_ptr<PreviewsBlackListItem> host_indifferent_black_list_item_; |
| 109 |
| 106 // Whether the black list is done being loaded from the backing store. | 110 // Whether the black list is done being loaded from the backing store. |
| 107 bool loaded_; | 111 bool loaded_; |
| 108 | 112 |
| 109 // The time of the last opt out for this session. | 113 // The time of the last opt out for this session. |
| 110 base::Optional<base::Time> last_opt_out_time_; | 114 base::Optional<base::Time> last_opt_out_time_; |
| 111 | 115 |
| 112 // The backing store of the black list information. | 116 // The backing store of the black list information. |
| 113 std::unique_ptr<PreviewsOptOutStore> opt_out_store_; | 117 std::unique_ptr<PreviewsOptOutStore> opt_out_store_; |
| 114 | 118 |
| 115 // Callbacks to be run after loading information from the backing store has | 119 // Callbacks to be run after loading information from the backing store has |
| 116 // completed. | 120 // completed. |
| 117 std::queue<base::Closure> pending_callbacks_; | 121 std::queue<base::Closure> pending_callbacks_; |
| 118 | 122 |
| 119 std::unique_ptr<base::Clock> clock_; | 123 std::unique_ptr<base::Clock> clock_; |
| 120 | 124 |
| 121 base::ThreadChecker thread_checker_; | 125 base::ThreadChecker thread_checker_; |
| 122 | 126 |
| 123 base::WeakPtrFactory<PreviewsBlackList> weak_factory_; | 127 base::WeakPtrFactory<PreviewsBlackList> weak_factory_; |
| 124 | 128 |
| 125 DISALLOW_COPY_AND_ASSIGN(PreviewsBlackList); | 129 DISALLOW_COPY_AND_ASSIGN(PreviewsBlackList); |
| 126 }; | 130 }; |
| 127 | 131 |
| 128 } // namespace previews | 132 } // namespace previews |
| 129 | 133 |
| 130 #endif // COMPONENTS_PREVIEWS_CORE_PREVIEWS_BLACK_LIST_H_ | 134 #endif // COMPONENTS_PREVIEWS_CORE_PREVIEWS_BLACK_LIST_H_ |
| OLD | NEW |