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

Side by Side Diff: components/previews/core/previews_io_data.cc

Issue 2760063002: Add support to previews/ for Server LoFi and LitePages (Closed)
Patch Set: rebase and previews_service_unittest.cc Created 3 years, 7 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 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 <string>
tbansal1 2017/05/02 21:49:31 This is already included in the header file, so it
RyanSturm 2017/05/02 22:57:19 Done.
8
7 #include "base/bind.h" 9 #include "base/bind.h"
8 #include "base/bind_helpers.h" 10 #include "base/bind_helpers.h"
9 #include "base/files/file_path.h" 11 #include "base/files/file_path.h"
10 #include "base/location.h" 12 #include "base/location.h"
11 #include "base/memory/ptr_util.h" 13 #include "base/memory/ptr_util.h"
12 #include "base/metrics/histogram_macros.h" 14 #include "base/metrics/histogram.h"
13 #include "base/sequenced_task_runner.h" 15 #include "base/sequenced_task_runner.h"
14 #include "base/time/default_clock.h" 16 #include "base/time/default_clock.h"
15 #include "components/previews/core/previews_black_list.h" 17 #include "components/previews/core/previews_black_list.h"
18 #include "components/previews/core/previews_experiments.h"
16 #include "components/previews/core/previews_opt_out_store.h" 19 #include "components/previews/core/previews_opt_out_store.h"
17 #include "components/previews/core/previews_ui_service.h" 20 #include "components/previews/core/previews_ui_service.h"
18 #include "net/base/load_flags.h" 21 #include "net/base/load_flags.h"
19 #include "net/nqe/network_quality_estimator.h" 22 #include "net/nqe/network_quality_estimator.h"
20 #include "net/url_request/url_request.h" 23 #include "net/url_request/url_request.h"
21 #include "net/url_request/url_request_context.h" 24 #include "net/url_request/url_request_context.h"
22 #include "url/gurl.h" 25 #include "url/gurl.h"
23 26
24 namespace previews { 27 namespace previews {
25 28
26 namespace { 29 namespace {
27 30
28 void LogPreviewsEligibilityReason(PreviewsEligibilityReason status, 31 void LogPreviewsEligibilityReason(PreviewsEligibilityReason status,
29 PreviewsType type) { 32 PreviewsType type) {
30 switch (type) { 33 std::string histogram_name("Previews.EligibilityReason.");
31 case PreviewsType::OFFLINE: 34 histogram_name.append(GetStringNameForType(type));
tbansal1 2017/05/02 21:49:31 same here. Use StringPiece of Printf as mentioned
RyanSturm 2017/05/02 22:57:19 Done.
32 UMA_HISTOGRAM_ENUMERATION( 35 int32_t max_limit = static_cast<int32_t>(PreviewsEligibilityReason::LAST);
33 "Previews.EligibilityReason.Offline", static_cast<int>(status), 36
34 static_cast<int>(PreviewsEligibilityReason::LAST)); 37 base::LinearHistogram::FactoryGet(
35 break; 38 histogram_name, 0, max_limit, max_limit + 1,
tbansal1 2017/05/02 21:49:31 min_bucket should be >= 1. https://cs.chromium.org
RyanSturm 2017/05/02 22:57:19 Done.
36 case PreviewsType::CLIENT_LOFI: 39 base::HistogramBase::kUmaTargetedHistogramFlag)
37 UMA_HISTOGRAM_ENUMERATION( 40 ->Add(static_cast<int>(status));
38 "Previews.EligibilityReason.ClientLoFi", static_cast<int>(status),
39 static_cast<int>(PreviewsEligibilityReason::LAST));
40 break;
41 default:
42 NOTREACHED();
43 }
44 } 41 }
45 42
46 net::EffectiveConnectionType GetEffectiveConnectionTypeThresholdForPreviewsType( 43 net::EffectiveConnectionType GetEffectiveConnectionTypeThresholdForPreviewsType(
47 PreviewsType type) { 44 PreviewsType type) {
48 switch (type) { 45 switch (type) {
46 // These types check network qualtiy on their own.
tbansal1 2017/05/02 21:49:31 typo in quality.
RyanSturm 2017/05/02 22:57:19 Done.
47 case PreviewsType::LITE_PAGE:
48 case PreviewsType::SERVER_LOFI:
49 return net::EFFECTIVE_CONNECTION_TYPE_4G;
49 case PreviewsType::OFFLINE: 50 case PreviewsType::OFFLINE:
50 return params::EffectiveConnectionTypeThresholdForOffline(); 51 return params::EffectiveConnectionTypeThresholdForOffline();
51 case PreviewsType::CLIENT_LOFI: 52 case PreviewsType::CLIENT_LOFI:
52 return params::EffectiveConnectionTypeThresholdForClientLoFi(); 53 return params::EffectiveConnectionTypeThresholdForClientLoFi();
53 case PreviewsType::NONE: 54 case PreviewsType::NONE:
54 case PreviewsType::LAST: 55 case PreviewsType::LAST:
55 break; 56 break;
56 } 57 }
57 NOTREACHED(); 58 NOTREACHED();
58 return net::EFFECTIVE_CONNECTION_TYPE_UNKNOWN; 59 return net::EFFECTIVE_CONNECTION_TYPE_UNKNOWN;
59 } 60 }
60 61
62 bool AllowedOnReload(PreviewsType type) {
63 switch (type) {
64 // These types return new content on refresh.
65 case PreviewsType::LITE_PAGE:
66 case PreviewsType::SERVER_LOFI:
67 case PreviewsType::CLIENT_LOFI:
68 return true;
69 // Loading these types will always be stale when refreshed.
70 case PreviewsType::OFFLINE:
71 return false;
72 case PreviewsType::NONE:
73 case PreviewsType::LAST:
74 break;
75 }
76 NOTREACHED();
77 return false;
78 }
79
61 } // namespace 80 } // namespace
62 81
63 PreviewsIOData::PreviewsIOData( 82 PreviewsIOData::PreviewsIOData(
64 const scoped_refptr<base::SingleThreadTaskRunner>& ui_task_runner, 83 const scoped_refptr<base::SingleThreadTaskRunner>& ui_task_runner,
65 const scoped_refptr<base::SingleThreadTaskRunner>& io_task_runner) 84 const scoped_refptr<base::SingleThreadTaskRunner>& io_task_runner)
66 : ui_task_runner_(ui_task_runner), 85 : ui_task_runner_(ui_task_runner),
67 io_task_runner_(io_task_runner), 86 io_task_runner_(io_task_runner),
68 weak_factory_(this) {} 87 weak_factory_(this) {}
69 88
70 PreviewsIOData::~PreviewsIOData() {} 89 PreviewsIOData::~PreviewsIOData() {}
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
112 PreviewsType type) const { 131 PreviewsType type) const {
113 if (is_enabled_callback_.is_null() || !previews_black_list_) { 132 if (is_enabled_callback_.is_null() || !previews_black_list_) {
114 LogPreviewsEligibilityReason( 133 LogPreviewsEligibilityReason(
115 PreviewsEligibilityReason::BLACKLIST_UNAVAILABLE, type); 134 PreviewsEligibilityReason::BLACKLIST_UNAVAILABLE, type);
116 return false; 135 return false;
117 } 136 }
118 if (!is_enabled_callback_.Run(type)) 137 if (!is_enabled_callback_.Run(type))
119 return false; 138 return false;
120 139
121 // The blacklist will disallow certain hosts for periods of time based on 140 // The blacklist will disallow certain hosts for periods of time based on
122 // user's opting out of the preview 141 // user's opting out of the preview.
123 PreviewsEligibilityReason status = 142 PreviewsEligibilityReason status =
124 previews_black_list_->IsLoadedAndAllowed(request.url(), type); 143 previews_black_list_->IsLoadedAndAllowed(request.url(), type);
125 if (status != PreviewsEligibilityReason::ALLOWED) { 144 if (status != PreviewsEligibilityReason::ALLOWED) {
126 LogPreviewsEligibilityReason(status, type); 145 LogPreviewsEligibilityReason(status, type);
127 return false; 146 return false;
128 } 147 }
129 net::NetworkQualityEstimator* network_quality_estimator = 148 net::NetworkQualityEstimator* network_quality_estimator =
130 request.context()->network_quality_estimator(); 149 request.context()->network_quality_estimator();
131 if (!network_quality_estimator || 150 if (!network_quality_estimator ||
132 network_quality_estimator->GetEffectiveConnectionType() < 151 network_quality_estimator->GetEffectiveConnectionType() <
133 net::EFFECTIVE_CONNECTION_TYPE_OFFLINE) { 152 net::EFFECTIVE_CONNECTION_TYPE_OFFLINE) {
134 LogPreviewsEligibilityReason( 153 LogPreviewsEligibilityReason(
135 PreviewsEligibilityReason::NETWORK_QUALITY_UNAVAILABLE, type); 154 PreviewsEligibilityReason::NETWORK_QUALITY_UNAVAILABLE, type);
136 return false; 155 return false;
137 } 156 }
138 157
139 if (network_quality_estimator->GetEffectiveConnectionType() > 158 if (network_quality_estimator->GetEffectiveConnectionType() >
140 GetEffectiveConnectionTypeThresholdForPreviewsType(type)) { 159 GetEffectiveConnectionTypeThresholdForPreviewsType(type)) {
141 LogPreviewsEligibilityReason(PreviewsEligibilityReason::NETWORK_NOT_SLOW, 160 LogPreviewsEligibilityReason(PreviewsEligibilityReason::NETWORK_NOT_SLOW,
142 type); 161 type);
143 return false; 162 return false;
144 } 163 }
145 // LOAD_VALIDATE_CACHE or LOAD_BYPASS_CACHE mean the user reloaded the page. 164 // LOAD_VALIDATE_CACHE or LOAD_BYPASS_CACHE mean the user reloaded the page.
146 // If this is a query for offline previews, reloads should be disallowed. 165 // If this is a query for offline previews, reloads should be disallowed.
147 if (type == PreviewsType::OFFLINE && 166 if (!AllowedOnReload(type) &&
148 (request.load_flags() & 167 request.load_flags() &
149 (net::LOAD_VALIDATE_CACHE | net::LOAD_BYPASS_CACHE))) { 168 (net::LOAD_VALIDATE_CACHE | net::LOAD_BYPASS_CACHE)) {
150 LogPreviewsEligibilityReason( 169 LogPreviewsEligibilityReason(PreviewsEligibilityReason::RELOAD_DISALLOWED,
151 PreviewsEligibilityReason::RELOAD_DISALLOWED_FOR_OFFLINE, type); 170 type);
152 return false; 171 return false;
153 } 172 }
173
154 LogPreviewsEligibilityReason(PreviewsEligibilityReason::ALLOWED, type); 174 LogPreviewsEligibilityReason(PreviewsEligibilityReason::ALLOWED, type);
155 return true; 175 return true;
156 } 176 }
157 177
158 } // namespace previews 178 } // namespace previews
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698