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

Unified Diff: chrome/browser/predictors/resource_prefetch_common.cc

Issue 2508933002: tools: Local tests for the speculative prefetch predictor. (Closed)
Patch Set: . 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: chrome/browser/predictors/resource_prefetch_common.cc
diff --git a/chrome/browser/predictors/resource_prefetch_common.cc b/chrome/browser/predictors/resource_prefetch_common.cc
index 2b97faf37164dbda4be152bfa7ef840985061557..d68ecd959bc3609f6e09847f600e99d42fda1ffa 100644
--- a/chrome/browser/predictors/resource_prefetch_common.cc
+++ b/chrome/browser/predictors/resource_prefetch_common.cc
@@ -25,8 +25,17 @@ using std::vector;
namespace predictors {
-const char kSpeculativePrefetchingTrialName[] =
+namespace {
+constexpr int kUrlHostLearningMode =
+ ResourcePrefetchPredictorConfig::URL_LEARNING |
+ ResourcePrefetchPredictorConfig::HOST_LEARNING;
+constexpr int kUrlHostPrefetchingMode =
+ ResourcePrefetchPredictorConfig::URL_PREFETCHING |
+ ResourcePrefetchPredictorConfig::HOST_PREFETCHING;
+
+constexpr char kSpeculativePrefetchingTrialName[] =
"SpeculativeResourcePrefetching";
+} // namespace
/*
* SpeculativeResourcePrefetching is a field trial, and its value must have the
@@ -68,14 +77,15 @@ bool IsSpeculativeResourcePrefetchingEnabled(
if (value == switches::kSpeculativeResourcePrefetchingDisabled) {
return false;
} else if (value == switches::kSpeculativeResourcePrefetchingLearning) {
- config->mode |= ResourcePrefetchPredictorConfig::URL_LEARNING;
- config->mode |= ResourcePrefetchPredictorConfig::HOST_LEARNING;
+ config->mode |= kUrlHostLearningMode;
+ return true;
+ } else if (value ==
+ switches::kSpeculativeResourceExternalPrefetchingEnabled) {
+ config->mode |= kUrlHostLearningMode | kUrlHostPrefetchingMode;
+ config->mode |= ResourcePrefetchPredictorConfig::EXTERNAL_ONLY;
return true;
} else if (value == switches::kSpeculativeResourcePrefetchingEnabled) {
- config->mode |= ResourcePrefetchPredictorConfig::URL_LEARNING;
- config->mode |= ResourcePrefetchPredictorConfig::HOST_LEARNING;
- config->mode |= ResourcePrefetchPredictorConfig::URL_PREFETCHING;
- config->mode |= ResourcePrefetchPredictorConfig::HOST_PRFETCHING;
+ config->mode |= kUrlHostLearningMode;
return true;
}
}
@@ -100,8 +110,7 @@ bool IsSpeculativeResourcePrefetchingEnabled(
config->mode |= ResourcePrefetchPredictorConfig::HOST_LEARNING;
} else {
// Default: both Url and Host
- config->mode |= ResourcePrefetchPredictorConfig::URL_LEARNING;
- config->mode |= ResourcePrefetchPredictorConfig::HOST_LEARNING;
+ config->mode |= kUrlHostLearningMode;
}
} else if (spec_prefetching == "Enabled") {
if (spec_predictor == "Url") {
@@ -109,13 +118,10 @@ bool IsSpeculativeResourcePrefetchingEnabled(
config->mode |= ResourcePrefetchPredictorConfig::URL_PREFETCHING;
} else if (spec_predictor == "Host") {
config->mode |= ResourcePrefetchPredictorConfig::HOST_LEARNING;
- config->mode |= ResourcePrefetchPredictorConfig::HOST_PRFETCHING;
+ config->mode |= ResourcePrefetchPredictorConfig::HOST_PREFETCHING;
} else {
// Default: both Url and Host
- config->mode |= ResourcePrefetchPredictorConfig::URL_LEARNING;
- config->mode |= ResourcePrefetchPredictorConfig::HOST_LEARNING;
- config->mode |= ResourcePrefetchPredictorConfig::URL_PREFETCHING;
- config->mode |= ResourcePrefetchPredictorConfig::HOST_PRFETCHING;
+ config->mode |= kUrlHostLearningMode | kUrlHostPrefetchingMode;
}
} else {
// Default: spec_prefetching == "Disabled"
@@ -220,6 +226,10 @@ bool ResourcePrefetchPredictorConfig::IsLearningEnabled() const {
return IsURLLearningEnabled() || IsHostLearningEnabled();
}
+bool ResourcePrefetchPredictorConfig::ExternalPrefetchingOnly() const {
+ return (mode & EXTERNAL_ONLY) > 0;
+}
+
bool ResourcePrefetchPredictorConfig::IsPrefetchingEnabled(
Profile* profile) const {
return IsURLPrefetchingEnabled(profile) || IsHostPrefetchingEnabled(profile);
@@ -252,7 +262,7 @@ bool ResourcePrefetchPredictorConfig::IsHostPrefetchingEnabled(
chrome_browser_net::NetworkPredictionStatus::ENABLED) {
return false;
}
- return (mode & HOST_PRFETCHING) > 0;
+ return (mode & HOST_PREFETCHING) > 0;
}
bool ResourcePrefetchPredictorConfig::IsLowConfidenceForTest() const {

Powered by Google App Engine
This is Rietveld 408576698