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

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

Issue 2477073002: Adding UMA to track previews opt outs and blacklist eligibility (Closed)
Patch Set: rebase 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..71ead03890e675e05a53966347bd145e84965021 100644
--- a/components/previews/core/previews_io_data.cc
+++ b/components/previews/core/previews_io_data.cc
@@ -2,32 +2,50 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#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/metrics/histogram.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_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 {
+namespace {
+
+void LogPreviewsEligibilityReason(PreviewsEligibilityReason status,
+ PreviewsType type) {
+ switch (type) {
+ case PreviewsType::OFFLINE:
+ UMA_HISTOGRAM_ENUMERATION(
+ "Previews.EligibilityReason.Offline", static_cast<int>(status),
tbansal1 2016/11/08 00:30:52 I would use Previews.Offline.EligibilityReason to
RyanSturm 2016/11/08 22:22:29 Like above, I was just going to suffix with the ty
+ 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)
: ui_task_runner_(ui_task_runner),
io_task_runner_(io_task_runner),
weak_factory_(this) {}
PreviewsIOData::~PreviewsIOData() {}
void PreviewsIOData::Initialize(
@@ -66,26 +84,40 @@ void PreviewsIOData::ClearBlackList(base::Time begin_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 (!IsPreviewsTypeEnabled(type))
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;
+ }
+ return true;
tbansal1 2016/11/08 00:30:52 Add: LogPreviewsEligibilityReason(PreviewsEligibil
tbansal1 2016/11/08 00:30:52 Also, add a test to components/previews/core/previ
RyanSturm 2016/11/08 22:22:29 Done.
RyanSturm 2016/11/08 22:22:29 Done.
}
} // namespace previews

Powered by Google App Engine
This is Rietveld 408576698