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" |
(...skipping 11 matching lines...) Expand all Loading... |
22 namespace prerender { | 22 namespace prerender { |
23 | 23 |
24 namespace { | 24 namespace { |
25 | 25 |
26 const char kOmniboxTrialName[] = "PrerenderFromOmnibox"; | 26 const char kOmniboxTrialName[] = "PrerenderFromOmnibox"; |
27 int g_omnibox_trial_default_group_number = kint32min; | 27 int g_omnibox_trial_default_group_number = kint32min; |
28 | 28 |
29 const char kLocalPredictorTrialName[] = "PrerenderLocalPredictor"; | 29 const char kLocalPredictorTrialName[] = "PrerenderLocalPredictor"; |
30 const char kLocalPredictorEnabledGroup[] = "Enabled"; | 30 const char kLocalPredictorEnabledGroup[] = "Enabled"; |
31 | 31 |
32 const char kLoggedInPredictorTrialName[] = "PrerenderLoggedInPredictor"; | |
33 const char kLoggedInPredictorEnabledGroup[] = "Enabled"; | |
34 const char kLoggedInPredictorDisabledGroup[] = "Disabled"; | |
35 | |
36 void SetupPrefetchFieldTrial() { | 32 void SetupPrefetchFieldTrial() { |
37 chrome::VersionInfo::Channel channel = chrome::VersionInfo::GetChannel(); | 33 chrome::VersionInfo::Channel channel = chrome::VersionInfo::GetChannel(); |
38 if (channel == chrome::VersionInfo::CHANNEL_STABLE || | 34 if (channel == chrome::VersionInfo::CHANNEL_STABLE || |
39 channel == chrome::VersionInfo::CHANNEL_BETA) { | 35 channel == chrome::VersionInfo::CHANNEL_BETA) { |
40 return; | 36 return; |
41 } | 37 } |
42 | 38 |
43 const FieldTrial::Probability divisor = 1000; | 39 const FieldTrial::Probability divisor = 1000; |
44 const FieldTrial::Probability prefetch_probability = 500; | 40 const FieldTrial::Probability prefetch_probability = 500; |
45 scoped_refptr<FieldTrial> trial( | 41 scoped_refptr<FieldTrial> trial( |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
138 PrerenderManager::SetMode( | 134 PrerenderManager::SetMode( |
139 PrerenderManager::PRERENDER_MODE_EXPERIMENT_NO_USE_GROUP); | 135 PrerenderManager::PRERENDER_MODE_EXPERIMENT_NO_USE_GROUP); |
140 } else { | 136 } else { |
141 NOTREACHED(); | 137 NOTREACHED(); |
142 } | 138 } |
143 } | 139 } |
144 | 140 |
145 } // end namespace | 141 } // end namespace |
146 | 142 |
147 void ConfigureOmniboxPrerender(); | 143 void ConfigureOmniboxPrerender(); |
148 void ConfigureLoggedInPredictor(); | |
149 | 144 |
150 void ConfigurePrefetchAndPrerender(const CommandLine& command_line) { | 145 void ConfigurePrefetchAndPrerender(const CommandLine& command_line) { |
151 enum PrerenderOption { | 146 enum PrerenderOption { |
152 PRERENDER_OPTION_AUTO, | 147 PRERENDER_OPTION_AUTO, |
153 PRERENDER_OPTION_DISABLED, | 148 PRERENDER_OPTION_DISABLED, |
154 PRERENDER_OPTION_ENABLED, | 149 PRERENDER_OPTION_ENABLED, |
155 PRERENDER_OPTION_PREFETCH_ONLY, | 150 PRERENDER_OPTION_PREFETCH_ONLY, |
156 }; | 151 }; |
157 | 152 |
158 PrerenderOption prerender_option = PRERENDER_OPTION_AUTO; | 153 PrerenderOption prerender_option = PRERENDER_OPTION_AUTO; |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
195 break; | 190 break; |
196 case PRERENDER_OPTION_PREFETCH_ONLY: | 191 case PRERENDER_OPTION_PREFETCH_ONLY: |
197 PrerenderManager::SetIsPrefetchEnabled(true); | 192 PrerenderManager::SetIsPrefetchEnabled(true); |
198 PrerenderManager::SetMode(PrerenderManager::PRERENDER_MODE_DISABLED); | 193 PrerenderManager::SetMode(PrerenderManager::PRERENDER_MODE_DISABLED); |
199 break; | 194 break; |
200 default: | 195 default: |
201 NOTREACHED(); | 196 NOTREACHED(); |
202 } | 197 } |
203 | 198 |
204 ConfigureOmniboxPrerender(); | 199 ConfigureOmniboxPrerender(); |
205 ConfigureLoggedInPredictor(); | |
206 } | 200 } |
207 | 201 |
208 void ConfigureOmniboxPrerender() { | 202 void ConfigureOmniboxPrerender() { |
209 // Field trial to see if we're enabled. | 203 // Field trial to see if we're enabled. |
210 const FieldTrial::Probability kDivisor = 100; | 204 const FieldTrial::Probability kDivisor = 100; |
211 | 205 |
212 FieldTrial::Probability kDisabledProbability = 10; | 206 FieldTrial::Probability kDisabledProbability = 10; |
213 chrome::VersionInfo::Channel channel = chrome::VersionInfo::GetChannel(); | 207 chrome::VersionInfo::Channel channel = chrome::VersionInfo::GetChannel(); |
214 if (channel == chrome::VersionInfo::CHANNEL_STABLE || | 208 if (channel == chrome::VersionInfo::CHANNEL_STABLE || |
215 channel == chrome::VersionInfo::CHANNEL_BETA) { | 209 channel == chrome::VersionInfo::CHANNEL_BETA) { |
216 kDisabledProbability = 1; | 210 kDisabledProbability = 1; |
217 } | 211 } |
218 scoped_refptr<FieldTrial> omnibox_prerender_trial( | 212 scoped_refptr<FieldTrial> omnibox_prerender_trial( |
219 FieldTrialList::FactoryGetFieldTrial( | 213 FieldTrialList::FactoryGetFieldTrial( |
220 kOmniboxTrialName, kDivisor, "OmniboxPrerenderEnabled", | 214 kOmniboxTrialName, kDivisor, "OmniboxPrerenderEnabled", |
221 2013, 12, 31, &g_omnibox_trial_default_group_number)); | 215 2013, 12, 31, &g_omnibox_trial_default_group_number)); |
222 omnibox_prerender_trial->AppendGroup("OmniboxPrerenderDisabled", | 216 omnibox_prerender_trial->AppendGroup("OmniboxPrerenderDisabled", |
223 kDisabledProbability); | 217 kDisabledProbability); |
224 } | 218 } |
225 | 219 |
226 void ConfigureLoggedInPredictor() { | |
227 chrome::VersionInfo::Channel channel = chrome::VersionInfo::GetChannel(); | |
228 if (channel == chrome::VersionInfo::CHANNEL_STABLE || | |
229 channel == chrome::VersionInfo::CHANNEL_BETA) { | |
230 return; | |
231 } | |
232 scoped_refptr<FieldTrial> logged_in_predictor_trial( | |
233 FieldTrialList::FactoryGetFieldTrial( | |
234 kLoggedInPredictorTrialName, 100, | |
235 kLoggedInPredictorDisabledGroup, 2013, 12, 31, NULL)); | |
236 logged_in_predictor_trial->AppendGroup(kLoggedInPredictorEnabledGroup, 100); | |
237 } | |
238 | |
239 bool IsOmniboxEnabled(Profile* profile) { | 220 bool IsOmniboxEnabled(Profile* profile) { |
240 if (!profile) | 221 if (!profile) |
241 return false; | 222 return false; |
242 | 223 |
243 if (!PrerenderManager::IsPrerenderingPossible()) | 224 if (!PrerenderManager::IsPrerenderingPossible()) |
244 return false; | 225 return false; |
245 | 226 |
246 // Override any field trial groups if the user has set a command line flag. | 227 // Override any field trial groups if the user has set a command line flag. |
247 if (CommandLine::ForCurrentProcess()->HasSwitch( | 228 if (CommandLine::ForCurrentProcess()->HasSwitch( |
248 switches::kPrerenderFromOmnibox)) { | 229 switches::kPrerenderFromOmnibox)) { |
(...skipping 13 matching lines...) Expand all Loading... |
262 const int group = FieldTrialList::FindValue(kOmniboxTrialName); | 243 const int group = FieldTrialList::FindValue(kOmniboxTrialName); |
263 return group == FieldTrial::kNotFinalized || | 244 return group == FieldTrial::kNotFinalized || |
264 group == g_omnibox_trial_default_group_number; | 245 group == g_omnibox_trial_default_group_number; |
265 } | 246 } |
266 | 247 |
267 bool IsLocalPredictorEnabled() { | 248 bool IsLocalPredictorEnabled() { |
268 return base::FieldTrialList::FindFullName(kLocalPredictorTrialName) == | 249 return base::FieldTrialList::FindFullName(kLocalPredictorTrialName) == |
269 kLocalPredictorEnabledGroup; | 250 kLocalPredictorEnabledGroup; |
270 } | 251 } |
271 | 252 |
272 bool IsLoggedInPredictorEnabled() { | |
273 return base::FieldTrialList::FindFullName(kLoggedInPredictorTrialName) == | |
274 kLoggedInPredictorEnabledGroup; | |
275 } | |
276 | |
277 } // namespace prerender | 253 } // namespace prerender |
OLD | NEW |