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" | |
| 10 #include "base/metrics/histogram.h" | |
| 11 #include "base/prefs/pref_service.h" | |
| 12 #include "base/strings/string_number_conversions.h" | |
| 13 #include "base/strings/string_split.h" | |
| 14 #include "chrome/browser/net/prediction_options.h" | 9 #include "chrome/browser/net/prediction_options.h" |
| 15 #include "chrome/browser/predictors/autocomplete_action_predictor.h" | 10 #include "chrome/browser/predictors/autocomplete_action_predictor.h" |
| 16 #include "chrome/browser/prerender/prerender_manager.h" | 11 #include "chrome/browser/prerender/prerender_manager.h" |
| 17 #include "chrome/browser/profiles/profile.h" | 12 #include "chrome/browser/profiles/profile.h" |
| 18 #include "chrome/browser/sync/profile_sync_service.h" | 13 #include "chrome/browser/sync/profile_sync_service.h" |
| 19 #include "chrome/browser/sync/profile_sync_service_factory.h" | 14 #include "chrome/browser/sync/profile_sync_service_factory.h" |
| 20 #include "chrome/common/chrome_switches.h" | 15 #include "chrome/common/chrome_switches.h" |
| 21 #include "chrome/common/chrome_version_info.h" | |
| 22 #include "components/metrics/metrics_service.h" | |
| 23 #include "components/variations/variations_associated_data.h" | |
| 24 | 16 |
| 25 using base::FieldTrial; | |
| 26 using base::FieldTrialList; | |
|
davidben
2015/03/30 20:21:23
This one is still used in IsOmniboxEnabled.
Ilya Sherman
2015/03/30 23:47:38
Done.
| |
| 27 using base::StringToInt; | |
| 28 using std::string; | 17 using std::string; |
| 29 using std::vector; | |
| 30 | 18 |
| 31 namespace prerender { | 19 namespace prerender { |
| 32 | 20 |
| 33 namespace { | 21 namespace { |
| 34 | 22 |
| 35 const char kDisabledGroup[] = "Disabled"; | 23 const char kDisabledGroup[] = "Disabled"; |
| 36 const char kEnabledGroup[] = "Enabled"; | 24 const char kEnabledGroup[] = "Enabled"; |
| 37 | 25 |
| 38 const char kLocalPredictorSpecTrialName[] = "PrerenderLocalPredictorSpec"; | |
| 39 const char kLocalPredictorKeyName[] = "LocalPredictor"; | |
| 40 const char kLocalPredictorUnencryptedSyncOnlyKeyName[] = | |
| 41 "LocalPredictorUnencryptedSyncOnly"; | |
| 42 const char kLocalPredictorNetworkPredictionEnabledOnly[] = | |
| 43 "LocalPredictorNetworkPredictionEnabledOnly"; | |
| 44 const char kLocalPredictorOnCellularOnly[] = "LocalPredictorOnCellularOnly"; | |
| 45 const char kSideEffectFreeWhitelistKeyName[] = "SideEffectFreeWhitelist"; | |
| 46 const char kPrerenderLaunchKeyName[] = "PrerenderLaunch"; | |
| 47 const char kPrerenderAlwaysControlKeyName[] = "PrerenderAlwaysControl"; | |
| 48 const char kPrerenderPrefetchKeyName[] = "PrerenderPrefetch"; | |
| 49 const char kPrerenderQueryPrerenderServiceKeyName[] = | |
| 50 "PrerenderQueryPrerenderService"; | |
| 51 const char kPrerenderQueryPrerenderServiceCurrentURLKeyName[] = | |
| 52 "PrerenderQueryPrerenderServiceCurrentURL"; | |
| 53 const char kPrerenderQueryPrerenderServiceCandidateURLsKeyName[] = | |
| 54 "PrerenderQueryPrerenderServiceCandidateURLs"; | |
| 55 const char kPrerenderServiceBehaviorIDKeyName[] = "PrerenderServiceBehaviorID"; | |
| 56 const char kPrerenderServiceFetchTimeoutKeyName[] = | |
| 57 "PrerenderServiceFetchTimeoutMs"; | |
| 58 const char kPrefetchListTimeoutKeyName[] = "PrefetchListTimeoutSeconds"; | |
| 59 const char kPrerenderTTLKeyName[] = "PrerenderTTLSeconds"; | |
| 60 const char kPrerenderPriorityHalfLifeTimeKeyName[] = | |
| 61 "PrerenderPriorityHalfLifeTimeSeconds"; | |
| 62 const char kMaxConcurrentPrerenderKeyName[] = "MaxConcurrentPrerenders"; | |
| 63 const char kMaxLaunchPrerenderKeyName[] = "MaxLaunchPrerenders"; | |
| 64 const char kSkipFragment[] = "SkipFragment"; | |
| 65 const char kSkipHTTPS[] = "SkipHTTPS"; | |
| 66 const char kSkipWhitelist[] = "SkipWhitelist"; | |
| 67 const char kSkipServiceWhitelist[] = "SkipServiceWhitelist"; | |
| 68 const char kSkipLoggedIn[] = "SkipLoggedIn"; | |
| 69 const char kSkipDefaultNoPrerender[] = "SkipDefaultNoPrerender"; | |
| 70 const char kPrerenderServiceURLPrefixParameterName[] = | |
| 71 "PrerenderServiceURLPrefix"; | |
| 72 const char kDefaultPrerenderServiceURLPrefix[] = | 26 const char kDefaultPrerenderServiceURLPrefix[] = |
| 73 "https://clients4.google.com/prerenderservice/?q="; | 27 "https://clients4.google.com/prerenderservice/?q="; |
| 74 const int kMinPrerenderServiceTimeoutMs = 1; | |
| 75 const int kMaxPrerenderServiceTimeoutMs = 10000; | |
| 76 const int kDefaultPrerenderServiceTimeoutMs = 1000; | 28 const int kDefaultPrerenderServiceTimeoutMs = 1000; |
| 77 const int kMinPrefetchListTimeoutSeconds = 1; | |
| 78 const int kMaxPrefetchListTimeoutSeconds = 1800; | |
| 79 const int kDefaultPrefetchListTimeoutSeconds = 300; | 29 const int kDefaultPrefetchListTimeoutSeconds = 300; |
| 80 const char kSkipPrerenderLocalCanadidates[] = "SkipPrerenderLocalCandidates"; | |
| 81 const char kSkipPrerenderServiceCanadidates[] = | |
| 82 "SkipPrerenderServiceCandidates"; | |
| 83 | |
| 84 void SetupPrerenderFieldTrial() { | |
| 85 const FieldTrial::Probability divisor = 1000; | |
| 86 | |
| 87 FieldTrial::Probability control_probability; | |
| 88 FieldTrial::Probability experiment_multi_prerender_probability; | |
| 89 FieldTrial::Probability experiment_15min_ttl_probability; | |
| 90 FieldTrial::Probability experiment_no_use_probability; | |
| 91 FieldTrial::Probability experiment_match_complete_probability; | |
| 92 | |
| 93 chrome::VersionInfo::Channel channel = chrome::VersionInfo::GetChannel(); | |
| 94 if (channel == chrome::VersionInfo::CHANNEL_STABLE || | |
| 95 channel == chrome::VersionInfo::CHANNEL_BETA) { | |
| 96 // Use very conservatives and stable settings in beta and stable. | |
| 97 const FieldTrial::Probability release_prerender_enabled_probability = 970; | |
| 98 const FieldTrial::Probability release_control_probability = 10; | |
| 99 const FieldTrial::Probability | |
| 100 release_experiment_multi_prerender_probability = 0; | |
| 101 const FieldTrial::Probability release_experiment_15min_ttl_probability = 10; | |
| 102 const FieldTrial::Probability release_experiment_no_use_probability = 0; | |
| 103 const FieldTrial::Probability | |
| 104 release_experiment_match_complete_probability = 10; | |
| 105 static_assert( | |
| 106 release_prerender_enabled_probability + | |
| 107 release_control_probability + | |
| 108 release_experiment_multi_prerender_probability + | |
| 109 release_experiment_15min_ttl_probability + | |
| 110 release_experiment_no_use_probability + | |
| 111 release_experiment_match_complete_probability == divisor, | |
| 112 "release experiment probabilities must equal divisor"); | |
| 113 | |
| 114 control_probability = release_control_probability; | |
| 115 experiment_multi_prerender_probability = | |
| 116 release_experiment_multi_prerender_probability; | |
| 117 experiment_15min_ttl_probability = release_experiment_15min_ttl_probability; | |
| 118 experiment_no_use_probability = release_experiment_no_use_probability; | |
| 119 experiment_match_complete_probability = | |
| 120 release_experiment_match_complete_probability; | |
| 121 } else { | |
| 122 // In testing channels, use more experiments and a larger control group to | |
| 123 // improve quality of data. | |
| 124 const FieldTrial::Probability dev_prerender_enabled_probability = 200; | |
| 125 const FieldTrial::Probability dev_control_probability = 200; | |
| 126 const FieldTrial::Probability | |
| 127 dev_experiment_multi_prerender_probability = 200; | |
| 128 const FieldTrial::Probability dev_experiment_15min_ttl_probability = 100; | |
| 129 const FieldTrial::Probability dev_experiment_no_use_probability = 100; | |
| 130 const FieldTrial::Probability | |
| 131 dev_experiment_match_complete_probability = 200; | |
| 132 static_assert(dev_prerender_enabled_probability + | |
| 133 dev_control_probability + | |
| 134 dev_experiment_multi_prerender_probability + | |
| 135 dev_experiment_15min_ttl_probability + | |
| 136 dev_experiment_no_use_probability + | |
| 137 dev_experiment_match_complete_probability == divisor, | |
| 138 "dev experiment probabilities must equal divisor"); | |
| 139 | |
| 140 control_probability = dev_control_probability; | |
| 141 experiment_multi_prerender_probability = | |
| 142 dev_experiment_multi_prerender_probability; | |
| 143 experiment_15min_ttl_probability = dev_experiment_15min_ttl_probability; | |
| 144 experiment_no_use_probability = dev_experiment_no_use_probability; | |
| 145 experiment_match_complete_probability = | |
| 146 dev_experiment_match_complete_probability; | |
| 147 } | |
| 148 | |
| 149 int prerender_enabled_group = -1; | |
| 150 scoped_refptr<FieldTrial> trial( | |
| 151 FieldTrialList::FactoryGetFieldTrial( | |
| 152 "Prerender", divisor, "PrerenderEnabled", | |
| 153 2014, 12, 31, FieldTrial::SESSION_RANDOMIZED, | |
| 154 &prerender_enabled_group)); | |
| 155 const int control_group = | |
| 156 trial->AppendGroup("PrerenderControl", | |
| 157 control_probability); | |
| 158 const int experiment_multi_prerender_group = | |
| 159 trial->AppendGroup("PrerenderMulti", | |
| 160 experiment_multi_prerender_probability); | |
| 161 const int experiment_15_min_TTL_group = | |
| 162 trial->AppendGroup("Prerender15minTTL", | |
| 163 experiment_15min_ttl_probability); | |
| 164 const int experiment_no_use_group = | |
| 165 trial->AppendGroup("PrerenderNoUse", | |
| 166 experiment_no_use_probability); | |
| 167 const int experiment_match_complete_group = | |
| 168 trial->AppendGroup("MatchComplete", | |
| 169 experiment_match_complete_probability); | |
| 170 | |
| 171 const int trial_group = trial->group(); | |
| 172 if (trial_group == prerender_enabled_group) { | |
| 173 PrerenderManager::SetMode( | |
| 174 PrerenderManager::PRERENDER_MODE_EXPERIMENT_PRERENDER_GROUP); | |
| 175 } else if (trial_group == control_group) { | |
| 176 PrerenderManager::SetMode( | |
| 177 PrerenderManager::PRERENDER_MODE_EXPERIMENT_CONTROL_GROUP); | |
| 178 } else if (trial_group == experiment_multi_prerender_group) { | |
| 179 PrerenderManager::SetMode( | |
| 180 PrerenderManager::PRERENDER_MODE_EXPERIMENT_MULTI_PRERENDER_GROUP); | |
| 181 } else if (trial_group == experiment_15_min_TTL_group) { | |
| 182 PrerenderManager::SetMode( | |
| 183 PrerenderManager::PRERENDER_MODE_EXPERIMENT_15MIN_TTL_GROUP); | |
| 184 } else if (trial_group == experiment_no_use_group) { | |
| 185 PrerenderManager::SetMode( | |
| 186 PrerenderManager::PRERENDER_MODE_EXPERIMENT_NO_USE_GROUP); | |
| 187 } else if (trial_group == experiment_match_complete_group) { | |
| 188 PrerenderManager::SetMode( | |
| 189 PrerenderManager::PRERENDER_MODE_EXPERIMENT_MATCH_COMPLETE_GROUP); | |
| 190 } else { | |
| 191 NOTREACHED(); | |
| 192 } | |
| 193 } | |
| 194 | 30 |
| 195 } // end namespace | 31 } // end namespace |
| 196 | 32 |
| 197 void ConfigurePrerender(const base::CommandLine& command_line) { | 33 void ConfigurePrerender(const base::CommandLine& command_line) { |
| 198 enum PrerenderOption { | 34 PrerenderManager::PrerenderManagerMode mode = |
| 199 PRERENDER_OPTION_AUTO, | 35 PrerenderManager::PRERENDER_MODE_ENABLED; |
| 200 PRERENDER_OPTION_DISABLED, | |
| 201 PRERENDER_OPTION_ENABLED, | |
| 202 }; | |
| 203 | |
| 204 PrerenderOption prerender_option = PRERENDER_OPTION_AUTO; | |
| 205 if (command_line.HasSwitch(switches::kPrerenderMode)) { | 36 if (command_line.HasSwitch(switches::kPrerenderMode)) { |
| 206 const string switch_value = | 37 const string switch_value = |
| 207 command_line.GetSwitchValueASCII(switches::kPrerenderMode); | 38 command_line.GetSwitchValueASCII(switches::kPrerenderMode); |
| 208 | 39 |
| 209 if (switch_value == switches::kPrerenderModeSwitchValueAuto) { | 40 if (switch_value == switches::kPrerenderModeSwitchValueDisabled) { |
| 210 prerender_option = PRERENDER_OPTION_AUTO; | 41 mode = PrerenderManager::PRERENDER_MODE_DISABLED; |
| 211 } else if (switch_value == switches::kPrerenderModeSwitchValueDisabled) { | |
| 212 prerender_option = PRERENDER_OPTION_DISABLED; | |
| 213 } else if (switch_value.empty() || | 42 } else if (switch_value.empty() || |
| 214 switch_value == switches::kPrerenderModeSwitchValueEnabled) { | 43 switch_value == switches::kPrerenderModeSwitchValueEnabled) { |
| 215 // The empty string means the option was provided with no value, and that | 44 // The empty string means the option was provided with no value, and that |
| 216 // means enable. | 45 // means enable. |
| 217 prerender_option = PRERENDER_OPTION_ENABLED; | 46 mode = PrerenderManager::PRERENDER_MODE_ENABLED; |
| 218 } else { | 47 } else { |
| 219 prerender_option = PRERENDER_OPTION_DISABLED; | 48 mode = PrerenderManager::PRERENDER_MODE_DISABLED; |
| 220 LOG(ERROR) << "Invalid --prerender option received on command line: " | 49 LOG(ERROR) << "Invalid --prerender option received on command line: " |
| 221 << switch_value; | 50 << switch_value; |
| 222 LOG(ERROR) << "Disabling prerendering!"; | 51 LOG(ERROR) << "Disabling prerendering!"; |
| 223 } | 52 } |
| 224 } | 53 } |
| 225 | 54 |
| 226 switch (prerender_option) { | 55 PrerenderManager::SetMode(mode); |
| 227 case PRERENDER_OPTION_AUTO: | |
| 228 SetupPrerenderFieldTrial(); | |
| 229 break; | |
| 230 case PRERENDER_OPTION_DISABLED: | |
| 231 PrerenderManager::SetMode(PrerenderManager::PRERENDER_MODE_DISABLED); | |
| 232 break; | |
| 233 case PRERENDER_OPTION_ENABLED: | |
| 234 PrerenderManager::SetMode(PrerenderManager::PRERENDER_MODE_ENABLED); | |
| 235 break; | |
| 236 default: | |
| 237 NOTREACHED(); | |
| 238 } | |
| 239 } | 56 } |
| 240 | 57 |
| 241 bool IsOmniboxEnabled(Profile* profile) { | 58 bool IsOmniboxEnabled(Profile* profile) { |
| 242 if (!profile) | 59 if (!profile) |
| 243 return false; | 60 return false; |
| 244 | 61 |
| 245 if (!PrerenderManager::IsPrerenderingPossible()) | 62 if (!PrerenderManager::IsPrerenderingPossible()) |
| 246 return false; | 63 return false; |
| 247 | 64 |
| 248 // Override any field trial groups if the user has set a command line flag. | 65 // Override any field trial groups if the user has set a command line flag. |
| 249 if (base::CommandLine::ForCurrentProcess()->HasSwitch( | 66 if (base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 250 switches::kPrerenderFromOmnibox)) { | 67 switches::kPrerenderFromOmnibox)) { |
| 251 const string switch_value = | 68 const string switch_value = |
| 252 base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII( | 69 base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII( |
| 253 switches::kPrerenderFromOmnibox); | 70 switches::kPrerenderFromOmnibox); |
| 254 | 71 |
| 255 if (switch_value == switches::kPrerenderFromOmniboxSwitchValueEnabled) | 72 if (switch_value == switches::kPrerenderFromOmniboxSwitchValueEnabled) |
| 256 return true; | 73 return true; |
| 257 | 74 |
| 258 if (switch_value == switches::kPrerenderFromOmniboxSwitchValueDisabled) | 75 if (switch_value == switches::kPrerenderFromOmniboxSwitchValueDisabled) |
| 259 return false; | 76 return false; |
| 260 | 77 |
| 261 DCHECK_EQ(switches::kPrerenderFromOmniboxSwitchValueAuto, switch_value); | 78 DCHECK_EQ(switches::kPrerenderFromOmniboxSwitchValueAuto, switch_value); |
| 262 } | 79 } |
| 263 | 80 |
| 264 return (FieldTrialList::FindFullName("PrerenderFromOmnibox") != | 81 return (FieldTrialList::FindFullName("PrerenderFromOmnibox") != |
| 265 "OmniboxPrerenderDisabled"); | 82 "OmniboxPrerenderDisabled"); |
| 266 } | 83 } |
| 267 | 84 |
| 268 /* | |
| 269 PrerenderLocalPredictorSpec is a field trial, and its value must have the | |
| 270 following format: | |
| 271 key1=value1:key2=value2:key3=value3 | |
| 272 eg "LocalPredictor=Enabled:SideEffectFreeWhitelist=Enabled" | |
| 273 The function below extracts the value corresponding to a key provided from the | |
| 274 LocalPredictorSpec. | |
| 275 */ | |
| 276 string GetLocalPredictorSpecValue(string spec_key) { | |
| 277 vector<string> elements; | |
| 278 base::SplitString(FieldTrialList::FindFullName(kLocalPredictorSpecTrialName), | |
| 279 ':', &elements); | |
| 280 for (int i = 0; i < static_cast<int>(elements.size()); i++) { | |
| 281 vector<string> key_value; | |
| 282 base::SplitString(elements[i], '=', &key_value); | |
| 283 if (key_value.size() == 2 && key_value[0] == spec_key) | |
| 284 return key_value[1]; | |
| 285 } | |
| 286 return string(); | |
| 287 } | |
| 288 | |
| 289 bool IsUnencryptedSyncEnabled(Profile* profile) { | 85 bool IsUnencryptedSyncEnabled(Profile* profile) { |
| 290 ProfileSyncService* service = ProfileSyncServiceFactory::GetInstance()-> | 86 ProfileSyncService* service = ProfileSyncServiceFactory::GetInstance()-> |
| 291 GetForProfile(profile); | 87 GetForProfile(profile); |
| 292 return service && service->GetOpenTabsUIDelegate() && | 88 return service && service->GetOpenTabsUIDelegate() && |
| 293 !service->EncryptEverythingEnabled(); | 89 !service->EncryptEverythingEnabled(); |
| 294 } | 90 } |
| 295 | 91 |
| 296 // Indicates whether the Local Predictor is enabled based on field trial | 92 // Indicates whether the Local Predictor is enabled based on field trial |
| 297 // selection. | 93 // selection. |
| 298 bool IsLocalPredictorEnabled() { | 94 bool IsLocalPredictorEnabled() { |
| 299 #if defined(OS_ANDROID) || defined(OS_IOS) | |
| 300 return false; | 95 return false; |
| 301 #endif | |
| 302 return !base::CommandLine::ForCurrentProcess()->HasSwitch( | |
| 303 switches::kDisablePrerenderLocalPredictor) && | |
| 304 GetLocalPredictorSpecValue(kLocalPredictorKeyName) == kEnabledGroup; | |
| 305 } | 96 } |
| 306 | 97 |
| 307 bool ShouldDisableLocalPredictorBasedOnSyncAndConfiguration(Profile* profile) { | 98 bool ShouldDisableLocalPredictorBasedOnSyncAndConfiguration(Profile* profile) { |
| 308 return | 99 return false; |
| 309 GetLocalPredictorSpecValue(kLocalPredictorUnencryptedSyncOnlyKeyName) == | |
| 310 kEnabledGroup && | |
| 311 !IsUnencryptedSyncEnabled(profile); | |
| 312 } | 100 } |
| 313 | 101 |
| 314 bool ShouldDisableLocalPredictorDueToPreferencesAndNetwork(Profile* profile) { | 102 bool ShouldDisableLocalPredictorDueToPreferencesAndNetwork(Profile* profile) { |
| 315 bool on_cellular = | 103 return false; |
| 316 net::NetworkChangeNotifier::IsConnectionCellular( | |
| 317 net::NetworkChangeNotifier::GetConnectionType()); | |
| 318 // If the user is not on a cellular connection, but we require a cellular | |
| 319 // connection, we must temporarily disable our local predictions. | |
| 320 if (!on_cellular && | |
| 321 GetLocalPredictorSpecValue(kLocalPredictorOnCellularOnly) == | |
| 322 kEnabledGroup) { | |
| 323 return true; | |
| 324 } | |
| 325 | |
| 326 // If we don't care whether or not network prediction will actually be | |
| 327 // exercised, we do not need to temporarily disable our predictions. | |
| 328 if (GetLocalPredictorSpecValue(kLocalPredictorNetworkPredictionEnabledOnly) != | |
| 329 kEnabledGroup) { | |
| 330 return false; | |
| 331 } | |
| 332 | |
| 333 // We should temporarily disable iff the predictive network action would | |
| 334 // not be exercised. | |
| 335 | |
| 336 return !chrome_browser_net::CanPrefetchAndPrerenderUI(profile->GetPrefs()); | |
| 337 } | 104 } |
| 338 | 105 |
| 339 bool IsLoggedInPredictorEnabled() { | 106 bool IsLoggedInPredictorEnabled() { |
| 340 return IsLocalPredictorEnabled(); | 107 return IsLocalPredictorEnabled(); |
| 341 } | 108 } |
| 342 | 109 |
| 343 bool IsSideEffectFreeWhitelistEnabled() { | 110 bool IsSideEffectFreeWhitelistEnabled() { |
| 344 return IsLocalPredictorEnabled() && | 111 return IsLocalPredictorEnabled(); |
| 345 GetLocalPredictorSpecValue(kSideEffectFreeWhitelistKeyName) != | |
| 346 kDisabledGroup; | |
| 347 } | 112 } |
| 348 | 113 |
| 349 bool IsLocalPredictorPrerenderLaunchEnabled() { | 114 bool IsLocalPredictorPrerenderLaunchEnabled() { |
| 350 return GetLocalPredictorSpecValue(kPrerenderLaunchKeyName) != kDisabledGroup; | 115 return true; |
| 351 } | 116 } |
| 352 | 117 |
| 353 bool IsLocalPredictorPrerenderAlwaysControlEnabled() { | 118 bool IsLocalPredictorPrerenderAlwaysControlEnabled() { |
| 354 // If we prefetch rather than prerender, we automatically also prerender | 119 // If we prefetch rather than prerender, we automatically also prerender |
| 355 // as a control group only. | 120 // as a control group only. |
| 356 return (GetLocalPredictorSpecValue(kPrerenderAlwaysControlKeyName) == | 121 return IsLocalPredictorPrerenderPrefetchEnabled(); |
| 357 kEnabledGroup) || IsLocalPredictorPrerenderPrefetchEnabled(); | |
| 358 } | 122 } |
| 359 | 123 |
| 360 bool IsLocalPredictorPrerenderPrefetchEnabled() { | 124 bool IsLocalPredictorPrerenderPrefetchEnabled() { |
| 361 return GetLocalPredictorSpecValue(kPrerenderPrefetchKeyName) == | 125 return false; |
| 362 kEnabledGroup; | |
| 363 } | 126 } |
| 364 | 127 |
| 365 bool ShouldQueryPrerenderService(Profile* profile) { | 128 bool ShouldQueryPrerenderService(Profile* profile) { |
| 366 return IsUnencryptedSyncEnabled(profile) && | 129 return false; |
| 367 GetLocalPredictorSpecValue(kPrerenderQueryPrerenderServiceKeyName) == | |
| 368 kEnabledGroup; | |
| 369 } | 130 } |
| 370 | 131 |
| 371 bool ShouldQueryPrerenderServiceForCurrentURL() { | 132 bool ShouldQueryPrerenderServiceForCurrentURL() { |
| 372 return GetLocalPredictorSpecValue( | 133 return true; |
| 373 kPrerenderQueryPrerenderServiceCurrentURLKeyName) != kDisabledGroup; | |
| 374 } | 134 } |
| 375 | 135 |
| 376 bool ShouldQueryPrerenderServiceForCandidateURLs() { | 136 bool ShouldQueryPrerenderServiceForCandidateURLs() { |
| 377 return GetLocalPredictorSpecValue( | 137 return true; |
| 378 kPrerenderQueryPrerenderServiceCandidateURLsKeyName) != kDisabledGroup; | |
| 379 } | 138 } |
| 380 | 139 |
| 381 string GetPrerenderServiceURLPrefix() { | 140 string GetPrerenderServiceURLPrefix() { |
| 382 string prefix = variations::GetVariationParamValue( | 141 return kDefaultPrerenderServiceURLPrefix; |
| 383 kLocalPredictorSpecTrialName, | |
| 384 kPrerenderServiceURLPrefixParameterName); | |
| 385 return prefix.empty() ? kDefaultPrerenderServiceURLPrefix : prefix; | |
| 386 } | 142 } |
| 387 | 143 |
| 388 int GetPrerenderServiceBehaviorID() { | 144 int GetPrerenderServiceBehaviorID() { |
| 389 int id; | 145 return 0; |
| 390 StringToInt(GetLocalPredictorSpecValue(kPrerenderServiceBehaviorIDKeyName), | |
| 391 &id); | |
| 392 // The behavior ID must be non-negative. | |
| 393 return std::max(id, 0); | |
| 394 } | 146 } |
| 395 | 147 |
| 396 int GetPrerenderServiceFetchTimeoutMs() { | 148 int GetPrerenderServiceFetchTimeoutMs() { |
| 397 int result; | 149 return kDefaultPrerenderServiceTimeoutMs; |
| 398 StringToInt(GetLocalPredictorSpecValue(kPrerenderServiceFetchTimeoutKeyName), | |
| 399 &result); | |
| 400 // If the value is outside the valid range, use the default value. | |
| 401 return (result < kMinPrerenderServiceTimeoutMs || | |
| 402 result > kMaxPrerenderServiceTimeoutMs) ? | |
| 403 kDefaultPrerenderServiceTimeoutMs : result; | |
| 404 } | 150 } |
| 405 | 151 |
| 406 int GetPrerenderPrefetchListTimeoutSeconds() { | 152 int GetPrerenderPrefetchListTimeoutSeconds() { |
| 407 int result; | 153 return kDefaultPrefetchListTimeoutSeconds; |
| 408 StringToInt(GetLocalPredictorSpecValue(kPrefetchListTimeoutKeyName), &result); | |
| 409 // If the value is outside the valid range, use the default value. | |
| 410 return (result < kMinPrefetchListTimeoutSeconds || | |
| 411 result > kMaxPrefetchListTimeoutSeconds) ? | |
| 412 kDefaultPrefetchListTimeoutSeconds : result; | |
| 413 } | 154 } |
| 414 | 155 |
| 415 int GetLocalPredictorTTLSeconds() { | 156 int GetLocalPredictorTTLSeconds() { |
| 416 int ttl; | 157 // Use a default value of 180s. |
| 417 StringToInt(GetLocalPredictorSpecValue(kPrerenderTTLKeyName), &ttl); | 158 return 180; |
| 418 // If the value is outside of 10s or 600s, use a default value of 180s. | |
| 419 return (ttl < 10 || ttl > 600) ? 180 : ttl; | |
| 420 } | 159 } |
| 421 | 160 |
| 422 int GetLocalPredictorPrerenderPriorityHalfLifeTimeSeconds() { | 161 int GetLocalPredictorPrerenderPriorityHalfLifeTimeSeconds() { |
| 423 int half_life_time; | 162 return 0; |
| 424 StringToInt(GetLocalPredictorSpecValue(kPrerenderPriorityHalfLifeTimeKeyName), | |
| 425 &half_life_time); | |
| 426 // Sanity check: Ensure the half life time is non-negative. | |
| 427 return std::max(half_life_time, 0); | |
| 428 } | 163 } |
| 429 | 164 |
| 430 int GetLocalPredictorMaxConcurrentPrerenders() { | 165 int GetLocalPredictorMaxConcurrentPrerenders() { |
| 431 int num_prerenders; | 166 return 1; |
| 432 StringToInt(GetLocalPredictorSpecValue(kMaxConcurrentPrerenderKeyName), | |
| 433 &num_prerenders); | |
| 434 // Sanity check: Ensure the number of prerenders is between 1 and 10. | |
| 435 return std::min(std::max(num_prerenders, 1), 10); | |
| 436 } | 167 } |
| 437 | 168 |
| 438 int GetLocalPredictorMaxLaunchPrerenders() { | 169 int GetLocalPredictorMaxLaunchPrerenders() { |
| 439 int num_prerenders; | 170 return 1; |
| 440 StringToInt(GetLocalPredictorSpecValue(kMaxLaunchPrerenderKeyName), | |
| 441 &num_prerenders); | |
| 442 // Sanity check: Ensure the number of prerenders is between 1 and 10. | |
| 443 return std::min(std::max(num_prerenders, 1), 10); | |
| 444 } | 171 } |
| 445 | 172 |
| 446 bool SkipLocalPredictorFragment() { | 173 bool SkipLocalPredictorFragment() { |
| 447 return GetLocalPredictorSpecValue(kSkipFragment) == kEnabledGroup; | 174 return false |
| 448 } | 175 } |
| 449 | 176 |
| 450 bool SkipLocalPredictorHTTPS() { | 177 bool SkipLocalPredictorHTTPS() { |
| 451 return GetLocalPredictorSpecValue(kSkipHTTPS) == kEnabledGroup; | 178 return false; |
| 452 } | 179 } |
| 453 | 180 |
| 454 bool SkipLocalPredictorWhitelist() { | 181 bool SkipLocalPredictorWhitelist() { |
| 455 return GetLocalPredictorSpecValue(kSkipWhitelist) == kEnabledGroup; | 182 return false; |
| 456 } | 183 } |
| 457 | 184 |
| 458 bool SkipLocalPredictorServiceWhitelist() { | 185 bool SkipLocalPredictorServiceWhitelist() { |
| 459 return GetLocalPredictorSpecValue(kSkipServiceWhitelist) == kEnabledGroup; | 186 return false; |
| 460 } | 187 } |
| 461 | 188 |
| 462 bool SkipLocalPredictorLoggedIn() { | 189 bool SkipLocalPredictorLoggedIn() { |
| 463 return GetLocalPredictorSpecValue(kSkipLoggedIn) == kEnabledGroup; | 190 return false; |
| 464 } | 191 } |
| 465 | 192 |
| 466 bool SkipLocalPredictorDefaultNoPrerender() { | 193 bool SkipLocalPredictorDefaultNoPrerender() { |
| 467 return GetLocalPredictorSpecValue(kSkipDefaultNoPrerender) == kEnabledGroup; | 194 return false; |
| 468 } | 195 } |
| 469 | 196 |
| 470 bool SkipLocalPredictorLocalCandidates() { | 197 bool SkipLocalPredictorLocalCandidates() { |
| 471 return GetLocalPredictorSpecValue(kSkipPrerenderLocalCanadidates) == | 198 return false; |
| 472 kEnabledGroup; | |
| 473 } | 199 } |
| 474 | 200 |
| 475 bool SkipLocalPredictorServiceCandidates() { | 201 bool SkipLocalPredictorServiceCandidates() { |
| 476 return GetLocalPredictorSpecValue(kSkipPrerenderServiceCanadidates) == | 202 return false; |
| 477 kEnabledGroup; | |
| 478 } | 203 } |
| 479 | 204 |
| 480 } // namespace prerender | 205 } // namespace prerender |
| OLD | NEW |