Chromium Code Reviews| 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 kKeyTypeParamName[] = "key-type"; | |
| 28 const char kUrlKeyType[] = "url"; | |
| 29 const char kHostKeyType[] = "host"; | |
| 30 const char kBothKeyType[] = "both"; | |
| 29 | 31 |
| 30 namespace { | 32 namespace { |
| 31 | 33 |
| 32 const base::Feature kSpeculativeResourcePrefetchingFeature{ | 34 const base::Feature kSpeculativeResourcePrefetchingFeature{ |
| 33 kSpeculativeResourcePrefetchingFeatureName, | 35 kSpeculativeResourcePrefetchingFeatureName, |
| 34 base::FEATURE_DISABLED_BY_DEFAULT}; | 36 base::FEATURE_DISABLED_BY_DEFAULT}; |
| 35 | 37 |
| 36 bool IsPrefetchingEnabledInternal(Profile* profile, int mode, int mask) { | 38 bool IsPrefetchingEnabledInternal(Profile* profile, int mode, int mask) { |
| 37 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 39 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 38 if ((mode & mask) == 0) | 40 if ((mode & mask) == 0) |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 54 ResourcePrefetchPredictorConfig* config) { | 56 ResourcePrefetchPredictorConfig* config) { |
| 55 DCHECK(config); | 57 DCHECK(config); |
| 56 | 58 |
| 57 // Disabled for of-the-record. Policy choice, not a technical limitation. | 59 // Disabled for of-the-record. Policy choice, not a technical limitation. |
| 58 if (!profile || profile->IsOffTheRecord()) | 60 if (!profile || profile->IsOffTheRecord()) |
| 59 return false; | 61 return false; |
| 60 | 62 |
| 61 if (!base::FeatureList::IsEnabled(kSpeculativeResourcePrefetchingFeature)) | 63 if (!base::FeatureList::IsEnabled(kSpeculativeResourcePrefetchingFeature)) |
| 62 return false; | 64 return false; |
| 63 | 65 |
| 64 std::string mode_value = variations::GetVariationParamValueByFeature( | 66 std::string key_type_value = base::GetFieldTrialParamValueByFeature( |
|
Benoit L
2017/03/01 16:04:41
Do we really want URL-only?
If not, can we simpli
alexilin
2017/03/01 16:55:56
Done.
| |
| 67 kSpeculativeResourcePrefetchingFeature, kKeyTypeParamName); | |
| 68 if (key_type_value == kUrlKeyType) { | |
| 69 config->mode |= ResourcePrefetchPredictorConfig::URL_LEARNING; | |
| 70 } else if (key_type_value == kHostKeyType) { | |
| 71 config->mode |= ResourcePrefetchPredictorConfig::HOST_LEARNING; | |
| 72 } else if (key_type_value == kBothKeyType) { | |
| 73 config->mode |= ResourcePrefetchPredictorConfig::URL_LEARNING | | |
| 74 ResourcePrefetchPredictorConfig::HOST_LEARNING; | |
| 75 } else { | |
| 76 // Only host learning by default. | |
| 77 config->mode |= ResourcePrefetchPredictorConfig::HOST_LEARNING; | |
| 78 } | |
| 79 | |
| 80 std::string mode_value = base::GetFieldTrialParamValueByFeature( | |
| 65 kSpeculativeResourcePrefetchingFeature, kModeParamName); | 81 kSpeculativeResourcePrefetchingFeature, kModeParamName); |
| 66 if (mode_value == kLearningMode) { | 82 if (mode_value == kLearningMode) { |
| 67 config->mode |= ResourcePrefetchPredictorConfig::LEARNING; | |
| 68 return true; | 83 return true; |
| 69 } else if (mode_value == kExternalPrefetchingMode) { | 84 } else if (mode_value == kExternalPrefetchingMode) { |
| 70 config->mode |= ResourcePrefetchPredictorConfig::LEARNING | | 85 config->mode |= ResourcePrefetchPredictorConfig::PREFETCHING_FOR_EXTERNAL; |
| 71 ResourcePrefetchPredictorConfig::PREFETCHING_FOR_EXTERNAL; | |
| 72 return true; | 86 return true; |
| 73 } else if (mode_value == kPrefetchingMode) { | 87 } else if (mode_value == kPrefetchingMode) { |
| 74 config->mode |= ResourcePrefetchPredictorConfig::LEARNING | | 88 config->mode |= ResourcePrefetchPredictorConfig::PREFETCHING_FOR_EXTERNAL | |
| 75 ResourcePrefetchPredictorConfig::PREFETCHING_FOR_EXTERNAL | | |
| 76 ResourcePrefetchPredictorConfig::PREFETCHING_FOR_NAVIGATION; | 89 ResourcePrefetchPredictorConfig::PREFETCHING_FOR_NAVIGATION; |
| 77 return true; | 90 return true; |
| 78 } | 91 } |
| 79 | 92 |
| 80 return false; | 93 return false; |
| 81 } | 94 } |
| 82 | 95 |
| 83 NavigationID::NavigationID() : tab_id(-1) {} | 96 NavigationID::NavigationID() : tab_id(-1) {} |
| 84 | 97 |
| 85 NavigationID::NavigationID(const NavigationID& other) | 98 NavigationID::NavigationID(const NavigationID& other) |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 128 max_prefetches_inflight_per_host_per_navigation(3) { | 141 max_prefetches_inflight_per_host_per_navigation(3) { |
| 129 } | 142 } |
| 130 | 143 |
| 131 ResourcePrefetchPredictorConfig::ResourcePrefetchPredictorConfig( | 144 ResourcePrefetchPredictorConfig::ResourcePrefetchPredictorConfig( |
| 132 const ResourcePrefetchPredictorConfig& other) = default; | 145 const ResourcePrefetchPredictorConfig& other) = default; |
| 133 | 146 |
| 134 ResourcePrefetchPredictorConfig::~ResourcePrefetchPredictorConfig() { | 147 ResourcePrefetchPredictorConfig::~ResourcePrefetchPredictorConfig() { |
| 135 } | 148 } |
| 136 | 149 |
| 137 bool ResourcePrefetchPredictorConfig::IsLearningEnabled() const { | 150 bool ResourcePrefetchPredictorConfig::IsLearningEnabled() const { |
| 138 return (mode & LEARNING) > 0; | 151 return IsURLLearningEnabled() || IsHostLearningEnabled(); |
| 152 } | |
| 153 | |
| 154 bool ResourcePrefetchPredictorConfig::IsURLLearningEnabled() const { | |
| 155 return (mode & URL_LEARNING) > 0; | |
| 156 } | |
| 157 | |
| 158 bool ResourcePrefetchPredictorConfig::IsHostLearningEnabled() const { | |
| 159 return (mode & HOST_LEARNING) > 0; | |
| 139 } | 160 } |
| 140 | 161 |
| 141 bool ResourcePrefetchPredictorConfig::IsPrefetchingEnabledForSomeOrigin( | 162 bool ResourcePrefetchPredictorConfig::IsPrefetchingEnabledForSomeOrigin( |
| 142 Profile* profile) const { | 163 Profile* profile) const { |
| 143 int mask = PREFETCHING_FOR_NAVIGATION | PREFETCHING_FOR_EXTERNAL; | 164 int mask = PREFETCHING_FOR_NAVIGATION | PREFETCHING_FOR_EXTERNAL; |
| 144 return IsPrefetchingEnabledInternal(profile, mode, mask); | 165 return IsPrefetchingEnabledInternal(profile, mode, mask); |
| 145 } | 166 } |
| 146 | 167 |
| 147 bool ResourcePrefetchPredictorConfig::IsPrefetchingEnabledForOrigin( | 168 bool ResourcePrefetchPredictorConfig::IsPrefetchingEnabledForOrigin( |
| 148 Profile* profile, | 169 Profile* profile, |
| (...skipping 24 matching lines...) Expand all Loading... | |
| 173 | 194 |
| 174 bool ResourcePrefetchPredictorConfig::IsMoreResourcesEnabledForTest() const { | 195 bool ResourcePrefetchPredictorConfig::IsMoreResourcesEnabledForTest() const { |
| 175 return max_resources_per_entry == 100; | 196 return max_resources_per_entry == 100; |
| 176 } | 197 } |
| 177 | 198 |
| 178 bool ResourcePrefetchPredictorConfig::IsSmallDBEnabledForTest() const { | 199 bool ResourcePrefetchPredictorConfig::IsSmallDBEnabledForTest() const { |
| 179 return max_urls_to_track == 200 && max_hosts_to_track == 100; | 200 return max_urls_to_track == 200 && max_hosts_to_track == 100; |
| 180 } | 201 } |
| 181 | 202 |
| 182 } // namespace predictors | 203 } // namespace predictors |
| OLD | NEW |