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/command_line.h" | 10 #include "base/feature_list.h" |
11 #include "base/metrics/field_trial.h" | 11 #include "base/metrics/field_trial_params.h" |
12 #include "chrome/browser/net/prediction_options.h" | 12 #include "chrome/browser/net/prediction_options.h" |
13 #include "chrome/browser/profiles/profile.h" | 13 #include "chrome/browser/profiles/profile.h" |
14 #include "chrome/browser/sessions/session_tab_helper.h" | 14 #include "chrome/browser/sessions/session_tab_helper.h" |
15 #include "chrome/common/chrome_switches.h" | |
16 #include "components/prefs/pref_service.h" | 15 #include "components/prefs/pref_service.h" |
17 #include "components/variations/variations_associated_data.h" | |
18 #include "content/public/browser/browser_thread.h" | 16 #include "content/public/browser/browser_thread.h" |
19 #include "content/public/browser/web_contents.h" | 17 #include "content/public/browser/web_contents.h" |
20 | 18 |
21 namespace predictors { | 19 namespace predictors { |
22 | 20 |
23 const char kSpeculativeResourcePrefetchingFeatureName[] = | 21 const char kSpeculativeResourcePrefetchingFeatureName[] = |
24 "SpeculativeResourcePrefetching"; | 22 "SpeculativeResourcePrefetching"; |
25 const char kModeParamName[] = "mode"; | 23 const char kModeParamName[] = "mode"; |
26 const char kLearningMode[] = "learning"; | 24 const char kLearningMode[] = "learning"; |
27 const char kExternalPrefetchingMode[] = "external-prefetching"; | 25 const char kExternalPrefetchingMode[] = "external-prefetching"; |
28 const char kPrefetchingMode[] = "prefetching"; | 26 const char kPrefetchingMode[] = "prefetching"; |
| 27 const char kEnableUrlLearningParamName[] = "enable-url-learning"; |
29 | 28 |
30 namespace { | 29 namespace { |
31 | 30 |
32 const base::Feature kSpeculativeResourcePrefetchingFeature{ | 31 const base::Feature kSpeculativeResourcePrefetchingFeature{ |
33 kSpeculativeResourcePrefetchingFeatureName, | 32 kSpeculativeResourcePrefetchingFeatureName, |
34 base::FEATURE_DISABLED_BY_DEFAULT}; | 33 base::FEATURE_DISABLED_BY_DEFAULT}; |
35 | 34 |
36 bool IsPrefetchingEnabledInternal(Profile* profile, int mode, int mask) { | 35 bool IsPrefetchingEnabledInternal(Profile* profile, int mode, int mask) { |
37 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 36 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
38 if ((mode & mask) == 0) | 37 if ((mode & mask) == 0) |
(...skipping 15 matching lines...) Expand all Loading... |
54 ResourcePrefetchPredictorConfig* config) { | 53 ResourcePrefetchPredictorConfig* config) { |
55 DCHECK(config); | 54 DCHECK(config); |
56 | 55 |
57 // Disabled for of-the-record. Policy choice, not a technical limitation. | 56 // Disabled for of-the-record. Policy choice, not a technical limitation. |
58 if (!profile || profile->IsOffTheRecord()) | 57 if (!profile || profile->IsOffTheRecord()) |
59 return false; | 58 return false; |
60 | 59 |
61 if (!base::FeatureList::IsEnabled(kSpeculativeResourcePrefetchingFeature)) | 60 if (!base::FeatureList::IsEnabled(kSpeculativeResourcePrefetchingFeature)) |
62 return false; | 61 return false; |
63 | 62 |
64 std::string mode_value = variations::GetVariationParamValueByFeature( | 63 std::string enable_url_learning_value = |
| 64 base::GetFieldTrialParamValueByFeature( |
| 65 kSpeculativeResourcePrefetchingFeature, kEnableUrlLearningParamName); |
| 66 if (enable_url_learning_value == "true") { |
| 67 config->is_url_learning_enabled = true; |
| 68 } |
| 69 |
| 70 std::string mode_value = base::GetFieldTrialParamValueByFeature( |
65 kSpeculativeResourcePrefetchingFeature, kModeParamName); | 71 kSpeculativeResourcePrefetchingFeature, kModeParamName); |
66 if (mode_value == kLearningMode) { | 72 if (mode_value == kLearningMode) { |
67 config->mode |= ResourcePrefetchPredictorConfig::LEARNING; | 73 config->mode |= ResourcePrefetchPredictorConfig::LEARNING; |
68 return true; | 74 return true; |
69 } else if (mode_value == kExternalPrefetchingMode) { | 75 } else if (mode_value == kExternalPrefetchingMode) { |
70 config->mode |= ResourcePrefetchPredictorConfig::LEARNING | | 76 config->mode |= ResourcePrefetchPredictorConfig::LEARNING | |
71 ResourcePrefetchPredictorConfig::PREFETCHING_FOR_EXTERNAL; | 77 ResourcePrefetchPredictorConfig::PREFETCHING_FOR_EXTERNAL; |
72 return true; | 78 return true; |
73 } else if (mode_value == kPrefetchingMode) { | 79 } else if (mode_value == kPrefetchingMode) { |
74 config->mode |= ResourcePrefetchPredictorConfig::LEARNING | | 80 config->mode |= ResourcePrefetchPredictorConfig::LEARNING | |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
118 : mode(0), | 124 : mode(0), |
119 max_navigation_lifetime_seconds(60), | 125 max_navigation_lifetime_seconds(60), |
120 max_urls_to_track(500), | 126 max_urls_to_track(500), |
121 max_hosts_to_track(200), | 127 max_hosts_to_track(200), |
122 min_url_visit_count(2), | 128 min_url_visit_count(2), |
123 max_resources_per_entry(50), | 129 max_resources_per_entry(50), |
124 max_consecutive_misses(3), | 130 max_consecutive_misses(3), |
125 min_resource_confidence_to_trigger_prefetch(0.7f), | 131 min_resource_confidence_to_trigger_prefetch(0.7f), |
126 min_resource_hits_to_trigger_prefetch(2), | 132 min_resource_hits_to_trigger_prefetch(2), |
127 max_prefetches_inflight_per_navigation(5), | 133 max_prefetches_inflight_per_navigation(5), |
128 max_prefetches_inflight_per_host_per_navigation(3) { | 134 max_prefetches_inflight_per_host_per_navigation(3), |
| 135 is_url_learning_enabled(false) { |
129 } | 136 } |
130 | 137 |
131 ResourcePrefetchPredictorConfig::ResourcePrefetchPredictorConfig( | 138 ResourcePrefetchPredictorConfig::ResourcePrefetchPredictorConfig( |
132 const ResourcePrefetchPredictorConfig& other) = default; | 139 const ResourcePrefetchPredictorConfig& other) = default; |
133 | 140 |
134 ResourcePrefetchPredictorConfig::~ResourcePrefetchPredictorConfig() { | 141 ResourcePrefetchPredictorConfig::~ResourcePrefetchPredictorConfig() { |
135 } | 142 } |
136 | 143 |
137 bool ResourcePrefetchPredictorConfig::IsLearningEnabled() const { | 144 bool ResourcePrefetchPredictorConfig::IsLearningEnabled() const { |
138 return (mode & LEARNING) > 0; | 145 return (mode & LEARNING) > 0; |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
173 | 180 |
174 bool ResourcePrefetchPredictorConfig::IsMoreResourcesEnabledForTest() const { | 181 bool ResourcePrefetchPredictorConfig::IsMoreResourcesEnabledForTest() const { |
175 return max_resources_per_entry == 100; | 182 return max_resources_per_entry == 100; |
176 } | 183 } |
177 | 184 |
178 bool ResourcePrefetchPredictorConfig::IsSmallDBEnabledForTest() const { | 185 bool ResourcePrefetchPredictorConfig::IsSmallDBEnabledForTest() const { |
179 return max_urls_to_track == 200 && max_hosts_to_track == 100; | 186 return max_urls_to_track == 200 && max_hosts_to_track == 100; |
180 } | 187 } |
181 | 188 |
182 } // namespace predictors | 189 } // namespace predictors |
OLD | NEW |