summaryrefslogtreecommitdiffstats
path: root/net/ocsp
diff options
context:
space:
mode:
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.