Bug 1620366 - Convert BackgroundFileSaver to use background thread pool. r=valentin,necko-reviewers

Differential Revision: https://phabricator.services.mozilla.com/D74546
This commit is contained in:
Chris Fronk 2020-05-27 00:06:16 +00:00
Родитель 280d4e0f46
Коммит 39313c3fb4
2 изменённых файлов: 8 добавлений и 8 удалений

Просмотреть файл

@ -84,7 +84,7 @@ uint32_t BackgroundFileSaver::sTelemetryMaxThreadCount = 0;
BackgroundFileSaver::BackgroundFileSaver()
: mControlEventTarget(nullptr),
mWorkerThread(nullptr),
mBackgroundET(nullptr),
mPipeOutputStream(nullptr),
mPipeInputStream(nullptr),
mObserver(nullptr),
@ -125,7 +125,7 @@ nsresult BackgroundFileSaver::Init() {
mControlEventTarget = GetCurrentThreadEventTarget();
NS_ENSURE_TRUE(mControlEventTarget, NS_ERROR_NOT_INITIALIZED);
rv = NS_NewNamedThread("BgFileSaver", getter_AddRefs(mWorkerThread));
rv = NS_CreateBackgroundTaskQueue("BgFileSaver", getter_AddRefs(mBackgroundET));
NS_ENSURE_SUCCESS(rv, rv);
sThreadCount++;
@ -286,10 +286,10 @@ nsresult BackgroundFileSaver::GetWorkerThreadAttention(
if (!mAsyncCopyContext) {
// Copy is not in progress, post an event to handle the change manually.
rv = mWorkerThread->Dispatch(
rv = mBackgroundET->Dispatch(
NewRunnableMethod("net::BackgroundFileSaver::ProcessAttention", this,
&BackgroundFileSaver::ProcessAttention),
NS_DISPATCH_NORMAL);
NS_DISPATCH_EVENT_MAY_BLOCK);
NS_ENSURE_SUCCESS(rv, rv);
} else if (aShouldInterruptCopy) {
// Interrupt the copy. The copy will be resumed, if needed, by the
@ -588,7 +588,7 @@ nsresult BackgroundFileSaver::ProcessStateChange() {
{
MutexAutoLock lock(mLock);
rv = NS_AsyncCopy(mPipeInputStream, outputStream, mWorkerThread,
rv = NS_AsyncCopy(mPipeInputStream, outputStream, mBackgroundET,
NS_ASYNCCOPY_VIA_READSEGMENTS, 4096, AsyncCopyCallback,
this, false, true, getter_AddRefs(mAsyncCopyContext),
GetProgressCallback());
@ -734,7 +734,7 @@ nsresult BackgroundFileSaver::NotifySaveComplete() {
// completion observer callback. Re-entering the loop can only delay the
// final release and destruction of this saver object, since we are keeping a
// reference to it through the event object.
mWorkerThread->Shutdown();
mBackgroundET = nullptr;
sThreadCount--;

Просмотреть файл

@ -23,7 +23,7 @@
#include "nsString.h"
class nsIAsyncInputStream;
class nsIThread;
class nsISerialEventTarget;
namespace mozilla {
namespace net {
@ -72,7 +72,7 @@ class BackgroundFileSaver : public nsIBackgroundFileSaver {
/**
* Thread to which the actual input/output is delegated.
*/
nsCOMPtr<nsIThread> mWorkerThread;
nsCOMPtr<nsISerialEventTarget> mBackgroundET;
/**
* Stream that receives data from derived classes. The received data will be