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 // Don't allow duplicates. | |
462 DCHECK((i == 0) || | |
463 (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.
| |
464 base::StringToDouble(kv_pairs[i].second, &num_matches_scores[i].second); | |
465 } | |
466 DCHECK(std::is_sorted(num_matches_scores.begin(), num_matches_scores.end())); | |
467 return num_matches_scores; | |
468 } | |
469 | |
446 size_t OmniboxFieldTrial::HQPNumTitleWordsToAllow() { | 470 size_t OmniboxFieldTrial::HQPNumTitleWordsToAllow() { |
447 // The value of the rule is a string that encodes an integer (actually | 471 // The value of the rule is a string that encodes an integer (actually |
448 // size_t) containing the number of words. | 472 // size_t) containing the number of words. |
449 size_t num_title_words; | 473 size_t num_title_words; |
450 if (!base::StringToSizeT( | 474 if (!base::StringToSizeT( |
451 variations::GetVariationParamValue(kBundledExperimentFieldTrialName, | 475 variations::GetVariationParamValue(kBundledExperimentFieldTrialName, |
452 kHQPNumTitleWordsRule), | 476 kHQPNumTitleWordsRule), |
453 &num_title_words)) | 477 &num_title_words)) |
454 return 20; | 478 return 20; |
455 return num_title_words; | 479 return num_title_words; |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
541 "DisableResultsCaching"; | 565 "DisableResultsCaching"; |
542 const char | 566 const char |
543 OmniboxFieldTrial::kMeasureSuggestPollingDelayFromLastKeystrokeRule[] = | 567 OmniboxFieldTrial::kMeasureSuggestPollingDelayFromLastKeystrokeRule[] = |
544 "MeasureSuggestPollingDelayFromLastKeystroke"; | 568 "MeasureSuggestPollingDelayFromLastKeystroke"; |
545 const char OmniboxFieldTrial::kSuggestPollingDelayMsRule[] = | 569 const char OmniboxFieldTrial::kSuggestPollingDelayMsRule[] = |
546 "SuggestPollingDelayMs"; | 570 "SuggestPollingDelayMs"; |
547 const char OmniboxFieldTrial::kHQPFixFewVisitsBugRule[] = "HQPFixFewVisitsBug"; | 571 const char OmniboxFieldTrial::kHQPFixFewVisitsBugRule[] = "HQPFixFewVisitsBug"; |
548 const char OmniboxFieldTrial::kHQPFreqencyUsesSumRule[] = "HQPFreqencyUsesSum"; | 572 const char OmniboxFieldTrial::kHQPFreqencyUsesSumRule[] = "HQPFreqencyUsesSum"; |
549 const char OmniboxFieldTrial::kHQPMaxVisitsToScoreRule[] = | 573 const char OmniboxFieldTrial::kHQPMaxVisitsToScoreRule[] = |
550 "HQPMaxVisitsToScoreRule"; | 574 "HQPMaxVisitsToScoreRule"; |
575 const char OmniboxFieldTrial::kHQPNumMatchesScoresRule[] = | |
576 "HQPNumMatchesScores"; | |
551 const char OmniboxFieldTrial::kHQPNumTitleWordsRule[] = "HQPNumTitleWords"; | 577 const char OmniboxFieldTrial::kHQPNumTitleWordsRule[] = "HQPNumTitleWords"; |
552 const char OmniboxFieldTrial::kHQPAlsoDoHUPLikeScoringRule[] = | 578 const char OmniboxFieldTrial::kHQPAlsoDoHUPLikeScoringRule[] = |
553 "HQPAlsoDoHUPLikeScoring"; | 579 "HQPAlsoDoHUPLikeScoring"; |
554 const char OmniboxFieldTrial::kHUPSearchDatabaseRule[] = | 580 const char OmniboxFieldTrial::kHUPSearchDatabaseRule[] = |
555 "HUPSearchDatabase"; | 581 "HUPSearchDatabase"; |
556 const char OmniboxFieldTrial::kKeywordRequiresRegistryRule[] = | 582 const char OmniboxFieldTrial::kKeywordRequiresRegistryRule[] = |
557 "KeywordRequiresRegistry"; | 583 "KeywordRequiresRegistry"; |
558 const char OmniboxFieldTrial::kKeywordRequiresPrefixMatchRule[] = | 584 const char OmniboxFieldTrial::kKeywordRequiresPrefixMatchRule[] = |
559 "KeywordRequiresPrefixMatch"; | 585 "KeywordRequiresPrefixMatch"; |
560 const char OmniboxFieldTrial::kKeywordScoreForSufficientlyCompleteMatchRule[] = | 586 const char OmniboxFieldTrial::kKeywordScoreForSufficientlyCompleteMatchRule[] = |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
646 if (it != params.end()) | 672 if (it != params.end()) |
647 return it->second; | 673 return it->second; |
648 // Fall back to the global instant extended context. | 674 // Fall back to the global instant extended context. |
649 it = params.find(rule + ":" + page_classification_str + ":*"); | 675 it = params.find(rule + ":" + page_classification_str + ":*"); |
650 if (it != params.end()) | 676 if (it != params.end()) |
651 return it->second; | 677 return it->second; |
652 // Look up rule in the global context. | 678 // Look up rule in the global context. |
653 it = params.find(rule + ":*:*"); | 679 it = params.find(rule + ":*:*"); |
654 return (it != params.end()) ? it->second : std::string(); | 680 return (it != params.end()) ? it->second : std::string(); |
655 } | 681 } |
OLD | NEW |