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 namespace prerender { | 19 namespace prerender { |
20 | 20 |
21 namespace { | 21 namespace { |
22 | 22 |
23 const char kOmniboxTrialName[] = "PrerenderFromOmnibox"; | 23 const char kOmniboxTrialName[] = "PrerenderFromOmnibox"; |
24 int g_omnibox_trial_default_group_number = -1; | 24 int g_omnibox_trial_default_group_number = -1; |
25 | 25 |
| 26 const char kSpeculativePrefetchingLearningTrialName[] = |
| 27 "SpeculativePrefetchingLearning"; |
| 28 int g_speculative_prefetching_learning_default_group_number = -1; |
| 29 |
26 void SetupPrefetchFieldTrial() { | 30 void SetupPrefetchFieldTrial() { |
27 chrome::VersionInfo::Channel channel = chrome::VersionInfo::GetChannel(); | 31 chrome::VersionInfo::Channel channel = chrome::VersionInfo::GetChannel(); |
28 if (channel == chrome::VersionInfo::CHANNEL_STABLE || | 32 if (channel == chrome::VersionInfo::CHANNEL_STABLE || |
29 channel == chrome::VersionInfo::CHANNEL_BETA) { | 33 channel == chrome::VersionInfo::CHANNEL_BETA) { |
30 return; | 34 return; |
31 } | 35 } |
32 | 36 |
33 const base::FieldTrial::Probability divisor = 1000; | 37 const base::FieldTrial::Probability divisor = 1000; |
34 const base::FieldTrial::Probability prefetch_probability = 500; | 38 const base::FieldTrial::Probability prefetch_probability = 500; |
35 scoped_refptr<base::FieldTrial> trial( | 39 scoped_refptr<base::FieldTrial> trial( |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
115 PrerenderManager::SetMode( | 119 PrerenderManager::SetMode( |
116 PrerenderManager::PRERENDER_MODE_EXPERIMENT_NO_USE_GROUP); | 120 PrerenderManager::PRERENDER_MODE_EXPERIMENT_NO_USE_GROUP); |
117 } else { | 121 } else { |
118 NOTREACHED(); | 122 NOTREACHED(); |
119 } | 123 } |
120 } | 124 } |
121 | 125 |
122 } // end namespace | 126 } // end namespace |
123 | 127 |
124 void ConfigureOmniboxPrerender(); | 128 void ConfigureOmniboxPrerender(); |
| 129 void ConfigureSpeculativePrefetching(); |
125 | 130 |
126 void ConfigurePrefetchAndPrerender(const CommandLine& command_line) { | 131 void ConfigurePrefetchAndPrerender(const CommandLine& command_line) { |
127 enum PrerenderOption { | 132 enum PrerenderOption { |
128 PRERENDER_OPTION_AUTO, | 133 PRERENDER_OPTION_AUTO, |
129 PRERENDER_OPTION_DISABLED, | 134 PRERENDER_OPTION_DISABLED, |
130 PRERENDER_OPTION_ENABLED, | 135 PRERENDER_OPTION_ENABLED, |
131 PRERENDER_OPTION_PREFETCH_ONLY, | 136 PRERENDER_OPTION_PREFETCH_ONLY, |
132 }; | 137 }; |
133 | 138 |
134 PrerenderOption prerender_option = PRERENDER_OPTION_AUTO; | 139 PrerenderOption prerender_option = PRERENDER_OPTION_AUTO; |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
175 break; | 180 break; |
176 default: | 181 default: |
177 NOTREACHED(); | 182 NOTREACHED(); |
178 } | 183 } |
179 | 184 |
180 UMA_HISTOGRAM_ENUMERATION("Prerender.Sessions", | 185 UMA_HISTOGRAM_ENUMERATION("Prerender.Sessions", |
181 PrerenderManager::GetMode(), | 186 PrerenderManager::GetMode(), |
182 PrerenderManager::PRERENDER_MODE_MAX); | 187 PrerenderManager::PRERENDER_MODE_MAX); |
183 | 188 |
184 ConfigureOmniboxPrerender(); | 189 ConfigureOmniboxPrerender(); |
| 190 ConfigureSpeculativePrefetching(); |
185 } | 191 } |
186 | 192 |
187 void ConfigureOmniboxPrerender() { | 193 void ConfigureOmniboxPrerender() { |
188 // Field trial to see if we're enabled. | 194 // Field trial to see if we're enabled. |
189 const base::FieldTrial::Probability kDivisor = 100; | 195 const base::FieldTrial::Probability kDivisor = 100; |
190 | 196 |
191 base::FieldTrial::Probability kDisabledProbability = 10; | 197 base::FieldTrial::Probability kDisabledProbability = 10; |
192 chrome::VersionInfo::Channel channel = chrome::VersionInfo::GetChannel(); | 198 chrome::VersionInfo::Channel channel = chrome::VersionInfo::GetChannel(); |
193 if (channel == chrome::VersionInfo::CHANNEL_STABLE || | 199 if (channel == chrome::VersionInfo::CHANNEL_STABLE || |
194 channel == chrome::VersionInfo::CHANNEL_BETA) { | 200 channel == chrome::VersionInfo::CHANNEL_BETA) { |
(...skipping 28 matching lines...) Expand all Loading... |
223 return false; | 229 return false; |
224 | 230 |
225 DCHECK(switch_value == switches::kPrerenderFromOmniboxSwitchValueAuto); | 231 DCHECK(switch_value == switches::kPrerenderFromOmniboxSwitchValueAuto); |
226 } | 232 } |
227 | 233 |
228 const int group = base::FieldTrialList::FindValue(kOmniboxTrialName); | 234 const int group = base::FieldTrialList::FindValue(kOmniboxTrialName); |
229 return group == base::FieldTrial::kNotFinalized || | 235 return group == base::FieldTrial::kNotFinalized || |
230 group == g_omnibox_trial_default_group_number; | 236 group == g_omnibox_trial_default_group_number; |
231 } | 237 } |
232 | 238 |
| 239 void ConfigureSpeculativePrefetching() { |
| 240 // Field trial to see if we're enabled. |
| 241 const base::FieldTrial::Probability kDivisor = 100; |
| 242 |
| 243 base::FieldTrial::Probability kDisabledProbability = 99; |
| 244 chrome::VersionInfo::Channel channel = chrome::VersionInfo::GetChannel(); |
| 245 if (channel == chrome::VersionInfo::CHANNEL_STABLE || |
| 246 channel == chrome::VersionInfo::CHANNEL_BETA) { |
| 247 kDisabledProbability = 100; |
| 248 } |
| 249 scoped_refptr<base::FieldTrial> speculative_prefetching_learning_trial( |
| 250 base::FieldTrialList::FactoryGetFieldTrial( |
| 251 kSpeculativePrefetchingLearningTrialName, |
| 252 kDivisor, |
| 253 "SpeculativePrefetchingLearningEnabled", |
| 254 2012, 12, 30, |
| 255 &g_speculative_prefetching_learning_default_group_number)); |
| 256 speculative_prefetching_learning_trial->AppendGroup( |
| 257 "SpeculativePrefetchingDisabled", |
| 258 kDisabledProbability); |
| 259 } |
| 260 |
| 261 bool IsSpeculativeResourcePrefetchingLearningEnabled(Profile* profile) { |
| 262 if (!profile) |
| 263 return false; |
| 264 |
| 265 // Override any field trial groups if the user has set a command line flag. |
| 266 if (CommandLine::ForCurrentProcess()->HasSwitch( |
| 267 switches::kSpeculativeResourcePrefetching)) { |
| 268 const std::string switch_value = |
| 269 CommandLine::ForCurrentProcess()->GetSwitchValueASCII( |
| 270 switches::kSpeculativeResourcePrefetching); |
| 271 |
| 272 if (switch_value == switches::kSpeculativeResourcePrefetchingLearning) |
| 273 return true; |
| 274 } |
| 275 |
| 276 const int group = base::FieldTrialList::FindValue( |
| 277 kSpeculativePrefetchingLearningTrialName); |
| 278 return group == g_speculative_prefetching_learning_default_group_number; |
| 279 } |
| 280 |
233 } // namespace prerender | 281 } // namespace prerender |
OLD | NEW |