Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(43)

Unified Diff: chrome/browser/metrics/chrome_metrics_services_manager_client.cc

Issue 2288853003: Adding local field trial for metrics/crash reports sampling. (Closed)
Patch Set: Adding local field trial for sampling. Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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..f6ebe6939d7ed4f967120d10d78940089bed0eb3 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.
+void AppendSamplingTrialGroup(const std::string& name,
+ 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() {
@@ -103,6 +114,35 @@ ChromeMetricsServicesManagerClient::ChromeMetricsServicesManagerClient(
ChromeMetricsServicesManagerClient::~ChromeMetricsServicesManagerClient() {}
+#if defined(OS_WIN) || defined(OS_ANDROID)
+// static
+void ChromeMetricsServicesManagerClient::CreateFallbackSamplingTrial(
+ base::FeatureList* feature_list) {
+ const std::string kTrialName = "MetricsAndCrashSampling";
Alexei Svitkine (slow) 2016/08/29 19:38:42 static const char[] same for the other ones below
jwd 2016/08/29 21:36:24 Done.
+ scoped_refptr<base::FieldTrial> trial(
+ base::FieldTrialList::FactoryGetFieldTrial(
+ kTrialName, 1000, "Default", base::FieldTrialList::kNoExpirationYear,
+ 1, 1, base::FieldTrial::ONE_TIME_RANDOMIZED, NULL));
+
+ // 100 per-mille sampling rate group.
+ const std::string kInSampleGroup = "InReportingSample";
+ AppendSamplingTrialGroup(kInSampleGroup, 100, trial.get());
+
+ // 900 per-mille sampled out.
+ const std::string 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());
+}
+#endif // defined(OS_WIN) || defined(OS_ANDROID)
+
// static
bool ChromeMetricsServicesManagerClient::IsClientInSample() {
// Only some clients are eligible for sampling. Clients that aren't eligible

Powered by Google App Engine
This is Rietveld 408576698