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 <algorithm> |
7 #include <cmath> | 8 #include <cmath> |
8 #include <string> | 9 #include <string> |
9 | 10 |
10 #include "base/command_line.h" | 11 #include "base/command_line.h" |
11 #include "base/metrics/field_trial.h" | 12 #include "base/metrics/field_trial.h" |
12 #include "base/strings/string_number_conversions.h" | 13 #include "base/strings/string_number_conversions.h" |
13 #include "base/strings/string_split.h" | 14 #include "base/strings/string_split.h" |
14 #include "base/strings/string_util.h" | 15 #include "base/strings/string_util.h" |
15 #include "base/time/time.h" | 16 #include "base/time/time.h" |
16 #include "build/build_config.h" | 17 #include "build/build_config.h" |
(...skipping 419 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
436 if (typed_value_str.empty()) | 437 if (typed_value_str.empty()) |
437 return 20; | 438 return 20; |
438 // This is a best-effort conversion; we trust the hand-crafted parameters | 439 // This is a best-effort conversion; we trust the hand-crafted parameters |
439 // downloaded from the server to be perfect. There's no need for handle | 440 // downloaded from the server to be perfect. There's no need for handle |
440 // errors smartly. | 441 // errors smartly. |
441 double typed_value; | 442 double typed_value; |
442 base::StringToDouble(typed_value_str, &typed_value); | 443 base::StringToDouble(typed_value_str, &typed_value); |
443 return typed_value; | 444 return typed_value; |
444 } | 445 } |
445 | 446 |
| 447 OmniboxFieldTrial::NumMatchesScores OmniboxFieldTrial::HQPNumMatchesScores() { |
| 448 std::string str = variations::GetVariationParamValue( |
| 449 kBundledExperimentFieldTrialName, kHQPNumMatchesScoresRule); |
| 450 // The parameter is a comma-separated list of (number, value) pairs, e.g. |
| 451 // "1:3,2:2.5,3:2,4:1.5". |
| 452 // This is a best-effort conversion; we trust the hand-crafted parameters |
| 453 // downloaded from the server to be perfect. There's no need to handle |
| 454 // errors smartly. |
| 455 base::StringPairs kv_pairs; |
| 456 if (!base::SplitStringIntoKeyValuePairs(str, ':', ',', &kv_pairs)) |
| 457 return NumMatchesScores{}; |
| 458 NumMatchesScores num_matches_scores(kv_pairs.size()); |
| 459 for (size_t i = 0; i < kv_pairs.size(); ++i) { |
| 460 base::StringToSizeT(kv_pairs[i].first, &num_matches_scores[i].first); |
| 461 // The input must be sorted by number of matches. |
| 462 DCHECK((i == 0) || |
| 463 (num_matches_scores[i].first > num_matches_scores[i - 1].first)); |
| 464 base::StringToDouble(kv_pairs[i].second, &num_matches_scores[i].second); |
| 465 } |
| 466 return num_matches_scores; |
| 467 } |
| 468 |
446 size_t OmniboxFieldTrial::HQPNumTitleWordsToAllow() { | 469 size_t OmniboxFieldTrial::HQPNumTitleWordsToAllow() { |
447 // The value of the rule is a string that encodes an integer (actually | 470 // The value of the rule is a string that encodes an integer (actually |
448 // size_t) containing the number of words. | 471 // size_t) containing the number of words. |
449 size_t num_title_words; | 472 size_t num_title_words; |
450 if (!base::StringToSizeT( | 473 if (!base::StringToSizeT( |
451 variations::GetVariationParamValue(kBundledExperimentFieldTrialName, | 474 variations::GetVariationParamValue(kBundledExperimentFieldTrialName, |
452 kHQPNumTitleWordsRule), | 475 kHQPNumTitleWordsRule), |
453 &num_title_words)) | 476 &num_title_words)) |
454 return 20; | 477 return 20; |
455 return num_title_words; | 478 return num_title_words; |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
541 "DisableResultsCaching"; | 564 "DisableResultsCaching"; |
542 const char | 565 const char |
543 OmniboxFieldTrial::kMeasureSuggestPollingDelayFromLastKeystrokeRule[] = | 566 OmniboxFieldTrial::kMeasureSuggestPollingDelayFromLastKeystrokeRule[] = |
544 "MeasureSuggestPollingDelayFromLastKeystroke"; | 567 "MeasureSuggestPollingDelayFromLastKeystroke"; |
545 const char OmniboxFieldTrial::kSuggestPollingDelayMsRule[] = | 568 const char OmniboxFieldTrial::kSuggestPollingDelayMsRule[] = |
546 "SuggestPollingDelayMs"; | 569 "SuggestPollingDelayMs"; |
547 const char OmniboxFieldTrial::kHQPFixFewVisitsBugRule[] = "HQPFixFewVisitsBug"; | 570 const char OmniboxFieldTrial::kHQPFixFewVisitsBugRule[] = "HQPFixFewVisitsBug"; |
548 const char OmniboxFieldTrial::kHQPFreqencyUsesSumRule[] = "HQPFreqencyUsesSum"; | 571 const char OmniboxFieldTrial::kHQPFreqencyUsesSumRule[] = "HQPFreqencyUsesSum"; |
549 const char OmniboxFieldTrial::kHQPMaxVisitsToScoreRule[] = | 572 const char OmniboxFieldTrial::kHQPMaxVisitsToScoreRule[] = |
550 "HQPMaxVisitsToScoreRule"; | 573 "HQPMaxVisitsToScoreRule"; |
| 574 const char OmniboxFieldTrial::kHQPNumMatchesScoresRule[] = |
| 575 "HQPNumMatchesScores"; |
551 const char OmniboxFieldTrial::kHQPNumTitleWordsRule[] = "HQPNumTitleWords"; | 576 const char OmniboxFieldTrial::kHQPNumTitleWordsRule[] = "HQPNumTitleWords"; |
552 const char OmniboxFieldTrial::kHQPAlsoDoHUPLikeScoringRule[] = | 577 const char OmniboxFieldTrial::kHQPAlsoDoHUPLikeScoringRule[] = |
553 "HQPAlsoDoHUPLikeScoring"; | 578 "HQPAlsoDoHUPLikeScoring"; |
554 const char OmniboxFieldTrial::kHUPSearchDatabaseRule[] = | 579 const char OmniboxFieldTrial::kHUPSearchDatabaseRule[] = |
555 "HUPSearchDatabase"; | 580 "HUPSearchDatabase"; |
556 const char OmniboxFieldTrial::kKeywordRequiresRegistryRule[] = | 581 const char OmniboxFieldTrial::kKeywordRequiresRegistryRule[] = |
557 "KeywordRequiresRegistry"; | 582 "KeywordRequiresRegistry"; |
558 const char OmniboxFieldTrial::kKeywordRequiresPrefixMatchRule[] = | 583 const char OmniboxFieldTrial::kKeywordRequiresPrefixMatchRule[] = |
559 "KeywordRequiresPrefixMatch"; | 584 "KeywordRequiresPrefixMatch"; |
560 const char OmniboxFieldTrial::kKeywordScoreForSufficientlyCompleteMatchRule[] = | 585 const char OmniboxFieldTrial::kKeywordScoreForSufficientlyCompleteMatchRule[] = |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
646 if (it != params.end()) | 671 if (it != params.end()) |
647 return it->second; | 672 return it->second; |
648 // Fall back to the global instant extended context. | 673 // Fall back to the global instant extended context. |
649 it = params.find(rule + ":" + page_classification_str + ":*"); | 674 it = params.find(rule + ":" + page_classification_str + ":*"); |
650 if (it != params.end()) | 675 if (it != params.end()) |
651 return it->second; | 676 return it->second; |
652 // Look up rule in the global context. | 677 // Look up rule in the global context. |
653 it = params.find(rule + ":*:*"); | 678 it = params.find(rule + ":*:*"); |
654 return (it != params.end()) ? it->second : std::string(); | 679 return (it != params.end()) ? it->second : std::string(); |
655 } | 680 } |
OLD | NEW |