Backed out changeset 85d3ad4be91a (bug 1456626) for causing leaks. CLOSED TREE

This commit is contained in:
Cosmin Sabou 2020-05-11 20:00:07 +03:00
Родитель 11ab196725
Коммит c7662689a3
2 изменённых файлов: 31 добавлений и 25 удалений

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

@ -200,6 +200,11 @@ nsresult nsJARChannel::Init(nsIURI* uri) {
LOG(("nsJARChannel::Init [this=%p]\n", this)); LOG(("nsJARChannel::Init [this=%p]\n", this));
nsresult rv; nsresult rv;
mWorker = do_GetService(NS_STREAMTRANSPORTSERVICE_CONTRACTID, &rv);
if (NS_FAILED(rv)) {
return rv;
}
mJarURI = do_QueryInterface(uri, &rv); mJarURI = do_QueryInterface(uri, &rv);
if (NS_FAILED(rv)) return rv; if (NS_FAILED(rv)) return rv;
@ -365,6 +370,7 @@ nsresult nsJARChannel::OpenLocalFile() {
MOZ_ASSERT(NS_IsMainThread()); MOZ_ASSERT(NS_IsMainThread());
MOZ_ASSERT(mWorker);
MOZ_ASSERT(mIsPending); MOZ_ASSERT(mIsPending);
MOZ_ASSERT(mJarFile); MOZ_ASSERT(mJarFile);
@ -403,34 +409,31 @@ nsresult nsJARChannel::OpenLocalFile() {
nsAutoCString innerJarEntry(mInnerJarEntry); nsAutoCString innerJarEntry(mInnerJarEntry);
RefPtr<nsJARChannel> self = this; RefPtr<nsJARChannel> self = this;
return NS_DispatchBackgroundTask( return mWorker->Dispatch(NS_NewRunnableFunction(
NS_NewRunnableFunction( "nsJARChannel::OpenLocalFile", [self, jarCache, clonedFile, localJARURI,
"nsJARChannel::OpenLocalFile", jarEntry, innerJarEntry]() mutable {
[self, jarCache, clonedFile, localJARURI, jarEntry, RefPtr<nsJARInputThunk> input;
innerJarEntry]() mutable { nsresult rv =
RefPtr<nsJARInputThunk> input; CreateLocalJarInput(jarCache, clonedFile, innerJarEntry,
nsresult rv = CreateLocalJarInput(jarCache, clonedFile, localJARURI, jarEntry, getter_AddRefs(input));
innerJarEntry, localJARURI,
jarEntry, getter_AddRefs(input));
nsCOMPtr<nsIRunnable> target; nsCOMPtr<nsIRunnable> target;
if (NS_SUCCEEDED(rv)) { if (NS_SUCCEEDED(rv)) {
target = NewRunnableMethod<RefPtr<nsJARInputThunk>, bool>( target = NewRunnableMethod<RefPtr<nsJARInputThunk>, bool>(
"nsJARChannel::ContinueOpenLocalFile", self, "nsJARChannel::ContinueOpenLocalFile", self,
&nsJARChannel::ContinueOpenLocalFile, input, false); &nsJARChannel::ContinueOpenLocalFile, input, false);
} else { } else {
target = NewRunnableMethod<nsresult, bool>( target = NewRunnableMethod<nsresult, bool>(
"nsJARChannel::OnOpenLocalFileComplete", self, "nsJARChannel::OnOpenLocalFileComplete", self,
&nsJARChannel::OnOpenLocalFileComplete, rv, false); &nsJARChannel::OnOpenLocalFileComplete, rv, false);
} }
// nsJARChannel must be release on main thread, and sometimes // nsJARChannel must be release on main thread, and sometimes
// this still hold nsJARChannel after dispatched. // this still hold nsJARChannel after dispatched.
self = nullptr; self = nullptr;
NS_DispatchToMainThread(target.forget()); NS_DispatchToMainThread(target.forget());
}), }));
NS_DISPATCH_EVENT_MAY_BLOCK);
} }
nsresult nsJARChannel::ContinueOpenLocalFile(nsJARInputThunk* aInput, nsresult nsJARChannel::ContinueOpenLocalFile(nsJARInputThunk* aInput,

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

@ -104,6 +104,9 @@ class nsJARChannel final : public nsIJARChannel,
nsCOMPtr<nsIURI> mJarBaseURI; nsCOMPtr<nsIURI> mJarBaseURI;
nsCString mJarEntry; nsCString mJarEntry;
nsCString mInnerJarEntry; nsCString mInnerJarEntry;
// use StreamTransportService as background thread
nsCOMPtr<nsIEventTarget> mWorker;
}; };
#endif // nsJARChannel_h__ #endif // nsJARChannel_h__