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