Backed out changeset 6084507f9104 (bug 1281874) for bustage
authorCarsten "Tomcat" Book <cbook@mozilla.com>
Fri, 01 Jul 2016 08:49:14 +0200
changeset 341790 ab7833ced02512db316393e8186982172159af79
parent 341789 6084507f9104e2fea2e61c3b9b11f569628851f8
child 341791 0ccbc3447026b29f51751c602336a36e7c6601ce
push id1183
push userraliiev@mozilla.com
push dateMon, 05 Sep 2016 20:01:49 +0000
treeherdermozilla-release@3148731bed45 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
bugs1281874
milestone49.0a2
backs out6084507f9104e2fea2e61c3b9b11f569628851f8
Backed out changeset 6084507f9104 (bug 1281874) for bustage
dom/crypto/WebCryptoTask.cpp
dom/crypto/WebCryptoTask.h
dom/crypto/moz.build
--- a/dom/crypto/WebCryptoTask.cpp
+++ b/dom/crypto/WebCryptoTask.cpp
@@ -4,29 +4,26 @@
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "pk11pub.h"
 #include "cryptohi.h"
 #include "secerr.h"
 #include "ScopedNSSTypes.h"
 #include "nsNSSComponent.h"
-#include "nsProxyRelease.h"
 
 #include "jsapi.h"
 #include "mozilla/Telemetry.h"
 #include "mozilla/dom/CryptoBuffer.h"
 #include "mozilla/dom/CryptoKey.h"
 #include "mozilla/dom/KeyAlgorithmProxy.h"
 #include "mozilla/dom/TypedArray.h"
 #include "mozilla/dom/WebCryptoCommon.h"
 #include "mozilla/dom/WebCryptoTask.h"
 #include "mozilla/dom/WebCryptoThreadPool.h"
-#include "mozilla/dom/WorkerPrivate.h"
-#include "mozilla/dom/workers/bindings/WorkerFeature.h"
 
 // Template taken from security/nss/lib/util/templates.c
 // This (or SGN_EncodeDigestInfo) would ideally be exported
 // by NSS and until that happens we have to keep our own copy.
 const SEC_ASN1Template SGN_DigestInfoTemplate[] = {
     { SEC_ASN1_SEQUENCE,
       0, NULL, sizeof(SGNDigestInfo) },
     { SEC_ASN1_INLINE,
@@ -35,21 +32,16 @@ const SEC_ASN1Template SGN_DigestInfoTem
     { SEC_ASN1_OCTET_STRING,
       offsetof(SGNDigestInfo,digest) },
     { 0, }
 };
 
 namespace mozilla {
 namespace dom {
 
-using mozilla::dom::workers::GetCurrentThreadWorkerPrivate;
-using mozilla::dom::workers::Status;
-using mozilla::dom::workers::WorkerFeature;
-using mozilla::dom::workers::WorkerPrivate;
-
 // Pre-defined identifiers for telemetry histograms
 
 enum TelemetryMethod {
   TM_ENCRYPT      = 0,
   TM_DECRYPT      = 1,
   TM_SIGN         = 2,
   TM_VERIFY       = 3,
   TM_DIGEST       = 4,
@@ -136,63 +128,16 @@ public:
   {
     JS_ClearPendingException(mCx);
   }
 
 private:
   JSContext* mCx;
 };
 
-class WebCryptoTask::InternalWorkerHolder final : public WorkerFeature
-{
-  bool mAddedToWorkerPrivate;
-
-  InternalWorkerHolder()
-    : mAddedToWorkerPrivate(false)
-  { }
-
-  ~InternalWorkerHolder()
-  {
-    NS_ASSERT_OWNINGTHREAD(InternalWorkerHolder)
-    if (mAddedToWorkerPrivate) {
-      WorkerPrivate* workerPrivate = GetCurrentThreadWorkerPrivate();
-      MOZ_ASSERT(workerPrivate);
-      workerPrivate->RemoveFeature(this);
-    }
-  }
-
-public:
-  static already_AddRefed<InternalWorkerHolder>
-  Create()
-  {
-    MOZ_ASSERT(!NS_IsMainThread());
-    WorkerPrivate* workerPrivate = GetCurrentThreadWorkerPrivate();
-    MOZ_ASSERT(workerPrivate);
-    RefPtr<InternalWorkerHolder> ref = new InternalWorkerHolder();
-    if (NS_WARN_IF(!workerPrivate->AddFeature(ref))) {
-      return nullptr;
-    }
-    ref->mAddedToWorkerPrivate = true;
-    return ref.forget();
-  }
-
-  virtual bool
-  Notify(Status aStatus) override
-  {
-    NS_ASSERT_OWNINGTHREAD(InternalWorkerHolder)
-    // Do nothing here.  Since WebCryptoTask dispatches back to
-    // the worker thread using nsThread::Dispatch() instead of
-    // WorkerRunnable it will always be able to execute its
-    // runnables.
-    return true;
-  }
-
-  NS_INLINE_DECL_REFCOUNTING(WebCryptoTask::InternalWorkerHolder)
-};
-
 template<class OOS>
 static nsresult
 GetAlgorithmName(JSContext* aCx, const OOS& aAlgorithm, nsString& aName)
 {
   ClearException ce(aCx);
 
   if (aAlgorithm.IsString()) {
     // If string, then treat as algorithm name
@@ -385,34 +330,18 @@ WebCryptoTask::DispatchWithPromise(Promi
 
   // Skip NSS if we're already done, or launch a CryptoTask
   if (mEarlyComplete) {
     CallCallback(mEarlyRv);
     Skip();
     return;
   }
 
-  // Store calling thread
+  // Store calling thread and dispatch to thread pool.
   mOriginalThread = NS_GetCurrentThread();
-
-  // If we are running on a worker thread we must hold the worker
-  // alive while we work on the thread pool.  Otherwise the worker
-  // private may get torn down before we dispatch back to complete
-  // the transaction.
-  if (!NS_IsMainThread()) {
-    mWorkerHolder = InternalWorkerHolder::Create();
-    // If we can't register a holder then the worker is already
-    // shutting down.  Don't start new work.
-    if (!mWorkerHolder) {
-      mEarlyRv = NS_BINDING_ABORTED;
-    }
-  }
-  MAYBE_EARLY_FAIL(mEarlyRv);
-
-  // dispatch to thread pool
   mEarlyRv = WebCryptoThreadPool::Dispatch(this);
   MAYBE_EARLY_FAIL(mEarlyRv)
 }
 
 NS_IMETHODIMP
 WebCryptoTask::Run()
 {
   // Run heavy crypto operations on the thread pool, off the original thread.
@@ -434,43 +363,30 @@ WebCryptoTask::Run()
 
   // Release NSS resources now, before calling CallCallback, so that
   // WebCryptoTasks have consistent behavior regardless of whether NSS is shut
   // down between CalculateResult being called and CallCallback being called.
   virtualDestroyNSSReference();
 
   CallCallback(mRv);
 
-  // Stop holding the worker thread alive now that the async work has
-  // been completed.
-  mWorkerHolder = nullptr;
-
-  return NS_OK;
-}
-
-NS_IMETHODIMP
-WebCryptoTask::Cancel()
-{
-  MOZ_ASSERT(IsOnOriginalThread());
-  FailWithError(NS_BINDING_ABORTED);
   return NS_OK;
 }
 
 void
 WebCryptoTask::FailWithError(nsresult aRv)
 {
   MOZ_ASSERT(IsOnOriginalThread());
   Telemetry::Accumulate(Telemetry::WEBCRYPTO_RESOLVED, false);
 
   // Blindly convert nsresult to DOMException
   // Individual tasks must ensure they pass the right values
   mResultPromise->MaybeReject(aRv);
   // Manually release mResultPromise while we're on the main thread
   mResultPromise = nullptr;
-  mWorkerHolder = nullptr;
   Cleanup();
 }
 
 nsresult
 WebCryptoTask::CalculateResult()
 {
   MOZ_ASSERT(!IsOnOriginalThread());
 
@@ -3710,33 +3626,10 @@ WebCryptoTask::CreateUnwrapKeyTask(nsIGl
     return new UnwrapKeyTask<RsaOaepTask>(aCx, aWrappedKey,
                                       aUnwrappingKey, aUnwrapAlgorithm,
                                       importTask);
   }
 
   return new FailureTask(NS_ERROR_DOM_NOT_SUPPORTED_ERR);
 }
 
-WebCryptoTask::WebCryptoTask()
-  : mEarlyRv(NS_OK)
-  , mEarlyComplete(false)
-  , mOriginalThread(nullptr)
-  , mReleasedNSSResources(false)
-  , mRv(NS_ERROR_NOT_INITIALIZED)
-{
-}
-
-WebCryptoTask::~WebCryptoTask()
-{
-  MOZ_ASSERT(mReleasedNSSResources);
-
-  nsNSSShutDownPreventionLock lock;
-  if (!isAlreadyShutDown()) {
-    shutdown(calledFromObject);
-  }
-
-  if (mWorkerHolder) {
-    NS_ProxyRelease(mOriginalThread, mWorkerHolder.forget());
-  }
-}
-
 } // namespace dom
 } // namespace mozilla
--- a/dom/crypto/WebCryptoTask.h
+++ b/dom/crypto/WebCryptoTask.h
@@ -164,18 +164,33 @@ public:
                           bool aExtractable,
                           const Sequence<nsString>& aKeyUsages);
 
 protected:
   RefPtr<Promise> mResultPromise;
   nsresult mEarlyRv;
   bool mEarlyComplete;
 
-  WebCryptoTask();
-  virtual ~WebCryptoTask();
+  WebCryptoTask()
+    : mEarlyRv(NS_OK)
+    , mEarlyComplete(false)
+    , mOriginalThread(nullptr)
+    , mReleasedNSSResources(false)
+    , mRv(NS_ERROR_NOT_INITIALIZED)
+  {}
+
+  virtual ~WebCryptoTask()
+  {
+    MOZ_ASSERT(mReleasedNSSResources);
+
+    nsNSSShutDownPreventionLock lock;
+    if (!isAlreadyShutDown()) {
+      shutdown(calledFromObject);
+    }
+  }
 
   bool IsOnOriginalThread() {
     return !mOriginalThread || NS_GetCurrentThread() == mOriginalThread;
   }
 
   // For things that need to happen on the main thread
   // either before or after CalculateResult
   virtual nsresult BeforeCrypto() { return NS_OK; }
@@ -191,33 +206,29 @@ protected:
   virtual void ReleaseNSSResources() {}
 
   virtual nsresult CalculateResult() final;
 
   virtual void CallCallback(nsresult rv) final;
 
 private:
   NS_IMETHOD Run() override final;
-  NS_IMETHOD Cancel() override final;
 
   virtual void
   virtualDestroyNSSReference() override final
   {
     MOZ_ASSERT(IsOnOriginalThread());
 
     if (!mReleasedNSSResources) {
       mReleasedNSSResources = true;
       ReleaseNSSResources();
     }
   }
 
-  class InternalWorkerHolder;
-
   nsCOMPtr<nsIThread> mOriginalThread;
-  RefPtr<InternalWorkerHolder> mWorkerHolder;
   bool mReleasedNSSResources;
   nsresult mRv;
 };
 
 // XXX This class is declared here (unlike others) to enable reuse by WebRTC.
 class GenerateAsymmetricKeyTask : public WebCryptoTask
 {
 public:
--- a/dom/crypto/moz.build
+++ b/dom/crypto/moz.build
@@ -21,15 +21,14 @@ UNIFIED_SOURCES += [
     'WebCryptoThreadPool.cpp',
 ]
 
 include('/ipc/chromium/chromium-config.mozbuild')
 
 FINAL_LIBRARY = 'xul'
 
 LOCAL_INCLUDES += [
-    '/dom/workers',
     '/security/manager/ssl',
     '/security/pkix/include',
     '/xpcom/build',
 ]
 
 MOCHITEST_MANIFESTS += ['test/mochitest.ini']