OLD | NEW |
---|---|
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "components/rappor/rappor_service.h" | 5 #include "components/rappor/rappor_service.h" |
6 | 6 |
7 #include "base/metrics/field_trial.h" | 7 #include "base/metrics/field_trial.h" |
8 #include "base/metrics/user_metrics.h" | |
8 #include "base/stl_util.h" | 9 #include "base/stl_util.h" |
9 #include "base/time/time.h" | 10 #include "base/time/time.h" |
10 #include "components/metrics/metrics_hashes.h" | 11 #include "components/metrics/metrics_hashes.h" |
11 #include "components/rappor/log_uploader.h" | 12 #include "components/rappor/log_uploader.h" |
12 #include "components/rappor/proto/rappor_metric.pb.h" | 13 #include "components/rappor/proto/rappor_metric.pb.h" |
13 #include "components/rappor/rappor_metric.h" | 14 #include "components/rappor/rappor_metric.h" |
14 #include "components/rappor/rappor_pref_names.h" | 15 #include "components/rappor/rappor_pref_names.h" |
15 #include "components/rappor/rappor_prefs.h" | 16 #include "components/rappor/rappor_prefs.h" |
16 #include "components/variations/variations_associated_data.h" | 17 #include "components/variations/variations_associated_data.h" |
17 | 18 |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
98 DVLOG(1) << server_url.spec() << " is invalid. " | 99 DVLOG(1) << server_url.spec() << " is invalid. " |
99 << "RapporService not started."; | 100 << "RapporService not started."; |
100 return; | 101 return; |
101 } | 102 } |
102 DVLOG(1) << "RapporService reporting to " << server_url.spec(); | 103 DVLOG(1) << "RapporService reporting to " << server_url.spec(); |
103 InitializeInternal(make_scoped_ptr(new LogUploader(server_url, | 104 InitializeInternal(make_scoped_ptr(new LogUploader(server_url, |
104 kMimeType, | 105 kMimeType, |
105 request_context)), | 106 request_context)), |
106 internal::LoadCohort(pref_service_), | 107 internal::LoadCohort(pref_service_), |
107 internal::LoadSecret(pref_service_)); | 108 internal::LoadSecret(pref_service_)); |
109 | |
110 EnableRecordFromUserMetrics(); | |
108 } | 111 } |
109 | 112 |
110 void RapporService::Update(RecordingLevel recording_level, bool may_upload) { | 113 void RapporService::Update(RecordingLevel recording_level, bool may_upload) { |
111 DCHECK(IsInitialized()); | 114 DCHECK(IsInitialized()); |
112 if (recording_level_ != recording_level) { | 115 if (recording_level_ != recording_level) { |
113 if (recording_level == RECORDING_DISABLED) { | 116 if (recording_level == RECORDING_DISABLED) { |
114 DVLOG(1) << "Rappor service stopped due to RECORDING_DISABLED."; | 117 DVLOG(1) << "Rappor service stopped due to RECORDING_DISABLED."; |
115 recording_level_ = RECORDING_DISABLED; | 118 recording_level_ = RECORDING_DISABLED; |
116 CancelNextLogRotation(); | 119 CancelNextLogRotation(); |
117 } else if (recording_level_ == RECORDING_DISABLED) { | 120 } else if (recording_level_ == RECORDING_DISABLED) { |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
176 std::string log_text; | 179 std::string log_text; |
177 bool success = reports.SerializeToString(&log_text); | 180 bool success = reports.SerializeToString(&log_text); |
178 DCHECK(success); | 181 DCHECK(success); |
179 DVLOG(1) << "RapporService sending a report of " | 182 DVLOG(1) << "RapporService sending a report of " |
180 << reports.report_size() << " value(s)."; | 183 << reports.report_size() << " value(s)."; |
181 uploader_->QueueLog(log_text); | 184 uploader_->QueueLog(log_text); |
182 } | 185 } |
183 ScheduleNextLogRotation(base::TimeDelta::FromSeconds(kLogIntervalSeconds)); | 186 ScheduleNextLogRotation(base::TimeDelta::FromSeconds(kLogIntervalSeconds)); |
184 } | 187 } |
185 | 188 |
189 void RapporService::EnableRecordFromUserMetrics() { | |
190 user_metrics_callback_ = base::Bind(&RapporService::OnUserMetricsCallback, | |
191 base::Unretained(this)); | |
192 base::AddRapporCallback(user_metrics_callback_); | |
193 } | |
194 | |
195 void RapporService::OnUserMetricsCallback( | |
196 const std::string& metric, | |
197 const std::string& sample) { | |
198 RecordSample(metric, COARSE_RAPPOR_TYPE, sample); | |
Steven Holte
2015/03/23 20:34:06
This should probably be ETLD_PLUS_ONE type or just
| |
199 } | |
200 | |
186 bool RapporService::ExportMetrics(RapporReports* reports) { | 201 bool RapporService::ExportMetrics(RapporReports* reports) { |
187 if (metrics_map_.empty()) { | 202 if (metrics_map_.empty()) { |
188 DVLOG(2) << "metrics_map_ is empty."; | 203 DVLOG(2) << "metrics_map_ is empty."; |
189 return false; | 204 return false; |
190 } | 205 } |
191 | 206 |
192 DCHECK_GE(cohort_, 0); | 207 DCHECK_GE(cohort_, 0); |
193 reports->set_cohort(cohort_); | 208 reports->set_cohort(cohort_); |
194 | 209 |
195 for (std::map<std::string, RapporMetric*>::const_iterator it = | 210 for (std::map<std::string, RapporMetric*>::const_iterator it = |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
253 DCHECK_EQ(parameters.ToString(), metric->parameters().ToString()); | 268 DCHECK_EQ(parameters.ToString(), metric->parameters().ToString()); |
254 return metric; | 269 return metric; |
255 } | 270 } |
256 | 271 |
257 RapporMetric* new_metric = new RapporMetric(metric_name, parameters, cohort_); | 272 RapporMetric* new_metric = new RapporMetric(metric_name, parameters, cohort_); |
258 metrics_map_[metric_name] = new_metric; | 273 metrics_map_[metric_name] = new_metric; |
259 return new_metric; | 274 return new_metric; |
260 } | 275 } |
261 | 276 |
262 } // namespace rappor | 277 } // namespace rappor |
OLD | NEW |