16e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)// Copyright 2014 The Chromium Authors. All rights reserved.
25821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be
35821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// found in the LICENSE file.
45821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
56e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)#ifndef COMPONENTS_OMNIBOX_OMNIBOX_FIELD_TRIAL_H_
66e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)#define COMPONENTS_OMNIBOX_OMNIBOX_FIELD_TRIAL_H_
75821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
8ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch#include <map>
95821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include <string>
10c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)#include <vector>
115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "base/basictypes.h"
13a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)#include "base/gtest_prod_util.h"
146d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles)#include "components/metrics/proto/omnibox_event.pb.h"
155f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)#include "components/omnibox/autocomplete_match_type.h"
165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
175d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)namespace base {
185d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)class TimeDelta;
195d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}
205d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
215d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// The set of parameters customizing the HUP scoring.
225d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)struct HUPScoringParams {
235d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // A set of parameters describing how to cap a given count score.  First,
245d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // we apply a half-life based decay of the given count and then find the
255d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // maximum relevance score in the corresponding bucket list.
265d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  class ScoreBuckets {
275d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)   public:
285d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    // (decayed_count, max_relevance) pair.
295d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    typedef std::pair<double, int> CountMaxRelevance;
305d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
315d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    ScoreBuckets();
325d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    ~ScoreBuckets();
335d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
345d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    // Computes a half-life time decay given the |elapsed_time|.
355d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    double HalfLifeTimeDecay(const base::TimeDelta& elapsed_time) const;
365d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
375d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    int relevance_cap() const { return relevance_cap_; }
385d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    void set_relevance_cap(int relevance_cap) {
395d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      relevance_cap_ = relevance_cap;
405d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    }
415d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
425d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    int half_life_days() const { return half_life_days_; }
435d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    void set_half_life_days(int half_life_days) {
445d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      half_life_days_ = half_life_days;
455d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    }
465d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
475d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    std::vector<CountMaxRelevance>& buckets() { return buckets_; }
485d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    const std::vector<CountMaxRelevance>& buckets() const { return buckets_; }
495d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
505d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)   private:
515d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    // History matches with relevance score greater or equal to |relevance_cap_|
525d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    // are not affected by this experiment.
535d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    // Set to -1, if there is no relevance cap in place and all matches are
545d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    // subject to demotion.
555d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    int relevance_cap_;
565d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
575d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    // Half life time for a decayed count as measured since the last visit.
585d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    // Set to -1 if not used.
595d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    int half_life_days_;
605d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
615d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    // The relevance score caps for given decayed count values.
625d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    // Each pair (decayed_count, max_score) indicates what the maximum relevance
635d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    // score is of a decayed count equal or greater than decayed_count.
645d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    //
655d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    // Consider this example:
665d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    //   [(1, 1000), (0.5, 500), (0, 100)]
675d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    // If decayed count is 2 (which is >= 1), the corresponding match's maximum
685d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    // relevance will be capped at 1000.  In case of 0.5, the score is capped
695d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    // at 500.  Anything below 0.5 is capped at 100.
705d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    //
715d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    // This list is sorted by the pair's first element in descending order.
725d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    std::vector<CountMaxRelevance> buckets_;
735d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  };
745d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
755d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  HUPScoringParams() : experimental_scoring_enabled(false) {}
765d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
775d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  bool experimental_scoring_enabled;
785d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
795d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  ScoreBuckets typed_count_buckets;
805d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
815d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // Used only when the typed count is 0.
825d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  ScoreBuckets visited_count_buckets;
835d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)};
845d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
852a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// This class manages the Omnibox field trials.
862a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)class OmniboxFieldTrial {
875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) public:
88ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch  // A mapping that contains multipliers indicating that matches of the
89ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch  // specified type should have their relevance score multiplied by the
90ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch  // given number.  Omitted types are assumed to have multipliers of 1.0.
91ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch  typedef std::map<AutocompleteMatchType::Type, float> DemotionMultipliers;
92ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch
932a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // Activates all dynamic field trials.  The main difference between
942a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // the autocomplete dynamic and static field trials is that the former
952a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // don't require any code changes on the Chrome side as they are controlled
962a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // on the server side.  Chrome binary simply propagates all necessary
97a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  // information through the X-Client-Data header.
985f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)  // This method may be called multiple times.
992a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  static void ActivateDynamicTrials();
1002a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
1012a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // Returns a bitmap containing AutocompleteProvider::Type values
1022a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // that should be disabled in AutocompleteController.
1032a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // This method simply goes over all autocomplete dynamic field trial groups
1042a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // and looks for group names like "ProvidersDisabled_NNN" where NNN is
1052a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // an integer corresponding to a bitmap mask.  All extracted bitmaps
1062a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // are OR-ed together and returned as the final result.
1072a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  static int GetDisabledProviderTypes();
1085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
109d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)  // Returns whether the user is in any dynamic field trial where the
110d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)  // group has a the prefix |group_prefix|.
111d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)  static bool HasDynamicFieldTrialGroupPrefix(const char *group_prefix);
112d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)
1135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // ---------------------------------------------------------
1145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // For the suggest field trial.
1155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
116c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  // Populates |field_trial_hash| with hashes of the active suggest field trial
117c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  // names, if any.
118c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  static void GetActiveSuggestFieldTrialHashes(
119c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)      std::vector<uint32>* field_trial_hash);
1205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // ---------------------------------------------------------
122c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  // For the AutocompleteController "stop timer" field trial.
1235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1245d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // Returns the duration to be used for the AutocompleteController's stop
1255d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // timer.  Returns the default value of 1.5 seconds if the stop timer
1265d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // override experiment isn't active or if parsing the experiment-provided
1275d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // duration fails.
1285d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  static base::TimeDelta StopTimerFieldTrialDuration();
129c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
130c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  // ---------------------------------------------------------
131c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  // For the ZeroSuggestProvider field trial.
132c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
133c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  // Returns whether the user is in any field trial where the
134c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  // ZeroSuggestProvider should be used to get suggestions when the
135c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  // user clicks on the omnibox but has not typed anything yet.
136c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  static bool InZeroSuggestFieldTrial();
1375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
138d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)  // Returns whether the user is in a ZeroSuggest field trial, but should
139d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)  // show most visited URL instead.  This is used to compare metrics of
140d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)  // ZeroSuggest and most visited suggestions.
141d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)  static bool InZeroSuggestMostVisitedFieldTrial();
142d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)
143f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  // Returns whether the user is in a ZeroSuggest field trial and URL-based
144f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  // suggestions can continue to appear after the user has started typing.
145f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  static bool InZeroSuggestAfterTypingFieldTrial();
146f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)
14723730a6e56a168d1879203e4b3819bb36e3d8f1fTorne (Richard Coles)  // Returns whether the user is in a ZeroSuggest field trial, but should
14823730a6e56a168d1879203e4b3819bb36e3d8f1fTorne (Richard Coles)  // show recently searched-for queries instead.
14923730a6e56a168d1879203e4b3819bb36e3d8f1fTorne (Richard Coles)  static bool InZeroSuggestPersonalizedFieldTrial();
15023730a6e56a168d1879203e4b3819bb36e3d8f1fTorne (Richard Coles)
151eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  // ---------------------------------------------------------
152ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch  // For the ShortcutsScoringMaxRelevance experiment that's part of the
153ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch  // bundled omnibox field trial.
154ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch
155ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch  // If the user is in an experiment group that, given the provided
156ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch  // |current_page_classification| context, changes the maximum relevance
157ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch  // ShortcutsProvider::CalculateScore() is supposed to assign, extract
158ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch  // that maximum relevance score and put in in |max_relevance|.  Returns
159ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch  // true on a successful extraction.  CalculateScore()'s return value is
160ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch  // a product of this maximum relevance score and some attenuating factors
161ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch  // that are all between 0 and 1.  (Note that Shortcuts results may have
162ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch  // their scores reduced later if the assigned score is higher than allowed
163ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch  // for non-inlineable results.  Shortcuts results are not allowed to be
164eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  // inlined.)
165ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch  static bool ShortcutsScoringMaxRelevance(
1666d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles)      metrics::OmniboxEventProto::PageClassification
1676d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles)          current_page_classification,
168ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch      int* max_relevance);
169eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch
1707dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch  // ---------------------------------------------------------
171a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)  // For the SearchHistory experiment that's part of the bundled omnibox
172a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)  // field trial.
1737dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch
174a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)  // Returns true if the user is in the experiment group that, given the
175a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)  // provided |current_page_classification| context, scores search history
176a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)  // query suggestions less aggressively so that they don't inline.
177a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)  static bool SearchHistoryPreventInlining(
1786d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles)      metrics::OmniboxEventProto::PageClassification
1796d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles)          current_page_classification);
1807dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch
181a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)  // Returns true if the user is in the experiment group that, given the
182a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)  // provided |current_page_classification| context, disables all query
183a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)  // suggestions from search history.
184a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)  static bool SearchHistoryDisable(
1856d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles)      metrics::OmniboxEventProto::PageClassification
1866d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles)          current_page_classification);
1877dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch
188ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch  // ---------------------------------------------------------
189ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch  // For the DemoteByType experiment that's part of the bundled omnibox field
190ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch  // trial.
191ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch
192ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch  // If the user is in an experiment group that, in the provided
193ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch  // |current_page_classification| context, demotes the relevance scores
194ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch  // of certain types of matches, populates the |demotions_by_type| map
195a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  // appropriately.  Otherwise, sets |demotions_by_type| to its default
196a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  // value based on the context.
197ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch  static void GetDemotionsByType(
1986d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles)      metrics::OmniboxEventProto::PageClassification
1996d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles)          current_page_classification,
200ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch      DemotionMultipliers* demotions_by_type);
201ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch
202c2db58bd994c04d98e4ee2cd7565b71548655fe3Ben Murdoch  // ---------------------------------------------------------
2035d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // For the HistoryURL provider new scoring experiment that is part of the
2045d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // bundled omnibox field trial.
2055d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
2065d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // Initializes the HUP |scoring_params| based on the active HUP scoring
2075d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // experiment.  If there is no such experiment, this function simply sets
2085d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // |scoring_params|->experimental_scoring_enabled to false.
2095d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  static void GetExperimentalHUPScoringParams(HUPScoringParams* scoring_params);
2105d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
211f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  // For the HQPBookmarkValue experiment that's part of the
212f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  // bundled omnibox field trial.
213f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)
214f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  // Returns the value an untyped visit to a bookmark should receive.
215f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  // Compare this value with the default of 1 for non-bookmarked untyped
216f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  // visits to pages and the default of 20 for typed visits.  Returns
217cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  // 10 if the bookmark value experiment isn't active.
218f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  static int HQPBookmarkValue();
219f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)
220f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  // ---------------------------------------------------------
221a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  // For the HQPAllowMatchInTLD experiment that's part of the
222a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  // bundled omnibox field trial.
223a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)
224a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  // Returns true if HQP should allow an input term to match in the
225a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  // top level domain (e.g., .com) of a URL.  Returns false if the
226a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  // allow match in TLD experiment isn't active.
227a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  static bool HQPAllowMatchInTLDValue();
228a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)
229a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  // ---------------------------------------------------------
230a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  // For the HQPAllowMatchInScheme experiment that's part of the
231a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  // bundled omnibox field trial.
232a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)
233a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  // Returns true if HQP should allow an input term to match in the
234a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  // scheme (e.g., http://) of a URL.  Returns false if the allow
235a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  // match in scheme experiment isn't active.
236a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  static bool HQPAllowMatchInSchemeValue();
237a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)
238a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  // ---------------------------------------------------------
23946d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)  // For the DisableInlining experiment that's part of the bundled omnibox
24046d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)  // field trial.
24146d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)
24246d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)  // Returns true if AutocompleteResult should prevent any suggestion with
24346d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)  // a non-empty |inline_autocomplete| from being the default match.  In
24446d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)  // other words, prevent an inline autocompletion from appearing as the
24546d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)  // top suggestion / within the omnibox itself, reordering matches as
24646d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)  // necessary to make this true.  Returns false if the experiment isn't
24746d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)  // active.
24846d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)  static bool DisableInlining();
24946d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)
25046d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)  // ---------------------------------------------------------
2516d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles)  // For the AnswersInSuggest experiment that's part of the bundled omnibox
2526d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles)  // field trial.
2536d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles)
2546d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles)  // Returns true if the AnswersInSuggest feature should be enabled causing
2556d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles)  // query responses such as current weather conditions or stock quotes
2566d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles)  // to be provided in the Omnibox suggestion list. Considers both the
2576d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles)  // field trial state as well as the overriding command-line flags.
2586d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles)  static bool EnableAnswersInSuggest();
2596d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles)
2606d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles)  // ---------------------------------------------------------
2616d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles)  // For the AddUWYTMatchEvenIfPromotedURLs experiment that's part of the
2626d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles)  // bundled omnibox field trial.
2636d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles)
2646d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles)  // Returns true if HistoryURL Provider should add the URL-what-you-typed match
2656d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles)  // (if valid and reasonable) even if the provider has good inline
2666d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles)  // autocompletions to offer.  Normally HistoryURL does not add the UWYT match
2676d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles)  // if there are good inline autocompletions, as the user could simply hit
2686d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles)  // backspace to delete the completion and get the what-you-typed match.
269116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  // However, for the disabling inlining experiment we want to have the UWYT
270116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  // always explicitly displayed at an option if possible.  Returns false if
271116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  // the experiment isn't active.
2726d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles)  static bool AddUWYTMatchEvenIfPromotedURLs();
2736d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles)
2746d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles)  // ---------------------------------------------------------
275116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  // For the DisplayHintTextWhenPossible experiment that's part of the
276116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  // bundled omnibox field trial.
277116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch
278116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  // Returns true if the omnibox should display hint text (Search
279116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  // <search engine> or type URL) when possible (i.e., the omnibox
280116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  // is otherwise non-empty).
281116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  static bool DisplayHintTextWhenPossible();
282116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch
283116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  // ---------------------------------------------------------
284c2db58bd994c04d98e4ee2cd7565b71548655fe3Ben Murdoch  // Exposed publicly for the sake of unittests.
285c2db58bd994c04d98e4ee2cd7565b71548655fe3Ben Murdoch  static const char kBundledExperimentFieldTrialName[];
286c2db58bd994c04d98e4ee2cd7565b71548655fe3Ben Murdoch  // Rule names used by the bundled experiment.
287c2db58bd994c04d98e4ee2cd7565b71548655fe3Ben Murdoch  static const char kShortcutsScoringMaxRelevanceRule[];
288c2db58bd994c04d98e4ee2cd7565b71548655fe3Ben Murdoch  static const char kSearchHistoryRule[];
289c2db58bd994c04d98e4ee2cd7565b71548655fe3Ben Murdoch  static const char kDemoteByTypeRule[];
290f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  static const char kHQPBookmarkValueRule[];
2915d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  static const char kHQPDiscountFrecencyWhenFewVisitsRule[];
292a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  static const char kHQPAllowMatchInTLDRule[];
293a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  static const char kHQPAllowMatchInSchemeRule[];
2945d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  static const char kZeroSuggestRule[];
2955d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  static const char kZeroSuggestVariantRule[];
29646d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)  static const char kDisableInliningRule[];
2976d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles)  static const char kAnswersInSuggestRule[];
2986d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles)  static const char kAddUWYTMatchEvenIfPromotedURLsRule[];
299116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  static const char kDisplayHintTextWhenPossibleRule[];
3005d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
3015d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // Parameter names used by the HUP new scoring experiments.
3025d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  static const char kHUPNewScoringEnabledParam[];
3035d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  static const char kHUPNewScoringTypedCountRelevanceCapParam[];
3045d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  static const char kHUPNewScoringTypedCountHalfLifeTimeParam[];
3055d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  static const char kHUPNewScoringTypedCountScoreBucketsParam[];
3065d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  static const char kHUPNewScoringVisitedCountRelevanceCapParam[];
3075d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  static const char kHUPNewScoringVisitedCountHalfLifeTimeParam[];
3085d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  static const char kHUPNewScoringVisitedCountScoreBucketsParam[];
309c2db58bd994c04d98e4ee2cd7565b71548655fe3Ben Murdoch
3105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) private:
311ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch  friend class OmniboxFieldTrialTest;
312a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)
313a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)  // The bundled omnibox experiment comes with a set of parameters
314a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)  // (key-value pairs).  Each key indicates a certain rule that applies in
315a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)  // a certain context.  The value indicates what the consequences of
316a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)  // applying the rule are.  For example, the value of a SearchHistory rule
317a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)  // in the context of a search results page might indicate that we should
318a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)  // prevent search history matches from inlining.
319a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)  //
320a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)  // This function returns the value associated with the |rule| that applies
321ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch  // in the current context (which currently consists of |page_classification|
322ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch  // and whether Instant Extended is enabled).  If no such rule exists in the
323ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch  // current context, fall back to the rule in various wildcard contexts and
324ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch  // return its value if found.  If the rule remains unfound in the global
325ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch  // context, returns the empty string.  For more details, including how we
326ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch  // prioritize different wildcard contexts, see the implementation.  How to
327ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch  // interpret the value is left to the caller; this is rule-dependent.
328a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)  static std::string GetValueForRuleInContext(
329a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)      const std::string& rule,
3306d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles)      metrics::OmniboxEventProto::PageClassification page_classification);
331a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)
3322a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  DISALLOW_IMPLICIT_CONSTRUCTORS(OmniboxFieldTrial);
3335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)};
3345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
3356e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)#endif  // COMPONENTS_OMNIBOX_OMNIBOX_FIELD_TRIAL_H_
336