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 185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
196 &CertificateReportingService::Shutdown, base::Unretained(this))); | 196 &CertificateReportingService::Shutdown, base::Unretained(this))); |
197 | 197 |
198 // Subscribe to SafeBrowsing preference change notifications. | 198 // Subscribe to SafeBrowsing preference change notifications. |
199 safe_browsing_state_subscription_ = | 199 safe_browsing_state_subscription_ = |
200 safe_browsing_service->RegisterStateCallback( | 200 safe_browsing_service->RegisterStateCallback( |
201 base::Bind(&CertificateReportingService::OnPreferenceChanged, | 201 base::Bind(&CertificateReportingService::OnPreferenceChanged, |
202 base::Unretained(this))); | 202 base::Unretained(this))); |
203 | 203 |
204 content::BrowserThread::PostTaskAndReply( | 204 content::BrowserThread::PostTaskAndReply( |
205 content::BrowserThread::IO, FROM_HERE, | 205 content::BrowserThread::IO, FROM_HERE, |
206 base::Bind(&CertificateReportingService::InitializeOnIOThread, | 206 base::BindOnce(&CertificateReportingService::InitializeOnIOThread, |
207 base::Unretained(this), true, url_request_context_getter, | 207 base::Unretained(this), true, url_request_context_getter, |
208 max_queued_report_count_, max_report_age_, clock_, | 208 max_queued_report_count_, max_report_age_, clock_, |
209 server_public_key_, server_public_key_version_), | 209 server_public_key_, server_public_key_version_), |
210 reset_callback_); | 210 reset_callback_); |
211 } | 211 } |
212 | 212 |
213 CertificateReportingService::~CertificateReportingService() { | 213 CertificateReportingService::~CertificateReportingService() { |
214 DCHECK(!reporter_); | 214 DCHECK(!reporter_); |
215 } | 215 } |
216 | 216 |
217 void CertificateReportingService::Shutdown() { | 217 void CertificateReportingService::Shutdown() { |
218 // Shutdown will be called twice: Once after SafeBrowsing shuts down, and once | 218 // Shutdown will be called twice: Once after SafeBrowsing shuts down, and once |
219 // when all KeyedServices shut down. All calls after the first one are no-op. | 219 // when all KeyedServices shut down. All calls after the first one are no-op. |
220 url_request_context_ = nullptr; | 220 url_request_context_ = nullptr; |
221 content::BrowserThread::PostTask( | 221 content::BrowserThread::PostTask( |
222 content::BrowserThread::IO, FROM_HERE, | 222 content::BrowserThread::IO, FROM_HERE, |
223 base::Bind(&CleanupOnIOThread, base::Passed(std::move(reporter_)))); | 223 base::BindOnce(&CleanupOnIOThread, base::Passed(std::move(reporter_)))); |
224 } | 224 } |
225 | 225 |
226 void CertificateReportingService::Send(const std::string& serialized_report) { | 226 void CertificateReportingService::Send(const std::string& serialized_report) { |
227 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 227 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
228 if (!reporter_) { | 228 if (!reporter_) { |
229 return; | 229 return; |
230 } | 230 } |
231 content::BrowserThread::PostTask( | 231 content::BrowserThread::PostTask( |
232 content::BrowserThread::IO, FROM_HERE, | 232 content::BrowserThread::IO, FROM_HERE, |
233 base::Bind(&CertificateReportingService::Reporter::Send, | 233 base::BindOnce(&CertificateReportingService::Reporter::Send, |
234 base::Unretained(reporter_.get()), serialized_report)); | 234 base::Unretained(reporter_.get()), serialized_report)); |
235 } | 235 } |
236 | 236 |
237 void CertificateReportingService::SendPending() { | 237 void CertificateReportingService::SendPending() { |
238 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 238 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
239 if (!reporter_) { | 239 if (!reporter_) { |
240 return; | 240 return; |
241 } | 241 } |
242 content::BrowserThread::PostTask( | 242 content::BrowserThread::PostTask( |
243 content::BrowserThread::IO, FROM_HERE, | 243 content::BrowserThread::IO, FROM_HERE, |
244 base::Bind(&CertificateReportingService::Reporter::SendPending, | 244 base::BindOnce(&CertificateReportingService::Reporter::SendPending, |
245 base::Unretained(reporter_.get()))); | 245 base::Unretained(reporter_.get()))); |
246 } | 246 } |
247 | 247 |
248 void CertificateReportingService::InitializeOnIOThread( | 248 void CertificateReportingService::InitializeOnIOThread( |
249 bool enabled, | 249 bool enabled, |
250 scoped_refptr<net::URLRequestContextGetter> url_request_context_getter, | 250 scoped_refptr<net::URLRequestContextGetter> url_request_context_getter, |
251 size_t max_queued_report_count, | 251 size_t max_queued_report_count, |
252 base::TimeDelta max_report_age, | 252 base::TimeDelta max_report_age, |
253 base::Clock* clock, | 253 base::Clock* clock, |
254 uint8_t* server_public_key, | 254 uint8_t* server_public_key, |
255 uint32_t server_public_key_version) { | 255 uint32_t server_public_key_version) { |
256 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); | 256 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); |
257 DCHECK(!url_request_context_); | 257 DCHECK(!url_request_context_); |
258 url_request_context_ = url_request_context_getter->GetURLRequestContext(); | 258 url_request_context_ = url_request_context_getter->GetURLRequestContext(); |
259 ResetOnIOThread(enabled, url_request_context_, max_queued_report_count, | 259 ResetOnIOThread(enabled, url_request_context_, max_queued_report_count, |
260 max_report_age, clock, server_public_key, | 260 max_report_age, clock, server_public_key, |
261 server_public_key_version); | 261 server_public_key_version); |
262 } | 262 } |
263 | 263 |
264 void CertificateReportingService::SetEnabled(bool enabled) { | 264 void CertificateReportingService::SetEnabled(bool enabled) { |
265 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 265 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
266 // Don't reset if the service is already shut down. | 266 // Don't reset if the service is already shut down. |
267 if (!url_request_context_) | 267 if (!url_request_context_) |
268 return; | 268 return; |
269 | 269 |
270 content::BrowserThread::PostTaskAndReply( | 270 content::BrowserThread::PostTaskAndReply( |
271 content::BrowserThread::IO, FROM_HERE, | 271 content::BrowserThread::IO, FROM_HERE, |
272 base::Bind(&CertificateReportingService::ResetOnIOThread, | 272 base::BindOnce(&CertificateReportingService::ResetOnIOThread, |
273 base::Unretained(this), enabled, url_request_context_, | 273 base::Unretained(this), enabled, url_request_context_, |
274 max_queued_report_count_, max_report_age_, clock_, | 274 max_queued_report_count_, max_report_age_, clock_, |
275 server_public_key_, server_public_key_version_), | 275 server_public_key_, server_public_key_version_), |
276 reset_callback_); | 276 reset_callback_); |
277 } | 277 } |
278 | 278 |
279 CertificateReportingService::Reporter* | 279 CertificateReportingService::Reporter* |
280 CertificateReportingService::GetReporterForTesting() const { | 280 CertificateReportingService::GetReporterForTesting() const { |
281 return reporter_.get(); | 281 return reporter_.get(); |
282 } | 282 } |
283 | 283 |
284 // static | 284 // static |
285 GURL CertificateReportingService::GetReportingURLForTesting() { | 285 GURL CertificateReportingService::GetReportingURLForTesting() { |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
321 } | 321 } |
322 | 322 |
323 void CertificateReportingService::OnPreferenceChanged() { | 323 void CertificateReportingService::OnPreferenceChanged() { |
324 safe_browsing::SafeBrowsingService* safe_browsing_service_ = | 324 safe_browsing::SafeBrowsingService* safe_browsing_service_ = |
325 g_browser_process->safe_browsing_service(); | 325 g_browser_process->safe_browsing_service(); |
326 const bool enabled = safe_browsing_service_ && | 326 const bool enabled = safe_browsing_service_ && |
327 safe_browsing_service_->enabled_by_prefs() && | 327 safe_browsing_service_->enabled_by_prefs() && |
328 safe_browsing::IsExtendedReportingEnabled(pref_service_); | 328 safe_browsing::IsExtendedReportingEnabled(pref_service_); |
329 SetEnabled(enabled); | 329 SetEnabled(enabled); |
330 } | 330 } |
OLD | NEW |