Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(57)

Side by Side Diff: net/cert/single_request_cert_verifier.cc

Issue 1115903002: Refactor the API for CertVerifier::Verify() and the implementation of MultiThreadedCertVerifier::Ver (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase again Created 5 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
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.
4
5 #include "net/cert/single_request_cert_verifier.h"
6
7 #include "base/bind.h"
8 #include "base/bind_helpers.h"
9 #include "net/base/net_errors.h"
10 #include "net/cert/x509_certificate.h"
11
12 namespace net {
13
14 SingleRequestCertVerifier::SingleRequestCertVerifier(
15 CertVerifier* cert_verifier)
16 : cert_verifier_(cert_verifier),
17 cur_request_(NULL) {
18 DCHECK(cert_verifier_ != NULL);
19 }
20
21 SingleRequestCertVerifier::~SingleRequestCertVerifier() {
22 if (cur_request_) {
23 cert_verifier_->CancelRequest(cur_request_);
24 cur_request_ = NULL;
25 }
26 }
27
28 int SingleRequestCertVerifier::Verify(X509Certificate* cert,
29 const std::string& hostname,
30 const std::string& ocsp_response,
31 int flags,
32 CRLSet* crl_set,
33 CertVerifyResult* verify_result,
34 const CompletionCallback& callback,
35 const BoundNetLog& net_log) {
36 // Should not be already in use.
37 DCHECK(!cur_request_ && cur_request_callback_.is_null());
38
39 CertVerifier::RequestHandle request = NULL;
40
41 // We need to be notified of completion before |callback| is called, so that
42 // we can clear out |cur_request_*|.
43 int rv = cert_verifier_->Verify(
44 cert, hostname, ocsp_response, flags, crl_set, verify_result,
45 base::Bind(&SingleRequestCertVerifier::OnVerifyCompletion,
46 base::Unretained(this)),
47 &request, net_log);
48
49 if (rv == ERR_IO_PENDING) {
50 // Cleared in OnVerifyCompletion().
51 cur_request_ = request;
52 cur_request_callback_ = callback;
53 }
54
55 return rv;
56 }
57
58 void SingleRequestCertVerifier::OnVerifyCompletion(int result) {
59 DCHECK(cur_request_ && !cur_request_callback_.is_null());
60
61 CompletionCallback callback = cur_request_callback_;
62
63 // Clear the outstanding request information.
64 cur_request_ = NULL;
65 cur_request_callback_.Reset();
66
67 // Call the user's original callback.
68 callback.Run(result);
69 }
70
71 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698