Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(557)

Unified Diff: components/previews/previews_black_list.h

Issue 2335023002: Adding a previews IO-thread blacklist (Closed)
Patch Set: tbansal comments Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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..dc395a04b246160989e59b5028e581c269f2658c
--- /dev/null
+++ b/components/previews/previews_black_list.h
@@ -0,0 +1,103 @@
+// 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:
+ // |opt_out_store| is the backing store to retrieve and store black list
+ // information, and can be null.
tbansal1 2016/09/14 17:00:03 May be explain how the |opt_out_store| is used? It
RyanSturm 2016/09/14 18:36:42 Done.
+ explicit PreviewsBlackList(
+ std::unique_ptr<PreviewsOptOutStore> opt_out_store);
+ ~PreviewsBlackList();
+
+ typedef base::Closure QueueClosure;
+ typedef base::Callback<void(bool)> BlackListedCallback;
+
+ // Asynchronously adds a new navigation to to the in-memory black list and
+ // backing 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,
tbansal1 2016/09/14 17:00:03 Is it possible to pass GURL? So that, the conversi
RyanSturm 2016/09/14 18:36:42 Done.
+ bool opt_out,
+ PreviewsType type);
+
+ // Synchronously determines if |host_name| should be allowed to show previews.
+ // If the black list has loaded yet, this will always return false.
+ bool IsLoadedAndAllowed(const std::string& host_name);
tbansal1 2016/09/14 17:00:03 Why does this function not take PreviewsType as in
RyanSturm 2016/09/14 18:36:42 The store will track PreviewsType, but PreviewsTyp
tbansal1 2016/09/14 20:17:50 okay, please add PreviewType so that callers do no
RyanSturm 2016/09/14 21:01:03 Done.
+
+ private:
+ // Synchronously adds a new navigation to the in-memory black list. Adds a new
+ // navigation to backing 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(const std::string& host_name,
+ bool create_if_needed);
+
+ // Callback passed to the backing store when loading black list information.
+ // Moves the returned map into the in-memory black list and runs any
+ // outstanding tasks.
+ void LoadBlackListDone(std::unique_ptr<BlackListItemMap> black_list_item_map);
+
+ // Called while waiting for the black list to be loaded from the backing
+ // store.
+ // Enqueues a task to run when when loading black list information has
+ // completed. Maintains the order that tasks were called in.
+ void QueuePendingTask(QueueClosure callback);
+
+ // Map maintaining the in-memory black list.
+ std::unique_ptr<BlackListItemMap> black_list_item_map_;
+
+ // Whether the black list is done being loaded from the backing store.
+ bool loaded_;
+
+ // The backing store of the black list information.
+ std::unique_ptr<PreviewsOptOutStore> opt_out_store_;
+
+ // Callbacks to be run after loading information from the backing store has
+ // completed.
+ std::queue<QueueClosure> pending_callbacks_;
tbansal1 2016/09/14 17:00:03 Is the queue really needed? Is it possible to just
RyanSturm 2016/09/14 18:36:42 I'd rather have it. It's possible, but unlikely th
tbansal1 2016/09/14 20:17:50 You can keep them in sync by simply dropping event
RyanSturm 2016/09/14 21:01:03 Acknowledged. Seems like we might as well not drop
+
+ base::ThreadChecker thread_checker_;
+
+ base::WeakPtrFactory<PreviewsBlackList> weak_factory_;
+
+ DISALLOW_COPY_AND_ASSIGN(PreviewsBlackList);
+};
+
+} // namespace previews
+
+#endif // COMPONENTS_PREVIEWS_PREVIEWS_BLACK_LIST_ITEM_H_

Powered by Google App Engine
This is Rietveld 408576698