Skip to content

Commit

Permalink
Ensure that OCSPIOLoop is associated with right thread if restarted.
Browse files Browse the repository at this point in the history
In tests, g_ocsp_io_loop can be shut down and restarted. Ensure that if it is
restarted it is associated with the current IO thread to avoid DCHECK's
potentially going off when it is subsequently (re-)shut down.


BUG=


Review URL: https://chromiumcodereview.appspot.com/11347039

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@166869 0039d316-1c4b-4281-b951-d872f2087c98
  • Loading branch information
blundell@chromium.org committed Nov 9, 2012
1 parent 86c2460 commit 06b2631
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
18 changes: 18 additions & 0 deletions net/ocsp/nss_ocsp.cc
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,20 @@ class OCSPIOLoop {
void AddRequest(OCSPRequestSession* request);
void RemoveRequest(OCSPRequestSession* request);

// Clears internal state and calls |StartUsing()|. Should be called only in
// the context of testing.
void ReuseForTesting() {
{
base::AutoLock autolock(lock_);
DCHECK(MessageLoopForIO::current());
thread_checker_.DetachFromThread();
thread_checker_.CalledOnValidThread();
shutdown_ = false;
used_ = false;
}
StartUsing();
}

private:
friend struct base::DefaultLazyInstanceTraits<OCSPIOLoop>;

Expand Down Expand Up @@ -934,6 +948,10 @@ void ShutdownNSSHttpIO() {
g_ocsp_io_loop.Get().Shutdown();
}

void ResetNSSHttpIOForTesting() {
g_ocsp_io_loop.Get().ReuseForTesting();
}

// This function would be called before NSS initialization.
void SetURLRequestContextForNSSHttpIO(URLRequestContext* request_context) {
pthread_mutex_lock(&g_request_context_lock);
Expand Down
4 changes: 4 additions & 0 deletions net/ocsp/nss_ocsp.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ NET_EXPORT void EnsureNSSHttpIOInit();
// related HTTP fetches.
NET_EXPORT void ShutdownNSSHttpIO();

// Can be called after a call to |ShutdownNSSHttpIO()| to reset internal state
// and associate it with the current thread.
NET_EXPORT void ResetNSSHttpIOForTesting();

// Sets the URLRequestContext for HTTP requests issued by NSS.
NET_EXPORT void SetURLRequestContextForNSSHttpIO(
URLRequestContext* request_context);
Expand Down

0 comments on commit 06b2631

Please sign in to comment.