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 | |
30 void SetupPrefetchFieldTrial() { | 26 void SetupPrefetchFieldTrial() { |
31 chrome::VersionInfo::Channel channel = chrome::VersionInfo::GetChannel(); | 27 chrome::VersionInfo::Channel channel = chrome::VersionInfo::GetChannel(); |
32 if (channel == chrome::VersionInfo::CHANNEL_STABLE || | 28 if (channel == chrome::VersionInfo::CHANNEL_STABLE || |
33 channel == chrome::VersionInfo::CHANNEL_BETA) { | 29 channel == chrome::VersionInfo::CHANNEL_BETA) { |
34 return; | 30 return; |
35 } | 31 } |
36 | 32 |
37 const base::FieldTrial::Probability divisor = 1000; | 33 const base::FieldTrial::Probability divisor = 1000; |
38 const base::FieldTrial::Probability prefetch_probability = 500; | 34 const base::FieldTrial::Probability prefetch_probability = 500; |
39 scoped_refptr<base::FieldTrial> trial( | 35 scoped_refptr<base::FieldTrial> trial( |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
119 PrerenderManager::SetMode( | 115 PrerenderManager::SetMode( |
120 PrerenderManager::PRERENDER_MODE_EXPERIMENT_NO_USE_GROUP); | 116 PrerenderManager::PRERENDER_MODE_EXPERIMENT_NO_USE_GROUP); |
121 } else { | 117 } else { |
122 NOTREACHED(); | 118 NOTREACHED(); |
123 } | 119 } |
124 } | 120 } |
125 | 121 |
126 } // end namespace | 122 } // end namespace |
127 | 123 |
128 void ConfigureOmniboxPrerender(); | 124 void ConfigureOmniboxPrerender(); |
129 void ConfigureSpeculativePrefetching(); | |
130 | 125 |
131 void ConfigurePrefetchAndPrerender(const CommandLine& command_line) { | 126 void ConfigurePrefetchAndPrerender(const CommandLine& command_line) { |
132 enum PrerenderOption { | 127 enum PrerenderOption { |
133 PRERENDER_OPTION_AUTO, | 128 PRERENDER_OPTION_AUTO, |
134 PRERENDER_OPTION_DISABLED, | 129 PRERENDER_OPTION_DISABLED, |
135 PRERENDER_OPTION_ENABLED, | 130 PRERENDER_OPTION_ENABLED, |
136 PRERENDER_OPTION_PREFETCH_ONLY, | 131 PRERENDER_OPTION_PREFETCH_ONLY, |
137 }; | 132 }; |
138 | 133 |
139 PrerenderOption prerender_option = PRERENDER_OPTION_AUTO; | 134 PrerenderOption prerender_option = PRERENDER_OPTION_AUTO; |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
180 break; | 175 break; |
181 default: | 176 default: |
182 NOTREACHED(); | 177 NOTREACHED(); |
183 } | 178 } |
184 | 179 |
185 UMA_HISTOGRAM_ENUMERATION("Prerender.Sessions", | 180 UMA_HISTOGRAM_ENUMERATION("Prerender.Sessions", |
186 PrerenderManager::GetMode(), | 181 PrerenderManager::GetMode(), |
187 PrerenderManager::PRERENDER_MODE_MAX); | 182 PrerenderManager::PRERENDER_MODE_MAX); |
188 | 183 |
189 ConfigureOmniboxPrerender(); | 184 ConfigureOmniboxPrerender(); |
190 ConfigureSpeculativePrefetching(); | |
191 } | 185 } |
192 | 186 |
193 void ConfigureOmniboxPrerender() { | 187 void ConfigureOmniboxPrerender() { |
194 // Field trial to see if we're enabled. | 188 // Field trial to see if we're enabled. |
195 const base::FieldTrial::Probability kDivisor = 100; | 189 const base::FieldTrial::Probability kDivisor = 100; |
196 | 190 |
197 base::FieldTrial::Probability kDisabledProbability = 10; | 191 base::FieldTrial::Probability kDisabledProbability = 10; |
198 chrome::VersionInfo::Channel channel = chrome::VersionInfo::GetChannel(); | 192 chrome::VersionInfo::Channel channel = chrome::VersionInfo::GetChannel(); |
199 if (channel == chrome::VersionInfo::CHANNEL_STABLE || | 193 if (channel == chrome::VersionInfo::CHANNEL_STABLE || |
200 channel == chrome::VersionInfo::CHANNEL_BETA) { | 194 channel == chrome::VersionInfo::CHANNEL_BETA) { |
(...skipping 28 matching lines...) Expand all Loading... |
229 return false; | 223 return false; |
230 | 224 |
231 DCHECK(switch_value == switches::kPrerenderFromOmniboxSwitchValueAuto); | 225 DCHECK(switch_value == switches::kPrerenderFromOmniboxSwitchValueAuto); |
232 } | 226 } |
233 | 227 |
234 const int group = base::FieldTrialList::FindValue(kOmniboxTrialName); | 228 const int group = base::FieldTrialList::FindValue(kOmniboxTrialName); |
235 return group == base::FieldTrial::kNotFinalized || | 229 return group == base::FieldTrial::kNotFinalized || |
236 group == g_omnibox_trial_default_group_number; | 230 group == g_omnibox_trial_default_group_number; |
237 } | 231 } |
238 | 232 |
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 | |
281 } // namespace prerender | 233 } // namespace prerender |
OLD | NEW |