OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 #include "chrome/browser/safe_browsing/certificate_reporting_service.h" | 4 #include "chrome/browser/safe_browsing/certificate_reporting_service.h" |
5 | 5 |
6 #include "base/bind_helpers.h" | 6 #include "base/bind_helpers.h" |
7 #include "base/metrics/histogram_macros.h" | 7 #include "base/metrics/histogram_macros.h" |
8 #include "base/metrics/sparse_histogram.h" | 8 #include "base/metrics/sparse_histogram.h" |
9 #include "base/time/clock.h" | 9 #include "base/time/clock.h" |
10 #include "chrome/browser/browser_process.h" | 10 #include "chrome/browser/browser_process.h" |
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
160 } | 160 } |
161 | 161 |
162 CertificateReportingService::CertificateReportingService( | 162 CertificateReportingService::CertificateReportingService( |
163 safe_browsing::SafeBrowsingService* safe_browsing_service, | 163 safe_browsing::SafeBrowsingService* safe_browsing_service, |
164 scoped_refptr<net::URLRequestContextGetter> url_request_context_getter, | 164 scoped_refptr<net::URLRequestContextGetter> url_request_context_getter, |
165 Profile* profile, | 165 Profile* profile, |
166 uint8_t server_public_key[/* 32 */], | 166 uint8_t server_public_key[/* 32 */], |
167 uint32_t server_public_key_version, | 167 uint32_t server_public_key_version, |
168 size_t max_queued_report_count, | 168 size_t max_queued_report_count, |
169 base::TimeDelta max_report_age, | 169 base::TimeDelta max_report_age, |
170 base::Clock* clock) | 170 base::Clock* clock, |
| 171 const base::Callback<void()>& reset_callback) |
171 : pref_service_(*profile->GetPrefs()), | 172 : pref_service_(*profile->GetPrefs()), |
172 url_request_context_(nullptr), | 173 url_request_context_(nullptr), |
173 max_queued_report_count_(max_queued_report_count), | 174 max_queued_report_count_(max_queued_report_count), |
174 max_report_age_(max_report_age), | 175 max_report_age_(max_report_age), |
175 clock_(clock), | 176 clock_(clock), |
| 177 reset_callback_(reset_callback), |
176 server_public_key_(server_public_key), | 178 server_public_key_(server_public_key), |
177 server_public_key_version_(server_public_key_version) { | 179 server_public_key_version_(server_public_key_version) { |
178 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 180 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
179 DCHECK(clock_); | 181 DCHECK(clock_); |
180 // Subscribe to SafeBrowsing shutdown notifications. | 182 // Subscribe to SafeBrowsing shutdown notifications. |
181 safe_browsing_service_shutdown_subscription_ = | 183 safe_browsing_service_shutdown_subscription_ = |
182 safe_browsing_service->RegisterShutdownCallback(base::Bind( | 184 safe_browsing_service->RegisterShutdownCallback(base::Bind( |
183 &CertificateReportingService::Shutdown, base::Unretained(this))); | 185 &CertificateReportingService::Shutdown, base::Unretained(this))); |
184 | 186 |
185 // Subscribe to SafeBrowsing preference change notifications. | 187 // Subscribe to SafeBrowsing preference change notifications. |
186 safe_browsing_state_subscription_ = | 188 safe_browsing_state_subscription_ = |
187 safe_browsing_service->RegisterStateCallback( | 189 safe_browsing_service->RegisterStateCallback( |
188 base::Bind(&CertificateReportingService::OnPreferenceChanged, | 190 base::Bind(&CertificateReportingService::OnPreferenceChanged, |
189 base::Unretained(this))); | 191 base::Unretained(this))); |
190 | 192 |
191 content::BrowserThread::PostTask( | 193 content::BrowserThread::PostTaskAndReply( |
192 content::BrowserThread::IO, FROM_HERE, | 194 content::BrowserThread::IO, FROM_HERE, |
193 base::Bind(&CertificateReportingService::InitializeOnIOThread, | 195 base::Bind(&CertificateReportingService::InitializeOnIOThread, |
194 base::Unretained(this), true, url_request_context_getter, | 196 base::Unretained(this), true, url_request_context_getter, |
195 max_queued_report_count_, max_report_age_, clock_, | 197 max_queued_report_count_, max_report_age_, clock_, |
196 server_public_key_, server_public_key_version_)); | 198 server_public_key_, server_public_key_version_), |
| 199 reset_callback_); |
197 } | 200 } |
198 | 201 |
199 CertificateReportingService::~CertificateReportingService() { | 202 CertificateReportingService::~CertificateReportingService() { |
200 DCHECK(!reporter_); | 203 DCHECK(!reporter_); |
201 } | 204 } |
202 | 205 |
203 void CertificateReportingService::Shutdown() { | 206 void CertificateReportingService::Shutdown() { |
204 // Shutdown will be called twice: Once after SafeBrowsing shuts down, and once | 207 // Shutdown will be called twice: Once after SafeBrowsing shuts down, and once |
205 // when all KeyedServices shut down. All calls after the first one are no-op. | 208 // when all KeyedServices shut down. All calls after the first one are no-op. |
206 url_request_context_ = nullptr; | 209 url_request_context_ = nullptr; |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
246 max_report_age, clock, server_public_key, | 249 max_report_age, clock, server_public_key, |
247 server_public_key_version); | 250 server_public_key_version); |
248 } | 251 } |
249 | 252 |
250 void CertificateReportingService::SetEnabled(bool enabled) { | 253 void CertificateReportingService::SetEnabled(bool enabled) { |
251 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 254 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
252 // Don't reset if the service is already shut down. | 255 // Don't reset if the service is already shut down. |
253 if (!url_request_context_) | 256 if (!url_request_context_) |
254 return; | 257 return; |
255 | 258 |
256 content::BrowserThread::PostTask( | 259 content::BrowserThread::PostTaskAndReply( |
257 content::BrowserThread::IO, FROM_HERE, | 260 content::BrowserThread::IO, FROM_HERE, |
258 base::Bind(&CertificateReportingService::ResetOnIOThread, | 261 base::Bind(&CertificateReportingService::ResetOnIOThread, |
259 base::Unretained(this), enabled, url_request_context_, | 262 base::Unretained(this), enabled, url_request_context_, |
260 max_queued_report_count_, max_report_age_, clock_, | 263 max_queued_report_count_, max_report_age_, clock_, |
261 server_public_key_, server_public_key_version_)); | 264 server_public_key_, server_public_key_version_), |
| 265 reset_callback_); |
262 } | 266 } |
263 | 267 |
264 CertificateReportingService::Reporter* | 268 CertificateReportingService::Reporter* |
265 CertificateReportingService::GetReporterForTesting() const { | 269 CertificateReportingService::GetReporterForTesting() const { |
266 return reporter_.get(); | 270 return reporter_.get(); |
267 } | 271 } |
268 | 272 |
269 // static | 273 // static |
270 GURL CertificateReportingService::GetReportingURLForTesting() { | 274 GURL CertificateReportingService::GetReportingURLForTesting() { |
271 return GURL(kExtendedReportingUploadUrl); | 275 return GURL(kExtendedReportingUploadUrl); |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
306 } | 310 } |
307 | 311 |
308 void CertificateReportingService::OnPreferenceChanged() { | 312 void CertificateReportingService::OnPreferenceChanged() { |
309 safe_browsing::SafeBrowsingService* safe_browsing_service_ = | 313 safe_browsing::SafeBrowsingService* safe_browsing_service_ = |
310 g_browser_process->safe_browsing_service(); | 314 g_browser_process->safe_browsing_service(); |
311 const bool enabled = safe_browsing_service_ && | 315 const bool enabled = safe_browsing_service_ && |
312 safe_browsing_service_->enabled_by_prefs() && | 316 safe_browsing_service_->enabled_by_prefs() && |
313 safe_browsing::IsExtendedReportingEnabled(pref_service_); | 317 safe_browsing::IsExtendedReportingEnabled(pref_service_); |
314 SetEnabled(enabled); | 318 SetEnabled(enabled); |
315 } | 319 } |
OLD | NEW |