#include "chrome/browser/metrics/chrome_browser_sampling_trials.h"
#include "base/feature_list.h"
#include "base/metrics/field_trial.h"
#include "base/metrics/field_trial_params.h"
#include "base/strings/string_number_conversions.h"
#include "chrome/browser/metrics/chrome_metrics_services_manager_client.h"
#include "chrome/common/channel_info.h"
#include "components/ukm/ukm_recorder_impl.h"
#include "components/version_info/channel.h"
namespace metrics {
namespace {
#if BUILDFLAG(IS_WIN) || BUILDFLAG(IS_ANDROID)
constexpr char kSamplingTrialName[] = "MetricsAndCrashSampling";
#endif
#if BUILDFLAG(IS_ANDROID)
constexpr char kPostFREFixSamplingTrialName[] =
"PostFREFixMetricsAndCrashSampling";
#endif
constexpr char kUkmSamplingTrialName[] = …;
#if BUILDFLAG(IS_WIN) || BUILDFLAG(IS_ANDROID)
void AppendSamplingTrialGroup(const std::string& group_name,
int rate,
base::FieldTrial* trial) {
std::map<std::string, std::string> params = {
{metrics::internal::kRateParamName, base::NumberToString(rate)}};
base::AssociateFieldTrialParams(trial->trial_name(), group_name, params);
trial->AppendGroup(group_name, rate);
}
void CreateFallbackSamplingTrial(
const base::FieldTrial::EntropyProvider& entropy_provider,
const std::string& trial_name,
const std::string& feature_name,
const int sampled_in_rate_per_mille,
const bool starts_active,
base::FeatureList* feature_list) {
scoped_refptr<base::FieldTrial> trial(
base::FieldTrialList::FactoryGetFieldTrial(
trial_name, 1000, "Default", entropy_provider));
const char kSampledOutGroup[] = "OutOfReportingSample";
const int sampled_out_rate_per_mille = 1000 - sampled_in_rate_per_mille;
AppendSamplingTrialGroup(kSampledOutGroup, sampled_out_rate_per_mille,
trial.get());
const char kInSampleGroup[] = "InReportingSample";
AppendSamplingTrialGroup(kInSampleGroup, sampled_in_rate_per_mille,
trial.get());
const std::string& group_name = trial->GetGroupNameWithoutActivation();
feature_list->RegisterFieldTrialOverride(
feature_name,
group_name == kSampledOutGroup
? base::FeatureList::OVERRIDE_DISABLE_FEATURE
: base::FeatureList::OVERRIDE_ENABLE_FEATURE,
trial.get());
if (starts_active) {
trial->Activate();
}
}
#endif
void CreateFallbackUkmSamplingTrial(
const base::FieldTrial::EntropyProvider& entropy_provider,
bool is_stable_channel,
base::FeatureList* feature_list) { … }
}
void CreateFallbackSamplingTrialsIfNeeded(
const base::FieldTrial::EntropyProvider& entropy_provider,
base::FeatureList* feature_list) { … }
void CreateFallbackUkmSamplingTrialIfNeeded(
const base::FieldTrial::EntropyProvider& entropy_provider,
base::FeatureList* feature_list) { … }
}