зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1455256 - Port more components to WorkerRef - part 3 - WebCrypto, r=asuth
This commit is contained in:
Родитель
53a373287d
Коммит
f1556fa2b9
|
@ -19,7 +19,7 @@
|
||||||
#include "mozilla/dom/WebCryptoCommon.h"
|
#include "mozilla/dom/WebCryptoCommon.h"
|
||||||
#include "mozilla/dom/WebCryptoTask.h"
|
#include "mozilla/dom/WebCryptoTask.h"
|
||||||
#include "mozilla/dom/WebCryptoThreadPool.h"
|
#include "mozilla/dom/WebCryptoThreadPool.h"
|
||||||
#include "mozilla/dom/WorkerHolder.h"
|
#include "mozilla/dom/WorkerRef.h"
|
||||||
#include "mozilla/dom/WorkerPrivate.h"
|
#include "mozilla/dom/WorkerPrivate.h"
|
||||||
|
|
||||||
// Template taken from security/nss/lib/util/templates.c
|
// Template taken from security/nss/lib/util/templates.c
|
||||||
|
@ -135,47 +135,6 @@ private:
|
||||||
JSContext* mCx;
|
JSContext* mCx;
|
||||||
};
|
};
|
||||||
|
|
||||||
class WebCryptoTask::InternalWorkerHolder final : public WorkerHolder
|
|
||||||
{
|
|
||||||
InternalWorkerHolder()
|
|
||||||
: WorkerHolder("WebCryptoTask::InternalWorkerHolder")
|
|
||||||
{ }
|
|
||||||
|
|
||||||
~InternalWorkerHolder()
|
|
||||||
{
|
|
||||||
NS_ASSERT_OWNINGTHREAD(InternalWorkerHolder);
|
|
||||||
// Nothing to do here since the parent destructor releases the
|
|
||||||
// worker automatically.
|
|
||||||
}
|
|
||||||
|
|
||||||
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(!ref->HoldWorker(workerPrivate, Canceling))) {
|
|
||||||
return nullptr;
|
|
||||||
}
|
|
||||||
return ref.forget();
|
|
||||||
}
|
|
||||||
|
|
||||||
virtual bool
|
|
||||||
Notify(WorkerStatus 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>
|
template<class OOS>
|
||||||
static nsresult
|
static nsresult
|
||||||
GetAlgorithmName(JSContext* aCx, const OOS& aAlgorithm, nsString& aName)
|
GetAlgorithmName(JSContext* aCx, const OOS& aAlgorithm, nsString& aName)
|
||||||
|
@ -385,11 +344,15 @@ WebCryptoTask::DispatchWithPromise(Promise* aResultPromise)
|
||||||
// private may get torn down before we dispatch back to complete
|
// private may get torn down before we dispatch back to complete
|
||||||
// the transaction.
|
// the transaction.
|
||||||
if (!NS_IsMainThread()) {
|
if (!NS_IsMainThread()) {
|
||||||
mWorkerHolder = InternalWorkerHolder::Create();
|
WorkerPrivate* workerPrivate = GetCurrentThreadWorkerPrivate();
|
||||||
// If we can't register a holder then the worker is already
|
MOZ_ASSERT(workerPrivate);
|
||||||
// shutting down. Don't start new work.
|
|
||||||
if (!mWorkerHolder) {
|
RefPtr<StrongWorkerRef> workerRef =
|
||||||
|
StrongWorkerRef::Create(workerPrivate, "WebCryptoTask");
|
||||||
|
if (NS_WARN_IF(!workerRef)) {
|
||||||
mEarlyRv = NS_BINDING_ABORTED;
|
mEarlyRv = NS_BINDING_ABORTED;
|
||||||
|
} else {
|
||||||
|
mWorkerRef = new ThreadSafeWorkerRef(workerRef);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
MAYBE_EARLY_FAIL(mEarlyRv);
|
MAYBE_EARLY_FAIL(mEarlyRv);
|
||||||
|
@ -416,7 +379,7 @@ WebCryptoTask::Run()
|
||||||
|
|
||||||
// Stop holding the worker thread alive now that the async work has
|
// Stop holding the worker thread alive now that the async work has
|
||||||
// been completed.
|
// been completed.
|
||||||
mWorkerHolder = nullptr;
|
mWorkerRef = nullptr;
|
||||||
|
|
||||||
return NS_OK;
|
return NS_OK;
|
||||||
}
|
}
|
||||||
|
@ -440,7 +403,7 @@ WebCryptoTask::FailWithError(nsresult aRv)
|
||||||
mResultPromise->MaybeReject(aRv);
|
mResultPromise->MaybeReject(aRv);
|
||||||
// Manually release mResultPromise while we're on the main thread
|
// Manually release mResultPromise while we're on the main thread
|
||||||
mResultPromise = nullptr;
|
mResultPromise = nullptr;
|
||||||
mWorkerHolder = nullptr;
|
mWorkerRef = nullptr;
|
||||||
Cleanup();
|
Cleanup();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3675,14 +3638,7 @@ WebCryptoTask::WebCryptoTask()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
WebCryptoTask::~WebCryptoTask()
|
WebCryptoTask::~WebCryptoTask() = default;
|
||||||
{
|
|
||||||
if (mWorkerHolder) {
|
|
||||||
NS_ProxyRelease(
|
|
||||||
"WebCryptoTask::mWorkerHolder",
|
|
||||||
mOriginalEventTarget, mWorkerHolder.forget());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
} // namespace dom
|
} // namespace dom
|
||||||
} // namespace mozilla
|
} // namespace mozilla
|
||||||
|
|
|
@ -17,6 +17,8 @@
|
||||||
namespace mozilla {
|
namespace mozilla {
|
||||||
namespace dom {
|
namespace dom {
|
||||||
|
|
||||||
|
class ThreadSafeWorkerRef;
|
||||||
|
|
||||||
typedef ArrayBufferViewOrArrayBuffer CryptoOperationData;
|
typedef ArrayBufferViewOrArrayBuffer CryptoOperationData;
|
||||||
typedef ArrayBufferViewOrArrayBuffer KeyData;
|
typedef ArrayBufferViewOrArrayBuffer KeyData;
|
||||||
|
|
||||||
|
@ -187,10 +189,8 @@ private:
|
||||||
NS_IMETHOD Run() final;
|
NS_IMETHOD Run() final;
|
||||||
nsresult Cancel() final;
|
nsresult Cancel() final;
|
||||||
|
|
||||||
class InternalWorkerHolder;
|
|
||||||
|
|
||||||
nsCOMPtr<nsISerialEventTarget> mOriginalEventTarget;
|
nsCOMPtr<nsISerialEventTarget> mOriginalEventTarget;
|
||||||
RefPtr<InternalWorkerHolder> mWorkerHolder;
|
RefPtr<ThreadSafeWorkerRef> mWorkerRef;
|
||||||
nsresult mRv;
|
nsresult mRv;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Загрузка…
Ссылка в новой задаче