зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1456626, use dedicated background thread for nsJARChannel::asyncOpen to avoid blocking r=valentin,michal,froydnj
Differential Revision: https://phabricator.services.mozilla.com/D73065
This commit is contained in:
Родитель
5276336dcf
Коммит
2ccb985109
|
@ -200,11 +200,6 @@ nsresult nsJARChannel::Init(nsIURI* uri) {
|
|||
LOG(("nsJARChannel::Init [this=%p]\n", this));
|
||||
nsresult rv;
|
||||
|
||||
mWorker = do_GetService(NS_STREAMTRANSPORTSERVICE_CONTRACTID, &rv);
|
||||
if (NS_FAILED(rv)) {
|
||||
return rv;
|
||||
}
|
||||
|
||||
mJarURI = do_QueryInterface(uri, &rv);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
|
@ -370,7 +365,6 @@ nsresult nsJARChannel::OpenLocalFile() {
|
|||
|
||||
MOZ_ASSERT(NS_IsMainThread());
|
||||
|
||||
MOZ_ASSERT(mWorker);
|
||||
MOZ_ASSERT(mIsPending);
|
||||
MOZ_ASSERT(mJarFile);
|
||||
|
||||
|
@ -409,31 +403,34 @@ nsresult nsJARChannel::OpenLocalFile() {
|
|||
nsAutoCString innerJarEntry(mInnerJarEntry);
|
||||
|
||||
RefPtr<nsJARChannel> self = this;
|
||||
return mWorker->Dispatch(NS_NewRunnableFunction(
|
||||
"nsJARChannel::OpenLocalFile", [self, jarCache, clonedFile, localJARURI,
|
||||
jarEntry, innerJarEntry]() mutable {
|
||||
RefPtr<nsJARInputThunk> input;
|
||||
nsresult rv =
|
||||
CreateLocalJarInput(jarCache, clonedFile, innerJarEntry,
|
||||
localJARURI, jarEntry, getter_AddRefs(input));
|
||||
return NS_DispatchBackgroundTask(
|
||||
NS_NewRunnableFunction(
|
||||
"nsJARChannel::OpenLocalFile",
|
||||
[self, jarCache, clonedFile, localJARURI, jarEntry,
|
||||
innerJarEntry]() mutable {
|
||||
RefPtr<nsJARInputThunk> input;
|
||||
nsresult rv = CreateLocalJarInput(jarCache, clonedFile,
|
||||
innerJarEntry, localJARURI,
|
||||
jarEntry, getter_AddRefs(input));
|
||||
|
||||
nsCOMPtr<nsIRunnable> target;
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
target = NewRunnableMethod<RefPtr<nsJARInputThunk>, bool>(
|
||||
"nsJARChannel::ContinueOpenLocalFile", self,
|
||||
&nsJARChannel::ContinueOpenLocalFile, input, false);
|
||||
} else {
|
||||
target = NewRunnableMethod<nsresult, bool>(
|
||||
"nsJARChannel::OnOpenLocalFileComplete", self,
|
||||
&nsJARChannel::OnOpenLocalFileComplete, rv, false);
|
||||
}
|
||||
nsCOMPtr<nsIRunnable> target;
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
target = NewRunnableMethod<RefPtr<nsJARInputThunk>, bool>(
|
||||
"nsJARChannel::ContinueOpenLocalFile", self,
|
||||
&nsJARChannel::ContinueOpenLocalFile, input, false);
|
||||
} else {
|
||||
target = NewRunnableMethod<nsresult, bool>(
|
||||
"nsJARChannel::OnOpenLocalFileComplete", self,
|
||||
&nsJARChannel::OnOpenLocalFileComplete, rv, false);
|
||||
}
|
||||
|
||||
// nsJARChannel must be release on main thread, and sometimes
|
||||
// this still hold nsJARChannel after dispatched.
|
||||
self = nullptr;
|
||||
// nsJARChannel must be release on main thread, and sometimes
|
||||
// this still hold nsJARChannel after dispatched.
|
||||
self = nullptr;
|
||||
|
||||
NS_DispatchToMainThread(target.forget());
|
||||
}));
|
||||
NS_DispatchToMainThread(target.forget());
|
||||
}),
|
||||
NS_DISPATCH_EVENT_MAY_BLOCK);
|
||||
}
|
||||
|
||||
nsresult nsJARChannel::ContinueOpenLocalFile(nsJARInputThunk* aInput,
|
||||
|
|
|
@ -104,9 +104,6 @@ class nsJARChannel final : public nsIJARChannel,
|
|||
nsCOMPtr<nsIURI> mJarBaseURI;
|
||||
nsCString mJarEntry;
|
||||
nsCString mInnerJarEntry;
|
||||
|
||||
// use StreamTransportService as background thread
|
||||
nsCOMPtr<nsIEventTarget> mWorker;
|
||||
};
|
||||
|
||||
#endif // nsJARChannel_h__
|
||||
|
|
Загрузка…
Ссылка в новой задаче