Chromium Code Reviews| Index: chrome/browser/omnibox/omnibox_field_trial.cc |
| diff --git a/chrome/browser/omnibox/omnibox_field_trial.cc b/chrome/browser/omnibox/omnibox_field_trial.cc |
| index 83b9143b73f6ac2e006944d6bfd49dc5a302a5c9..fdefed622e3cd1adcd767f4064679efe6f7d5a49 100644 |
| --- a/chrome/browser/omnibox/omnibox_field_trial.cc |
| +++ b/chrome/browser/omnibox/omnibox_field_trial.cc |
| @@ -8,6 +8,7 @@ |
| #include "base/metrics/field_trial.h" |
| #include "base/strings/string_number_conversions.h" |
| +#include "base/strings/string_split.h" |
| #include "base/strings/string_util.h" |
| #include "base/strings/stringprintf.h" |
| #include "chrome/common/metrics/metrics_util.h" |
| @@ -26,6 +27,7 @@ const char kBundledExperimentFieldTrialName[] = "OmniboxBundledExperimentV1"; |
| // Rule names used by the bundled experiment. |
| const char kSearchHistoryRule[] = "SearchHistory"; |
| +const char kDemoteByTypeRule[] = "DemoteByType"; |
| // The autocomplete dynamic field trial name prefix. Each field trial is |
| // configured dynamically and is retrieved automatically by Chrome during |
| @@ -233,6 +235,34 @@ bool OmniboxFieldTrial::SearchHistoryDisable( |
| kSearchHistoryRule, current_page_classification) == "Disable"; |
| } |
| +void OmniboxFieldTrial::GetDemotionsByType( |
| + AutocompleteInput::PageClassification current_page_classification, |
| + DemotionMultiplierByType* demotions_by_type) { |
| + demotions_by_type->clear(); |
| + const std::string demotion_rule = |
| + OmniboxFieldTrial::GetValueForRuleInContext( |
| + kDemoteByTypeRule, |
| + current_page_classification); |
| + // The value of the DemoteByType rule is a comma-separated list of |
| + // {ResultType + ":" + Number} where ResultType is an AutocompleteMatchType:: |
| + // Type enum represented as an integer and Number is an integer number |
| + // between 0 and 100 inclusive. Relevance scores of matches of that result |
| + // type are multiplied by Number / 100. 100 means no change. |
| + std::vector<std::pair<std::string, std::string> > kv_pairs; |
|
Peter Kasting
2013/08/06 19:33:50
Nit: This suggests that string_split.h should have
Mark P
2013/08/06 22:00:15
Done.
|
| + if (base::SplitStringIntoKeyValuePairs(demotion_rule, ':', ',', &kv_pairs)) { |
| + for (size_t i = 0; i < kv_pairs.size(); ++i) { |
| + // This is a best-effort conversion; we trust the hand-crafted parameters |
| + // downloaded from the server to be perfect. There's no need for handle |
| + // errors smartly. |
| + int k, v; |
| + base::StringToInt(kv_pairs[i].first, &k); |
| + base::StringToInt(kv_pairs[i].second, &v); |
| + (*demotions_by_type)[static_cast<AutocompleteMatchType::Type>(k)] = |
| + static_cast<float>(v) / 100.0f; |
| + } |
| + } |
| +} |
| + |
| // Background and implementation details: |
| // |
| // Each experiment group in any field trial can come with an optional set of |