зеркало из https://github.com/electron/electron.git
fix: destroy url loader wrapper when JS env exits (#44730)
* fix: destroy url loader wrapper when JS env exits Co-authored-by: deepak1556 <hop2deep@gmail.com> * Revert "fix: destroy url loader wrapper when JS env exits" This reverts commit419151a98a
. Co-authored-by: deepak1556 <hop2deep@gmail.com> * Revert "Revert "fix: destroy url loader wrapper when JS env exits"" This reverts commit4b401b03c6
. Co-authored-by: deepak1556 <hop2deep@gmail.com> * fix: double free of JSChunkedDataPipeGetter Co-authored-by: deepak1556 <hop2deep@gmail.com> * fix: crash on process exit after stream completes Co-authored-by: deepak1556 <hop2deep@gmail.com> --------- Co-authored-by: trop[bot] <37223003+trop[bot]@users.noreply.github.com> Co-authored-by: deepak1556 <hop2deep@gmail.com>
This commit is contained in:
Родитель
50edc9bfe2
Коммит
42c88eba7c
|
@ -379,13 +379,13 @@ void SimpleURLLoaderWrapper::Start() {
|
|||
loader_->SetAllowHttpErrorResults(true);
|
||||
loader_->SetURLLoaderFactoryOptions(request_options_);
|
||||
loader_->SetOnResponseStartedCallback(base::BindOnce(
|
||||
&SimpleURLLoaderWrapper::OnResponseStarted, base::Unretained(this)));
|
||||
&SimpleURLLoaderWrapper::OnResponseStarted, weak_factory_.GetWeakPtr()));
|
||||
loader_->SetOnRedirectCallback(base::BindRepeating(
|
||||
&SimpleURLLoaderWrapper::OnRedirect, base::Unretained(this)));
|
||||
&SimpleURLLoaderWrapper::OnRedirect, weak_factory_.GetWeakPtr()));
|
||||
loader_->SetOnUploadProgressCallback(base::BindRepeating(
|
||||
&SimpleURLLoaderWrapper::OnUploadProgress, base::Unretained(this)));
|
||||
&SimpleURLLoaderWrapper::OnUploadProgress, weak_factory_.GetWeakPtr()));
|
||||
loader_->SetOnDownloadProgressCallback(base::BindRepeating(
|
||||
&SimpleURLLoaderWrapper::OnDownloadProgress, base::Unretained(this)));
|
||||
&SimpleURLLoaderWrapper::OnDownloadProgress, weak_factory_.GetWeakPtr()));
|
||||
|
||||
url_loader_factory_ = GetURLLoaderFactoryForURL(request_ref->url);
|
||||
loader_->DownloadAsStream(url_loader_factory_.get(), this);
|
||||
|
@ -716,14 +716,19 @@ void SimpleURLLoaderWrapper::OnDataReceived(std::string_view string_piece,
|
|||
}
|
||||
|
||||
void SimpleURLLoaderWrapper::OnComplete(bool success) {
|
||||
auto self = weak_factory_.GetWeakPtr();
|
||||
if (success) {
|
||||
Emit("complete");
|
||||
} else {
|
||||
Emit("error", net::ErrorToString(loader_->NetError()));
|
||||
}
|
||||
loader_.reset();
|
||||
pinned_wrapper_.Reset();
|
||||
pinned_chunk_pipe_getter_.Reset();
|
||||
// If users initiate process shutdown when the event is emitted, then
|
||||
// we would perform cleanup of the wrapper and we should bail out below.
|
||||
if (self) {
|
||||
loader_.reset();
|
||||
pinned_wrapper_.Reset();
|
||||
pinned_chunk_pipe_getter_.Reset();
|
||||
}
|
||||
}
|
||||
|
||||
void SimpleURLLoaderWrapper::OnRetry(base::OnceClosure start_retry) {}
|
||||
|
|
|
@ -22,6 +22,7 @@
|
|||
#include "services/network/public/mojom/url_loader_network_service_observer.mojom.h"
|
||||
#include "services/network/public/mojom/url_response_head.mojom.h"
|
||||
#include "shell/browser/event_emitter_mixin.h"
|
||||
#include "shell/common/gin_helper/cleaned_up_at_exit.h"
|
||||
#include "url/gurl.h"
|
||||
#include "v8/include/v8.h"
|
||||
|
||||
|
@ -47,6 +48,7 @@ namespace electron::api {
|
|||
class SimpleURLLoaderWrapper final
|
||||
: public gin::Wrappable<SimpleURLLoaderWrapper>,
|
||||
public gin_helper::EventEmitterMixin<SimpleURLLoaderWrapper>,
|
||||
public gin_helper::CleanedUpAtExit,
|
||||
private network::SimpleURLLoaderStreamConsumer,
|
||||
private network::mojom::URLLoaderNetworkServiceObserver {
|
||||
public:
|
||||
|
|
Загрузка…
Ссылка в новой задаче