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

Unified Diff: components/previews/previews_black_list_item.h

Issue 2335023002: Adding a previews IO-thread blacklist (Closed)
Patch Set: updated 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_item.h
diff --git a/components/previews/previews_black_list_item.h b/components/previews/previews_black_list_item.h
new file mode 100644
index 0000000000000000000000000000000000000000..ca129179dafbc178a8b5939958523adb1967727c
--- /dev/null
+++ b/components/previews/previews_black_list_item.h
@@ -0,0 +1,74 @@
+// 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_ITEM_H_
+#define COMPONENTS_PREVIEWS_PREVIEWS_BLACK_LIST_ITEM_H_
+
+#include <stdint.h>
+
+#include <list>
+#include <map>
+#include <memory>
+#include <string>
+
+#include "base/callback.h"
+#include "base/macros.h"
+#include "base/optional.h"
+#include "base/time/time.h"
+
+namespace previews {
+enum class PreviewsType;
+
+// Stores the recent black list history for a single host. Stores
+// |stored_history_length| of the most recent previews navigations. To determine
+// previews eligiblity fewer than |opt_out_black_list_threshold| out of the past
+// |stored_history_length| navigations must be opt outs. |black_list_duration|
+// is the amount of time that elapses until the host is no longer on the black
+// list.
+class PreviewsBlackListItem {
+ public:
+ PreviewsBlackListItem(const int stored_history_length,
+ const int opt_out_black_list_threshold,
+ const base::TimeDelta& black_list_duration);
+
+ ~PreviewsBlackListItem();
+
+ struct TimeOptOut {
tbansal1 2016/09/13 23:52:45 comments please.
RyanSturm 2016/09/14 16:44:30 Done.
+ base::Time entry_time;
+ bool opt_out;
+ };
+
+ // Adds a new navigation and returns the base::Time that the event was
+ // recorded.
+ void AddPreviewNavigation(bool opt_out, const base::Time& entry_time);
+
+ // Whether the host name corresponding to |this| should be disallowed from
+ // showing previews.
+ bool IsBlackListed(const base::Time& now) const;
+
+ private:
+ // The amount of entries to store to determine preview eligibility.
+ const int stored_history_length_;
+ // The number opt outs in recent history that will trigger blacklisting.
+ const int opt_out_black_list_threshold_;
+ // The amount of time to black list a domain after the most recent opt out.
+ const base::TimeDelta black_list_duration_;
+
+ // The |stored_history_length_| most recent preivews navigation. Is maintained
+ // as a sorted vector.
+ std::list<TimeOptOut> opt_out_history_;
+
+ // Time of the most recent opt out.
+ base::Optional<base::Time> most_recent_opt_out_time_;
+
+ // The total number of opt outs currently in |opt_out_history_|.
+ int total_opt_out_;
+};
+
+typedef std::map<std::string, std::unique_ptr<PreviewsBlackListItem>>
+ BlackListItemMap;
+
+} // namespace previews
+
+#endif // COMPONENTS_PREVIEWS_PREVIEWS_BLACK_LIST_ITEM_H_

Powered by Google App Engine
This is Rietveld 408576698