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" |
| (...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 | |
| 32 void SetupPrefetchFieldTrial() { | 36 void SetupPrefetchFieldTrial() { |
| 33 chrome::VersionInfo::Channel channel = chrome::VersionInfo::GetChannel(); | 37 chrome::VersionInfo::Channel channel = chrome::VersionInfo::GetChannel(); |
| 34 if (channel == chrome::VersionInfo::CHANNEL_STABLE || | 38 if (channel == chrome::VersionInfo::CHANNEL_STABLE || |
| 35 channel == chrome::VersionInfo::CHANNEL_BETA) { | 39 channel == chrome::VersionInfo::CHANNEL_BETA) { |
| 36 return; | 40 return; |
| 37 } | 41 } |
| 38 | 42 |
| 39 const FieldTrial::Probability divisor = 1000; | 43 const FieldTrial::Probability divisor = 1000; |
| 40 const FieldTrial::Probability prefetch_probability = 500; | 44 const FieldTrial::Probability prefetch_probability = 500; |
| 41 scoped_refptr<FieldTrial> trial( | 45 scoped_refptr<FieldTrial> trial( |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 134 PrerenderManager::SetMode( | 138 PrerenderManager::SetMode( |
| 135 PrerenderManager::PRERENDER_MODE_EXPERIMENT_NO_USE_GROUP); | 139 PrerenderManager::PRERENDER_MODE_EXPERIMENT_NO_USE_GROUP); |
| 136 } else { | 140 } else { |
| 137 NOTREACHED(); | 141 NOTREACHED(); |
| 138 } | 142 } |
| 139 } | 143 } |
| 140 | 144 |
| 141 } // end namespace | 145 } // end namespace |
| 142 | 146 |
| 143 void ConfigureOmniboxPrerender(); | 147 void ConfigureOmniboxPrerender(); |
| 148 void ConfigureLoggedInPredictor(); | |
| 144 | 149 |
| 145 void ConfigurePrefetchAndPrerender(const CommandLine& command_line) { | 150 void ConfigurePrefetchAndPrerender(const CommandLine& command_line) { |
| 146 enum PrerenderOption { | 151 enum PrerenderOption { |
| 147 PRERENDER_OPTION_AUTO, | 152 PRERENDER_OPTION_AUTO, |
| 148 PRERENDER_OPTION_DISABLED, | 153 PRERENDER_OPTION_DISABLED, |
| 149 PRERENDER_OPTION_ENABLED, | 154 PRERENDER_OPTION_ENABLED, |
| 150 PRERENDER_OPTION_PREFETCH_ONLY, | 155 PRERENDER_OPTION_PREFETCH_ONLY, |
| 151 }; | 156 }; |
| 152 | 157 |
| 153 PrerenderOption prerender_option = PRERENDER_OPTION_AUTO; | 158 PrerenderOption prerender_option = PRERENDER_OPTION_AUTO; |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 190 break; | 195 break; |
| 191 case PRERENDER_OPTION_PREFETCH_ONLY: | 196 case PRERENDER_OPTION_PREFETCH_ONLY: |
| 192 PrerenderManager::SetIsPrefetchEnabled(true); | 197 PrerenderManager::SetIsPrefetchEnabled(true); |
| 193 PrerenderManager::SetMode(PrerenderManager::PRERENDER_MODE_DISABLED); | 198 PrerenderManager::SetMode(PrerenderManager::PRERENDER_MODE_DISABLED); |
| 194 break; | 199 break; |
| 195 default: | 200 default: |
| 196 NOTREACHED(); | 201 NOTREACHED(); |
| 197 } | 202 } |
| 198 | 203 |
| 199 ConfigureOmniboxPrerender(); | 204 ConfigureOmniboxPrerender(); |
| 205 ConfigureLoggedInPredictor(); | |
| 200 } | 206 } |
| 201 | 207 |
| 202 void ConfigureOmniboxPrerender() { | 208 void ConfigureOmniboxPrerender() { |
| 203 // Field trial to see if we're enabled. | 209 // Field trial to see if we're enabled. |
| 204 const FieldTrial::Probability kDivisor = 100; | 210 const FieldTrial::Probability kDivisor = 100; |
| 205 | 211 |
| 206 FieldTrial::Probability kDisabledProbability = 10; | 212 FieldTrial::Probability kDisabledProbability = 10; |
| 207 chrome::VersionInfo::Channel channel = chrome::VersionInfo::GetChannel(); | 213 chrome::VersionInfo::Channel channel = chrome::VersionInfo::GetChannel(); |
| 208 if (channel == chrome::VersionInfo::CHANNEL_STABLE || | 214 if (channel == chrome::VersionInfo::CHANNEL_STABLE || |
| 209 channel == chrome::VersionInfo::CHANNEL_BETA) { | 215 channel == chrome::VersionInfo::CHANNEL_BETA) { |
| 210 kDisabledProbability = 1; | 216 kDisabledProbability = 1; |
| 211 } | 217 } |
| 212 scoped_refptr<FieldTrial> omnibox_prerender_trial( | 218 scoped_refptr<FieldTrial> omnibox_prerender_trial( |
| 213 FieldTrialList::FactoryGetFieldTrial( | 219 FieldTrialList::FactoryGetFieldTrial( |
| 214 kOmniboxTrialName, kDivisor, "OmniboxPrerenderEnabled", | 220 kOmniboxTrialName, kDivisor, "OmniboxPrerenderEnabled", |
| 215 2013, 12, 31, &g_omnibox_trial_default_group_number)); | 221 2013, 12, 31, &g_omnibox_trial_default_group_number)); |
| 216 omnibox_prerender_trial->AppendGroup("OmniboxPrerenderDisabled", | 222 omnibox_prerender_trial->AppendGroup("OmniboxPrerenderDisabled", |
| 217 kDisabledProbability); | 223 kDisabledProbability); |
| 218 } | 224 } |
| 219 | 225 |
| 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); | |
|
Shishir
2013/04/16 21:22:04
Not using finch?
tburkard
2013/04/16 21:47:19
Not for canary/dev at this point.
| |
| 237 } | |
| 238 | |
| 220 bool IsOmniboxEnabled(Profile* profile) { | 239 bool IsOmniboxEnabled(Profile* profile) { |
| 221 if (!profile) | 240 if (!profile) |
| 222 return false; | 241 return false; |
| 223 | 242 |
| 224 if (!PrerenderManager::IsPrerenderingPossible()) | 243 if (!PrerenderManager::IsPrerenderingPossible()) |
| 225 return false; | 244 return false; |
| 226 | 245 |
| 227 // Override any field trial groups if the user has set a command line flag. | 246 // Override any field trial groups if the user has set a command line flag. |
| 228 if (CommandLine::ForCurrentProcess()->HasSwitch( | 247 if (CommandLine::ForCurrentProcess()->HasSwitch( |
| 229 switches::kPrerenderFromOmnibox)) { | 248 switches::kPrerenderFromOmnibox)) { |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 243 const int group = FieldTrialList::FindValue(kOmniboxTrialName); | 262 const int group = FieldTrialList::FindValue(kOmniboxTrialName); |
| 244 return group == FieldTrial::kNotFinalized || | 263 return group == FieldTrial::kNotFinalized || |
| 245 group == g_omnibox_trial_default_group_number; | 264 group == g_omnibox_trial_default_group_number; |
| 246 } | 265 } |
| 247 | 266 |
| 248 bool IsLocalPredictorEnabled() { | 267 bool IsLocalPredictorEnabled() { |
| 249 return base::FieldTrialList::FindFullName(kLocalPredictorTrialName) == | 268 return base::FieldTrialList::FindFullName(kLocalPredictorTrialName) == |
| 250 kLocalPredictorEnabledGroup; | 269 kLocalPredictorEnabledGroup; |
| 251 } | 270 } |
| 252 | 271 |
| 272 bool IsLoggedInPredictorEnabled() { | |
| 273 return base::FieldTrialList::FindFullName(kLoggedInPredictorTrialName) == | |
|
Shishir
2013/04/16 21:22:04
You should also respect the "predict network actio
tburkard
2013/04/16 21:47:19
Since we are not taking any actual action (but jus
tburkard
2013/04/16 21:47:19
Since we are not taking any actual action (but jus
Shishir
2013/04/16 22:25:14
Add a todo to ensure that you dont forget this.
tburkard
2013/04/16 22:45:33
The predictor itself is never taking any action -
| |
| 274 kLoggedInPredictorEnabledGroup; | |
| 275 } | |
| 276 | |
| 253 } // namespace prerender | 277 } // namespace prerender |
| OLD | NEW |