chrome/browser/chrome_browser_field_trials.cc
// Set up a uniformity field trial. |one_time_randomized| indicates if the
// field trial is one-time randomized or session-randomized. |trial_name_string|
// must contain a "%d" since the percentage of the group will be inserted in
// the trial name. |num_trial_groups| must be a divisor of 100 (e.g. 5, 20)
Set up a uniformity field trial. |one_time_randomized| indicates if the
field trial is one-time randomized or session-randomized. |trial_name_string|
must contain a "%d" since the percentage of the group will be inserted in
the trial name. |num_trial_groups| must be a divisor of 100
Set up a uniformity field trial . |one_time_randomized| indicates if the field trial is one - time randomized or session - randomized . |trial_name_string| must contain a " %d " since the percentage of the group will be inserted in the trial name . |num_trial_groups| must be a divisor of 100
void SetupSingleUniformityFieldTrial(
    bool one_time_randomized,
    const std::string& trial_name_string,
    const chrome_variations::VariationID trial_base_id,
    int num_trial_groups) {
  static const base::FieldTrial::Probability kProbabilityPerGroup = 1;
  const std::string kDefaultGroupName = "default";
  const base::FieldTrial::Probability divisor = num_trial_groups;
  DCHECK_EQ(100 % num_trial_groups, 0);
  const int group_percent = 100 / num_trial_groups;
  const std::string trial_name = StringPrintf(trial_name_string.c_str(),
                                              group_percent);
  DVLOG(1) << "Trial name = " << trial_name;
  scoped_refptr<base::FieldTrial> trial(
      base::FieldTrialList::FactoryGetFieldTrial(
          trial_name, divisor, kDefaultGroupName, 2015, 1, 1, NULL));
  if (one_time_randomized)
    trial->UseOneTimeRandomization();
  chrome_variations::AssociateGoogleVariationID(
      chrome_variations::GOOGLE_WEB_PROPERTIES, trial_name, kDefaultGroupName,
      trial_base_id);
  for (int group_number = 1; group_number < num_trial_groups; ++group_number) {
    const std::string group_name = StringPrintf("group_%02d", group_number);
    DVLOG(1) << "    Group name = " << group_name;
    trial->AppendGroup(group_name, kProbabilityPerGroup);
    chrome_variations::AssociateGoogleVariationID(
        chrome_variations::GOOGLE_WEB_PROPERTIES, trial_name, group_name,
        static_cast<chrome_variations::VariationID>(trial_base_id +
                                                    group_number));
  }
  const int chosen_group = trial->group();
  DVLOG(1) << "Chosen Group: " << chosen_group;
}
void SetupSingleUniformityFieldTrial ( bool one_time_randomized , const std :: string & trial_name_string , const chrome_variations :: VariationID trial_base_id , int num_trial_groups ) { static const base :: FieldTrial :: Probability kProbabilityPerGroup = 1 ; const std :: string kDefaultGroupName = " " ; const base :: FieldTrial :: Probability divisor = num_trial_groups ; DCHECK_EQ ( 100 % num_trial_groups , 0 ) ; const int group_percent = 100 / num_trial_groups ; const std :: string trial_name = StringPrintf ( trial_name_string . c_str ( ) , group_percent ) ; DVLOG ( 1 ) << " " << trial_name ; scoped_refptr < base :: FieldTrial > trial ( base :: FieldTrialList :: FactoryGetFieldTrial ( trial_name , divisor , kDefaultGroupName , 2015 , 1 , 1 , NULL ) ) ; if ( one_time_randomized ) trial -> UseOneTimeRandomization ( ) ; chrome_variations :: AssociateGoogleVariationID ( chrome_variations :: GOOGLE_WEB_PROPERTIES , trial_name , kDefaultGroupName , trial_base_id ) ; for ( int group_number = 1 ; group_number < num_trial_groups ; ++ group_number ) { const std :: string group_name = StringPrintf ( " " , group_number ) ; DVLOG ( 1 ) << " " << group_name ; trial -> AppendGroup ( group_name , kProbabilityPerGroup ) ; chrome_variations :: AssociateGoogleVariationID ( chrome_variations :: GOOGLE_WEB_PROPERTIES , trial_name , group_name , static_cast < chrome_variations :: VariationID > ( trial_base_id + group_number ) ) ; } const int chosen_group = trial -> group ( ) ; DVLOG ( 1 ) << " " << chosen_group ; }
Set up a uniformity field trial.
Set up a uniformity field trial .
// Probability per group remains constant for all uniformity trials, what // changes is the probability divisor. // Loop starts with group 1 because the field trial automatically creates a // default group, which would be group 0. // Now that all groups have been appended, call group() on the trial to // ensure that our trial is registered. This resolves an off-by-one issue // where the default group never gets chosen if we don't "use" the trial.