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

Unified Diff: net/base/multi_threaded_cert_verifier.cc

Issue 9476035: Make CertVerifier a pure virtual interface. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Win shared fix Created 8 years, 9 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « net/base/multi_threaded_cert_verifier.h ('k') | net/base/multi_threaded_cert_verifier_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: net/base/multi_threaded_cert_verifier.cc
===================================================================
--- net/base/multi_threaded_cert_verifier.cc (revision 128056)
+++ net/base/multi_threaded_cert_verifier.cc (working copy)
@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include "net/base/cert_verifier.h"
+#include "net/base/multi_threaded_cert_verifier.h"
#include "base/bind.h"
#include "base/bind_helpers.h"
@@ -29,42 +29,42 @@
// Life of a request:
//
-// CertVerifier CertVerifierJob CertVerifierWorker Request
-// | (origin loop) (worker loop)
+// MultiThreadedCertVerifier CertVerifierJob CertVerifierWorker Request
+// | (origin loop) (worker loop)
// |
// Verify()
+// |---->-------------------------------------<creates>
+// |
// |---->-------------------<creates>
// |
-// |---->----<creates>
+// |---->-------------------------------------------------------<creates>
// |
-// |---->---------------------------------------------------<creates>
+// |---->---------------------------------------Start
+// | |
+// | PostTask
// |
-// |---->--------------------Start
-// | |
-// | PostTask
-// |
-// | <starts verifying>
-// |---->-----AddRequest |
-// |
-// |
-// |
-// Finish
-// |
-// PostTask
+// | <starts verifying>
+// |---->-------------------AddRequest |
+// |
+// |
+// |
+// Finish
+// |
+// PostTask
//
-// |
-// DoReply
-// |----<-----------------------|
+// |
+// DoReply
+// |----<-----------------------------------------|
// HandleResult
// |
-// |---->-----HandleResult
-// |
-// |------>-----------------------------------Post
+// |---->------------------HandleResult
+// |
+// |------>---------------------------Post
//
//
//
-// On a cache hit, CertVerifier::Verify() returns synchronously without
-// posting a task to a worker thread.
+// On a cache hit, MultiThreadedCertVerifier::Verify() returns synchronously
+// without posting a task to a worker thread.
namespace {
@@ -76,9 +76,9 @@
} // namespace
-CertVerifier::CachedResult::CachedResult() : error(ERR_FAILED) {}
+MultiThreadedCertVerifier::CachedResult::CachedResult() : error(ERR_FAILED) {}
-CertVerifier::CachedResult::~CachedResult() {}
+MultiThreadedCertVerifier::CachedResult::~CachedResult() {}
// Represents the output and result callback of a request.
class CertVerifierRequest {
@@ -105,7 +105,7 @@
// Copies the contents of |verify_result| to the caller's
// CertVerifyResult and calls the callback.
- void Post(const CertVerifier::CachedResult& verify_result) {
+ void Post(const MultiThreadedCertVerifier::CachedResult& verify_result) {
if (!callback_.is_null()) {
net_log_.EndEvent(NetLog::TYPE_CERT_VERIFIER_REQUEST, NULL);
*verify_result_ = verify_result.result;
@@ -134,7 +134,7 @@
const std::string& hostname,
int flags,
CRLSet* crl_set,
- CertVerifier* cert_verifier)
+ MultiThreadedCertVerifier* cert_verifier)
: cert_(cert),
hostname_(hostname),
flags_(flags),
@@ -157,8 +157,8 @@
true /* task is slow */);
}
- // Cancel is called from the origin loop when the CertVerifier is getting
- // deleted.
+ // Cancel is called from the origin loop when the MultiThreadedCertVerifier is
+ // getting deleted.
void Cancel() {
DCHECK_EQ(MessageLoop::current(), origin_loop_);
base::AutoLock locked(lock_);
@@ -201,11 +201,12 @@
void Finish() {
// Runs on the worker thread.
- // We assume that the origin loop outlives the CertVerifier. If the
- // CertVerifier is deleted, it will call Cancel on us. If it does so
- // before the Acquire, we'll delete ourselves and return. If it's trying to
- // do so concurrently, then it'll block on the lock and we'll call PostTask
- // while the CertVerifier (and therefore the MessageLoop) is still alive.
+ // We assume that the origin loop outlives the MultiThreadedCertVerifier. If
+ // the MultiThreadedCertVerifier is deleted, it will call Cancel on us. If
+ // it does so before the Acquire, we'll delete ourselves and return. If it's
+ // trying to do so concurrently, then it'll block on the lock and we'll call
+ // PostTask while the MultiThreadedCertVerifier (and therefore the
+ // MessageLoop) is still alive.
// If it does so after this function, we assume that the MessageLoop will
// process pending tasks. In which case we'll notice the |canceled_| flag
// in DoReply.
@@ -230,7 +231,7 @@
const int flags_;
scoped_refptr<CRLSet> crl_set_;
MessageLoop* const origin_loop_;
- CertVerifier* const cert_verifier_;
+ MultiThreadedCertVerifier* const cert_verifier_;
// lock_ protects canceled_.
base::Lock lock_;
@@ -278,7 +279,8 @@
requests_.push_back(request);
}
- void HandleResult(const CertVerifier::CachedResult& verify_result) {
+ void HandleResult(
+ const MultiThreadedCertVerifier::CachedResult& verify_result) {
worker_ = NULL;
net_log_.EndEvent(NetLog::TYPE_CERT_VERIFIER_JOB, NULL);
UMA_HISTOGRAM_CUSTOM_TIMES("Net.CertVerifier_Job_Latency",
@@ -290,7 +292,7 @@
}
private:
- void PostAll(const CertVerifier::CachedResult& verify_result) {
+ void PostAll(const MultiThreadedCertVerifier::CachedResult& verify_result) {
std::vector<CertVerifierRequest*> requests;
requests_.swap(requests);
@@ -318,7 +320,7 @@
const BoundNetLog net_log_;
};
-CertVerifier::CertVerifier()
+MultiThreadedCertVerifier::MultiThreadedCertVerifier()
: cache_(kMaxCacheEntries),
requests_(0),
cache_hits_(0),
@@ -326,20 +328,20 @@
CertDatabase::AddObserver(this);
}
-CertVerifier::~CertVerifier() {
+MultiThreadedCertVerifier::~MultiThreadedCertVerifier() {
STLDeleteValues(&inflight_);
CertDatabase::RemoveObserver(this);
}
-int CertVerifier::Verify(X509Certificate* cert,
- const std::string& hostname,
- int flags,
- CRLSet* crl_set,
- CertVerifyResult* verify_result,
- const CompletionCallback& callback,
- RequestHandle* out_req,
- const BoundNetLog& net_log) {
+int MultiThreadedCertVerifier::Verify(X509Certificate* cert,
+ const std::string& hostname,
+ int flags,
+ CRLSet* crl_set,
+ CertVerifyResult* verify_result,
+ const CompletionCallback& callback,
+ RequestHandle* out_req,
+ const BoundNetLog& net_log) {
DCHECK(CalledOnValidThread());
if (callback.is_null() || !verify_result || hostname.empty()) {
@@ -394,7 +396,7 @@
return ERR_IO_PENDING;
}
-void CertVerifier::CancelRequest(RequestHandle req) {
+void MultiThreadedCertVerifier::CancelRequest(RequestHandle req) {
DCHECK(CalledOnValidThread());
CertVerifierRequest* request = reinterpret_cast<CertVerifierRequest*>(req);
request->Cancel();
@@ -402,11 +404,12 @@
// HandleResult is called by CertVerifierWorker on the origin message loop.
// It deletes CertVerifierJob.
-void CertVerifier::HandleResult(X509Certificate* cert,
- const std::string& hostname,
- int flags,
- int error,
- const CertVerifyResult& verify_result) {
+void MultiThreadedCertVerifier::HandleResult(
+ X509Certificate* cert,
+ const std::string& hostname,
+ int flags,
+ int error,
+ const CertVerifyResult& verify_result) {
DCHECK(CalledOnValidThread());
const RequestParams key(cert->fingerprint(), cert->ca_fingerprint(),
@@ -431,72 +434,11 @@
delete job;
}
-void CertVerifier::OnCertTrustChanged(const X509Certificate* cert) {
+void MultiThreadedCertVerifier::OnCertTrustChanged(
+ const X509Certificate* cert) {
DCHECK(CalledOnValidThread());
ClearCache();
}
-/////////////////////////////////////////////////////////////////////
-
-SingleRequestCertVerifier::SingleRequestCertVerifier(
- CertVerifier* cert_verifier)
- : cert_verifier_(cert_verifier),
- cur_request_(NULL) {
- DCHECK(cert_verifier_ != NULL);
-}
-
-SingleRequestCertVerifier::~SingleRequestCertVerifier() {
- if (cur_request_) {
- cert_verifier_->CancelRequest(cur_request_);
- cur_request_ = NULL;
- }
-}
-
-int SingleRequestCertVerifier::Verify(X509Certificate* cert,
- const std::string& hostname,
- int flags,
- CRLSet* crl_set,
- CertVerifyResult* verify_result,
- const CompletionCallback& callback,
- const BoundNetLog& net_log) {
- // Should not be already in use.
- DCHECK(!cur_request_ && cur_request_callback_.is_null());
-
- // Do a synchronous verification.
- if (callback.is_null())
- return cert->Verify(hostname, flags, crl_set, verify_result);
-
- CertVerifier::RequestHandle request = NULL;
-
- // We need to be notified of completion before |callback| is called, so that
- // we can clear out |cur_request_*|.
- int rv = cert_verifier_->Verify(
- cert, hostname, flags, crl_set, verify_result,
- base::Bind(&SingleRequestCertVerifier::OnVerifyCompletion,
- base::Unretained(this)),
- &request, net_log);
-
- if (rv == ERR_IO_PENDING) {
- // Cleared in OnVerifyCompletion().
- cur_request_ = request;
- cur_request_callback_ = callback;
- }
-
- return rv;
-}
-
-void SingleRequestCertVerifier::OnVerifyCompletion(int result) {
- DCHECK(cur_request_ && !cur_request_callback_.is_null());
-
- CompletionCallback callback = cur_request_callback_;
-
- // Clear the outstanding request information.
- cur_request_ = NULL;
- cur_request_callback_.Reset();
-
- // Call the user's original callback.
- callback.Run(result);
-}
-
} // namespace net
« no previous file with comments | « net/base/multi_threaded_cert_verifier.h ('k') | net/base/multi_threaded_cert_verifier_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698