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
3 // found in the LICENSE file.
5 #include "net/cert/single_request_cert_verifier.h"
8 #include "base/bind_helpers.h"
9 #include "net/base/net_errors.h"
10 #include "net/cert/x509_certificate.h"
14 SingleRequestCertVerifier::SingleRequestCertVerifier(
15 CertVerifier
* cert_verifier
)
16 : cert_verifier_(cert_verifier
),
18 DCHECK(cert_verifier_
!= NULL
);
21 SingleRequestCertVerifier::~SingleRequestCertVerifier() {
23 cert_verifier_
->CancelRequest(cur_request_
);
28 int SingleRequestCertVerifier::Verify(X509Certificate
* cert
,
29 const std::string
& hostname
,
32 CertVerifyResult
* verify_result
,
33 const CompletionCallback
& callback
,
34 const BoundNetLog
& net_log
) {
35 // Should not be already in use.
36 DCHECK(!cur_request_
&& cur_request_callback_
.is_null());
38 CertVerifier::RequestHandle request
= NULL
;
40 // We need to be notified of completion before |callback| is called, so that
41 // we can clear out |cur_request_*|.
42 int rv
= cert_verifier_
->Verify(
43 cert
, hostname
, flags
, crl_set
, verify_result
,
44 base::Bind(&SingleRequestCertVerifier::OnVerifyCompletion
,
45 base::Unretained(this)),
48 if (rv
== ERR_IO_PENDING
) {
49 // Cleared in OnVerifyCompletion().
50 cur_request_
= request
;
51 cur_request_callback_
= callback
;
57 void SingleRequestCertVerifier::OnVerifyCompletion(int result
) {
58 DCHECK(cur_request_
&& !cur_request_callback_
.is_null());
60 CompletionCallback callback
= cur_request_callback_
;
62 // Clear the outstanding request information.
64 cur_request_callback_
.Reset();
66 // Call the user's original callback.