| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "chrome/browser/predictors/resource_prefetch_common.h" | 5 #include "chrome/browser/predictors/resource_prefetch_common.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 #include <tuple> | 8 #include <tuple> |
| 9 | 9 |
| 10 #include "base/metrics/field_trial_params.h" | 10 #include "base/metrics/field_trial_params.h" |
| 11 #include "chrome/browser/net/prediction_options.h" | 11 #include "chrome/browser/net/prediction_options.h" |
| 12 #include "chrome/browser/profiles/profile.h" | 12 #include "chrome/browser/profiles/profile.h" |
| 13 #include "chrome/browser/sessions/session_tab_helper.h" | 13 #include "chrome/browser/sessions/session_tab_helper.h" |
| 14 #include "components/prefs/pref_service.h" | 14 #include "components/prefs/pref_service.h" |
| 15 #include "content/public/browser/browser_thread.h" | 15 #include "content/public/browser/browser_thread.h" |
| 16 #include "content/public/browser/web_contents.h" | 16 #include "content/public/browser/web_contents.h" |
| 17 | 17 |
| 18 namespace predictors { | 18 namespace predictors { |
| 19 | 19 |
| 20 const char kSpeculativeResourcePrefetchingFeatureName[] = | 20 const char kSpeculativeResourcePrefetchingFeatureName[] = |
| 21 "SpeculativeResourcePrefetching"; | 21 "SpeculativeResourcePrefetching"; |
| 22 const char kModeParamName[] = "mode"; | 22 const char kModeParamName[] = "mode"; |
| 23 const char kLearningMode[] = "learning"; | 23 const char kLearningMode[] = "learning"; |
| 24 const char kExternalPrefetchingMode[] = "external-prefetching"; | 24 const char kExternalPrefetchingMode[] = "external-prefetching"; |
| 25 const char kPrefetchingMode[] = "prefetching"; | 25 const char kPrefetchingMode[] = "prefetching"; |
| 26 const char kEnableUrlLearningParamName[] = "enable-url-learning"; | 26 const char kEnableUrlLearningParamName[] = "enable-url-learning"; |
| 27 const char kEnableManifestsParamName[] = "enable-manifests"; |
| 27 | 28 |
| 28 const base::Feature kSpeculativeResourcePrefetchingFeature = | 29 const base::Feature kSpeculativeResourcePrefetchingFeature = |
| 29 base::Feature(kSpeculativeResourcePrefetchingFeatureName, | 30 base::Feature(kSpeculativeResourcePrefetchingFeatureName, |
| 30 base::FEATURE_DISABLED_BY_DEFAULT); | 31 base::FEATURE_DISABLED_BY_DEFAULT); |
| 31 | 32 |
| 32 namespace { | 33 namespace { |
| 33 | 34 |
| 34 bool IsPrefetchingEnabledInternal(Profile* profile, int mode, int mask) { | 35 bool IsPrefetchingEnabledInternal(Profile* profile, int mode, int mask) { |
| 35 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 36 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 36 if ((mode & mask) == 0) | 37 if ((mode & mask) == 0) |
| (...skipping 18 matching lines...) Expand all Loading... |
| 55 // Disabled for of-the-record. Policy choice, not a technical limitation. | 56 // Disabled for of-the-record. Policy choice, not a technical limitation. |
| 56 if (!profile || profile->IsOffTheRecord()) | 57 if (!profile || profile->IsOffTheRecord()) |
| 57 return false; | 58 return false; |
| 58 | 59 |
| 59 if (!base::FeatureList::IsEnabled(kSpeculativeResourcePrefetchingFeature)) | 60 if (!base::FeatureList::IsEnabled(kSpeculativeResourcePrefetchingFeature)) |
| 60 return false; | 61 return false; |
| 61 | 62 |
| 62 std::string enable_url_learning_value = | 63 std::string enable_url_learning_value = |
| 63 base::GetFieldTrialParamValueByFeature( | 64 base::GetFieldTrialParamValueByFeature( |
| 64 kSpeculativeResourcePrefetchingFeature, kEnableUrlLearningParamName); | 65 kSpeculativeResourcePrefetchingFeature, kEnableUrlLearningParamName); |
| 65 if (enable_url_learning_value == "true") { | 66 if (enable_url_learning_value == "true") |
| 66 config->is_url_learning_enabled = true; | 67 config->is_url_learning_enabled = true; |
| 67 } | 68 |
| 69 std::string enable_manifests_value = base::GetFieldTrialParamValueByFeature( |
| 70 kSpeculativeResourcePrefetchingFeature, kEnableManifestsParamName); |
| 71 if (enable_manifests_value == "true") |
| 72 config->is_manifests_enabled = true; |
| 68 | 73 |
| 69 // Ensure that a resource that was only seen once is never prefetched. This | 74 // Ensure that a resource that was only seen once is never prefetched. This |
| 70 // prevents the easy mistake of trying to prefetch an ephemeral url. | 75 // prevents the easy mistake of trying to prefetch an ephemeral url. |
| 71 DCHECK_GT(config->min_resource_hits_to_trigger_prefetch, 1U); | 76 DCHECK_GT(config->min_resource_hits_to_trigger_prefetch, 1U); |
| 72 if (config->min_resource_hits_to_trigger_prefetch < 2) | 77 if (config->min_resource_hits_to_trigger_prefetch < 2) |
| 73 config->min_resource_hits_to_trigger_prefetch = 2; | 78 config->min_resource_hits_to_trigger_prefetch = 2; |
| 74 | 79 |
| 75 std::string mode_value = base::GetFieldTrialParamValueByFeature( | 80 std::string mode_value = base::GetFieldTrialParamValueByFeature( |
| 76 kSpeculativeResourcePrefetchingFeature, kModeParamName); | 81 kSpeculativeResourcePrefetchingFeature, kModeParamName); |
| 77 if (mode_value == kLearningMode) { | 82 if (mode_value == kLearningMode) { |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 130 max_navigation_lifetime_seconds(60), | 135 max_navigation_lifetime_seconds(60), |
| 131 max_urls_to_track(500), | 136 max_urls_to_track(500), |
| 132 max_hosts_to_track(200), | 137 max_hosts_to_track(200), |
| 133 min_url_visit_count(2), | 138 min_url_visit_count(2), |
| 134 max_resources_per_entry(50), | 139 max_resources_per_entry(50), |
| 135 max_consecutive_misses(3), | 140 max_consecutive_misses(3), |
| 136 min_resource_confidence_to_trigger_prefetch(0.7f), | 141 min_resource_confidence_to_trigger_prefetch(0.7f), |
| 137 min_resource_hits_to_trigger_prefetch(2), | 142 min_resource_hits_to_trigger_prefetch(2), |
| 138 max_prefetches_inflight_per_navigation(5), | 143 max_prefetches_inflight_per_navigation(5), |
| 139 max_prefetches_inflight_per_host_per_navigation(3), | 144 max_prefetches_inflight_per_host_per_navigation(3), |
| 140 is_url_learning_enabled(false) { | 145 is_url_learning_enabled(false), |
| 141 } | 146 is_manifests_enabled(false) {} |
| 142 | 147 |
| 143 ResourcePrefetchPredictorConfig::ResourcePrefetchPredictorConfig( | 148 ResourcePrefetchPredictorConfig::ResourcePrefetchPredictorConfig( |
| 144 const ResourcePrefetchPredictorConfig& other) = default; | 149 const ResourcePrefetchPredictorConfig& other) = default; |
| 145 | 150 |
| 146 ResourcePrefetchPredictorConfig::~ResourcePrefetchPredictorConfig() { | 151 ResourcePrefetchPredictorConfig::~ResourcePrefetchPredictorConfig() { |
| 147 } | 152 } |
| 148 | 153 |
| 149 bool ResourcePrefetchPredictorConfig::IsLearningEnabled() const { | 154 bool ResourcePrefetchPredictorConfig::IsLearningEnabled() const { |
| 150 return (mode & LEARNING) > 0; | 155 return (mode & LEARNING) > 0; |
| 151 } | 156 } |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 185 | 190 |
| 186 bool ResourcePrefetchPredictorConfig::IsMoreResourcesEnabledForTest() const { | 191 bool ResourcePrefetchPredictorConfig::IsMoreResourcesEnabledForTest() const { |
| 187 return max_resources_per_entry == 100; | 192 return max_resources_per_entry == 100; |
| 188 } | 193 } |
| 189 | 194 |
| 190 bool ResourcePrefetchPredictorConfig::IsSmallDBEnabledForTest() const { | 195 bool ResourcePrefetchPredictorConfig::IsSmallDBEnabledForTest() const { |
| 191 return max_urls_to_track == 200 && max_hosts_to_track == 100; | 196 return max_urls_to_track == 200 && max_hosts_to_track == 100; |
| 192 } | 197 } |
| 193 | 198 |
| 194 } // namespace predictors | 199 } // namespace predictors |
| OLD | NEW |