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

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

Issue 2718253002: Remove Safebrowsing Rappor support (Closed)
Patch Set: Remove sb include Created 3 years, 9 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_impl.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_impl.h" 5 #include "components/rappor/rappor_service_impl.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 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
52 52
53 RapporServiceImpl::RapporServiceImpl( 53 RapporServiceImpl::RapporServiceImpl(
54 PrefService* pref_service, 54 PrefService* pref_service,
55 const base::Callback<bool(void)> is_incognito_callback) 55 const base::Callback<bool(void)> is_incognito_callback)
56 : pref_service_(pref_service), 56 : pref_service_(pref_service),
57 is_incognito_callback_(is_incognito_callback), 57 is_incognito_callback_(is_incognito_callback),
58 cohort_(-1), 58 cohort_(-1),
59 daily_event_(pref_service, 59 daily_event_(pref_service,
60 prefs::kRapporLastDailySample, 60 prefs::kRapporLastDailySample,
61 kRapporDailyEventHistogram), 61 kRapporDailyEventHistogram),
62 recording_groups_(0) {} 62 recording_enabled_(false) {}
63 63
64 RapporServiceImpl::~RapporServiceImpl() {} 64 RapporServiceImpl::~RapporServiceImpl() {}
65 65
66 void RapporServiceImpl::AddDailyObserver( 66 void RapporServiceImpl::AddDailyObserver(
67 std::unique_ptr<metrics::DailyEvent::Observer> observer) { 67 std::unique_ptr<metrics::DailyEvent::Observer> observer) {
68 daily_event_.AddObserver(std::move(observer)); 68 daily_event_.AddObserver(std::move(observer));
69 } 69 }
70 70
71 void RapporServiceImpl::Initialize( 71 void RapporServiceImpl::Initialize(
72 net::URLRequestContextGetter* request_context) { 72 net::URLRequestContextGetter* request_context) {
73 DCHECK(thread_checker_.CalledOnValidThread()); 73 DCHECK(thread_checker_.CalledOnValidThread());
74 DCHECK(!IsInitialized()); 74 DCHECK(!IsInitialized());
75 const GURL server_url = GetServerUrl(); 75 const GURL server_url = GetServerUrl();
76 if (!server_url.is_valid()) { 76 if (!server_url.is_valid()) {
77 DVLOG(1) << server_url.spec() << " is invalid. " 77 DVLOG(1) << server_url.spec() << " is invalid. "
78 << "RapporServiceImpl not started."; 78 << "RapporServiceImpl not started.";
79 return; 79 return;
80 } 80 }
81 DVLOG(1) << "RapporServiceImpl reporting to " << server_url.spec(); 81 DVLOG(1) << "RapporServiceImpl reporting to " << server_url.spec();
82 InitializeInternal( 82 InitializeInternal(
83 base::MakeUnique<LogUploader>(server_url, kMimeType, request_context), 83 base::MakeUnique<LogUploader>(server_url, kMimeType, request_context),
84 internal::LoadCohort(pref_service_), internal::LoadSecret(pref_service_)); 84 internal::LoadCohort(pref_service_), internal::LoadSecret(pref_service_));
85 } 85 }
86 86
87 void RapporServiceImpl::Update(int recording_groups, bool may_upload) { 87 void RapporServiceImpl::Update(bool may_record, bool may_upload) {
88 DCHECK(thread_checker_.CalledOnValidThread()); 88 DCHECK(thread_checker_.CalledOnValidThread());
89 DCHECK(IsInitialized()); 89 DCHECK(IsInitialized());
90 if (recording_groups_ != recording_groups) { 90 if (recording_enabled_ != may_record) {
91 if (recording_groups == 0) { 91 recording_enabled_ = may_record;
92 if (!may_record) {
92 DVLOG(1) << "Rappor service stopped because all groups were disabled."; 93 DVLOG(1) << "Rappor service stopped because all groups were disabled.";
93 recording_groups_ = 0;
94 CancelNextLogRotation(); 94 CancelNextLogRotation();
95 } else if (recording_groups_ == 0) { 95 } else {
96 DVLOG(1) << "RapporServiceImpl started for groups: " << recording_groups; 96 DVLOG(1) << "RapporServiceImpl started.";
97 recording_groups_ = recording_groups;
98 ScheduleNextLogRotation( 97 ScheduleNextLogRotation(
99 base::TimeDelta::FromSeconds(kInitialLogIntervalSeconds)); 98 base::TimeDelta::FromSeconds(kInitialLogIntervalSeconds));
100 } else {
101 DVLOG(1) << "RapporServiceImpl recording_groups changed:"
102 << recording_groups;
103 recording_groups_ = recording_groups;
104 } 99 }
105 } 100 }
106 101
107 DVLOG(1) << "RapporServiceImpl recording_groups=" << recording_groups_ 102 DVLOG(1) << "RapporServiceImpl recording_groups=" << recording_enabled_
108 << " may_upload=" << may_upload; 103 << " may_upload=" << may_upload;
109 if (may_upload) { 104 if (may_upload) {
110 uploader_->Start(); 105 uploader_->Start();
111 } else { 106 } else {
112 uploader_->Stop(); 107 uploader_->Stop();
113 } 108 }
114 } 109 }
115 110
116 // static 111 // static
117 void RapporServiceImpl::RegisterPrefs(PrefRegistrySimple* registry) { 112 void RapporServiceImpl::RegisterPrefs(PrefRegistrySimple* registry) {
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
184 return cohort_ >= 0; 179 return cohort_ >= 0;
185 } 180 }
186 181
187 bool RapporServiceImpl::RecordingAllowed(const RapporParameters& parameters) { 182 bool RapporServiceImpl::RecordingAllowed(const RapporParameters& parameters) {
188 // Skip recording in incognito mode. 183 // Skip recording in incognito mode.
189 if (is_incognito_callback_.Run()) { 184 if (is_incognito_callback_.Run()) {
190 DVLOG(2) << "Metric not logged due to incognito mode."; 185 DVLOG(2) << "Metric not logged due to incognito mode.";
191 return false; 186 return false;
192 } 187 }
193 // Skip this metric if its recording_group is not enabled. 188 // Skip this metric if its recording_group is not enabled.
194 if (!(recording_groups_ & parameters.recording_group)) { 189 if (!recording_enabled_) {
195 DVLOG(2) << "Metric not logged due to recording_group " << recording_groups_ 190 DVLOG(2) << "Metric not logged due to recording_enabled_ = false.";
196 << " < " << parameters.recording_group;
197 return false; 191 return false;
198 } 192 }
199 return true; 193 return true;
200 } 194 }
201 195
202 void RapporServiceImpl::RecordSampleString(const std::string& metric_name, 196 void RapporServiceImpl::RecordSampleString(const std::string& metric_name,
203 RapporType type, 197 RapporType type,
204 const std::string& sample) { 198 const std::string& sample) {
205 DCHECK(thread_checker_.CalledOnValidThread()); 199 DCHECK(thread_checker_.CalledOnValidThread());
206 // Ignore the sample if the service hasn't started yet. 200 // Ignore the sample if the service hasn't started yet.
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
251 void RapporServiceImpl::RecordSample(const std::string& metric_name, 245 void RapporServiceImpl::RecordSample(const std::string& metric_name,
252 std::unique_ptr<Sample> sample) { 246 std::unique_ptr<Sample> sample) {
253 DCHECK(thread_checker_.CalledOnValidThread()); 247 DCHECK(thread_checker_.CalledOnValidThread());
254 if (!RecordingAllowed(sample->parameters())) 248 if (!RecordingAllowed(sample->parameters()))
255 return; 249 return;
256 DVLOG(1) << "Recording sample of metric \"" << metric_name << "\""; 250 DVLOG(1) << "Recording sample of metric \"" << metric_name << "\"";
257 sampler_.AddSample(metric_name, std::move(sample)); 251 sampler_.AddSample(metric_name, std::move(sample));
258 } 252 }
259 253
260 } // namespace rappor 254 } // namespace rappor
OLDNEW
« no previous file with comments | « components/rappor/rappor_service_impl.h ('k') | components/rappor/rappor_service_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698