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

Unified Diff: components/previews/core/previews_io_data.cc

Issue 2388253002: Use the previews black list for offline previews (Closed)
Patch Set: mmenke comments Created 4 years, 2 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
« no previous file with comments | « components/previews/core/previews_io_data.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: components/previews/core/previews_io_data.cc
diff --git a/components/previews/core/previews_io_data.cc b/components/previews/core/previews_io_data.cc
index 54b5d0725c0e6c64600462971aa81eadfa030e36..740e18f9e015fec835f9d1842007b77f53468bd9 100644
--- a/components/previews/core/previews_io_data.cc
+++ b/components/previews/core/previews_io_data.cc
@@ -5,22 +5,26 @@
#include "components/previews/core/previews_io_data.h"
#include "base/bind.h"
#include "base/bind_helpers.h"
#include "base/files/file_path.h"
#include "base/location.h"
#include "base/memory/ptr_util.h"
#include "base/sequenced_task_runner.h"
#include "base/time/default_clock.h"
#include "components/previews/core/previews_black_list.h"
+#include "components/previews/core/previews_experiments.h"
#include "components/previews/core/previews_opt_out_store.h"
#include "components/previews/core/previews_ui_service.h"
+#include "net/nqe/network_quality_estimator.h"
+#include "net/url_request/url_request.h"
+#include "net/url_request/url_request_context.h"
#include "url/gurl.h"
namespace previews {
PreviewsIOData::PreviewsIOData(
const scoped_refptr<base::SingleThreadTaskRunner>& ui_task_runner,
const scoped_refptr<base::SingleThreadTaskRunner>& io_task_runner)
: ui_task_runner_(ui_task_runner),
io_task_runner_(io_task_runner),
weak_factory_(this) {}
@@ -57,11 +61,32 @@ void PreviewsIOData::AddPreviewNavigation(const GURL& url,
DCHECK(io_task_runner_->BelongsToCurrentThread());
previews_black_list_->AddPreviewNavigation(url, opt_out, type);
}
void PreviewsIOData::ClearBlackList(base::Time begin_time,
base::Time end_time) {
DCHECK(io_task_runner_->BelongsToCurrentThread());
previews_black_list_->ClearBlackList(begin_time, end_time);
}
+bool PreviewsIOData::ShouldAllowPreview(const net::URLRequest& request,
+ PreviewsType type) const {
+ if (!IsOfflinePreviewsEnabled())
+ return false;
+ // The blacklist will disallow certain hosts for periods of time based on
+ // user's opting out of the preview
+ if (!previews_black_list_ ||
+ !previews_black_list_->IsLoadedAndAllowed(request.url(), type)) {
+ return false;
+ }
+ net::NetworkQualityEstimator* network_quality_estimator =
+ request.context()->network_quality_estimator();
+ if (!network_quality_estimator)
+ return false;
+
+ net::EffectiveConnectionType effective_connection_type =
+ network_quality_estimator->GetEffectiveConnectionType();
+ return effective_connection_type >= net::EFFECTIVE_CONNECTION_TYPE_OFFLINE &&
+ effective_connection_type <= net::EFFECTIVE_CONNECTION_TYPE_SLOW_2G;
+}
+
} // namespace previews
« no previous file with comments | « components/previews/core/previews_io_data.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698