security/manager/ssl/src/CryptoTask.cpp

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
michael@0 2 /* vim: set ts=2 et sw=2 tw=80: */
michael@0 3 /* This Source Code Form is subject to the terms of the Mozilla Public
michael@0 4 * License, v. 2.0. If a copy of the MPL was not distributed with this file,
michael@0 5 * You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 6
michael@0 7 #include "CryptoTask.h"
michael@0 8
michael@0 9 namespace mozilla {
michael@0 10
michael@0 11 CryptoTask::~CryptoTask()
michael@0 12 {
michael@0 13 MOZ_ASSERT(mReleasedNSSResources);
michael@0 14
michael@0 15 nsNSSShutDownPreventionLock lock;
michael@0 16 if (!isAlreadyShutDown()) {
michael@0 17 shutdown(calledFromObject);
michael@0 18 }
michael@0 19 }
michael@0 20
michael@0 21 NS_IMETHODIMP
michael@0 22 CryptoTask::Run()
michael@0 23 {
michael@0 24 if (!NS_IsMainThread()) {
michael@0 25 nsNSSShutDownPreventionLock locker;
michael@0 26 if (isAlreadyShutDown()) {
michael@0 27 mRv = NS_ERROR_NOT_AVAILABLE;
michael@0 28 } else {
michael@0 29 mRv = CalculateResult();
michael@0 30 }
michael@0 31 NS_DispatchToMainThread(this);
michael@0 32 } else {
michael@0 33 // back on the main thread
michael@0 34
michael@0 35 // call ReleaseNSSResources now, before calling CallCallback, so that
michael@0 36 // CryptoTasks have consistent behavior regardless of whether NSS is shut
michael@0 37 // down between CalculateResult being called and CallCallback being called.
michael@0 38 if (!mReleasedNSSResources) {
michael@0 39 mReleasedNSSResources = true;
michael@0 40 ReleaseNSSResources();
michael@0 41 }
michael@0 42
michael@0 43 CallCallback(mRv);
michael@0 44
michael@0 45 // Not all uses of CryptoTask use a transient thread
michael@0 46 if (mThread) {
michael@0 47 // Don't leak threads!
michael@0 48 mThread->Shutdown(); // can't Shutdown from the thread itself, darn
michael@0 49 // Don't null out mThread!
michael@0 50 // See bug 999104. We must hold a ref to the thread across Dispatch()
michael@0 51 // since the internal mThread ref could be released while processing
michael@0 52 // the Dispatch(), and Dispatch/PutEvent itself doesn't hold a ref; it
michael@0 53 // assumes the caller does.
michael@0 54 }
michael@0 55 }
michael@0 56
michael@0 57 return NS_OK;
michael@0 58 }
michael@0 59
michael@0 60 void
michael@0 61 CryptoTask::virtualDestroyNSSReference()
michael@0 62 {
michael@0 63 NS_ABORT_IF_FALSE(NS_IsMainThread(),
michael@0 64 "virtualDestroyNSSReference called off the main thread");
michael@0 65 if (!mReleasedNSSResources) {
michael@0 66 mReleasedNSSResources = true;
michael@0 67 ReleaseNSSResources();
michael@0 68 }
michael@0 69 }
michael@0 70
michael@0 71 } // namespace mozilla

mercurial