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

Side by Side 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 unified diff | Download patch
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "components/previews/core/previews_io_data.h" 5 #include "components/previews/core/previews_io_data.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/bind_helpers.h" 8 #include "base/bind_helpers.h"
9 #include "base/files/file_path.h" 9 #include "base/files/file_path.h"
10 #include "base/location.h" 10 #include "base/location.h"
11 #include "base/memory/ptr_util.h" 11 #include "base/memory/ptr_util.h"
12 #include "base/metrics/histogram.h"
12 #include "base/sequenced_task_runner.h" 13 #include "base/sequenced_task_runner.h"
13 #include "base/time/default_clock.h" 14 #include "base/time/default_clock.h"
14 #include "components/previews/core/previews_black_list.h" 15 #include "components/previews/core/previews_black_list.h"
15 #include "components/previews/core/previews_opt_out_store.h" 16 #include "components/previews/core/previews_opt_out_store.h"
16 #include "components/previews/core/previews_ui_service.h" 17 #include "components/previews/core/previews_ui_service.h"
17 #include "net/nqe/network_quality_estimator.h" 18 #include "net/nqe/network_quality_estimator.h"
18 #include "net/url_request/url_request.h" 19 #include "net/url_request/url_request.h"
19 #include "net/url_request/url_request_context.h" 20 #include "net/url_request/url_request_context.h"
20 #include "url/gurl.h" 21 #include "url/gurl.h"
21 22
22 namespace previews { 23 namespace previews {
23 24
25 namespace {
26
27 void LogPreviewsEligibilityReason(PreviewsEligibilityReason status,
28 PreviewsType type) {
29 switch (type) {
30 case PreviewsType::OFFLINE:
31 UMA_HISTOGRAM_ENUMERATION(
32 "Previews.EligibilityReason.Offline", static_cast<int>(status),
33 static_cast<int>(PreviewsEligibilityReason::LAST));
34 break;
35 default:
36 NOTREACHED();
37 }
38 }
39
40 } // namespace
41
24 PreviewsIOData::PreviewsIOData( 42 PreviewsIOData::PreviewsIOData(
25 const scoped_refptr<base::SingleThreadTaskRunner>& ui_task_runner, 43 const scoped_refptr<base::SingleThreadTaskRunner>& ui_task_runner,
26 const scoped_refptr<base::SingleThreadTaskRunner>& io_task_runner) 44 const scoped_refptr<base::SingleThreadTaskRunner>& io_task_runner)
27 : ui_task_runner_(ui_task_runner), 45 : ui_task_runner_(ui_task_runner),
28 io_task_runner_(io_task_runner), 46 io_task_runner_(io_task_runner),
29 weak_factory_(this) {} 47 weak_factory_(this) {}
30 48
31 PreviewsIOData::~PreviewsIOData() {} 49 PreviewsIOData::~PreviewsIOData() {}
32 50
33 void PreviewsIOData::Initialize( 51 void PreviewsIOData::Initialize(
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
66 DCHECK(io_task_runner_->BelongsToCurrentThread()); 84 DCHECK(io_task_runner_->BelongsToCurrentThread());
67 previews_black_list_->ClearBlackList(begin_time, end_time); 85 previews_black_list_->ClearBlackList(begin_time, end_time);
68 } 86 }
69 87
70 bool PreviewsIOData::ShouldAllowPreview(const net::URLRequest& request, 88 bool PreviewsIOData::ShouldAllowPreview(const net::URLRequest& request,
71 PreviewsType type) const { 89 PreviewsType type) const {
72 if (!IsPreviewsTypeEnabled(type)) 90 if (!IsPreviewsTypeEnabled(type))
73 return false; 91 return false;
74 // The blacklist will disallow certain hosts for periods of time based on 92 // The blacklist will disallow certain hosts for periods of time based on
75 // user's opting out of the preview 93 // user's opting out of the preview
76 if (!previews_black_list_ || 94 if (!previews_black_list_) {
77 !previews_black_list_->IsLoadedAndAllowed(request.url(), type)) { 95 LogPreviewsEligibilityReason(
96 PreviewsEligibilityReason::BLACKLIST_UNAVAILABLE, type);
97 return false;
98 }
99 PreviewsEligibilityReason status =
100 previews_black_list_->IsLoadedAndAllowed(request.url(), type);
101 if (status != PreviewsEligibilityReason::ALLOWED) {
102 LogPreviewsEligibilityReason(status, type);
78 return false; 103 return false;
79 } 104 }
80 net::NetworkQualityEstimator* network_quality_estimator = 105 net::NetworkQualityEstimator* network_quality_estimator =
81 request.context()->network_quality_estimator(); 106 request.context()->network_quality_estimator();
82 if (!network_quality_estimator) 107 if (!network_quality_estimator ||
108 network_quality_estimator->GetEffectiveConnectionType() <
109 net::EFFECTIVE_CONNECTION_TYPE_OFFLINE) {
110 LogPreviewsEligibilityReason(
111 PreviewsEligibilityReason::NETWORK_QUALITY_UNAVAILABLE, type);
83 return false; 112 return false;
84 113 }
85 net::EffectiveConnectionType effective_connection_type = 114 if (network_quality_estimator->GetEffectiveConnectionType() >
86 network_quality_estimator->GetEffectiveConnectionType(); 115 net::EFFECTIVE_CONNECTION_TYPE_SLOW_2G) {
87 return effective_connection_type >= net::EFFECTIVE_CONNECTION_TYPE_OFFLINE && 116 LogPreviewsEligibilityReason(PreviewsEligibilityReason::NETWORK_NOT_SLOW,
88 effective_connection_type <= net::EFFECTIVE_CONNECTION_TYPE_SLOW_2G; 117 type);
118 return false;
119 }
120 LogPreviewsEligibilityReason(PreviewsEligibilityReason::ALLOWED, type);
121 return true;
89 } 122 }
90 123
91 } // namespace previews 124 } // namespace previews
OLDNEW
« 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