This source file includes following definitions.
- SetupSingleUniformityFieldTrial
- SetupNewInstallUniformityTrial
- SetupUniformityFieldTrials
#include "chrome/common/metrics/variations/uniformity_field_trials.h"
#include <string>
#include "base/metrics/field_trial.h"
#include "base/strings/stringprintf.h"
#include "base/time/time.h"
#include "chrome/common/metrics/variations/variation_ids.h"
#include "chrome/common/metrics/variations/variations_util.h"
namespace chrome_variations {
namespace {
void SetupSingleUniformityFieldTrial(
base::FieldTrial::RandomizationType randomization_type,
const std::string& trial_name_string,
const 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 = base::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,
randomization_type, NULL));
AssociateGoogleVariationID(GOOGLE_UPDATE_SERVICE, trial_name,
kDefaultGroupName, trial_base_id);
for (int group_number = 1; group_number < num_trial_groups; ++group_number) {
const std::string group_name =
base::StringPrintf("group_%02d", group_number);
DVLOG(1) << " Group name = " << group_name;
trial->AppendGroup(group_name, kProbabilityPerGroup);
AssociateGoogleVariationID(
GOOGLE_UPDATE_SERVICE, trial_name, group_name,
static_cast<VariationID>(trial_base_id + group_number));
}
const int chosen_group = trial->group();
DVLOG(1) << "Chosen Group: " << chosen_group;
}
void SetupNewInstallUniformityTrial(const base::Time install_date) {
const base::Time::Exploded kStartDate = {
2012, 11, 0, 6,
0, 0, 0, 0
};
scoped_refptr<base::FieldTrial> trial(
base::FieldTrialList::FactoryGetFieldTrial(
"UMA-New-Install-Uniformity-Trial", 100, "Disabled",
2015, 1, 1, base::FieldTrial::ONE_TIME_RANDOMIZED, NULL));
trial->AppendGroup("Control", 50);
trial->AppendGroup("Experiment", 50);
const base::Time start_date = base::Time::FromLocalExploded(kStartDate);
if (install_date < start_date)
trial->Disable();
else
trial->group();
}
}
void SetupUniformityFieldTrials(const base::Time install_date) {
base::FieldTrial* trial =
base::FieldTrialList::CreateFieldTrial("UMA-Uniformity-Trial-100-Percent",
"group_01");
trial->group();
const int num_trial_groups[] = { 100, 20, 10, 5, 2 };
const VariationID trial_base_ids[] = {
UNIFORMITY_1_PERCENT_BASE,
UNIFORMITY_5_PERCENT_BASE,
UNIFORMITY_10_PERCENT_BASE,
UNIFORMITY_20_PERCENT_BASE,
UNIFORMITY_50_PERCENT_BASE
};
const std::string kOneTimeRandomizedTrialName =
"UMA-Uniformity-Trial-%d-Percent";
for (size_t i = 0; i < arraysize(num_trial_groups); ++i) {
SetupSingleUniformityFieldTrial(base::FieldTrial::ONE_TIME_RANDOMIZED,
kOneTimeRandomizedTrialName,
trial_base_ids[i], num_trial_groups[i]);
}
const std::string kSessionRandomizedTrialName =
"UMA-Session-Randomized-Uniformity-Trial-%d-Percent";
SetupSingleUniformityFieldTrial(
base::FieldTrial::SESSION_RANDOMIZED, kSessionRandomizedTrialName,
UNIFORMITY_SESSION_RANDOMIZED_5_PERCENT_BASE, 20);
SetupNewInstallUniformityTrial(install_date);
}
}