OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "net/cert/multi_threaded_cert_verifier.h" | 5 #include "net/cert/multi_threaded_cert_verifier.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <utility> | 8 #include <utility> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
11 #include "base/bind_helpers.h" | 11 #include "base/bind_helpers.h" |
12 #include "base/callback_helpers.h" | 12 #include "base/callback_helpers.h" |
13 #include "base/compiler_specific.h" | 13 #include "base/compiler_specific.h" |
14 #include "base/containers/linked_list.h" | 14 #include "base/containers/linked_list.h" |
15 #include "base/message_loop/message_loop.h" | 15 #include "base/message_loop/message_loop.h" |
16 #include "base/metrics/histogram_macros.h" | 16 #include "base/metrics/histogram_macros.h" |
17 #include "base/profiler/scoped_tracker.h" | 17 #include "base/profiler/scoped_tracker.h" |
18 #include "base/sha1.h" | 18 #include "base/sha1.h" |
19 #include "base/stl_util.h" | 19 #include "base/stl_util.h" |
20 #include "base/threading/worker_pool.h" | 20 #include "base/threading/worker_pool.h" |
21 #include "base/time/time.h" | 21 #include "base/time/time.h" |
| 22 #include "base/trace_event/trace_event.h" |
22 #include "base/values.h" | 23 #include "base/values.h" |
23 #include "net/base/hash_value.h" | 24 #include "net/base/hash_value.h" |
24 #include "net/base/net_errors.h" | 25 #include "net/base/net_errors.h" |
25 #include "net/cert/cert_trust_anchor_provider.h" | 26 #include "net/cert/cert_trust_anchor_provider.h" |
26 #include "net/cert/cert_verify_proc.h" | 27 #include "net/cert/cert_verify_proc.h" |
27 #include "net/cert/crl_set.h" | 28 #include "net/cert/crl_set.h" |
28 #include "net/cert/x509_certificate.h" | 29 #include "net/cert/x509_certificate.h" |
29 #include "net/cert/x509_certificate_net_log_param.h" | 30 #include "net/cert/x509_certificate_net_log_param.h" |
30 #include "net/log/net_log.h" | 31 #include "net/log/net_log.h" |
31 | 32 |
(...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
227 // thread. The output parameters (error and result) must remain alive. | 228 // thread. The output parameters (error and result) must remain alive. |
228 void DoVerifyOnWorkerThread(const scoped_refptr<CertVerifyProc>& verify_proc, | 229 void DoVerifyOnWorkerThread(const scoped_refptr<CertVerifyProc>& verify_proc, |
229 const scoped_refptr<X509Certificate>& cert, | 230 const scoped_refptr<X509Certificate>& cert, |
230 const std::string& hostname, | 231 const std::string& hostname, |
231 const std::string& ocsp_response, | 232 const std::string& ocsp_response, |
232 int flags, | 233 int flags, |
233 const scoped_refptr<CRLSet>& crl_set, | 234 const scoped_refptr<CRLSet>& crl_set, |
234 const CertificateList& additional_trust_anchors, | 235 const CertificateList& additional_trust_anchors, |
235 int* error, | 236 int* error, |
236 CertVerifyResult* result) { | 237 CertVerifyResult* result) { |
| 238 TRACE_EVENT0("net", "DoVerifyOnWorkerThread"); |
237 *error = verify_proc->Verify(cert.get(), hostname, ocsp_response, flags, | 239 *error = verify_proc->Verify(cert.get(), hostname, ocsp_response, flags, |
238 crl_set.get(), additional_trust_anchors, result); | 240 crl_set.get(), additional_trust_anchors, result); |
239 | 241 |
240 #if defined(USE_NSS_VERIFIER) | 242 #if defined(USE_NSS_VERIFIER) |
241 // Detach the thread from NSPR. | 243 // Detach the thread from NSPR. |
242 // Calling NSS functions attaches the thread to NSPR, which stores | 244 // Calling NSS functions attaches the thread to NSPR, which stores |
243 // the NSPR thread ID in thread-specific data. | 245 // the NSPR thread ID in thread-specific data. |
244 // The threads in our thread pool terminate after we have called | 246 // The threads in our thread pool terminate after we have called |
245 // PR_Cleanup. Unless we detach them from NSPR, net_unittests gets | 247 // PR_Cleanup. Unless we detach them from NSPR, net_unittests gets |
246 // segfaults on shutdown when the threads' thread-specific data | 248 // segfaults on shutdown when the threads' thread-specific data |
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
352 UMA_HISTOGRAM_CUSTOM_TIMES("Net.CertVerifier_First_Job_Latency", | 354 UMA_HISTOGRAM_CUSTOM_TIMES("Net.CertVerifier_First_Job_Latency", |
353 latency, | 355 latency, |
354 base::TimeDelta::FromMilliseconds(1), | 356 base::TimeDelta::FromMilliseconds(1), |
355 base::TimeDelta::FromMinutes(10), | 357 base::TimeDelta::FromMinutes(10), |
356 100); | 358 100); |
357 } | 359 } |
358 } | 360 } |
359 | 361 |
360 void OnJobCompleted( | 362 void OnJobCompleted( |
361 scoped_ptr<MultiThreadedCertVerifier::CachedResult> verify_result) { | 363 scoped_ptr<MultiThreadedCertVerifier::CachedResult> verify_result) { |
| 364 TRACE_EVENT0("net", "CertVerifierJob::OnJobCompleted"); |
362 scoped_ptr<CertVerifierJob> keep_alive = cert_verifier_->RemoveJob(this); | 365 scoped_ptr<CertVerifierJob> keep_alive = cert_verifier_->RemoveJob(this); |
363 | 366 |
364 LogMetrics(*verify_result); | 367 LogMetrics(*verify_result); |
365 cert_verifier_->SaveResultToCache(key_, *verify_result); | 368 cert_verifier_->SaveResultToCache(key_, *verify_result); |
366 cert_verifier_ = nullptr; | 369 cert_verifier_ = nullptr; |
367 | 370 |
368 // TODO(eroman): If the cert_verifier_ is deleted from within one of the | 371 // TODO(eroman): If the cert_verifier_ is deleted from within one of the |
369 // callbacks, any remaining requests for that job should be cancelled. Right | 372 // callbacks, any remaining requests for that job should be cancelled. Right |
370 // now they will be called. | 373 // now they will be called. |
371 while (!requests_.empty()) { | 374 while (!requests_.empty()) { |
(...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
584 // The JobSet is kept in sorted order so items can be found using binary | 587 // The JobSet is kept in sorted order so items can be found using binary |
585 // search. | 588 // search. |
586 auto it = std::lower_bound(inflight_.begin(), inflight_.end(), key, | 589 auto it = std::lower_bound(inflight_.begin(), inflight_.end(), key, |
587 JobToRequestParamsComparator()); | 590 JobToRequestParamsComparator()); |
588 if (it != inflight_.end() && !(key < (*it)->key())) | 591 if (it != inflight_.end() && !(key < (*it)->key())) |
589 return *it; | 592 return *it; |
590 return nullptr; | 593 return nullptr; |
591 } | 594 } |
592 | 595 |
593 } // namespace net | 596 } // namespace net |
OLD | NEW |