| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "components/omnibox/browser/omnibox_field_trial.h" | 5 #include "components/omnibox/browser/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 413 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 424 if (typed_value_str.empty()) | 424 if (typed_value_str.empty()) |
| 425 return 20; | 425 return 20; |
| 426 // This is a best-effort conversion; we trust the hand-crafted parameters | 426 // This is a best-effort conversion; we trust the hand-crafted parameters |
| 427 // downloaded from the server to be perfect. There's no need for handle | 427 // downloaded from the server to be perfect. There's no need for handle |
| 428 // errors smartly. | 428 // errors smartly. |
| 429 double typed_value; | 429 double typed_value; |
| 430 base::StringToDouble(typed_value_str, &typed_value); | 430 base::StringToDouble(typed_value_str, &typed_value); |
| 431 return typed_value; | 431 return typed_value; |
| 432 } | 432 } |
| 433 | 433 |
| 434 OmniboxFieldTrial::NumMatchesScores OmniboxFieldTrial::HQPNumMatchesScores() { |
| 435 std::string str = variations::GetVariationParamValue( |
| 436 kBundledExperimentFieldTrialName, kHQPNumMatchesScoresRule); |
| 437 // The parameter is a comma-separated list of (number, value) pairs, e.g. |
| 438 // "1:3,2:2.5,3:2,4:1.5". |
| 439 // This is a best-effort conversion; we trust the hand-crafted parameters |
| 440 // downloaded from the server to be perfect. There's no need to handle |
| 441 // errors smartly. |
| 442 base::StringPairs kv_pairs; |
| 443 if (!base::SplitStringIntoKeyValuePairs(str, ':', ',', &kv_pairs)) |
| 444 return NumMatchesScores{}; |
| 445 NumMatchesScores num_matches_scores(kv_pairs.size()); |
| 446 for (size_t i = 0; i < kv_pairs.size(); ++i) { |
| 447 base::StringToSizeT(kv_pairs[i].first, &num_matches_scores[i].first); |
| 448 // The input must be sorted by number of matches. |
| 449 DCHECK((i == 0) || |
| 450 (num_matches_scores[i].first > num_matches_scores[i - 1].first)); |
| 451 base::StringToDouble(kv_pairs[i].second, &num_matches_scores[i].second); |
| 452 } |
| 453 return num_matches_scores; |
| 454 } |
| 455 |
| 434 size_t OmniboxFieldTrial::HQPNumTitleWordsToAllow() { | 456 size_t OmniboxFieldTrial::HQPNumTitleWordsToAllow() { |
| 435 // The value of the rule is a string that encodes an integer (actually | 457 // The value of the rule is a string that encodes an integer (actually |
| 436 // size_t) containing the number of words. | 458 // size_t) containing the number of words. |
| 437 size_t num_title_words; | 459 size_t num_title_words; |
| 438 if (!base::StringToSizeT( | 460 if (!base::StringToSizeT( |
| 439 variations::GetVariationParamValue(kBundledExperimentFieldTrialName, | 461 variations::GetVariationParamValue(kBundledExperimentFieldTrialName, |
| 440 kHQPNumTitleWordsRule), | 462 kHQPNumTitleWordsRule), |
| 441 &num_title_words)) | 463 &num_title_words)) |
| 442 return 20; | 464 return 20; |
| 443 return num_title_words; | 465 return num_title_words; |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 529 "DisableResultsCaching"; | 551 "DisableResultsCaching"; |
| 530 const char | 552 const char |
| 531 OmniboxFieldTrial::kMeasureSuggestPollingDelayFromLastKeystrokeRule[] = | 553 OmniboxFieldTrial::kMeasureSuggestPollingDelayFromLastKeystrokeRule[] = |
| 532 "MeasureSuggestPollingDelayFromLastKeystroke"; | 554 "MeasureSuggestPollingDelayFromLastKeystroke"; |
| 533 const char OmniboxFieldTrial::kSuggestPollingDelayMsRule[] = | 555 const char OmniboxFieldTrial::kSuggestPollingDelayMsRule[] = |
| 534 "SuggestPollingDelayMs"; | 556 "SuggestPollingDelayMs"; |
| 535 const char OmniboxFieldTrial::kHQPFixFewVisitsBugRule[] = "HQPFixFewVisitsBug"; | 557 const char OmniboxFieldTrial::kHQPFixFewVisitsBugRule[] = "HQPFixFewVisitsBug"; |
| 536 const char OmniboxFieldTrial::kHQPFreqencyUsesSumRule[] = "HQPFreqencyUsesSum"; | 558 const char OmniboxFieldTrial::kHQPFreqencyUsesSumRule[] = "HQPFreqencyUsesSum"; |
| 537 const char OmniboxFieldTrial::kHQPMaxVisitsToScoreRule[] = | 559 const char OmniboxFieldTrial::kHQPMaxVisitsToScoreRule[] = |
| 538 "HQPMaxVisitsToScoreRule"; | 560 "HQPMaxVisitsToScoreRule"; |
| 561 const char OmniboxFieldTrial::kHQPNumMatchesScoresRule[] = |
| 562 "HQPNumMatchesScores"; |
| 539 const char OmniboxFieldTrial::kHQPNumTitleWordsRule[] = "HQPNumTitleWords"; | 563 const char OmniboxFieldTrial::kHQPNumTitleWordsRule[] = "HQPNumTitleWords"; |
| 540 const char OmniboxFieldTrial::kHQPAlsoDoHUPLikeScoringRule[] = | 564 const char OmniboxFieldTrial::kHQPAlsoDoHUPLikeScoringRule[] = |
| 541 "HQPAlsoDoHUPLikeScoring"; | 565 "HQPAlsoDoHUPLikeScoring"; |
| 542 const char OmniboxFieldTrial::kHUPSearchDatabaseRule[] = | 566 const char OmniboxFieldTrial::kHUPSearchDatabaseRule[] = |
| 543 "HUPSearchDatabase"; | 567 "HUPSearchDatabase"; |
| 544 const char OmniboxFieldTrial::kKeywordRequiresRegistryRule[] = | 568 const char OmniboxFieldTrial::kKeywordRequiresRegistryRule[] = |
| 545 "KeywordRequiresRegistry"; | 569 "KeywordRequiresRegistry"; |
| 546 const char OmniboxFieldTrial::kKeywordRequiresPrefixMatchRule[] = | 570 const char OmniboxFieldTrial::kKeywordRequiresPrefixMatchRule[] = |
| 547 "KeywordRequiresPrefixMatch"; | 571 "KeywordRequiresPrefixMatch"; |
| 548 const char OmniboxFieldTrial::kKeywordScoreForSufficientlyCompleteMatchRule[] = | 572 const char OmniboxFieldTrial::kKeywordScoreForSufficientlyCompleteMatchRule[] = |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 632 if (it != params.end()) | 656 if (it != params.end()) |
| 633 return it->second; | 657 return it->second; |
| 634 // Fall back to the global instant extended context. | 658 // Fall back to the global instant extended context. |
| 635 it = params.find(rule + ":" + page_classification_str + ":*"); | 659 it = params.find(rule + ":" + page_classification_str + ":*"); |
| 636 if (it != params.end()) | 660 if (it != params.end()) |
| 637 return it->second; | 661 return it->second; |
| 638 // Look up rule in the global context. | 662 // Look up rule in the global context. |
| 639 it = params.find(rule + ":*:*"); | 663 it = params.find(rule + ":*:*"); |
| 640 return (it != params.end()) ? it->second : std::string(); | 664 return (it != params.end()) ? it->second : std::string(); |
| 641 } | 665 } |
| OLD | NEW |