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.

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

mercurial