| 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 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 173 | 179 |
| 174 bool ResourcePrefetchPredictorConfig::IsMoreResourcesEnabledForTest() const { | 180 bool ResourcePrefetchPredictorConfig::IsMoreResourcesEnabledForTest() const { |
| 175 return max_resources_per_entry == 100; | 181 return max_resources_per_entry == 100; |
| 176 } | 182 } |
| 177 | 183 |
| 178 bool ResourcePrefetchPredictorConfig::IsSmallDBEnabledForTest() const { | 184 bool ResourcePrefetchPredictorConfig::IsSmallDBEnabledForTest() const { |
| 179 return max_urls_to_track == 200 && max_hosts_to_track == 100; | 185 return max_urls_to_track == 200 && max_hosts_to_track == 100; |
| 180 } | 186 } |
| 181 | 187 |
| 182 } // namespace predictors | 188 } // namespace predictors |
| OLD | NEW |