Chromium Code Reviews| Index: components/rappor/rappor_service.cc |
| diff --git a/components/rappor/rappor_service.cc b/components/rappor/rappor_service.cc |
| index 6ca64b70f94b8b2cf3e8924d5949d64726bacafa..fe1de4ec424afc732372e3890a85abbc1eae493e 100644 |
| --- a/components/rappor/rappor_service.cc |
| +++ b/components/rappor/rappor_service.cc |
| @@ -41,12 +41,7 @@ const char kRapporRolloutRequireUmaParam[] = "RequireUma"; |
| // The rappor server's URL. |
| const char kDefaultServerUrl[] = "https://clients4.google.com/rappor"; |
| -GURL GetServerUrl(bool metrics_enabled) { |
| - bool require_uma = variations::GetVariationParamValue( |
| - kRapporRolloutFieldTrialName, |
| - kRapporRolloutRequireUmaParam) != "False"; |
| - if (!metrics_enabled && require_uma) |
| - return GURL(); // Invalid URL disables Rappor. |
| +GURL GetServerUrl() { |
| std::string server_url = variations::GetVariationParamValue( |
| kRapporRolloutFieldTrialName, |
| kRapporRolloutServerUrlParam); |
| @@ -56,6 +51,13 @@ GURL GetServerUrl(bool metrics_enabled) { |
| return GURL(kDefaultServerUrl); |
| } |
| +bool ShouldEnableAllMetrics(bool metrics_enabled) { |
| + bool require_uma = variations::GetVariationParamValue( |
| + kRapporRolloutFieldTrialName, |
| + kRapporRolloutRequireUmaParam) != "False"; |
|
jwd
2014/08/29 15:45:47
Super good, awesome choice for the condition!
|
| + return metrics_enabled || !require_uma; |
| +} |
| + |
| const RapporParameters kRapporParametersForType[NUM_RAPPOR_TYPES] = { |
| // ETLD_PLUS_ONE_RAPPOR_TYPE |
| {128 /* Num cohorts */, |
| @@ -64,7 +66,17 @@ const RapporParameters kRapporParametersForType[NUM_RAPPOR_TYPES] = { |
| rappor::PROBABILITY_50 /* Fake data probability */, |
| rappor::PROBABILITY_50 /* Fake one probability */, |
| rappor::PROBABILITY_75 /* One coin probability */, |
| - rappor::PROBABILITY_25 /* Zero coin probability */}, |
| + rappor::PROBABILITY_25 /* Zero coin probability */, |
| + false /* Require UMA */}, |
| + // SAFE_BROWSING_PATTERN_RAPPOR_TYPE |
| + {64 /* Num cohorts */, |
| + 16 /* Bloom filter size bytes */, |
| + 2 /* Bloom filter hash count */, |
| + rappor::PROBABILITY_50 /* Fake data probability */, |
| + rappor::PROBABILITY_50 /* Fake one probability */, |
| + rappor::PROBABILITY_75 /* One coin probability */, |
| + rappor::PROBABILITY_25 /* Zero coin probability */, |
| + true /* Don't require UMA */}, |
| }; |
| } // namespace |
| @@ -78,12 +90,14 @@ RapporService::~RapporService() { |
| void RapporService::Start(PrefService* pref_service, |
| net::URLRequestContextGetter* request_context, |
| bool metrics_enabled) { |
| - const GURL server_url = GetServerUrl(metrics_enabled); |
| + const GURL server_url = GetServerUrl(); |
| if (!server_url.is_valid()) { |
| DVLOG(1) << server_url.spec() << " is invalid. " |
| << "RapporService not started."; |
| return; |
| } |
| + all_metrics_enabled_ = ShouldEnableAllMetrics(metrics_enabled); |
| + DVLOG(1) << "RapporService all_metrics_enabled_? " << all_metrics_enabled_; |
| DVLOG(1) << "RapporService started. Reporting to " << server_url.spec(); |
| DCHECK(!uploader_); |
| LoadSecret(pref_service); |
| @@ -188,10 +202,15 @@ void RapporService::RecordSample(const std::string& metric_name, |
| if (!IsInitialized()) |
| return; |
| DCHECK_LT(type, NUM_RAPPOR_TYPES); |
| + const RapporParameters& parameters = kRapporParametersForType[type]; |
| + // Skip this metric if all metrics aren't enabled and this isn't a |
| + // whitelisted metric. |
| + if (!all_metrics_enabled_ && !parameters.always_enabled) |
| + return; |
| DVLOG(2) << "Recording sample \"" << sample |
| << "\" for metric \"" << metric_name |
| << "\" of type: " << type; |
| - RecordSampleInternal(metric_name, kRapporParametersForType[type], sample); |
| + RecordSampleInternal(metric_name, parameters, sample); |
| } |
| void RapporService::RecordSampleInternal(const std::string& metric_name, |