Chromium Code Reviews| Index: chrome/browser/metrics/chrome_metrics_services_manager_client.cc |
| diff --git a/chrome/browser/metrics/chrome_metrics_services_manager_client.cc b/chrome/browser/metrics/chrome_metrics_services_manager_client.cc |
| index 0e9c68f6f580be49c3f49e1670eb436b7154ca3b..11b08989e6a395634e4d725bec9ae007b3f18a36 100644 |
| --- a/chrome/browser/metrics/chrome_metrics_services_manager_client.cc |
| +++ b/chrome/browser/metrics/chrome_metrics_services_manager_client.cc |
| @@ -63,6 +63,17 @@ void PostStoreMetricsClientInfo(const metrics::ClientInfo& client_info) { |
| base::Bind(&GoogleUpdateSettings::StoreMetricsClientInfo, client_info)); |
| } |
| +// Appends a group to the sampling controlling |trial|. The group will be |
| +// associated with a variation param for reporting samlping |rate| in per mille. |
|
Alexei Svitkine (slow)
2016/08/30 18:17:05
Nit: "samlping" -> "sampling"
jwd
2016/08/30 18:59:41
Done.
|
| +void AppendSamplingTrialGroup(const std::string& name, |
|
Alexei Svitkine (slow)
2016/08/30 18:17:05
Nit: name -> group_name
jwd
2016/08/30 18:59:41
Done.
|
| + int rate, |
| + base::FieldTrial* trial) { |
| + std::map<std::string, std::string> params = { |
| + {kRateParamName, base::IntToString(rate)}}; |
| + variations::AssociateVariationParams(trial->trial_name(), name, params); |
| + trial->AppendGroup(name, rate); |
| +} |
| + |
| // Only clients that were given an opt-out metrics-reporting consent flow are |
| // eligible for sampling. |
| bool IsClientEligibleForSampling() { |
| @@ -104,6 +115,40 @@ ChromeMetricsServicesManagerClient::ChromeMetricsServicesManagerClient( |
| ChromeMetricsServicesManagerClient::~ChromeMetricsServicesManagerClient() {} |
| // static |
| +void ChromeMetricsServicesManagerClient::CreateFallbackSamplingTrial( |
| + base::FeatureList* feature_list) { |
| + // The trial name must be kept in sync with the server config controlling |
| + // sampling. If they don't match, then clients will be shuffled into different |
| + // groups when the server config takes over from the fallback trial. |
| + static const char kTrialName[] = "MetricsAndCrashSampling"; |
| + scoped_refptr<base::FieldTrial> trial( |
| + base::FieldTrialList::FactoryGetFieldTrial( |
| + kTrialName, 1000, "Default", base::FieldTrialList::kNoExpirationYear, |
| + 1, 1, base::FieldTrial::ONE_TIME_RANDOMIZED, NULL)); |
|
Alexei Svitkine (slow)
2016/08/30 18:17:05
Nit: nullptr
jwd
2016/08/30 18:59:41
Done.
|
| + |
| + // Like the trial name, the order that these two groups are added to the trial |
| + // must be kept in sync with the order that they appear in the server |
| + // config. |
| + |
| + // 100 per-mille sampling rate group. |
| + static const char kInSampleGroup[] = "InReportingSample"; |
| + AppendSamplingTrialGroup(kInSampleGroup, 100, trial.get()); |
| + |
| + // 900 per-mille sampled out. |
| + static const char kSampledOutGroup[] = "OutOfReportingSample"; |
| + AppendSamplingTrialGroup(kSampledOutGroup, 900, trial.get()); |
| + |
| + // Setup the feature. |
| + const std::string& group_name = trial->GetGroupNameWithoutActivation(); |
| + feature_list->RegisterFieldTrialOverride( |
| + kMetricsReportingFeature.name, |
| + group_name == kSampledOutGroup |
| + ? base::FeatureList::OVERRIDE_DISABLE_FEATURE |
| + : base::FeatureList::OVERRIDE_ENABLE_FEATURE, |
| + trial.get()); |
| +} |
| + |
| +// static |
| bool ChromeMetricsServicesManagerClient::IsClientInSample() { |
| // Only some clients are eligible for sampling. Clients that aren't eligible |
| // will always be considered "in sample". In this case, we don't want the |