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 <memory> | 8 #include <memory> |
9 #include <utility> | 9 #include <utility> |
10 | 10 |
(...skipping 327 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
338 | 338 |
339 bool is_first_job_; | 339 bool is_first_job_; |
340 base::WeakPtrFactory<CertVerifierJob> weak_ptr_factory_; | 340 base::WeakPtrFactory<CertVerifierJob> weak_ptr_factory_; |
341 }; | 341 }; |
342 | 342 |
343 MultiThreadedCertVerifier::MultiThreadedCertVerifier( | 343 MultiThreadedCertVerifier::MultiThreadedCertVerifier( |
344 CertVerifyProc* verify_proc) | 344 CertVerifyProc* verify_proc) |
345 : requests_(0), inflight_joins_(0), verify_proc_(verify_proc) {} | 345 : requests_(0), inflight_joins_(0), verify_proc_(verify_proc) {} |
346 | 346 |
347 MultiThreadedCertVerifier::~MultiThreadedCertVerifier() { | 347 MultiThreadedCertVerifier::~MultiThreadedCertVerifier() { |
| 348 DCHECK_CALLED_ON_VALID_THREAD(thread_checker_); |
348 } | 349 } |
349 | 350 |
350 int MultiThreadedCertVerifier::Verify(const RequestParams& params, | 351 int MultiThreadedCertVerifier::Verify(const RequestParams& params, |
351 CRLSet* crl_set, | 352 CRLSet* crl_set, |
352 CertVerifyResult* verify_result, | 353 CertVerifyResult* verify_result, |
353 const CompletionCallback& callback, | 354 const CompletionCallback& callback, |
354 std::unique_ptr<Request>* out_req, | 355 std::unique_ptr<Request>* out_req, |
355 const NetLogWithSource& net_log) { | 356 const NetLogWithSource& net_log) { |
356 out_req->reset(); | 357 out_req->reset(); |
357 | 358 |
358 DCHECK(CalledOnValidThread()); | 359 DCHECK_CALLED_ON_VALID_THREAD(thread_checker_); |
359 | 360 |
360 if (callback.is_null() || !verify_result || params.hostname().empty()) | 361 if (callback.is_null() || !verify_result || params.hostname().empty()) |
361 return ERR_INVALID_ARGUMENT; | 362 return ERR_INVALID_ARGUMENT; |
362 | 363 |
363 requests_++; | 364 requests_++; |
364 | 365 |
365 // See if an identical request is currently in flight. | 366 // See if an identical request is currently in flight. |
366 CertVerifierJob* job = FindJob(params); | 367 CertVerifierJob* job = FindJob(params); |
367 if (job) { | 368 if (job) { |
368 // An identical request is in flight already. We'll just attach our | 369 // An identical request is in flight already. We'll just attach our |
(...skipping 28 matching lines...) Expand all Loading... |
397 } | 398 } |
398 | 399 |
399 bool MultiThreadedCertVerifier::JobComparator::operator()( | 400 bool MultiThreadedCertVerifier::JobComparator::operator()( |
400 const CertVerifierJob* job1, | 401 const CertVerifierJob* job1, |
401 const CertVerifierJob* job2) const { | 402 const CertVerifierJob* job2) const { |
402 return job1->key() < job2->key(); | 403 return job1->key() < job2->key(); |
403 } | 404 } |
404 | 405 |
405 std::unique_ptr<CertVerifierJob> MultiThreadedCertVerifier::RemoveJob( | 406 std::unique_ptr<CertVerifierJob> MultiThreadedCertVerifier::RemoveJob( |
406 CertVerifierJob* job) { | 407 CertVerifierJob* job) { |
407 DCHECK(CalledOnValidThread()); | 408 DCHECK_CALLED_ON_VALID_THREAD(thread_checker_); |
408 auto it = inflight_.find(job); | 409 auto it = inflight_.find(job); |
409 DCHECK(it != inflight_.end()); | 410 DCHECK(it != inflight_.end()); |
410 std::unique_ptr<CertVerifierJob> job_ptr = std::move(it->second); | 411 std::unique_ptr<CertVerifierJob> job_ptr = std::move(it->second); |
411 inflight_.erase(it); | 412 inflight_.erase(it); |
412 return job_ptr; | 413 return job_ptr; |
413 } | 414 } |
414 | 415 |
415 struct MultiThreadedCertVerifier::JobToRequestParamsComparator { | 416 struct MultiThreadedCertVerifier::JobToRequestParamsComparator { |
416 bool operator()(const std::pair<CertVerifierJob* const, | 417 bool operator()(const std::pair<CertVerifierJob* const, |
417 std::unique_ptr<CertVerifierJob>>& item, | 418 std::unique_ptr<CertVerifierJob>>& item, |
418 const CertVerifier::RequestParams& value) const { | 419 const CertVerifier::RequestParams& value) const { |
419 return item.first->key() < value; | 420 return item.first->key() < value; |
420 } | 421 } |
421 }; | 422 }; |
422 | 423 |
423 CertVerifierJob* MultiThreadedCertVerifier::FindJob(const RequestParams& key) { | 424 CertVerifierJob* MultiThreadedCertVerifier::FindJob(const RequestParams& key) { |
424 DCHECK(CalledOnValidThread()); | 425 DCHECK_CALLED_ON_VALID_THREAD(thread_checker_); |
425 | 426 |
426 // The JobSet is kept in sorted order so items can be found using binary | 427 // The JobSet is kept in sorted order so items can be found using binary |
427 // search. | 428 // search. |
428 auto it = std::lower_bound(inflight_.begin(), inflight_.end(), key, | 429 auto it = std::lower_bound(inflight_.begin(), inflight_.end(), key, |
429 JobToRequestParamsComparator()); | 430 JobToRequestParamsComparator()); |
430 if (it != inflight_.end() && !(key < it->first->key())) | 431 if (it != inflight_.end() && !(key < it->first->key())) |
431 return it->first; | 432 return it->first; |
432 return nullptr; | 433 return nullptr; |
433 } | 434 } |
434 | 435 |
435 } // namespace net | 436 } // namespace net |
OLD | NEW |