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

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

Issue 2760063002: Add support to previews/ for Server LoFi and LitePages (Closed)
Patch Set: build fix Created 3 years, 9 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
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 9645fa249513ccc186559024eee32088444a2ec5..b80752848f424621cebe2bb9e67dde2e4ef712a9 100644
--- a/components/previews/core/previews_io_data.cc
+++ b/components/previews/core/previews_io_data.cc
@@ -28,16 +28,61 @@ namespace {
void LogPreviewsEligibilityReason(PreviewsEligibilityReason status,
PreviewsType type) {
switch (type) {
+ case PreviewsType::LITE_PAGE:
+ UMA_HISTOGRAM_ENUMERATION(
+ "Previews.EligibilityReason.LitePage", static_cast<int>(status),
tbansal1 2017/03/20 22:55:13 Maybe use histogram factory here to avoid code dup
RyanSturm 2017/05/02 20:08:12 Done.
+ static_cast<int>(PreviewsEligibilityReason::LAST));
+ break;
+ case PreviewsType::SERVER_LOFI:
+ UMA_HISTOGRAM_ENUMERATION(
+ "Previews.EligibilityReason.ServerLoFi", static_cast<int>(status),
+ static_cast<int>(PreviewsEligibilityReason::LAST));
+ break;
case PreviewsType::OFFLINE:
UMA_HISTOGRAM_ENUMERATION(
"Previews.EligibilityReason.Offline", static_cast<int>(status),
static_cast<int>(PreviewsEligibilityReason::LAST));
break;
- default:
+ case PreviewsType::NONE:
+ case PreviewsType::LAST:
NOTREACHED();
}
}
+bool ShouldCheckNetworkQuality(PreviewsType type) {
tbansal1 2017/03/20 22:55:13 May be change it to return the ECT threshold? and
RyanSturm 2017/05/02 20:08:12 Acknowledged.
+ switch (type) {
+ // These types check network qualtiy on their own.
+ case PreviewsType::LITE_PAGE:
+ case PreviewsType::SERVER_LOFI:
+ return false;
+ // These types use the default previews network quality behavior.
+ case PreviewsType::OFFLINE:
+ return true;
+ case PreviewsType::NONE:
+ case PreviewsType::LAST:
+ break;
+ }
+ NOTREACHED();
+ return false;
+}
+
+bool AllowedOnReload(PreviewsType type) {
+ switch (type) {
+ // These types return new content on refresh.
+ case PreviewsType::LITE_PAGE:
+ case PreviewsType::SERVER_LOFI:
+ return true;
+ // Loading these types will always be stale when refreshed.
+ case PreviewsType::OFFLINE:
+ return false;
+ case PreviewsType::NONE:
+ case PreviewsType::LAST:
+ break;
+ }
+ NOTREACHED();
+ return false;
+}
+
} // namespace
PreviewsIOData::PreviewsIOData(
@@ -106,29 +151,31 @@ bool PreviewsIOData::ShouldAllowPreview(const net::URLRequest& request,
LogPreviewsEligibilityReason(status, type);
return false;
}
- net::NetworkQualityEstimator* network_quality_estimator =
- request.context()->network_quality_estimator();
- if (!network_quality_estimator ||
- network_quality_estimator->GetEffectiveConnectionType() <
- net::EFFECTIVE_CONNECTION_TYPE_OFFLINE) {
- LogPreviewsEligibilityReason(
- PreviewsEligibilityReason::NETWORK_QUALITY_UNAVAILABLE, type);
- return false;
- }
- if (network_quality_estimator->GetEffectiveConnectionType() >
- params::EffectiveConnectionTypeThreshold()) {
- LogPreviewsEligibilityReason(PreviewsEligibilityReason::NETWORK_NOT_SLOW,
- type);
- return false;
- }
- // LOAD_VALIDATE_CACHE or LOAD_BYPASS_CACHE mean the user reloaded the page.
- // If this is a query for offline previews, reloads should be disallowed.
- if (type == PreviewsType::OFFLINE &&
- request.load_flags() &
- (net::LOAD_VALIDATE_CACHE | net::LOAD_BYPASS_CACHE)) {
- LogPreviewsEligibilityReason(
- PreviewsEligibilityReason::RELOAD_DISALLOWED_FOR_OFFLINE, type);
- return false;
+ if (ShouldCheckNetworkQuality(type)) {
tbansal1 2017/03/20 22:55:13 nit: it might be more readable to move this (inclu
RyanSturm 2017/05/02 20:08:12 Done.
+ net::NetworkQualityEstimator* network_quality_estimator =
+ request.context()->network_quality_estimator();
+ if (!network_quality_estimator ||
+ network_quality_estimator->GetEffectiveConnectionType() <
+ net::EFFECTIVE_CONNECTION_TYPE_OFFLINE) {
+ LogPreviewsEligibilityReason(
+ PreviewsEligibilityReason::NETWORK_QUALITY_UNAVAILABLE, type);
+ return false;
+ }
+ if (network_quality_estimator->GetEffectiveConnectionType() >
+ params::EffectiveConnectionTypeThreshold()) {
+ LogPreviewsEligibilityReason(PreviewsEligibilityReason::NETWORK_NOT_SLOW,
+ type);
+ return false;
+ }
+ // LOAD_VALIDATE_CACHE or LOAD_BYPASS_CACHE mean the user reloaded the page.
+ // If this is a query for offline previews, reloads should be disallowed.
+ if (!AllowedOnReload(type) &&
+ request.load_flags() &
+ (net::LOAD_VALIDATE_CACHE | net::LOAD_BYPASS_CACHE)) {
+ LogPreviewsEligibilityReason(PreviewsEligibilityReason::RELOAD_DISALLOWED,
+ type);
+ return false;
+ }
}
LogPreviewsEligibilityReason(PreviewsEligibilityReason::ALLOWED, type);
return true;

Powered by Google App Engine
This is Rietveld 408576698