Chromium Code Reviews| Index: components/omnibox/browser/omnibox_field_trial.cc |
| diff --git a/components/omnibox/browser/omnibox_field_trial.cc b/components/omnibox/browser/omnibox_field_trial.cc |
| index cbcf6f6c652608ac671e6122705442e1a3457401..440df5a716a9337773c2d6e441ee7e22965fe2b2 100644 |
| --- a/components/omnibox/browser/omnibox_field_trial.cc |
| +++ b/components/omnibox/browser/omnibox_field_trial.cc |
| @@ -4,6 +4,7 @@ |
| #include "components/omnibox/browser/omnibox_field_trial.h" |
| +#include <algorithm> |
| #include <cmath> |
| #include <string> |
| @@ -443,6 +444,29 @@ float OmniboxFieldTrial::HQPTypedValue() { |
| return typed_value; |
| } |
| +OmniboxFieldTrial::NumMatchesScores OmniboxFieldTrial::HQPNumMatchesScores() { |
| + std::string str = variations::GetVariationParamValue( |
| + kBundledExperimentFieldTrialName, kHQPNumMatchesScoresRule); |
| + // The parameter is a comma-separated list of (number, value) pairs, e.g. |
| + // "1:3,2:2.5,3:2,4:1.5". |
| + // This is a best-effort conversion; we trust the hand-crafted parameters |
| + // downloaded from the server to be perfect. There's no need to handle |
| + // errors smartly. |
| + base::StringPairs kv_pairs; |
| + if (!base::SplitStringIntoKeyValuePairs(str, ':', ',', &kv_pairs)) |
| + return NumMatchesScores{}; |
| + NumMatchesScores num_matches_scores(kv_pairs.size()); |
| + for (size_t i = 0; i < kv_pairs.size(); ++i) { |
| + base::StringToSizeT(kv_pairs[i].first, &num_matches_scores[i].first); |
| + // Don't allow duplicates. |
| + DCHECK((i == 0) || |
| + (num_matches_scores[i].first != num_matches_scores[i - 1].first)); |
|
Peter Kasting
2016/12/06 05:19:30
Wouldn't using ">" here obviate the need for the i
Mark P
2016/12/08 00:21:31
Of these two suggestions, I prefer the first one.
|
| + base::StringToDouble(kv_pairs[i].second, &num_matches_scores[i].second); |
| + } |
| + DCHECK(std::is_sorted(num_matches_scores.begin(), num_matches_scores.end())); |
| + return num_matches_scores; |
| +} |
| + |
| size_t OmniboxFieldTrial::HQPNumTitleWordsToAllow() { |
| // The value of the rule is a string that encodes an integer (actually |
| // size_t) containing the number of words. |
| @@ -548,6 +572,8 @@ const char OmniboxFieldTrial::kHQPFixFewVisitsBugRule[] = "HQPFixFewVisitsBug"; |
| const char OmniboxFieldTrial::kHQPFreqencyUsesSumRule[] = "HQPFreqencyUsesSum"; |
| const char OmniboxFieldTrial::kHQPMaxVisitsToScoreRule[] = |
| "HQPMaxVisitsToScoreRule"; |
| +const char OmniboxFieldTrial::kHQPNumMatchesScoresRule[] = |
| + "HQPNumMatchesScores"; |
| const char OmniboxFieldTrial::kHQPNumTitleWordsRule[] = "HQPNumTitleWords"; |
| const char OmniboxFieldTrial::kHQPAlsoDoHUPLikeScoringRule[] = |
| "HQPAlsoDoHUPLikeScoring"; |