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 commit 419151a98a16814ea63e9abc197c6ae27f48128c. Co-authored-by: deepak1556 <hop2deep@gmail.com> * Revert "Revert "fix: destroy url loader wrapper when JS env exits"" This reverts commit 4b401b03c62aca79498660f995825491ae52f179. 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:
parent
50edc9bfe2
commit
42c88eba7c
2 changed files with 14 additions and 7 deletions
|
@ -379,13 +379,13 @@ void SimpleURLLoaderWrapper::Start() {
|
||||||
loader_->SetAllowHttpErrorResults(true);
|
loader_->SetAllowHttpErrorResults(true);
|
||||||
loader_->SetURLLoaderFactoryOptions(request_options_);
|
loader_->SetURLLoaderFactoryOptions(request_options_);
|
||||||
loader_->SetOnResponseStartedCallback(base::BindOnce(
|
loader_->SetOnResponseStartedCallback(base::BindOnce(
|
||||||
&SimpleURLLoaderWrapper::OnResponseStarted, base::Unretained(this)));
|
&SimpleURLLoaderWrapper::OnResponseStarted, weak_factory_.GetWeakPtr()));
|
||||||
loader_->SetOnRedirectCallback(base::BindRepeating(
|
loader_->SetOnRedirectCallback(base::BindRepeating(
|
||||||
&SimpleURLLoaderWrapper::OnRedirect, base::Unretained(this)));
|
&SimpleURLLoaderWrapper::OnRedirect, weak_factory_.GetWeakPtr()));
|
||||||
loader_->SetOnUploadProgressCallback(base::BindRepeating(
|
loader_->SetOnUploadProgressCallback(base::BindRepeating(
|
||||||
&SimpleURLLoaderWrapper::OnUploadProgress, base::Unretained(this)));
|
&SimpleURLLoaderWrapper::OnUploadProgress, weak_factory_.GetWeakPtr()));
|
||||||
loader_->SetOnDownloadProgressCallback(base::BindRepeating(
|
loader_->SetOnDownloadProgressCallback(base::BindRepeating(
|
||||||
&SimpleURLLoaderWrapper::OnDownloadProgress, base::Unretained(this)));
|
&SimpleURLLoaderWrapper::OnDownloadProgress, weak_factory_.GetWeakPtr()));
|
||||||
|
|
||||||
url_loader_factory_ = GetURLLoaderFactoryForURL(request_ref->url);
|
url_loader_factory_ = GetURLLoaderFactoryForURL(request_ref->url);
|
||||||
loader_->DownloadAsStream(url_loader_factory_.get(), this);
|
loader_->DownloadAsStream(url_loader_factory_.get(), this);
|
||||||
|
@ -716,14 +716,19 @@ void SimpleURLLoaderWrapper::OnDataReceived(std::string_view string_piece,
|
||||||
}
|
}
|
||||||
|
|
||||||
void SimpleURLLoaderWrapper::OnComplete(bool success) {
|
void SimpleURLLoaderWrapper::OnComplete(bool success) {
|
||||||
|
auto self = weak_factory_.GetWeakPtr();
|
||||||
if (success) {
|
if (success) {
|
||||||
Emit("complete");
|
Emit("complete");
|
||||||
} else {
|
} else {
|
||||||
Emit("error", net::ErrorToString(loader_->NetError()));
|
Emit("error", net::ErrorToString(loader_->NetError()));
|
||||||
}
|
}
|
||||||
loader_.reset();
|
// If users initiate process shutdown when the event is emitted, then
|
||||||
pinned_wrapper_.Reset();
|
// we would perform cleanup of the wrapper and we should bail out below.
|
||||||
pinned_chunk_pipe_getter_.Reset();
|
if (self) {
|
||||||
|
loader_.reset();
|
||||||
|
pinned_wrapper_.Reset();
|
||||||
|
pinned_chunk_pipe_getter_.Reset();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void SimpleURLLoaderWrapper::OnRetry(base::OnceClosure start_retry) {}
|
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_loader_network_service_observer.mojom.h"
|
||||||
#include "services/network/public/mojom/url_response_head.mojom.h"
|
#include "services/network/public/mojom/url_response_head.mojom.h"
|
||||||
#include "shell/browser/event_emitter_mixin.h"
|
#include "shell/browser/event_emitter_mixin.h"
|
||||||
|
#include "shell/common/gin_helper/cleaned_up_at_exit.h"
|
||||||
#include "url/gurl.h"
|
#include "url/gurl.h"
|
||||||
#include "v8/include/v8.h"
|
#include "v8/include/v8.h"
|
||||||
|
|
||||||
|
@ -47,6 +48,7 @@ namespace electron::api {
|
||||||
class SimpleURLLoaderWrapper final
|
class SimpleURLLoaderWrapper final
|
||||||
: public gin::Wrappable<SimpleURLLoaderWrapper>,
|
: public gin::Wrappable<SimpleURLLoaderWrapper>,
|
||||||
public gin_helper::EventEmitterMixin<SimpleURLLoaderWrapper>,
|
public gin_helper::EventEmitterMixin<SimpleURLLoaderWrapper>,
|
||||||
|
public gin_helper::CleanedUpAtExit,
|
||||||
private network::SimpleURLLoaderStreamConsumer,
|
private network::SimpleURLLoaderStreamConsumer,
|
||||||
private network::mojom::URLLoaderNetworkServiceObserver {
|
private network::mojom::URLLoaderNetworkServiceObserver {
|
||||||
public:
|
public:
|
||||||
|
|
Loading…
Reference in a new issue