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

Side by Side Diff: components/rappor/rappor_service.cc

Issue 1921923002: Convert //components/[o-t]* from scoped_ptr to std::unique_ptr (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: . Created 4 years, 7 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 unified diff | 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 »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/metrics/field_trial.h" 10 #include "base/metrics/field_trial.h"
10 #include "base/metrics/metrics_hashes.h" 11 #include "base/metrics/metrics_hashes.h"
11 #include "base/stl_util.h" 12 #include "base/stl_util.h"
12 #include "base/time/time.h" 13 #include "base/time/time.h"
13 #include "components/rappor/log_uploader.h" 14 #include "components/rappor/log_uploader.h"
14 #include "components/rappor/proto/rappor_metric.pb.h" 15 #include "components/rappor/proto/rappor_metric.pb.h"
15 #include "components/rappor/rappor_metric.h" 16 #include "components/rappor/rappor_metric.h"
16 #include "components/rappor/rappor_pref_names.h" 17 #include "components/rappor/rappor_pref_names.h"
17 #include "components/rappor/rappor_prefs.h" 18 #include "components/rappor/rappor_prefs.h"
18 #include "components/variations/variations_associated_data.h" 19 #include "components/variations/variations_associated_data.h"
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
61 prefs::kRapporLastDailySample, 62 prefs::kRapporLastDailySample,
62 kRapporDailyEventHistogram), 63 kRapporDailyEventHistogram),
63 recording_groups_(0) { 64 recording_groups_(0) {
64 } 65 }
65 66
66 RapporService::~RapporService() { 67 RapporService::~RapporService() {
67 STLDeleteValues(&metrics_map_); 68 STLDeleteValues(&metrics_map_);
68 } 69 }
69 70
70 void RapporService::AddDailyObserver( 71 void RapporService::AddDailyObserver(
71 scoped_ptr<metrics::DailyEvent::Observer> observer) { 72 std::unique_ptr<metrics::DailyEvent::Observer> observer) {
72 daily_event_.AddObserver(std::move(observer)); 73 daily_event_.AddObserver(std::move(observer));
73 } 74 }
74 75
75 void RapporService::Initialize(net::URLRequestContextGetter* request_context) { 76 void RapporService::Initialize(net::URLRequestContextGetter* request_context) {
76 DCHECK(thread_checker_.CalledOnValidThread()); 77 DCHECK(thread_checker_.CalledOnValidThread());
77 DCHECK(!IsInitialized()); 78 DCHECK(!IsInitialized());
78 const GURL server_url = GetServerUrl(); 79 const GURL server_url = GetServerUrl();
79 if (!server_url.is_valid()) { 80 if (!server_url.is_valid()) {
80 DVLOG(1) << server_url.spec() << " is invalid. " 81 DVLOG(1) << server_url.spec() << " is invalid. "
81 << "RapporService not started."; 82 << "RapporService not started.";
82 return; 83 return;
83 } 84 }
84 DVLOG(1) << "RapporService reporting to " << server_url.spec(); 85 DVLOG(1) << "RapporService reporting to " << server_url.spec();
85 InitializeInternal(make_scoped_ptr(new LogUploader(server_url, 86 InitializeInternal(
86 kMimeType, 87 base::WrapUnique(new LogUploader(server_url, kMimeType, request_context)),
87 request_context)), 88 internal::LoadCohort(pref_service_), internal::LoadSecret(pref_service_));
88 internal::LoadCohort(pref_service_),
89 internal::LoadSecret(pref_service_));
90 } 89 }
91 90
92 void RapporService::Update(int recording_groups, bool may_upload) { 91 void RapporService::Update(int recording_groups, bool may_upload) {
93 DCHECK(thread_checker_.CalledOnValidThread()); 92 DCHECK(thread_checker_.CalledOnValidThread());
94 DCHECK(IsInitialized()); 93 DCHECK(IsInitialized());
95 if (recording_groups_ != recording_groups) { 94 if (recording_groups_ != recording_groups) {
96 if (recording_groups == 0) { 95 if (recording_groups == 0) {
97 DVLOG(1) << "Rappor service stopped because all groups were disabled."; 96 DVLOG(1) << "Rappor service stopped because all groups were disabled.";
98 recording_groups_ = 0; 97 recording_groups_ = 0;
99 CancelNextLogRotation(); 98 CancelNextLogRotation();
(...skipping 17 matching lines...) Expand all
117 uploader_->Stop(); 116 uploader_->Stop();
118 } 117 }
119 } 118 }
120 119
121 // static 120 // static
122 void RapporService::RegisterPrefs(PrefRegistrySimple* registry) { 121 void RapporService::RegisterPrefs(PrefRegistrySimple* registry) {
123 internal::RegisterPrefs(registry); 122 internal::RegisterPrefs(registry);
124 } 123 }
125 124
126 void RapporService::InitializeInternal( 125 void RapporService::InitializeInternal(
127 scoped_ptr<LogUploaderInterface> uploader, 126 std::unique_ptr<LogUploaderInterface> uploader,
128 int32_t cohort, 127 int32_t cohort,
129 const std::string& secret) { 128 const std::string& secret) {
130 DCHECK(thread_checker_.CalledOnValidThread()); 129 DCHECK(thread_checker_.CalledOnValidThread());
131 DCHECK(!IsInitialized()); 130 DCHECK(!IsInitialized());
132 DCHECK(secret_.empty()); 131 DCHECK(secret_.empty());
133 uploader_.swap(uploader); 132 uploader_.swap(uploader);
134 cohort_ = cohort; 133 cohort_ = cohort;
135 secret_ = secret; 134 secret_ = secret;
136 } 135 }
137 136
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
242 RapporMetric* metric = it->second; 241 RapporMetric* metric = it->second;
243 DCHECK_EQ(parameters.ToString(), metric->parameters().ToString()); 242 DCHECK_EQ(parameters.ToString(), metric->parameters().ToString());
244 return metric; 243 return metric;
245 } 244 }
246 245
247 RapporMetric* new_metric = new RapporMetric(metric_name, parameters, cohort_); 246 RapporMetric* new_metric = new RapporMetric(metric_name, parameters, cohort_);
248 metrics_map_[metric_name] = new_metric; 247 metrics_map_[metric_name] = new_metric;
249 return new_metric; 248 return new_metric;
250 } 249 }
251 250
252 scoped_ptr<Sample> RapporService::CreateSample(RapporType type) { 251 std::unique_ptr<Sample> RapporService::CreateSample(RapporType type) {
253 DCHECK(thread_checker_.CalledOnValidThread()); 252 DCHECK(thread_checker_.CalledOnValidThread());
254 DCHECK(IsInitialized()); 253 DCHECK(IsInitialized());
255 return scoped_ptr<Sample>( 254 return base::WrapUnique(
256 new Sample(cohort_, internal::kRapporParametersForType[type])); 255 new Sample(cohort_, internal::kRapporParametersForType[type]));
257 } 256 }
258 257
259 void RapporService::RecordSampleObj(const std::string& metric_name, 258 void RapporService::RecordSampleObj(const std::string& metric_name,
260 scoped_ptr<Sample> sample) { 259 std::unique_ptr<Sample> sample) {
261 DCHECK(thread_checker_.CalledOnValidThread()); 260 DCHECK(thread_checker_.CalledOnValidThread());
262 if (!RecordingAllowed(sample->parameters())) 261 if (!RecordingAllowed(sample->parameters()))
263 return; 262 return;
264 DVLOG(1) << "Recording sample of metric \"" << metric_name << "\""; 263 DVLOG(1) << "Recording sample of metric \"" << metric_name << "\"";
265 sampler_.AddSample(metric_name, std::move(sample)); 264 sampler_.AddSample(metric_name, std::move(sample));
266 } 265 }
267 266
268 } // namespace rappor 267 } // namespace rappor
OLDNEW
« 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