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

Unified Diff: components/rappor/rappor_service.cc

Issue 1090683003: Alternative Multi-dimensional Rappor (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Use 64-bit shift Created 5 years, 8 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
« no previous file with comments | « components/rappor/rappor_service.h ('k') | components/rappor/rappor_service_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: components/rappor/rappor_service.cc
diff --git a/components/rappor/rappor_service.cc b/components/rappor/rappor_service.cc
index 7fc4fce7fb4e86f94b330d1e6a94df7927960137..9c950b5cc14a290bf4c6f023c1a1d9669fceb6a2 100644
--- a/components/rappor/rappor_service.cc
+++ b/components/rappor/rappor_service.cc
@@ -184,26 +184,23 @@ void RapporService::OnLogInterval() {
}
bool RapporService::ExportMetrics(RapporReports* reports) {
- if (metrics_map_.empty()) {
- DVLOG(2) << "metrics_map_ is empty.";
- return false;
- }
-
DCHECK_GE(cohort_, 0);
reports->set_cohort(cohort_);
- for (std::map<std::string, RapporMetric*>::const_iterator it =
- metrics_map_.begin();
- it != metrics_map_.end();
- ++it) {
- const RapporMetric* metric = it->second;
+ for (const auto& kv : metrics_map_) {
+ const RapporMetric* metric = kv.second;
RapporReports::Report* report = reports->add_report();
- report->set_name_hash(metrics::HashMetricName(it->first));
+ report->set_name_hash(metrics::HashMetricName(kv.first));
ByteVector bytes = metric->GetReport(secret_);
report->set_bits(std::string(bytes.begin(), bytes.end()));
}
STLDeleteValues(&metrics_map_);
- return true;
+
+ sampler_.ExportMetrics(secret_, reports);
+
+ DVLOG(2) << "Generated a report with " << reports->report_size()
+ << "metrics.";
+ return reports->report_size() > 0;
}
bool RapporService::IsInitialized() const {
@@ -232,7 +229,7 @@ void RapporService::RecordSampleInternal(const std::string& metric_name,
DVLOG(2) << "Metric not logged due to incognito mode.";
return;
}
- // Skip this metric if it's reporting level is less than the enabled
+ // Skip this metric if its reporting level is less than the enabled
// reporting level.
if (recording_level_ < parameters.recording_level) {
DVLOG(2) << "Metric not logged due to recording_level "
@@ -259,4 +256,27 @@ RapporMetric* RapporService::LookUpMetric(const std::string& metric_name,
return new_metric;
}
+scoped_ptr<Sample> RapporService::CreateSample(RapporType type) {
+ DCHECK(IsInitialized());
+ return scoped_ptr<Sample>(
+ new Sample(cohort_, kRapporParametersForType[type]));
+}
+
+void RapporService::RecordSampleObj(const std::string& metric_name,
+ scoped_ptr<Sample> sample) {
+ if (is_incognito_callback_.Run()) {
+ DVLOG(2) << "Metric not logged due to incognito mode.";
+ return;
+ }
+ // Skip this metric if its reporting level is less than the enabled
+ // reporting level.
+ if (recording_level_ < sample->parameters().recording_level) {
+ DVLOG(2) << "Metric not logged due to recording_level "
+ << recording_level_ << " < "
+ << sample->parameters().recording_level;
+ return;
+ }
+ sampler_.AddSample(metric_name, sample.Pass());
+}
+
} // namespace rappor
« no previous file with comments | « components/rappor/rappor_service.h ('k') | components/rappor/rappor_service_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698