Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1773)

Unified Diff: chrome/browser/predictors/resource_prefetch_common.cc

Issue 2652313002: predictors: Move the configuration of speculative prefetch to field trials. (Closed)
Patch Set: Address comments. Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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 174848d8e9f14fe856155a06a3093347ae4e4cb6..27ea7933c98834c5ddcc57903fc9775dce60cd82 100644
--- a/chrome/browser/predictors/resource_prefetch_common.cc
+++ b/chrome/browser/predictors/resource_prefetch_common.cc
@@ -8,18 +8,31 @@
#include <tuple>
#include "base/command_line.h"
+#include "base/metrics/field_trial.h"
#include "chrome/browser/net/prediction_options.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/sessions/session_tab_helper.h"
#include "chrome/common/chrome_switches.h"
#include "components/prefs/pref_service.h"
+#include "components/variations/variations_associated_data.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/web_contents.h"
namespace predictors {
+const char kSpeculativeResourcePrefetchingFeatureName[] =
+ "SpeculativeResourcePrefetching";
+const char kModeParamName[] = "mode";
+const char kLearningMode[] = "learning";
+const char kExternalPrefetchingMode[] = "external-prefetching";
+const char kPrefetchingMode[] = "prefetching";
+
namespace {
+const base::Feature kSpeculativeResourcePrefetchingFeature{
+ kSpeculativeResourcePrefetchingFeatureName,
+ base::FEATURE_DISABLED_BY_DEFAULT};
+
bool IsPrefetchingEnabledInternal(Profile* profile, int mode, int mask) {
DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
if ((mode & mask) == 0)
@@ -41,35 +54,27 @@ bool IsSpeculativeResourcePrefetchingEnabled(
ResourcePrefetchPredictorConfig* config) {
DCHECK(config);
- // Off the record - disabled.
+ // Disabled for of-the-record. Policy choice, not a technical limitation.
if (!profile || profile->IsOffTheRecord())
return false;
- // Enabled by command line switch. The config has the default params already
- // set. The command line with just enable them with the default params.
- if (base::CommandLine::ForCurrentProcess()->HasSwitch(
- switches::kSpeculativeResourcePrefetching)) {
- const std::string value =
- base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII(
- switches::kSpeculativeResourcePrefetching);
-
- if (value == switches::kSpeculativeResourcePrefetchingDisabled) {
- return false;
- } else if (value == switches::kSpeculativeResourcePrefetchingLearning) {
- config->mode |= ResourcePrefetchPredictorConfig::LEARNING;
- return true;
- } else if (value ==
- switches::kSpeculativeResourcePrefetchingEnabledExternal) {
- config->mode |= ResourcePrefetchPredictorConfig::LEARNING |
- ResourcePrefetchPredictorConfig::PREFETCHING_FOR_EXTERNAL;
- return true;
- } else if (value == switches::kSpeculativeResourcePrefetchingEnabled) {
- config->mode |=
- ResourcePrefetchPredictorConfig::LEARNING |
- ResourcePrefetchPredictorConfig::PREFETCHING_FOR_NAVIGATION |
- ResourcePrefetchPredictorConfig::PREFETCHING_FOR_EXTERNAL;
- return true;
- }
+ if (!base::FeatureList::IsEnabled(kSpeculativeResourcePrefetchingFeature))
+ return false;
+
+ std::string mode_value = variations::GetVariationParamValueByFeature(
+ kSpeculativeResourcePrefetchingFeature, kModeParamName);
+ if (mode_value == kLearningMode) {
+ config->mode |= ResourcePrefetchPredictorConfig::LEARNING;
+ return true;
+ } else if (mode_value == kExternalPrefetchingMode) {
+ config->mode |= ResourcePrefetchPredictorConfig::LEARNING |
+ ResourcePrefetchPredictorConfig::PREFETCHING_FOR_EXTERNAL;
+ return true;
+ } else if (mode_value == kPrefetchingMode) {
+ config->mode |= ResourcePrefetchPredictorConfig::LEARNING |
+ ResourcePrefetchPredictorConfig::PREFETCHING_FOR_EXTERNAL |
+ ResourcePrefetchPredictorConfig::PREFETCHING_FOR_NAVIGATION;
+ return true;
}
return false;
« no previous file with comments | « chrome/browser/predictors/resource_prefetch_common.h ('k') | chrome/browser/predictors/resource_prefetch_common_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698