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

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

Issue 2477073002: Adding UMA to track previews opt outs and blacklist eligibility (Closed)
Patch Set: typo Created 4 years, 1 month 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/core/previews_io_data.cc
diff --git a/components/previews/core/previews_io_data.cc b/components/previews/core/previews_io_data.cc
index 496ef6dd69141a7c0af73634837ad38984b1c451..ed9f784d7cbd27e7da14f95ecaa8508f7c0e5cb0 100644
--- a/components/previews/core/previews_io_data.cc
+++ b/components/previews/core/previews_io_data.cc
@@ -9,6 +9,7 @@
#include "base/files/file_path.h"
#include "base/location.h"
#include "base/memory/ptr_util.h"
+#include "base/metrics/histogram.h"
#include "base/sequenced_task_runner.h"
#include "base/time/default_clock.h"
#include "components/previews/core/previews_black_list.h"
@@ -21,6 +22,23 @@
namespace previews {
+namespace {
+
+void LogPreviewsEligibilityReason(PreviewsEligibilityReason status,
+ PreviewsType type) {
+ switch (type) {
+ case PreviewsType::OFFLINE:
+ UMA_HISTOGRAM_ENUMERATION(
+ "Previews.EligibilityReason.Offline", static_cast<int>(status),
+ static_cast<int>(PreviewsEligibilityReason::LAST));
+ break;
+ default:
+ NOTREACHED();
+ }
+}
+
+} // namespace
+
PreviewsIOData::PreviewsIOData(
const scoped_refptr<base::SingleThreadTaskRunner>& ui_task_runner,
const scoped_refptr<base::SingleThreadTaskRunner>& io_task_runner)
@@ -73,19 +91,34 @@ bool PreviewsIOData::ShouldAllowPreview(const net::URLRequest& request,
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)) {
+ if (!previews_black_list_) {
+ LogPreviewsEligibilityReason(
+ PreviewsEligibilityReason::BLACKLIST_UNAVAILABLE, type);
+ return false;
+ }
+ PreviewsEligibilityReason status =
+ previews_black_list_->IsLoadedAndAllowed(request.url(), type);
+ if (status != PreviewsEligibilityReason::ALLOWED) {
+ LogPreviewsEligibilityReason(status, type);
return false;
}
net::NetworkQualityEstimator* network_quality_estimator =
request.context()->network_quality_estimator();
- if (!network_quality_estimator)
+ if (!network_quality_estimator ||
+ network_quality_estimator->GetEffectiveConnectionType() <
+ net::EFFECTIVE_CONNECTION_TYPE_OFFLINE) {
+ LogPreviewsEligibilityReason(
+ PreviewsEligibilityReason::NETWORK_QUALITY_UNAVAILABLE, type);
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;
+ }
+ if (network_quality_estimator->GetEffectiveConnectionType() >
+ net::EFFECTIVE_CONNECTION_TYPE_SLOW_2G) {
+ LogPreviewsEligibilityReason(PreviewsEligibilityReason::NETWORK_NOT_SLOW,
+ type);
+ return false;
+ }
+ LogPreviewsEligibilityReason(PreviewsEligibilityReason::ALLOWED, type);
+ return true;
}
} // namespace previews
« no previous file with comments | « components/previews/core/previews_black_list_unittest.cc ('k') | components/previews/core/previews_io_data_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698