Chromium Code Reviews| 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..d4801d0b7bf052fa44c0d9669cde3b6160902400 100644 |
| --- a/chrome/browser/predictors/resource_prefetch_common.cc |
| +++ b/chrome/browser/predictors/resource_prefetch_common.cc |
| @@ -25,8 +25,16 @@ using std::vector; |
| namespace predictors { |
| +namespace { |
| +const int kUrlHostLearningMode = ResourcePrefetchPredictorConfig::URL_LEARNING | |
|
pasko
2016/11/17 15:59:04
constexpr has less risks creating entries in .data
Benoit L
2016/11/21 13:40:32
Done.
|
| + ResourcePrefetchPredictorConfig::HOST_LEARNING; |
| +const int kUrlHostPrefetchingMode = |
| + ResourcePrefetchPredictorConfig::URL_PREFETCHING | |
| + ResourcePrefetchPredictorConfig::HOST_PREFETCHING; |
| + |
| const char kSpeculativePrefetchingTrialName[] = |
| "SpeculativeResourcePrefetching"; |
| +} // namespace |
| /* |
| * SpeculativeResourcePrefetching is a field trial, and its value must have the |
| @@ -68,14 +76,14 @@ 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; |
| } 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 +108,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 +116,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 +224,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 +260,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 { |