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/omnibox/omnibox_field_trial.h" | 5 #include "chrome/browser/omnibox/omnibox_field_trial.h" |
6 | 6 |
7 #include <cmath> | 7 #include <cmath> |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
(...skipping 236 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
247 base::TimeDelta OmniboxFieldTrial::StopTimerFieldTrialDuration() { | 247 base::TimeDelta OmniboxFieldTrial::StopTimerFieldTrialDuration() { |
248 int stop_timer_ms; | 248 int stop_timer_ms; |
249 if (base::StringToInt( | 249 if (base::StringToInt( |
250 base::FieldTrialList::FindFullName(kStopTimerFieldTrialName), | 250 base::FieldTrialList::FindFullName(kStopTimerFieldTrialName), |
251 &stop_timer_ms)) | 251 &stop_timer_ms)) |
252 return base::TimeDelta::FromMilliseconds(stop_timer_ms); | 252 return base::TimeDelta::FromMilliseconds(stop_timer_ms); |
253 return base::TimeDelta::FromMilliseconds(1500); | 253 return base::TimeDelta::FromMilliseconds(1500); |
254 } | 254 } |
255 | 255 |
256 bool OmniboxFieldTrial::InZeroSuggestFieldTrial() { | 256 bool OmniboxFieldTrial::InZeroSuggestFieldTrial() { |
257 if (chrome_variations::GetVariationParamValue( | 257 if (variations::GetVariationParamValue( |
258 kBundledExperimentFieldTrialName, kZeroSuggestRule) == "true") | 258 kBundledExperimentFieldTrialName, kZeroSuggestRule) == "true") |
259 return true; | 259 return true; |
260 if (chrome_variations::GetVariationParamValue( | 260 if (variations::GetVariationParamValue( |
261 kBundledExperimentFieldTrialName, kZeroSuggestRule) == "false") | 261 kBundledExperimentFieldTrialName, kZeroSuggestRule) == "false") |
262 return false; | 262 return false; |
263 #if defined(OS_WIN) || defined(OS_CHROMEOS) || defined(OS_LINUX) || \ | 263 #if defined(OS_WIN) || defined(OS_CHROMEOS) || defined(OS_LINUX) || \ |
264 (defined(OS_MACOSX) && !defined(OS_IOS)) | 264 (defined(OS_MACOSX) && !defined(OS_IOS)) |
265 return true; | 265 return true; |
266 #else | 266 #else |
267 return false; | 267 return false; |
268 #endif | 268 #endif |
269 } | 269 } |
270 | 270 |
271 bool OmniboxFieldTrial::InZeroSuggestMostVisitedFieldTrial() { | 271 bool OmniboxFieldTrial::InZeroSuggestMostVisitedFieldTrial() { |
272 return chrome_variations::GetVariationParamValue( | 272 return variations::GetVariationParamValue( |
273 kBundledExperimentFieldTrialName, | 273 kBundledExperimentFieldTrialName, |
274 kZeroSuggestVariantRule) == "MostVisited"; | 274 kZeroSuggestVariantRule) == "MostVisited"; |
275 } | 275 } |
276 | 276 |
277 bool OmniboxFieldTrial::InZeroSuggestAfterTypingFieldTrial() { | 277 bool OmniboxFieldTrial::InZeroSuggestAfterTypingFieldTrial() { |
278 return chrome_variations::GetVariationParamValue( | 278 return variations::GetVariationParamValue( |
279 kBundledExperimentFieldTrialName, | 279 kBundledExperimentFieldTrialName, |
280 kZeroSuggestVariantRule) == "AfterTyping"; | 280 kZeroSuggestVariantRule) == "AfterTyping"; |
281 } | 281 } |
282 | 282 |
283 bool OmniboxFieldTrial::InZeroSuggestPersonalizedFieldTrial() { | 283 bool OmniboxFieldTrial::InZeroSuggestPersonalizedFieldTrial() { |
284 return chrome_variations::GetVariationParamValue( | 284 return variations::GetVariationParamValue( |
285 kBundledExperimentFieldTrialName, | 285 kBundledExperimentFieldTrialName, |
286 kZeroSuggestVariantRule) == "Personalized"; | 286 kZeroSuggestVariantRule) == "Personalized"; |
287 } | 287 } |
288 | 288 |
289 bool OmniboxFieldTrial::ShortcutsScoringMaxRelevance( | 289 bool OmniboxFieldTrial::ShortcutsScoringMaxRelevance( |
290 OmniboxEventProto::PageClassification current_page_classification, | 290 OmniboxEventProto::PageClassification current_page_classification, |
291 int* max_relevance) { | 291 int* max_relevance) { |
292 // The value of the rule is a string that encodes an integer containing | 292 // The value of the rule is a string that encodes an integer containing |
293 // the max relevance. | 293 // the max relevance. |
294 const std::string& max_relevance_str = | 294 const std::string& max_relevance_str = |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
346 static_cast<float>(v) / 100.0f; | 346 static_cast<float>(v) / 100.0f; |
347 } | 347 } |
348 } | 348 } |
349 } | 349 } |
350 | 350 |
351 void OmniboxFieldTrial::GetExperimentalHUPScoringParams( | 351 void OmniboxFieldTrial::GetExperimentalHUPScoringParams( |
352 HUPScoringParams* scoring_params) { | 352 HUPScoringParams* scoring_params) { |
353 scoring_params->experimental_scoring_enabled = false; | 353 scoring_params->experimental_scoring_enabled = false; |
354 | 354 |
355 VariationParams params; | 355 VariationParams params; |
356 if (!chrome_variations::GetVariationParams(kBundledExperimentFieldTrialName, | 356 if (!variations::GetVariationParams(kBundledExperimentFieldTrialName, |
357 ¶ms)) | 357 ¶ms)) |
358 return; | 358 return; |
359 | 359 |
360 VariationParams::const_iterator it = params.find(kHUPNewScoringEnabledParam); | 360 VariationParams::const_iterator it = params.find(kHUPNewScoringEnabledParam); |
361 if (it != params.end()) { | 361 if (it != params.end()) { |
362 int enabled = 0; | 362 int enabled = 0; |
363 if (base::StringToInt(it->second, &enabled)) | 363 if (base::StringToInt(it->second, &enabled)) |
364 scoring_params->experimental_scoring_enabled = (enabled != 0); | 364 scoring_params->experimental_scoring_enabled = (enabled != 0); |
365 } | 365 } |
366 | 366 |
367 InitializeScoreBuckets(params, kHUPNewScoringTypedCountRelevanceCapParam, | 367 InitializeScoreBuckets(params, kHUPNewScoringTypedCountRelevanceCapParam, |
368 kHUPNewScoringTypedCountHalfLifeTimeParam, | 368 kHUPNewScoringTypedCountHalfLifeTimeParam, |
369 kHUPNewScoringTypedCountScoreBucketsParam, | 369 kHUPNewScoringTypedCountScoreBucketsParam, |
370 &scoring_params->typed_count_buckets); | 370 &scoring_params->typed_count_buckets); |
371 InitializeScoreBuckets(params, kHUPNewScoringVisitedCountRelevanceCapParam, | 371 InitializeScoreBuckets(params, kHUPNewScoringVisitedCountRelevanceCapParam, |
372 kHUPNewScoringVisitedCountHalfLifeTimeParam, | 372 kHUPNewScoringVisitedCountHalfLifeTimeParam, |
373 kHUPNewScoringVisitedCountScoreBucketsParam, | 373 kHUPNewScoringVisitedCountScoreBucketsParam, |
374 &scoring_params->visited_count_buckets); | 374 &scoring_params->visited_count_buckets); |
375 } | 375 } |
376 | 376 |
377 int OmniboxFieldTrial::HQPBookmarkValue() { | 377 int OmniboxFieldTrial::HQPBookmarkValue() { |
378 std::string bookmark_value_str = chrome_variations:: | 378 std::string bookmark_value_str = |
379 GetVariationParamValue(kBundledExperimentFieldTrialName, | 379 variations::GetVariationParamValue(kBundledExperimentFieldTrialName, |
380 kHQPBookmarkValueRule); | 380 kHQPBookmarkValueRule); |
381 if (bookmark_value_str.empty()) | 381 if (bookmark_value_str.empty()) |
382 return 10; | 382 return 10; |
383 // This is a best-effort conversion; we trust the hand-crafted parameters | 383 // This is a best-effort conversion; we trust the hand-crafted parameters |
384 // downloaded from the server to be perfect. There's no need for handle | 384 // downloaded from the server to be perfect. There's no need for handle |
385 // errors smartly. | 385 // errors smartly. |
386 int bookmark_value; | 386 int bookmark_value; |
387 base::StringToInt(bookmark_value_str, &bookmark_value); | 387 base::StringToInt(bookmark_value_str, &bookmark_value); |
388 return bookmark_value; | 388 return bookmark_value; |
389 } | 389 } |
390 | 390 |
391 bool OmniboxFieldTrial::HQPAllowMatchInTLDValue() { | 391 bool OmniboxFieldTrial::HQPAllowMatchInTLDValue() { |
392 return chrome_variations::GetVariationParamValue( | 392 return variations::GetVariationParamValue( |
393 kBundledExperimentFieldTrialName, | 393 kBundledExperimentFieldTrialName, |
394 kHQPAllowMatchInTLDRule) == "true"; | 394 kHQPAllowMatchInTLDRule) == "true"; |
395 } | 395 } |
396 | 396 |
397 bool OmniboxFieldTrial::HQPAllowMatchInSchemeValue() { | 397 bool OmniboxFieldTrial::HQPAllowMatchInSchemeValue() { |
398 return chrome_variations::GetVariationParamValue( | 398 return variations::GetVariationParamValue( |
399 kBundledExperimentFieldTrialName, | 399 kBundledExperimentFieldTrialName, |
400 kHQPAllowMatchInSchemeRule) == "true"; | 400 kHQPAllowMatchInSchemeRule) == "true"; |
401 } | 401 } |
402 | 402 |
403 bool OmniboxFieldTrial::BookmarksIndexURLsValue() { | 403 bool OmniboxFieldTrial::BookmarksIndexURLsValue() { |
404 return chrome_variations::GetVariationParamValue( | 404 return variations::GetVariationParamValue( |
405 kBundledExperimentFieldTrialName, | 405 kBundledExperimentFieldTrialName, |
406 kBookmarksIndexURLsRule) == "true"; | 406 kBookmarksIndexURLsRule) == "true"; |
407 } | 407 } |
408 | 408 |
409 bool OmniboxFieldTrial::DisableInlining() { | 409 bool OmniboxFieldTrial::DisableInlining() { |
410 return chrome_variations::GetVariationParamValue( | 410 return variations::GetVariationParamValue( |
411 kBundledExperimentFieldTrialName, | 411 kBundledExperimentFieldTrialName, |
412 kDisableInliningRule) == "true"; | 412 kDisableInliningRule) == "true"; |
413 } | 413 } |
414 | 414 |
415 bool OmniboxFieldTrial::EnableAnswersInSuggest() { | 415 bool OmniboxFieldTrial::EnableAnswersInSuggest() { |
416 const CommandLine* cl = CommandLine::ForCurrentProcess(); | 416 const CommandLine* cl = CommandLine::ForCurrentProcess(); |
417 if (cl->HasSwitch(switches::kDisableAnswersInSuggest)) | 417 if (cl->HasSwitch(switches::kDisableAnswersInSuggest)) |
418 return false; | 418 return false; |
419 if (cl->HasSwitch(switches::kEnableAnswersInSuggest)) | 419 if (cl->HasSwitch(switches::kEnableAnswersInSuggest)) |
420 return true; | 420 return true; |
421 | 421 |
422 return chrome_variations::GetVariationParamValue( | 422 return variations::GetVariationParamValue( |
423 kBundledExperimentFieldTrialName, | 423 kBundledExperimentFieldTrialName, |
424 kAnswersInSuggestRule) == "true"; | 424 kAnswersInSuggestRule) == "true"; |
425 } | 425 } |
426 | 426 |
427 bool OmniboxFieldTrial::AddUWYTMatchEvenIfPromotedURLs() { | 427 bool OmniboxFieldTrial::AddUWYTMatchEvenIfPromotedURLs() { |
428 return chrome_variations::GetVariationParamValue( | 428 return variations::GetVariationParamValue( |
429 kBundledExperimentFieldTrialName, | 429 kBundledExperimentFieldTrialName, |
430 kAddUWYTMatchEvenIfPromotedURLsRule) == "true"; | 430 kAddUWYTMatchEvenIfPromotedURLsRule) == "true"; |
431 } | 431 } |
432 | 432 |
433 bool OmniboxFieldTrial::DisplayHintTextWhenPossible() { | 433 bool OmniboxFieldTrial::DisplayHintTextWhenPossible() { |
434 return chrome_variations::GetVariationParamValue( | 434 return variations::GetVariationParamValue( |
435 kBundledExperimentFieldTrialName, | 435 kBundledExperimentFieldTrialName, |
436 kDisplayHintTextWhenPossibleRule) == "true"; | 436 kDisplayHintTextWhenPossibleRule) == "true"; |
437 } | 437 } |
438 | 438 |
439 const char OmniboxFieldTrial::kBundledExperimentFieldTrialName[] = | 439 const char OmniboxFieldTrial::kBundledExperimentFieldTrialName[] = |
440 "OmniboxBundledExperimentV1"; | 440 "OmniboxBundledExperimentV1"; |
441 const char OmniboxFieldTrial::kShortcutsScoringMaxRelevanceRule[] = | 441 const char OmniboxFieldTrial::kShortcutsScoringMaxRelevanceRule[] = |
442 "ShortcutsScoringMaxRelevance"; | 442 "ShortcutsScoringMaxRelevance"; |
443 const char OmniboxFieldTrial::kSearchHistoryRule[] = "SearchHistory"; | 443 const char OmniboxFieldTrial::kSearchHistoryRule[] = "SearchHistory"; |
444 const char OmniboxFieldTrial::kDemoteByTypeRule[] = "DemoteByType"; | 444 const char OmniboxFieldTrial::kDemoteByTypeRule[] = "DemoteByType"; |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
502 // | 502 // |
503 // In short, this function tries to find the value associated with key | 503 // In short, this function tries to find the value associated with key |
504 // |rule|:|page_classification|:|instant_extended|, failing that it looks up | 504 // |rule|:|page_classification|:|instant_extended|, failing that it looks up |
505 // |rule|:*:|instant_extended|, failing that it looks up | 505 // |rule|:*:|instant_extended|, failing that it looks up |
506 // |rule|:|page_classification|:*, failing that it looks up |rule|:*:*, | 506 // |rule|:|page_classification|:*, failing that it looks up |rule|:*:*, |
507 // and failing that it returns the empty string. | 507 // and failing that it returns the empty string. |
508 std::string OmniboxFieldTrial::GetValueForRuleInContext( | 508 std::string OmniboxFieldTrial::GetValueForRuleInContext( |
509 const std::string& rule, | 509 const std::string& rule, |
510 OmniboxEventProto::PageClassification page_classification) { | 510 OmniboxEventProto::PageClassification page_classification) { |
511 VariationParams params; | 511 VariationParams params; |
512 if (!chrome_variations::GetVariationParams(kBundledExperimentFieldTrialName, | 512 if (!variations::GetVariationParams(kBundledExperimentFieldTrialName, |
513 ¶ms)) { | 513 ¶ms)) { |
514 return std::string(); | 514 return std::string(); |
515 } | 515 } |
516 const std::string page_classification_str = | 516 const std::string page_classification_str = |
517 base::IntToString(static_cast<int>(page_classification)); | 517 base::IntToString(static_cast<int>(page_classification)); |
518 const std::string instant_extended = | 518 const std::string instant_extended = |
519 chrome::IsInstantExtendedAPIEnabled() ? "1" : "0"; | 519 chrome::IsInstantExtendedAPIEnabled() ? "1" : "0"; |
520 // Look up rule in this exact context. | 520 // Look up rule in this exact context. |
521 VariationParams::const_iterator it = params.find( | 521 VariationParams::const_iterator it = params.find( |
522 rule + ":" + page_classification_str + ":" + instant_extended); | 522 rule + ":" + page_classification_str + ":" + instant_extended); |
523 if (it != params.end()) | 523 if (it != params.end()) |
524 return it->second; | 524 return it->second; |
525 // Fall back to the global page classification context. | 525 // Fall back to the global page classification context. |
526 it = params.find(rule + ":*:" + instant_extended); | 526 it = params.find(rule + ":*:" + instant_extended); |
527 if (it != params.end()) | 527 if (it != params.end()) |
528 return it->second; | 528 return it->second; |
529 // Fall back to the global instant extended context. | 529 // Fall back to the global instant extended context. |
530 it = params.find(rule + ":" + page_classification_str + ":*"); | 530 it = params.find(rule + ":" + page_classification_str + ":*"); |
531 if (it != params.end()) | 531 if (it != params.end()) |
532 return it->second; | 532 return it->second; |
533 // Look up rule in the global context. | 533 // Look up rule in the global context. |
534 it = params.find(rule + ":*:*"); | 534 it = params.find(rule + ":*:*"); |
535 return (it != params.end()) ? it->second : std::string(); | 535 return (it != params.end()) ? it->second : std::string(); |
536 } | 536 } |
OLD | NEW |