summaryrefslogtreecommitdiffstats
path: root/net/ocsp
diff options
context:
space:
mode:
authorwillchan@chromium.org <willchan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-09-13 22:20:27 +0000
committerwillchan@chromium.org <willchan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-09-13 22:20:27 +0000
commitc0b50b7ef1b2f277e5d564079a273bba1cc7ee16 (patch)
tree0b48eb59d4449812fd1f1b5c4b3f1ebbae9c9bf6 /net/ocsp
parent749eefa86bfae16ea4bdc6aeba3f97bfa98f22f7 (diff)
downloadchromium_src-c0b50b7ef1b2f277e5d564079a273bba1cc7ee16.zip
chromium_src-c0b50b7ef1b2f277e5d564079a273bba1cc7ee16.tar.gz
chromium_src-c0b50b7ef1b2f277e5d564079a273bba1cc7ee16.tar.bz2
Eagerly set the IO loop used for OCSP.
This prevents the IO loop being set to sync's thread instead of the IO thread. BUG=36740 TEST=none Review URL: http://codereview.chromium.org/3377002 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@59289 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net/ocsp')
-rw-r--r--net/ocsp/nss_ocsp.cc45
-rw-r--r--net/ocsp/nss_ocsp.h5
2 files changed, 47 insertions, 3 deletions
diff --git a/net/ocsp/nss_ocsp.cc b/net/ocsp/nss_ocsp.cc
index bd6a70b..28d2d1a 100644
--- a/net/ocsp/nss_ocsp.cc
+++ b/net/ocsp/nss_ocsp.cc
@@ -17,6 +17,7 @@
#include "base/condition_variable.h"
#include "base/histogram.h"
#include "base/logging.h"
+#include "base/lock.h"
#include "base/message_loop.h"
#include "base/singleton.h"
#include "base/string_util.h"
@@ -32,6 +33,15 @@
namespace {
+// Protects |g_io_loop| and |g_io_loop_used|.
+static Lock g_io_loop_lock;
+
+// The io loop used for OCSP. Read only during OCSPInitSingleton's constructor.
+MessageLoopForIO* g_io_loop = NULL;
+// |g_io_loop_used| is set to true after read by OCSPInitSingleton's
+// constructor.
+bool g_io_loop_used = false;
+
const int kRecvBufferSize = 4096;
// All OCSP handlers should be called in the context of
@@ -100,6 +110,13 @@ class OCSPInitSingleton : public MessageLoop::DestructionObserver {
OCSPInitSingleton()
: io_loop_(MessageLoopForIO::current()) {
+ {
+ AutoLock lock(g_io_loop_lock);
+ DCHECK(!g_io_loop_used);
+ g_io_loop_used = true;
+ if (g_io_loop)
+ io_loop_ = g_io_loop;
+ }
DCHECK(io_loop_);
io_loop_->AddDestructionObserver(this);
@@ -141,9 +158,16 @@ class OCSPInitSingleton : public MessageLoop::DestructionObserver {
virtual ~OCSPInitSingleton() {
// IO thread was already deleted before the singleton is deleted
// in AtExitManager.
- AutoLock autolock(lock_);
- DCHECK(!io_loop_);
- DCHECK(!request_context_);
+ {
+ AutoLock autolock(lock_);
+ DCHECK(!io_loop_);
+ DCHECK(!request_context_);
+ }
+ {
+ AutoLock lock(g_io_loop_lock);
+ g_io_loop_used = false;
+ g_io_loop = NULL;
+ }
}
SEC_HttpClientFcn client_fcn_;
@@ -782,6 +806,21 @@ char* GetAlternateOCSPAIAInfo(CERTCertificate *cert) {
namespace net {
+void SetMessageLoopForOCSP(MessageLoopForIO* message_loop) {
+ DCHECK(message_loop);
+ AutoLock lock(g_io_loop_lock);
+ if (g_io_loop) {
+ LOG(DFATAL) << "Setting OCSP message loop more than once!";
+ return;
+ }
+ if (g_io_loop_used) {
+ LOG(DFATAL) << "Tried to set message loop for OCSP after "
+ << "it's already been used by OCSPInitSingleton!";
+ return;
+ }
+ g_io_loop = message_loop;
+}
+
void EnsureOCSPInit() {
Singleton<OCSPInitSingleton>::get();
}
diff --git a/net/ocsp/nss_ocsp.h b/net/ocsp/nss_ocsp.h
index a31d025..5dec05c 100644
--- a/net/ocsp/nss_ocsp.h
+++ b/net/ocsp/nss_ocsp.h
@@ -6,10 +6,15 @@
#define NET_OCSP_NSS_OCSP_H_
#pragma once
+class MessageLoopForIO;
class URLRequestContext;
namespace net {
+// Sets the MessageLoop for OCSP. This should be called before EnsureOCSPInit()
+// if you want to control the message loop for OCSP.
+void SetMessageLoopForOCSP(MessageLoopForIO* message_loop);
+
// Initializes OCSP handlers for NSS. This must be called before any
// certificate verification functions. This function is thread-safe, and OCSP
// handlers will only ever be initialized once.