Chromium Code Reviews| Index: components/previews/previews_black_list.h |
| diff --git a/components/previews/previews_black_list.h b/components/previews/previews_black_list.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..5d626b806a2e45128f1b58a6ad509430d1940145 |
| --- /dev/null |
| +++ b/components/previews/previews_black_list.h |
| @@ -0,0 +1,112 @@ |
| +// Copyright 2016 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#ifndef COMPONENTS_PREVIEWS_PREVIEWS_BLACK_LIST_H_ |
| +#define COMPONENTS_PREVIEWS_PREVIEWS_BLACK_LIST_H_ |
| + |
| +#include <stdint.h> |
| + |
| +#include <memory> |
| +#include <queue> |
| +#include <string> |
| +#include <vector> |
| + |
| +#include "base/callback.h" |
| +#include "base/macros.h" |
| +#include "base/memory/weak_ptr.h" |
| +#include "base/threading/thread_checker.h" |
| +#include "components/previews/previews_opt_out_store.h" |
| + |
| +namespace base { |
| +class Time; |
| +} |
| + |
| +namespace previews { |
| +class PreviewsBlackListItem; |
| + |
| +// Manages the state of black listed domains for the previews experiment. Loads |
| +// the stored black list from |opt_out_store| and manages an in memory black |
| +// list on the IO thread. Updates to the black list are stored in memory and |
| +// pushed to the store. Asynchronous modifications are stored in a queue and |
| +// executed in order. Reading from the black list is always synchronous, and if |
| +// the black list is not currently loaded (e.g., at startup, after clearing |
| +// browsing history), domains are reported as black listed. |
| +class PreviewsBlackList { |
| + public: |
| + PreviewsBlackList(std::unique_ptr<PreviewsOptOutStore> opt_out_store); |
|
tbansal1
2016/09/13 23:52:45
explicit.
RyanSturm
2016/09/14 16:44:30
Done.
|
| + ~PreviewsBlackList(); |
| + |
| + typedef base::Closure QueueClosure; |
| + typedef base::Callback<void(bool)> BlackListedCallback; |
| + |
| + // Asynchronously adds a new navigation to |black_list_item_map_| and |
| + // |opt_out_store_|. |opt_out| is whether the uesr opted out of the preview or |
| + // navigated away from the page by another way. |
| + void AddPreviewNavigation(const std::string& host_name, |
| + bool opt_out, |
| + PreviewsType type); |
| + |
| + // Synchronously determines if |host_name| should be allowed to show previews. |
| + // If LoadBlackListDone has not been called yet, this will always return |
|
tbansal1
2016/09/13 23:52:45
what is LoadBlackListDone?
RyanSturm
2016/09/14 16:44:30
Done.
|
| + // false. |
| + bool IsLoadedAndAllowed(const std::string& host_name); |
| + |
| + // Asynchronously deletes all entries in |black_list_item_map_|. Informs |
| + // |opt_out_store_| to delete entries between |begin_time| and |end_time|. |
|
tbansal1
2016/09/13 23:52:45
Generally, documentation of public functions shoul
RyanSturm
2016/09/14 16:44:30
Done.
|
| + // Reloads entries into memory from |opt_out_store_|. If |opt_out_store_| is |
| + // null, resets all history in |black_list_item_map_|. |
| + void ClearBlackList(const base::Time& begin_time, const base::Time& end_time); |
| + |
| + private: |
| + // Synchronously adds a new navigation to |black_list_item_map_|. Adds a new |
| + // navigation to |opt_out_store_|. |opt_out| is whether the uesr opted out of |
| + // the preview or navigated away from the page by another way. |
| + void AddPreviewNavigationSync(const std::string& host_name, |
| + bool opt_out, |
| + PreviewsType type); |
| + |
| + // Returns the PreviewsBlackListItem representing |host_name|. If there is no |
| + // item for |host_name|, one will be created iff |create_if_needed| is true. |
| + PreviewsBlackListItem* GetBlackListItem(std::string host_name, |
|
tbansal1
2016/09/13 23:52:45
pass std::string as const ref?
RyanSturm
2016/09/14 16:44:30
Done.
|
| + bool create_if_needed); |
| + |
| + // Synchronously deletes all entries in |black_list_item_map_|. Informs |
| + // |opt_out_store_| to delete entries between |begin_time| and |end_time|. |
| + // Reloads entries into memory from |opt_out_store_|. If |opt_out_store_| is |
| + // null, resets all history in |black_list_item_map_|. |
| + void ClearBlackListSync(const base::Time& begin_time, |
| + const base::Time& end_time); |
| + |
| + // Callback passed to PreviewsOptOutStore::LoadBlackList. Moves the returned |
| + // map into |black_list_item_map_| and runs any outstanding |
| + // |pending_callbacks_|. |
| + void LoadBlackListDone(std::unique_ptr<BlackListItemMap> black_list_item_map); |
| + |
| + // Called while waiting for the black list to be loaded from |opt_out_store_|. |
| + // Enqueues a task to run when PreviewsOptOutStore::LoadBlackList has |
| + // completed. Maintains the order that tasks were called in. |
| + void QueuePendingTask(QueueClosure callback); |
| + |
| + // Map maintaining the black list in memory. |
| + std::unique_ptr<BlackListItemMap> black_list_item_map_; |
| + |
| + // Whether the black list is done being loaded from |opt_out_store_|. |
| + bool loaded_; |
| + |
| + // Backing store representation of the black list. |
| + std::unique_ptr<PreviewsOptOutStore> opt_out_store_; |
| + |
| + // Callbacks to be run after PreviewsOptOutStore::LoadBlackList has completed. |
| + std::queue<QueueClosure> pending_callbacks_; |
| + |
| + base::ThreadChecker thread_checker_; |
| + |
| + base::WeakPtrFactory<PreviewsBlackList> weak_factory_; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(PreviewsBlackList); |
| +}; |
| + |
| +} // namespace previews |
| + |
| +#endif // COMPONENTS_PREVIEWS_PREVIEWS_BLACK_LIST_ITEM_H_ |