| Index: components/rappor/rappor_service.cc
|
| diff --git a/components/rappor/rappor_service.cc b/components/rappor/rappor_service.cc
|
| index 7fc4fce7fb4e86f94b330d1e6a94df7927960137..54953b55727986ea859d93649befdd58eedaed09 100644
|
| --- a/components/rappor/rappor_service.cc
|
| +++ b/components/rappor/rappor_service.cc
|
| @@ -48,19 +48,41 @@ GURL GetServerUrl() {
|
| }
|
|
|
| const RapporParameters kRapporParametersForType[NUM_RAPPOR_TYPES] = {
|
| - // ETLD_PLUS_ONE_RAPPOR_TYPE
|
| + // UMA_STRING_RAPPOR_TYPE
|
| {128 /* Num cohorts */,
|
| 16 /* Bloom filter size bytes */,
|
| 2 /* Bloom filter hash count */,
|
| + 0, /* Flag bytes */
|
| rappor::PROBABILITY_50 /* Fake data probability */,
|
| rappor::PROBABILITY_50 /* Fake one probability */,
|
| rappor::PROBABILITY_75 /* One coin probability */,
|
| rappor::PROBABILITY_25 /* Zero coin probability */,
|
| FINE_LEVEL /* Recording level */},
|
| - // COARSE_RAPPOR_TYPE
|
| + // UMA_STRING_AND_FLAGS_RAPPOR_TYPE
|
| + {128 /* Num cohorts */,
|
| + 4 /* Bloom filter size bytes */,
|
| + 2 /* Bloom filter hash count */,
|
| + 4, /* Flag bytes */
|
| + rappor::PROBABILITY_50 /* Fake data probability */,
|
| + rappor::PROBABILITY_50 /* Fake one probability */,
|
| + rappor::PROBABILITY_75 /* One coin probability */,
|
| + rappor::PROBABILITY_25 /* Zero coin probability */,
|
| + FINE_LEVEL /* Recording level */},
|
| + // SB_STRING_RAPPOR_TYPE
|
| {128 /* Num cohorts */,
|
| 1 /* Bloom filter size bytes */,
|
| 2 /* Bloom filter hash count */,
|
| + 0, /* Flag bytes */
|
| + rappor::PROBABILITY_50 /* Fake data probability */,
|
| + rappor::PROBABILITY_50 /* Fake one probability */,
|
| + rappor::PROBABILITY_75 /* One coin probability */,
|
| + rappor::PROBABILITY_25 /* Zero coin probability */,
|
| + COARSE_LEVEL /* Recording level */},
|
| + // SB_STRING_AND_FLAGS_RAPPOR_TYPE
|
| + {128 /* Num cohorts */,
|
| + 1 /* Bloom filter size bytes */,
|
| + 2 /* Bloom filter hash count */,
|
| + 1, /* Flag bytes */
|
| rappor::PROBABILITY_50 /* Fake data probability */,
|
| rappor::PROBABILITY_50 /* Fake one probability */,
|
| rappor::PROBABILITY_75 /* One coin probability */,
|
| @@ -192,11 +214,11 @@ bool RapporService::ExportMetrics(RapporReports* reports) {
|
| DCHECK_GE(cohort_, 0);
|
| reports->set_cohort(cohort_);
|
|
|
| - for (std::map<std::string, RapporMetric*>::const_iterator it =
|
| + for (std::map<std::string, internal::RapporMetric*>::const_iterator it =
|
| metrics_map_.begin();
|
| it != metrics_map_.end();
|
| ++it) {
|
| - const RapporMetric* metric = it->second;
|
| + const internal::RapporMetric* metric = it->second;
|
| RapporReports::Report* report = reports->add_report();
|
| report->set_name_hash(metrics::HashMetricName(it->first));
|
| ByteVector bytes = metric->GetReport(secret_);
|
| @@ -212,21 +234,30 @@ bool RapporService::IsInitialized() const {
|
|
|
| void RapporService::RecordSample(const std::string& metric_name,
|
| RapporType type,
|
| - const std::string& sample) {
|
| + const std::string& str) {
|
| + RecordStringAndFlags(metric_name, type, str, 0);
|
| +}
|
| +
|
| +void RapporService::RecordStringAndFlags(const std::string& metric_name,
|
| + RapporType type,
|
| + const std::string& str,
|
| + uint64_t flags) {
|
| // Ignore the sample if the service hasn't started yet.
|
| if (!IsInitialized())
|
| return;
|
| DCHECK_LT(type, NUM_RAPPOR_TYPES);
|
| const RapporParameters& parameters = kRapporParametersForType[type];
|
| - DVLOG(2) << "Recording sample \"" << sample
|
| - << "\" for metric \"" << metric_name
|
| + DVLOG(2) << "Recording sample \"" << str << "\"," << flags
|
| + << " for metric \"" << metric_name
|
| << "\" of type: " << type;
|
| + internal::Sample sample;
|
| + internal::SetSampleBits(parameters, cohort_, str, flags, &sample);
|
| RecordSampleInternal(metric_name, parameters, sample);
|
| }
|
|
|
| void RapporService::RecordSampleInternal(const std::string& metric_name,
|
| const RapporParameters& parameters,
|
| - const std::string& sample) {
|
| + const internal::Sample& sample) {
|
| DCHECK(IsInitialized());
|
| if (is_incognito_callback_.Run()) {
|
| DVLOG(2) << "Metric not logged due to incognito mode.";
|
| @@ -239,22 +270,24 @@ void RapporService::RecordSampleInternal(const std::string& metric_name,
|
| << recording_level_ << " < " << parameters.recording_level;
|
| return;
|
| }
|
| - RapporMetric* metric = LookUpMetric(metric_name, parameters);
|
| + internal::RapporMetric* metric = LookUpMetric(metric_name, parameters);
|
| metric->AddSample(sample);
|
| }
|
|
|
| -RapporMetric* RapporService::LookUpMetric(const std::string& metric_name,
|
| - const RapporParameters& parameters) {
|
| +internal::RapporMetric* RapporService::LookUpMetric(
|
| + const std::string& metric_name,
|
| + const RapporParameters& parameters) {
|
| DCHECK(IsInitialized());
|
| - std::map<std::string, RapporMetric*>::const_iterator it =
|
| + std::map<std::string, internal::RapporMetric*>::const_iterator it =
|
| metrics_map_.find(metric_name);
|
| if (it != metrics_map_.end()) {
|
| - RapporMetric* metric = it->second;
|
| + internal::RapporMetric* metric = it->second;
|
| DCHECK_EQ(parameters.ToString(), metric->parameters().ToString());
|
| return metric;
|
| }
|
|
|
| - RapporMetric* new_metric = new RapporMetric(metric_name, parameters, cohort_);
|
| + internal::RapporMetric* new_metric =
|
| + new internal::RapporMetric(metric_name, parameters);
|
| metrics_map_[metric_name] = new_metric;
|
| return new_metric;
|
| }
|
|
|