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 <utility> | 7 #include <utility> |
8 | 8 |
9 #include "base/memory/ptr_util.h" | 9 #include "base/memory/ptr_util.h" |
10 #include "base/metrics/field_trial.h" | 10 #include "base/metrics/field_trial.h" |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
58 : pref_service_(pref_service), | 58 : pref_service_(pref_service), |
59 is_incognito_callback_(is_incognito_callback), | 59 is_incognito_callback_(is_incognito_callback), |
60 cohort_(-1), | 60 cohort_(-1), |
61 daily_event_(pref_service, | 61 daily_event_(pref_service, |
62 prefs::kRapporLastDailySample, | 62 prefs::kRapporLastDailySample, |
63 kRapporDailyEventHistogram), | 63 kRapporDailyEventHistogram), |
64 recording_groups_(0) { | 64 recording_groups_(0) { |
65 } | 65 } |
66 | 66 |
67 RapporService::~RapporService() { | 67 RapporService::~RapporService() { |
68 STLDeleteValues(&metrics_map_); | 68 base::STLDeleteValues(&metrics_map_); |
69 } | 69 } |
70 | 70 |
71 void RapporService::AddDailyObserver( | 71 void RapporService::AddDailyObserver( |
72 std::unique_ptr<metrics::DailyEvent::Observer> observer) { | 72 std::unique_ptr<metrics::DailyEvent::Observer> observer) { |
73 daily_event_.AddObserver(std::move(observer)); | 73 daily_event_.AddObserver(std::move(observer)); |
74 } | 74 } |
75 | 75 |
76 void RapporService::Initialize(net::URLRequestContextGetter* request_context) { | 76 void RapporService::Initialize(net::URLRequestContextGetter* request_context) { |
77 DCHECK(thread_checker_.CalledOnValidThread()); | 77 DCHECK(thread_checker_.CalledOnValidThread()); |
78 DCHECK(!IsInitialized()); | 78 DCHECK(!IsInitialized()); |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
129 DCHECK(thread_checker_.CalledOnValidThread()); | 129 DCHECK(thread_checker_.CalledOnValidThread()); |
130 DCHECK(!IsInitialized()); | 130 DCHECK(!IsInitialized()); |
131 DCHECK(secret_.empty()); | 131 DCHECK(secret_.empty()); |
132 uploader_.swap(uploader); | 132 uploader_.swap(uploader); |
133 cohort_ = cohort; | 133 cohort_ = cohort; |
134 secret_ = secret; | 134 secret_ = secret; |
135 } | 135 } |
136 | 136 |
137 void RapporService::CancelNextLogRotation() { | 137 void RapporService::CancelNextLogRotation() { |
138 DCHECK(thread_checker_.CalledOnValidThread()); | 138 DCHECK(thread_checker_.CalledOnValidThread()); |
139 STLDeleteValues(&metrics_map_); | 139 base::STLDeleteValues(&metrics_map_); |
140 log_rotation_timer_.Stop(); | 140 log_rotation_timer_.Stop(); |
141 } | 141 } |
142 | 142 |
143 void RapporService::ScheduleNextLogRotation(base::TimeDelta interval) { | 143 void RapporService::ScheduleNextLogRotation(base::TimeDelta interval) { |
144 log_rotation_timer_.Start(FROM_HERE, | 144 log_rotation_timer_.Start(FROM_HERE, |
145 interval, | 145 interval, |
146 this, | 146 this, |
147 &RapporService::OnLogInterval); | 147 &RapporService::OnLogInterval); |
148 } | 148 } |
149 | 149 |
(...skipping 20 matching lines...) Expand all Loading... |
170 reports->set_cohort(cohort_); | 170 reports->set_cohort(cohort_); |
171 | 171 |
172 for (const auto& kv : metrics_map_) { | 172 for (const auto& kv : metrics_map_) { |
173 const RapporMetric* metric = kv.second; | 173 const RapporMetric* metric = kv.second; |
174 RapporReports::Report* report = reports->add_report(); | 174 RapporReports::Report* report = reports->add_report(); |
175 report->set_name_hash(base::HashMetricName(kv.first)); | 175 report->set_name_hash(base::HashMetricName(kv.first)); |
176 ByteVector bytes = metric->GetReport(secret_); | 176 ByteVector bytes = metric->GetReport(secret_); |
177 report->set_bits(std::string(bytes.begin(), bytes.end())); | 177 report->set_bits(std::string(bytes.begin(), bytes.end())); |
178 DVLOG(2) << "Exporting metric " << kv.first; | 178 DVLOG(2) << "Exporting metric " << kv.first; |
179 } | 179 } |
180 STLDeleteValues(&metrics_map_); | 180 base::STLDeleteValues(&metrics_map_); |
181 | 181 |
182 sampler_.ExportMetrics(secret_, reports); | 182 sampler_.ExportMetrics(secret_, reports); |
183 | 183 |
184 DVLOG(2) << "Generated a report with " << reports->report_size() | 184 DVLOG(2) << "Generated a report with " << reports->report_size() |
185 << " metrics."; | 185 << " metrics."; |
186 return reports->report_size() > 0; | 186 return reports->report_size() > 0; |
187 } | 187 } |
188 | 188 |
189 bool RapporService::IsInitialized() const { | 189 bool RapporService::IsInitialized() const { |
190 return cohort_ >= 0; | 190 return cohort_ >= 0; |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
258 void RapporService::RecordSampleObj(const std::string& metric_name, | 258 void RapporService::RecordSampleObj(const std::string& metric_name, |
259 std::unique_ptr<Sample> sample) { | 259 std::unique_ptr<Sample> sample) { |
260 DCHECK(thread_checker_.CalledOnValidThread()); | 260 DCHECK(thread_checker_.CalledOnValidThread()); |
261 if (!RecordingAllowed(sample->parameters())) | 261 if (!RecordingAllowed(sample->parameters())) |
262 return; | 262 return; |
263 DVLOG(1) << "Recording sample of metric \"" << metric_name << "\""; | 263 DVLOG(1) << "Recording sample of metric \"" << metric_name << "\""; |
264 sampler_.AddSample(metric_name, std::move(sample)); | 264 sampler_.AddSample(metric_name, std::move(sample)); |
265 } | 265 } |
266 | 266 |
267 } // namespace rappor | 267 } // namespace rappor |
OLD | NEW |