Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(130)

Side by Side Diff: chrome/browser/prerender/prerender_field_trial.cc

Issue 291653007: Cleanup, mostly replacing uses of SplitStringUsingSubstr() with SplitString(), (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | chrome/common/variations/experiment_labels.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "base/prefs/pref_service.h" 11 #include "base/prefs/pref_service.h"
12 #include "base/strings/string_number_conversions.h" 12 #include "base/strings/string_number_conversions.h"
13 #include "base/strings/string_split.h" 13 #include "base/strings/string_split.h"
14 #include "chrome/browser/metrics/metrics_service.h" 14 #include "chrome/browser/metrics/metrics_service.h"
15 #include "chrome/browser/predictors/autocomplete_action_predictor.h" 15 #include "chrome/browser/predictors/autocomplete_action_predictor.h"
16 #include "chrome/browser/prerender/prerender_manager.h" 16 #include "chrome/browser/prerender/prerender_manager.h"
17 #include "chrome/browser/profiles/profile.h" 17 #include "chrome/browser/profiles/profile.h"
18 #include "chrome/browser/sync/profile_sync_service.h" 18 #include "chrome/browser/sync/profile_sync_service.h"
19 #include "chrome/browser/sync/profile_sync_service_factory.h" 19 #include "chrome/browser/sync/profile_sync_service_factory.h"
20 #include "chrome/common/chrome_switches.h" 20 #include "chrome/common/chrome_switches.h"
21 #include "chrome/common/chrome_version_info.h" 21 #include "chrome/common/chrome_version_info.h"
22 #include "components/variations/variations_associated_data.h" 22 #include "components/variations/variations_associated_data.h"
23 23
24 using base::FieldTrial; 24 using base::FieldTrial;
25 using base::FieldTrialList; 25 using base::FieldTrialList;
26 using base::SplitStringUsingSubstr;
27 using base::StringToInt; 26 using base::StringToInt;
28 using std::string; 27 using std::string;
29 using std::vector; 28 using std::vector;
30 29
31 namespace prerender { 30 namespace prerender {
32 31
33 namespace { 32 namespace {
34 33
35 const char kOmniboxTrialName[] = "PrerenderFromOmnibox"; 34 const char kOmniboxTrialName[] = "PrerenderFromOmnibox";
36 int g_omnibox_trial_default_group_number = kint32min; 35 int g_omnibox_trial_default_group_number = kint32min;
(...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after
251 const string switch_value = 250 const string switch_value =
252 CommandLine::ForCurrentProcess()->GetSwitchValueASCII( 251 CommandLine::ForCurrentProcess()->GetSwitchValueASCII(
253 switches::kPrerenderFromOmnibox); 252 switches::kPrerenderFromOmnibox);
254 253
255 if (switch_value == switches::kPrerenderFromOmniboxSwitchValueEnabled) 254 if (switch_value == switches::kPrerenderFromOmniboxSwitchValueEnabled)
256 return true; 255 return true;
257 256
258 if (switch_value == switches::kPrerenderFromOmniboxSwitchValueDisabled) 257 if (switch_value == switches::kPrerenderFromOmniboxSwitchValueDisabled)
259 return false; 258 return false;
260 259
261 DCHECK(switch_value == switches::kPrerenderFromOmniboxSwitchValueAuto); 260 DCHECK_EQ(switches::kPrerenderFromOmniboxSwitchValueAuto, switch_value);
262 } 261 }
263 262
264 const int group = FieldTrialList::FindValue(kOmniboxTrialName); 263 const int group = FieldTrialList::FindValue(kOmniboxTrialName);
265 return group == FieldTrial::kNotFinalized || 264 return group == FieldTrial::kNotFinalized ||
266 group == g_omnibox_trial_default_group_number; 265 group == g_omnibox_trial_default_group_number;
267 } 266 }
268 267
269 /* 268 /*
270 PrerenderLocalPredictorSpec is a field trial, and its value must have the 269 PrerenderLocalPredictorSpec is a field trial, and its value must have the
271 following format: 270 following format:
272 key1=value1:key2=value2:key3=value3 271 key1=value1:key2=value2:key3=value3
273 eg "LocalPredictor=Enabled:SideEffectFreeWhitelist=Enabled" 272 eg "LocalPredictor=Enabled:SideEffectFreeWhitelist=Enabled"
274 The function below extracts the value corresponding to a key provided from the 273 The function below extracts the value corresponding to a key provided from the
275 LocalPredictorSpec. 274 LocalPredictorSpec.
276 */ 275 */
277 string GetLocalPredictorSpecValue(string spec_key) { 276 string GetLocalPredictorSpecValue(string spec_key) {
278 vector<string> elements; 277 vector<string> elements;
279 SplitStringUsingSubstr( 278 base::SplitString(FieldTrialList::FindFullName(kLocalPredictorSpecTrialName),
280 FieldTrialList::FindFullName(kLocalPredictorSpecTrialName), 279 ':', &elements);
281 ":",
282 &elements);
283 for (int i = 0; i < static_cast<int>(elements.size()); i++) { 280 for (int i = 0; i < static_cast<int>(elements.size()); i++) {
284 vector<string> key_value; 281 vector<string> key_value;
285 SplitStringUsingSubstr(elements[i], "=", &key_value); 282 base::SplitString(elements[i], '=', &key_value);
286 if (key_value.size() == 2 && key_value[0] == spec_key) 283 if (key_value.size() == 2 && key_value[0] == spec_key)
287 return key_value[1]; 284 return key_value[1];
288 } 285 }
289 return string(); 286 return string();
290 } 287 }
291 288
292 bool IsUnencryptedSyncEnabled(Profile* profile) { 289 bool IsUnencryptedSyncEnabled(Profile* profile) {
293 ProfileSyncService* service = ProfileSyncServiceFactory::GetInstance()-> 290 ProfileSyncService* service = ProfileSyncServiceFactory::GetInstance()->
294 GetForProfile(profile); 291 GetForProfile(profile);
295 return service && service->GetOpenTabsUIDelegate() && 292 return service && service->GetOpenTabsUIDelegate() &&
296 !service->EncryptEverythingEnabled(); 293 !service->EncryptEverythingEnabled();
297 } 294 }
298 295
299 // Indicates whether the Local Predictor is enabled based on field trial 296 // Indicates whether the Local Predictor is enabled based on field trial
300 // selection. 297 // selection.
301 bool IsLocalPredictorEnabled() { 298 bool IsLocalPredictorEnabled() {
302 #if defined(OS_ANDROID) || defined(OS_IOS) 299 #if defined(OS_ANDROID) || defined(OS_IOS)
303 return false; 300 return false;
304 #endif 301 #endif
305 if (CommandLine::ForCurrentProcess()->HasSwitch( 302 return
306 switches::kDisablePrerenderLocalPredictor)) { 303 !CommandLine::ForCurrentProcess()->HasSwitch(
307 return false; 304 switches::kDisablePrerenderLocalPredictor) &&
308 } 305 GetLocalPredictorSpecValue(kLocalPredictorKeyName) == kEnabledGroup;
309 return GetLocalPredictorSpecValue(kLocalPredictorKeyName) == kEnabledGroup;
310 } 306 }
311 307
312 bool DisableLocalPredictorBasedOnSyncAndConfiguration(Profile* profile) { 308 bool DisableLocalPredictorBasedOnSyncAndConfiguration(Profile* profile) {
313 return 309 return
314 GetLocalPredictorSpecValue(kLocalPredictorUnencryptedSyncOnlyKeyName) == 310 GetLocalPredictorSpecValue(kLocalPredictorUnencryptedSyncOnlyKeyName) ==
315 kEnabledGroup && 311 kEnabledGroup &&
316 !IsUnencryptedSyncEnabled(profile); 312 !IsUnencryptedSyncEnabled(profile);
317 } 313 }
318 314
319 bool IsLoggedInPredictorEnabled() { 315 bool IsLoggedInPredictorEnabled() {
320 return IsLocalPredictorEnabled(); 316 return IsLocalPredictorEnabled();
321 } 317 }
322 318
323 bool IsSideEffectFreeWhitelistEnabled() { 319 bool IsSideEffectFreeWhitelistEnabled() {
324 return IsLocalPredictorEnabled() && 320 return IsLocalPredictorEnabled() &&
325 GetLocalPredictorSpecValue(kSideEffectFreeWhitelistKeyName) != 321 GetLocalPredictorSpecValue(kSideEffectFreeWhitelistKeyName) !=
(...skipping 22 matching lines...) Expand all
348 344
349 bool ShouldQueryPrerenderServiceForCandidateURLs() { 345 bool ShouldQueryPrerenderServiceForCandidateURLs() {
350 return GetLocalPredictorSpecValue( 346 return GetLocalPredictorSpecValue(
351 kPrerenderQueryPrerenderServiceCandidateURLsKeyName) != kDisabledGroup; 347 kPrerenderQueryPrerenderServiceCandidateURLsKeyName) != kDisabledGroup;
352 } 348 }
353 349
354 string GetPrerenderServiceURLPrefix() { 350 string GetPrerenderServiceURLPrefix() {
355 string prefix = chrome_variations::GetVariationParamValue( 351 string prefix = chrome_variations::GetVariationParamValue(
356 kLocalPredictorSpecTrialName, 352 kLocalPredictorSpecTrialName,
357 kPrerenderServiceURLPrefixParameterName); 353 kPrerenderServiceURLPrefixParameterName);
358 if (prefix.empty()) 354 return prefix.empty() ? kDefaultPrerenderServiceURLPrefix : prefix;
359 prefix = kDefaultPrerenderServiceURLPrefix;
360 return prefix;
361 } 355 }
362 356
363 int GetPrerenderServiceBehaviorID() { 357 int GetPrerenderServiceBehaviorID() {
364 int id; 358 int id;
365 StringToInt(GetLocalPredictorSpecValue(kPrerenderServiceBehaviorIDKeyName), 359 StringToInt(GetLocalPredictorSpecValue(kPrerenderServiceBehaviorIDKeyName),
366 &id); 360 &id);
367 // The behavior ID must be non-negative. 361 // The behavior ID must be non-negative.
368 if (id < 0) 362 return std::max(id, 0);
369 id = 0;
370 return id;
371 } 363 }
372 364
373 int GetPrerenderServiceFetchTimeoutMs() { 365 int GetPrerenderServiceFetchTimeoutMs() {
374 int result; 366 int result;
375 StringToInt(GetLocalPredictorSpecValue(kPrerenderServiceFetchTimeoutKeyName), 367 StringToInt(GetLocalPredictorSpecValue(kPrerenderServiceFetchTimeoutKeyName),
376 &result); 368 &result);
377 // The behavior ID must be non-negative. 369 // If the value is outside the valid range, use the default value.
378 if (result < kMinPrerenderServiceTimeoutMs || 370 return (result < kMinPrerenderServiceTimeoutMs ||
379 result > kMaxPrerenderServiceTimeoutMs) { 371 result > kMaxPrerenderServiceTimeoutMs) ?
380 result = kDefaultPrerenderServiceTimeoutMs; 372 kDefaultPrerenderServiceTimeoutMs : result;
381 }
382 return result;
383 } 373 }
384 374
385 int GetLocalPredictorTTLSeconds() { 375 int GetLocalPredictorTTLSeconds() {
386 int ttl; 376 int ttl;
387 StringToInt(GetLocalPredictorSpecValue(kPrerenderTTLKeyName), &ttl); 377 StringToInt(GetLocalPredictorSpecValue(kPrerenderTTLKeyName), &ttl);
388 // If the value is outside of 10s or 600s, use a default value of 180s. 378 // If the value is outside of 10s or 600s, use a default value of 180s.
389 if (ttl < 10 || ttl > 600) 379 return (ttl < 10 || ttl > 600) ? 180 : ttl;
390 ttl = 180;
391 return ttl;
392 } 380 }
393 381
394 int GetLocalPredictorPrerenderPriorityHalfLifeTimeSeconds() { 382 int GetLocalPredictorPrerenderPriorityHalfLifeTimeSeconds() {
395 int half_life_time; 383 int half_life_time;
396 StringToInt(GetLocalPredictorSpecValue(kPrerenderPriorityHalfLifeTimeKeyName), 384 StringToInt(GetLocalPredictorSpecValue(kPrerenderPriorityHalfLifeTimeKeyName),
397 &half_life_time); 385 &half_life_time);
398 // Sanity check: Ensure the half life time is non-negative. 386 // Sanity check: Ensure the half life time is non-negative.
399 if (half_life_time < 0) 387 return std::max(half_life_time, 0);
400 half_life_time = 0;
401 return half_life_time;
402 } 388 }
403 389
404 int GetLocalPredictorMaxConcurrentPrerenders() { 390 int GetLocalPredictorMaxConcurrentPrerenders() {
405 int num_prerenders; 391 int num_prerenders;
406 StringToInt(GetLocalPredictorSpecValue(kMaxConcurrentPrerenderKeyName), 392 StringToInt(GetLocalPredictorSpecValue(kMaxConcurrentPrerenderKeyName),
407 &num_prerenders); 393 &num_prerenders);
408 // Sanity check: Ensure the number of prerenders is at least 1. 394 // Sanity check: Ensure the number of prerenders is between 1 and 10.
409 if (num_prerenders < 1) 395 return std::min(std::max(num_prerenders, 1), 10);
410 num_prerenders = 1; 396 }
411 // Sanity check: Ensure the number of prerenders is at most 10.
412 if (num_prerenders > 10)
413 num_prerenders = 10;
414 return num_prerenders;
415 };
416 397
417 bool SkipLocalPredictorFragment() { 398 bool SkipLocalPredictorFragment() {
418 return GetLocalPredictorSpecValue(kSkipFragment) == kEnabledGroup; 399 return GetLocalPredictorSpecValue(kSkipFragment) == kEnabledGroup;
419 } 400 }
420 401
421 bool SkipLocalPredictorHTTPS() { 402 bool SkipLocalPredictorHTTPS() {
422 return GetLocalPredictorSpecValue(kSkipHTTPS) == kEnabledGroup; 403 return GetLocalPredictorSpecValue(kSkipHTTPS) == kEnabledGroup;
423 } 404 }
424 405
425 bool SkipLocalPredictorWhitelist() { 406 bool SkipLocalPredictorWhitelist() {
(...skipping 21 matching lines...) Expand all
447 return GetLocalPredictorSpecValue(kSkipPrerenderServiceCanadidates) == 428 return GetLocalPredictorSpecValue(kSkipPrerenderServiceCanadidates) ==
448 kEnabledGroup; 429 kEnabledGroup;
449 } 430 }
450 431
451 bool ShouldMergeSessionStorageNamespaces() { 432 bool ShouldMergeSessionStorageNamespaces() {
452 return GetLocalPredictorSpecValue(kDisableSessionStorageNamespaceMerging) != 433 return GetLocalPredictorSpecValue(kDisableSessionStorageNamespaceMerging) !=
453 kDisabledGroup; 434 kDisabledGroup;
454 } 435 }
455 436
456 } // namespace prerender 437 } // namespace prerender
OLDNEW
« no previous file with comments | « no previous file | chrome/common/variations/experiment_labels.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698