| 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 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 58 // If the black list has loaded yet, this will always return false. |type| is | 58 // If the black list has loaded yet, this will always return false. |type| is |
| 59 // not used to make this decision. | 59 // not used to make this decision. |
| 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 |
| 69 // item to |black_list_item_map|. |
| 70 static PreviewsBlackListItem* GetOrCreateBlackListItem( |
| 71 BlackListItemMap* black_list_item_map, |
| 72 const std::string& host_name); |
| 73 |
| 74 // Returns the PreviewsBlackListItem representing |host_name| in |
| 75 // |black_list_item_map|. If there is no item for |host_name|, returns null. |
| 76 static PreviewsBlackListItem* GetBlackListItem( |
| 77 const BlackListItemMap& black_list_item_map, |
| 78 const std::string& host_name); |
| 79 |
| 68 private: | 80 private: |
| 69 // Synchronous version of AddPreviewNavigation method. | 81 // Synchronous version of AddPreviewNavigation method. |
| 70 void AddPreviewNavigationSync(const GURL& host_name, | 82 void AddPreviewNavigationSync(const GURL& host_name, |
| 71 bool opt_out, | 83 bool opt_out, |
| 72 PreviewsType type); | 84 PreviewsType type); |
| 73 | 85 |
| 74 // Returns the PreviewsBlackListItem representing |host_name|. If there is no | |
| 75 // item for |host_name|, returns null. | |
| 76 PreviewsBlackListItem* GetBlackListItem(const std::string& host_name) const; | |
| 77 | |
| 78 // Synchronous version of ClearBlackList method. | 86 // Synchronous version of ClearBlackList method. |
| 79 void ClearBlackListSync(base::Time begin_time, base::Time end_time); | 87 void ClearBlackListSync(base::Time begin_time, base::Time end_time); |
| 80 | 88 |
| 81 // Returns a new PreviewsBlackListItem representing |host_name|. Adds the new | |
| 82 // item to the in-memory map. | |
| 83 PreviewsBlackListItem* CreateBlackListItem(const std::string& host_name); | |
| 84 | |
| 85 // Callback passed to the backing store when loading black list information. | 89 // Callback passed to the backing store when loading black list information. |
| 86 // Moves the returned map into the in-memory black list and runs any | 90 // Moves the returned map into the in-memory black list and runs any |
| 87 // outstanding tasks. | 91 // outstanding tasks. |
| 88 void LoadBlackListDone(std::unique_ptr<BlackListItemMap> black_list_item_map); | 92 void LoadBlackListDone(std::unique_ptr<BlackListItemMap> black_list_item_map); |
| 89 | 93 |
| 90 // Called while waiting for the black list to be loaded from the backing | 94 // Called while waiting for the black list to be loaded from the backing |
| 91 // store. | 95 // store. |
| 92 // Enqueues a task to run when when loading black list information has | 96 // Enqueues a task to run when when loading black list information has |
| 93 // completed. Maintains the order that tasks were called in. | 97 // completed. Maintains the order that tasks were called in. |
| 94 void QueuePendingTask(base::Closure callback); | 98 void QueuePendingTask(base::Closure callback); |
| 95 | 99 |
| 96 // Evicts one entry from the in-memory black list based on recency of a hosts | |
| 97 // most recent opt out time. | |
| 98 void EvictOldestOptOut(); | |
| 99 | |
| 100 // Map maintaining the in-memory black list. | 100 // Map maintaining the in-memory black list. |
| 101 std::unique_ptr<BlackListItemMap> black_list_item_map_; | 101 std::unique_ptr<BlackListItemMap> black_list_item_map_; |
| 102 | 102 |
| 103 // Whether the black list is done being loaded from the backing store. | 103 // Whether the black list is done being loaded from the backing store. |
| 104 bool loaded_; | 104 bool loaded_; |
| 105 | 105 |
| 106 // The backing store of the black list information. | 106 // The backing store of the black list information. |
| 107 std::unique_ptr<PreviewsOptOutStore> opt_out_store_; | 107 std::unique_ptr<PreviewsOptOutStore> opt_out_store_; |
| 108 | 108 |
| 109 // Callbacks to be run after loading information from the backing store has | 109 // Callbacks to be run after loading information from the backing store has |
| 110 // completed. | 110 // completed. |
| 111 std::queue<base::Closure> pending_callbacks_; | 111 std::queue<base::Closure> pending_callbacks_; |
| 112 | 112 |
| 113 std::unique_ptr<base::Clock> clock_; | 113 std::unique_ptr<base::Clock> clock_; |
| 114 | 114 |
| 115 base::ThreadChecker thread_checker_; | 115 base::ThreadChecker thread_checker_; |
| 116 | 116 |
| 117 base::WeakPtrFactory<PreviewsBlackList> weak_factory_; | 117 base::WeakPtrFactory<PreviewsBlackList> weak_factory_; |
| 118 | 118 |
| 119 DISALLOW_COPY_AND_ASSIGN(PreviewsBlackList); | 119 DISALLOW_COPY_AND_ASSIGN(PreviewsBlackList); |
| 120 }; | 120 }; |
| 121 | 121 |
| 122 } // namespace previews | 122 } // namespace previews |
| 123 | 123 |
| 124 #endif // COMPONENTS_PREVIEWS_CORE_PREVIEWS_BLACK_LIST_H_ | 124 #endif // COMPONENTS_PREVIEWS_CORE_PREVIEWS_BLACK_LIST_H_ |
| OLD | NEW |