Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/prerender/prerender_field_trial.h" | 5 #include "chrome/browser/prerender/prerender_field_trial.h" |
| 6 | 6 |
| 7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "base/metrics/field_trial.h" | 9 #include "base/metrics/field_trial.h" |
| 10 #include "base/metrics/histogram.h" | 10 #include "base/metrics/histogram.h" |
| 11 #include "chrome/browser/metrics/metrics_service.h" | 11 #include "chrome/browser/metrics/metrics_service.h" |
| 12 #include "chrome/browser/predictors/autocomplete_action_predictor.h" | 12 #include "chrome/browser/predictors/autocomplete_action_predictor.h" |
| 13 #include "chrome/browser/prefs/pref_service.h" | 13 #include "chrome/browser/prefs/pref_service.h" |
| 14 #include "chrome/browser/prerender/prerender_manager.h" | 14 #include "chrome/browser/prerender/prerender_manager.h" |
| 15 #include "chrome/browser/profiles/profile.h" | 15 #include "chrome/browser/profiles/profile.h" |
| 16 #include "chrome/common/chrome_switches.h" | 16 #include "chrome/common/chrome_switches.h" |
| 17 #include "chrome/common/chrome_version_info.h" | 17 #include "chrome/common/chrome_version_info.h" |
| 18 | 18 |
| 19 using base::FieldTrial; | |
| 20 using base::FieldTrialList; | |
| 21 | |
| 19 namespace prerender { | 22 namespace prerender { |
| 20 | 23 |
| 21 namespace { | 24 namespace { |
| 22 | 25 |
| 23 const char kOmniboxTrialName[] = "PrerenderFromOmnibox"; | 26 const char kOmniboxTrialName[] = "PrerenderFromOmnibox"; |
| 24 int g_omnibox_trial_default_group_number = kint32min; | 27 int g_omnibox_trial_default_group_number = kint32min; |
| 25 | 28 |
| 26 const char kSpeculativePrefetchingLearningTrialName[] = | 29 const char kSpeculativePrefetchingLearningTrialName[] = |
| 27 "SpeculativePrefetchingLearning"; | 30 "SpeculativePrefetchingLearning"; |
| 28 int g_speculative_prefetching_learning_default_group_number = kint32min; | 31 int g_speculative_prefetching_learning_default_group_number = kint32min; |
| 29 | 32 |
| 30 void SetupPrefetchFieldTrial() { | 33 void SetupPrefetchFieldTrial() { |
| 31 chrome::VersionInfo::Channel channel = chrome::VersionInfo::GetChannel(); | 34 chrome::VersionInfo::Channel channel = chrome::VersionInfo::GetChannel(); |
| 32 if (channel == chrome::VersionInfo::CHANNEL_STABLE || | 35 if (channel == chrome::VersionInfo::CHANNEL_STABLE || |
| 33 channel == chrome::VersionInfo::CHANNEL_BETA) { | 36 channel == chrome::VersionInfo::CHANNEL_BETA) { |
| 34 return; | 37 return; |
| 35 } | 38 } |
| 36 | 39 |
| 37 const base::FieldTrial::Probability divisor = 1000; | 40 const FieldTrial::Probability divisor = 1000; |
| 38 const base::FieldTrial::Probability prefetch_probability = 500; | 41 const FieldTrial::Probability prefetch_probability = 500; |
| 39 scoped_refptr<base::FieldTrial> trial( | 42 scoped_refptr<FieldTrial> trial( |
| 40 base::FieldTrialList::FactoryGetFieldTrial( | 43 FieldTrialList::FactoryGetFieldTrial( |
| 41 "Prefetch", divisor, "ContentPrefetchPrefetchOff", | 44 "Prefetch", divisor, "ContentPrefetchPrefetchOff", |
| 42 2013, 6, 30, NULL)); | 45 2013, 6, 30, NULL)); |
| 43 const int kPrefetchOnGroup = trial->AppendGroup("ContentPrefetchPrefetchOn", | 46 const int kPrefetchOnGroup = trial->AppendGroup("ContentPrefetchPrefetchOn", |
| 44 prefetch_probability); | 47 prefetch_probability); |
| 45 PrerenderManager::SetIsPrefetchEnabled(trial->group() == kPrefetchOnGroup); | 48 PrerenderManager::SetIsPrefetchEnabled(trial->group() == kPrefetchOnGroup); |
| 46 } | 49 } |
| 47 | 50 |
| 48 void SetupPrerenderFieldTrial() { | 51 void SetupPrerenderFieldTrial() { |
| 49 base::FieldTrial::Probability divisor = 1000; | 52 const FieldTrial::Probability divisor = 1000; |
| 50 | 53 |
| 51 base::FieldTrial::Probability exp1_probability = 166; | 54 FieldTrial::Probability prerender_on_probability; |
| 52 base::FieldTrial::Probability exp1_5min_ttl_probability = 83; | 55 FieldTrial::Probability control_probability; |
| 53 base::FieldTrial::Probability control1_probability = 166; | 56 FieldTrial::Probability experiment_5min_ttl_probability; |
| 54 base::FieldTrial::Probability no_use1_probability = 83; | 57 FieldTrial::Probability experiment_no_use_probability; |
| 55 | |
| 56 base::FieldTrial::Probability exp2_probability = 167; | |
| 57 base::FieldTrial::Probability exp2_5min_ttl_probability = 84; | |
| 58 base::FieldTrial::Probability control2_probability = 167; | |
| 59 base::FieldTrial::Probability no_use2_probability = 84; | |
| 60 | 58 |
| 61 chrome::VersionInfo::Channel channel = chrome::VersionInfo::GetChannel(); | 59 chrome::VersionInfo::Channel channel = chrome::VersionInfo::GetChannel(); |
| 62 if (channel == chrome::VersionInfo::CHANNEL_STABLE || | 60 if (channel == chrome::VersionInfo::CHANNEL_STABLE || |
| 63 channel == chrome::VersionInfo::CHANNEL_BETA) { | 61 channel == chrome::VersionInfo::CHANNEL_BETA) { |
| 64 exp1_probability = 490; | 62 // Use very conservatives and stable settings in beta and stable. |
| 65 exp1_5min_ttl_probability = 5; | 63 const FieldTrial::Probability release_prerender_on_probability = 980; |
| 66 control1_probability = 5; | 64 const FieldTrial::Probability release_control_probability = 10; |
| 67 no_use1_probability = 0; | 65 const FieldTrial::Probability release_experiment_5min_ttl_probability = 10; |
| 68 exp2_probability = 490; | 66 const FieldTrial::Probability release_experiment_no_use_probability = 0; |
| 69 exp2_5min_ttl_probability = 5; | 67 COMPILE_ASSERT( |
| 70 control2_probability = 5; | 68 release_prerender_on_probability + release_control_probability + |
| 71 no_use2_probability = 0; | 69 release_experiment_5min_ttl_probability + |
| 70 release_experiment_no_use_probability == divisor, | |
| 71 release_experiment_probabilities_must_equal_divisor); | |
| 72 | |
| 73 prerender_on_probability = release_prerender_on_probability; | |
| 74 control_probability = release_experiment_5min_ttl_probability; | |
| 75 experiment_5min_ttl_probability = release_control_probability; | |
| 76 experiment_no_use_probability = release_experiment_no_use_probability; | |
| 77 } else { | |
| 78 // In testing channels, use more experiments and a larger control group to | |
| 79 // improve quality of data. | |
| 80 const FieldTrial::Probability dev_prerender_on_probability = 333; | |
| 81 const FieldTrial::Probability dev_control_probability = 333; | |
| 82 const FieldTrial::Probability dev_experiment_5min_ttl_probability = 167; | |
| 83 const FieldTrial::Probability dev_experiment_no_use_probability = 167; | |
| 84 COMPILE_ASSERT(dev_prerender_on_probability + dev_control_probability + | |
| 85 dev_experiment_5min_ttl_probability + | |
| 86 dev_experiment_no_use_probability == divisor, | |
| 87 dev_experiment_probabilities_must_equal_divisor); | |
| 88 | |
| 89 prerender_on_probability = dev_prerender_on_probability; | |
| 90 control_probability = dev_experiment_5min_ttl_probability; | |
| 91 experiment_5min_ttl_probability = dev_control_probability; | |
| 92 experiment_no_use_probability = dev_experiment_no_use_probability; | |
| 72 } | 93 } |
| 73 CHECK_EQ(divisor, exp1_probability + exp1_5min_ttl_probability + | |
| 74 control1_probability + no_use1_probability + exp2_probability + | |
| 75 exp2_5min_ttl_probability + control2_probability + | |
| 76 no_use2_probability); | |
| 77 int experiment_1_group = -1; | |
| 78 scoped_refptr<base::FieldTrial> trial( | |
| 79 base::FieldTrialList::FactoryGetFieldTrial( | |
| 80 "Prerender", divisor, "ContentPrefetchPrerender1", | |
| 81 2013, 6, 30, &experiment_1_group)); | |
| 82 | 94 |
| 83 const int experiment_15_min_TTL_group = | 95 int prerender_on_group = -1; |
| 84 trial->AppendGroup("ContentPrefetchPrerenderExp5minTTL1", | 96 scoped_refptr<FieldTrial> trial( |
| 85 exp1_5min_ttl_probability); | 97 FieldTrialList::FactoryGetFieldTrial( |
| 86 const int control_1_group = | 98 "Prerender", divisor, "PrerenderOn", |
|
dominich
2012/07/23 16:56:41
PrerenderEnabled?
gavinp
2012/07/23 17:01:05
Done.
| |
| 87 trial->AppendGroup("ContentPrefetchPrerenderControl1", | 99 2013, 6, 30, &prerender_on_group)); |
| 88 control1_probability); | 100 const int control_group = |
| 89 const int no_use_1_group = | 101 trial->AppendGroup("PrerenderControlGroup", |
|
dominich
2012/07/23 16:56:41
drop the Group. Just PrerenderControl. It's cleane
gavinp
2012/07/23 17:01:05
Done.
| |
| 90 trial->AppendGroup("ContentPrefetchPrerenderNoUse1", | 102 control_probability); |
| 91 no_use1_probability); | 103 const int experiment_5_min_TTL_group = |
| 92 const int experiment_2_group = | 104 trial->AppendGroup("Prerender5minTTL", |
| 93 trial->AppendGroup("ContentPrefetchPrerender2", | 105 experiment_5min_ttl_probability); |
| 94 exp2_probability); | 106 const int experiment_no_use_group = |
| 95 const int experiment_25_min_TTL_group = | 107 trial->AppendGroup("PrerenderNoUse", |
| 96 trial->AppendGroup("ContentPrefetchPrerenderExp5minTTL2", | 108 experiment_no_use_probability); |
| 97 exp2_5min_ttl_probability); | 109 |
| 98 const int control_2_group = | |
| 99 trial->AppendGroup("ContentPrefetchPrerenderControl2", | |
| 100 control2_probability); | |
| 101 const int no_use_2_group = | |
| 102 trial->AppendGroup("ContentPrefetchPrerenderNoUse2", | |
| 103 no_use2_probability); | |
| 104 const int trial_group = trial->group(); | 110 const int trial_group = trial->group(); |
| 105 if (trial_group == experiment_1_group || | 111 if (trial_group == prerender_on_group) { |
|
dominich
2012/07/23 16:56:41
switch statement
gavinp
2012/07/23 17:01:05
No can do without some ungainly plumbing, since ca
| |
| 106 trial_group == experiment_2_group) { | |
| 107 PrerenderManager::SetMode( | 112 PrerenderManager::SetMode( |
| 108 PrerenderManager::PRERENDER_MODE_EXPERIMENT_PRERENDER_GROUP); | 113 PrerenderManager::PRERENDER_MODE_EXPERIMENT_PRERENDER_GROUP); |
| 109 } else if (trial_group == experiment_15_min_TTL_group || | 114 } else if (trial_group == control_group) { |
| 110 trial_group == experiment_25_min_TTL_group) { | 115 PrerenderManager::SetMode( |
| 116 PrerenderManager::PRERENDER_MODE_EXPERIMENT_CONTROL_GROUP); | |
| 117 } else if (trial_group == experiment_5_min_TTL_group) { | |
| 111 PrerenderManager::SetMode( | 118 PrerenderManager::SetMode( |
| 112 PrerenderManager::PRERENDER_MODE_EXPERIMENT_5MIN_TTL_GROUP); | 119 PrerenderManager::PRERENDER_MODE_EXPERIMENT_5MIN_TTL_GROUP); |
| 113 } else if (trial_group == control_1_group || | 120 } else if (trial_group == experiment_no_use_group) { |
| 114 trial_group == control_2_group) { | |
| 115 PrerenderManager::SetMode( | |
| 116 PrerenderManager::PRERENDER_MODE_EXPERIMENT_CONTROL_GROUP); | |
| 117 } else if (trial_group == no_use_1_group || | |
| 118 trial_group == no_use_2_group) { | |
| 119 PrerenderManager::SetMode( | 121 PrerenderManager::SetMode( |
| 120 PrerenderManager::PRERENDER_MODE_EXPERIMENT_NO_USE_GROUP); | 122 PrerenderManager::PRERENDER_MODE_EXPERIMENT_NO_USE_GROUP); |
| 121 } else { | 123 } else { |
| 122 NOTREACHED(); | 124 NOTREACHED(); |
| 123 } | 125 } |
| 124 } | 126 } |
| 125 | 127 |
| 126 } // end namespace | 128 } // end namespace |
| 127 | 129 |
| 128 void ConfigureOmniboxPrerender(); | 130 void ConfigureOmniboxPrerender(); |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 185 UMA_HISTOGRAM_ENUMERATION("Prerender.Sessions", | 187 UMA_HISTOGRAM_ENUMERATION("Prerender.Sessions", |
| 186 PrerenderManager::GetMode(), | 188 PrerenderManager::GetMode(), |
| 187 PrerenderManager::PRERENDER_MODE_MAX); | 189 PrerenderManager::PRERENDER_MODE_MAX); |
| 188 | 190 |
| 189 ConfigureOmniboxPrerender(); | 191 ConfigureOmniboxPrerender(); |
| 190 ConfigureSpeculativePrefetching(); | 192 ConfigureSpeculativePrefetching(); |
| 191 } | 193 } |
| 192 | 194 |
| 193 void ConfigureOmniboxPrerender() { | 195 void ConfigureOmniboxPrerender() { |
| 194 // Field trial to see if we're enabled. | 196 // Field trial to see if we're enabled. |
| 195 const base::FieldTrial::Probability kDivisor = 100; | 197 const FieldTrial::Probability kDivisor = 100; |
| 196 | 198 |
| 197 base::FieldTrial::Probability kDisabledProbability = 10; | 199 FieldTrial::Probability kDisabledProbability = 10; |
| 198 chrome::VersionInfo::Channel channel = chrome::VersionInfo::GetChannel(); | 200 chrome::VersionInfo::Channel channel = chrome::VersionInfo::GetChannel(); |
| 199 if (channel == chrome::VersionInfo::CHANNEL_STABLE || | 201 if (channel == chrome::VersionInfo::CHANNEL_STABLE || |
| 200 channel == chrome::VersionInfo::CHANNEL_BETA) { | 202 channel == chrome::VersionInfo::CHANNEL_BETA) { |
| 201 kDisabledProbability = 1; | 203 kDisabledProbability = 1; |
| 202 } | 204 } |
| 203 scoped_refptr<base::FieldTrial> omnibox_prerender_trial( | 205 scoped_refptr<FieldTrial> omnibox_prerender_trial( |
| 204 base::FieldTrialList::FactoryGetFieldTrial( | 206 FieldTrialList::FactoryGetFieldTrial( |
| 205 kOmniboxTrialName, kDivisor, "OmniboxPrerenderEnabled", | 207 kOmniboxTrialName, kDivisor, "OmniboxPrerenderEnabled", |
| 206 2012, 12, 30, &g_omnibox_trial_default_group_number)); | 208 2012, 12, 30, &g_omnibox_trial_default_group_number)); |
| 207 omnibox_prerender_trial->AppendGroup("OmniboxPrerenderDisabled", | 209 omnibox_prerender_trial->AppendGroup("OmniboxPrerenderDisabled", |
| 208 kDisabledProbability); | 210 kDisabledProbability); |
| 209 } | 211 } |
| 210 | 212 |
| 211 bool IsOmniboxEnabled(Profile* profile) { | 213 bool IsOmniboxEnabled(Profile* profile) { |
| 212 if (!profile) | 214 if (!profile) |
| 213 return false; | 215 return false; |
| 214 | 216 |
| 215 if (!PrerenderManager::IsPrerenderingPossible()) | 217 if (!PrerenderManager::IsPrerenderingPossible()) |
| 216 return false; | 218 return false; |
| 217 | 219 |
| 218 // Override any field trial groups if the user has set a command line flag. | 220 // Override any field trial groups if the user has set a command line flag. |
| 219 if (CommandLine::ForCurrentProcess()->HasSwitch( | 221 if (CommandLine::ForCurrentProcess()->HasSwitch( |
| 220 switches::kPrerenderFromOmnibox)) { | 222 switches::kPrerenderFromOmnibox)) { |
| 221 const std::string switch_value = | 223 const std::string switch_value = |
| 222 CommandLine::ForCurrentProcess()->GetSwitchValueASCII( | 224 CommandLine::ForCurrentProcess()->GetSwitchValueASCII( |
| 223 switches::kPrerenderFromOmnibox); | 225 switches::kPrerenderFromOmnibox); |
| 224 | 226 |
| 225 if (switch_value == switches::kPrerenderFromOmniboxSwitchValueEnabled) | 227 if (switch_value == switches::kPrerenderFromOmniboxSwitchValueEnabled) |
| 226 return true; | 228 return true; |
| 227 | 229 |
| 228 if (switch_value == switches::kPrerenderFromOmniboxSwitchValueDisabled) | 230 if (switch_value == switches::kPrerenderFromOmniboxSwitchValueDisabled) |
| 229 return false; | 231 return false; |
| 230 | 232 |
| 231 DCHECK(switch_value == switches::kPrerenderFromOmniboxSwitchValueAuto); | 233 DCHECK(switch_value == switches::kPrerenderFromOmniboxSwitchValueAuto); |
| 232 } | 234 } |
| 233 | 235 |
| 234 const int group = base::FieldTrialList::FindValue(kOmniboxTrialName); | 236 const int group = FieldTrialList::FindValue(kOmniboxTrialName); |
| 235 return group == base::FieldTrial::kNotFinalized || | 237 return group == FieldTrial::kNotFinalized || |
| 236 group == g_omnibox_trial_default_group_number; | 238 group == g_omnibox_trial_default_group_number; |
| 237 } | 239 } |
| 238 | 240 |
| 239 void ConfigureSpeculativePrefetching() { | 241 void ConfigureSpeculativePrefetching() { |
| 240 // Field trial to see if we're enabled. | 242 // Field trial to see if we're enabled. |
| 241 const base::FieldTrial::Probability kDivisor = 100; | 243 const FieldTrial::Probability kDivisor = 100; |
| 242 | 244 |
| 243 base::FieldTrial::Probability kDisabledProbability = 99; | 245 FieldTrial::Probability kDisabledProbability = 99; |
| 244 chrome::VersionInfo::Channel channel = chrome::VersionInfo::GetChannel(); | 246 chrome::VersionInfo::Channel channel = chrome::VersionInfo::GetChannel(); |
| 245 if (channel == chrome::VersionInfo::CHANNEL_STABLE || | 247 if (channel == chrome::VersionInfo::CHANNEL_STABLE || |
| 246 channel == chrome::VersionInfo::CHANNEL_BETA) { | 248 channel == chrome::VersionInfo::CHANNEL_BETA) { |
| 247 kDisabledProbability = 100; | 249 kDisabledProbability = 100; |
| 248 } | 250 } |
| 249 scoped_refptr<base::FieldTrial> speculative_prefetching_learning_trial( | 251 scoped_refptr<FieldTrial> speculative_prefetching_learning_trial( |
| 250 base::FieldTrialList::FactoryGetFieldTrial( | 252 FieldTrialList::FactoryGetFieldTrial( |
| 251 kSpeculativePrefetchingLearningTrialName, | 253 kSpeculativePrefetchingLearningTrialName, |
| 252 kDivisor, | 254 kDivisor, |
| 253 "SpeculativePrefetchingLearningEnabled", | 255 "SpeculativePrefetchingLearningEnabled", |
| 254 2012, 12, 30, | 256 2012, 12, 30, |
| 255 &g_speculative_prefetching_learning_default_group_number)); | 257 &g_speculative_prefetching_learning_default_group_number)); |
| 256 speculative_prefetching_learning_trial->AppendGroup( | 258 speculative_prefetching_learning_trial->AppendGroup( |
| 257 "SpeculativePrefetchingDisabled", | 259 "SpeculativePrefetchingDisabled", |
| 258 kDisabledProbability); | 260 kDisabledProbability); |
| 259 } | 261 } |
| 260 | 262 |
| 261 bool IsSpeculativeResourcePrefetchingLearningEnabled(Profile* profile) { | 263 bool IsSpeculativeResourcePrefetchingLearningEnabled(Profile* profile) { |
| 262 if (!profile) | 264 if (!profile) |
| 263 return false; | 265 return false; |
| 264 | 266 |
| 265 // Override any field trial groups if the user has set a command line flag. | 267 // Override any field trial groups if the user has set a command line flag. |
| 266 if (CommandLine::ForCurrentProcess()->HasSwitch( | 268 if (CommandLine::ForCurrentProcess()->HasSwitch( |
| 267 switches::kSpeculativeResourcePrefetching)) { | 269 switches::kSpeculativeResourcePrefetching)) { |
| 268 const std::string switch_value = | 270 const std::string switch_value = |
| 269 CommandLine::ForCurrentProcess()->GetSwitchValueASCII( | 271 CommandLine::ForCurrentProcess()->GetSwitchValueASCII( |
| 270 switches::kSpeculativeResourcePrefetching); | 272 switches::kSpeculativeResourcePrefetching); |
| 271 | 273 |
| 272 if (switch_value == switches::kSpeculativeResourcePrefetchingLearning) | 274 if (switch_value == switches::kSpeculativeResourcePrefetchingLearning) |
| 273 return true; | 275 return true; |
| 274 } | 276 } |
| 275 | 277 |
| 276 const int group = base::FieldTrialList::FindValue( | 278 const int group = FieldTrialList::FindValue( |
| 277 kSpeculativePrefetchingLearningTrialName); | 279 kSpeculativePrefetchingLearningTrialName); |
| 278 return group == g_speculative_prefetching_learning_default_group_number; | 280 return group == g_speculative_prefetching_learning_default_group_number; |
| 279 } | 281 } |
| 280 | 282 |
| 281 } // namespace prerender | 283 } // namespace prerender |
| OLD | NEW |