fix: crash when resolving proxy due to network service restart (#42878)
This commit is contained in:
parent
bbd7f4a5ad
commit
1e1dc22e16
4 changed files with 24 additions and 12 deletions
|
@ -329,7 +329,7 @@ const std::string& BrowserProcessImpl::GetSystemLocale() const {
|
||||||
electron::ResolveProxyHelper* BrowserProcessImpl::GetResolveProxyHelper() {
|
electron::ResolveProxyHelper* BrowserProcessImpl::GetResolveProxyHelper() {
|
||||||
if (!resolve_proxy_helper_) {
|
if (!resolve_proxy_helper_) {
|
||||||
resolve_proxy_helper_ = base::MakeRefCounted<electron::ResolveProxyHelper>(
|
resolve_proxy_helper_ = base::MakeRefCounted<electron::ResolveProxyHelper>(
|
||||||
system_network_context_manager()->GetContext());
|
nullptr /* browser_context */);
|
||||||
}
|
}
|
||||||
return resolve_proxy_helper_.get();
|
return resolve_proxy_helper_.get();
|
||||||
}
|
}
|
||||||
|
|
|
@ -609,8 +609,7 @@ ElectronBrowserContext::GetFileSystemAccessPermissionContext() {
|
||||||
|
|
||||||
ResolveProxyHelper* ElectronBrowserContext::GetResolveProxyHelper() {
|
ResolveProxyHelper* ElectronBrowserContext::GetResolveProxyHelper() {
|
||||||
if (!resolve_proxy_helper_) {
|
if (!resolve_proxy_helper_) {
|
||||||
resolve_proxy_helper_ = base::MakeRefCounted<ResolveProxyHelper>(
|
resolve_proxy_helper_ = base::MakeRefCounted<ResolveProxyHelper>(this);
|
||||||
GetDefaultStoragePartition()->GetNetworkContext());
|
|
||||||
}
|
}
|
||||||
return resolve_proxy_helper_.get();
|
return resolve_proxy_helper_.get();
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,17 +8,20 @@
|
||||||
|
|
||||||
#include "base/functional/bind.h"
|
#include "base/functional/bind.h"
|
||||||
#include "content/public/browser/browser_thread.h"
|
#include "content/public/browser/browser_thread.h"
|
||||||
|
#include "content/public/browser/storage_partition.h"
|
||||||
#include "mojo/public/cpp/bindings/pending_remote.h"
|
#include "mojo/public/cpp/bindings/pending_remote.h"
|
||||||
#include "net/base/network_anonymization_key.h"
|
#include "net/base/network_anonymization_key.h"
|
||||||
#include "net/proxy_resolution/proxy_info.h"
|
#include "net/proxy_resolution/proxy_info.h"
|
||||||
|
#include "services/network/public/mojom/network_context.mojom.h"
|
||||||
|
#include "shell/browser/electron_browser_context.h"
|
||||||
|
#include "shell/browser/net/system_network_context_manager.h"
|
||||||
|
|
||||||
using content::BrowserThread;
|
using content::BrowserThread;
|
||||||
|
|
||||||
namespace electron {
|
namespace electron {
|
||||||
|
|
||||||
ResolveProxyHelper::ResolveProxyHelper(
|
ResolveProxyHelper::ResolveProxyHelper(ElectronBrowserContext* browser_context)
|
||||||
network::mojom::NetworkContext* network_context)
|
: browser_context_(browser_context) {}
|
||||||
: network_context_(network_context) {}
|
|
||||||
|
|
||||||
ResolveProxyHelper::~ResolveProxyHelper() {
|
ResolveProxyHelper::~ResolveProxyHelper() {
|
||||||
DCHECK_CURRENTLY_ON(BrowserThread::UI);
|
DCHECK_CURRENTLY_ON(BrowserThread::UI);
|
||||||
|
@ -52,9 +55,18 @@ void ResolveProxyHelper::StartPendingRequest() {
|
||||||
receiver_.set_disconnect_handler(
|
receiver_.set_disconnect_handler(
|
||||||
base::BindOnce(&ResolveProxyHelper::OnProxyLookupComplete,
|
base::BindOnce(&ResolveProxyHelper::OnProxyLookupComplete,
|
||||||
base::Unretained(this), net::ERR_ABORTED, std::nullopt));
|
base::Unretained(this), net::ERR_ABORTED, std::nullopt));
|
||||||
network_context_->LookUpProxyForURL(pending_requests_.front().url,
|
network::mojom::NetworkContext* network_context = nullptr;
|
||||||
net::NetworkAnonymizationKey(),
|
if (browser_context_) {
|
||||||
std::move(proxy_lookup_client));
|
network_context =
|
||||||
|
browser_context_->GetDefaultStoragePartition()->GetNetworkContext();
|
||||||
|
} else {
|
||||||
|
DCHECK(SystemNetworkContextManager::GetInstance());
|
||||||
|
network_context = SystemNetworkContextManager::GetInstance()->GetContext();
|
||||||
|
}
|
||||||
|
CHECK(network_context);
|
||||||
|
network_context->LookUpProxyForURL(pending_requests_.front().url,
|
||||||
|
net::NetworkAnonymizationKey(),
|
||||||
|
std::move(proxy_lookup_client));
|
||||||
}
|
}
|
||||||
|
|
||||||
void ResolveProxyHelper::OnProxyLookupComplete(
|
void ResolveProxyHelper::OnProxyLookupComplete(
|
||||||
|
|
|
@ -12,19 +12,20 @@
|
||||||
#include "base/memory/raw_ptr.h"
|
#include "base/memory/raw_ptr.h"
|
||||||
#include "base/memory/ref_counted.h"
|
#include "base/memory/ref_counted.h"
|
||||||
#include "mojo/public/cpp/bindings/receiver.h"
|
#include "mojo/public/cpp/bindings/receiver.h"
|
||||||
#include "services/network/public/mojom/network_context.mojom.h"
|
|
||||||
#include "services/network/public/mojom/proxy_lookup_client.mojom.h"
|
#include "services/network/public/mojom/proxy_lookup_client.mojom.h"
|
||||||
#include "url/gurl.h"
|
#include "url/gurl.h"
|
||||||
|
|
||||||
namespace electron {
|
namespace electron {
|
||||||
|
|
||||||
|
class ElectronBrowserContext;
|
||||||
|
|
||||||
class ResolveProxyHelper
|
class ResolveProxyHelper
|
||||||
: public base::RefCountedThreadSafe<ResolveProxyHelper>,
|
: public base::RefCountedThreadSafe<ResolveProxyHelper>,
|
||||||
network::mojom::ProxyLookupClient {
|
network::mojom::ProxyLookupClient {
|
||||||
public:
|
public:
|
||||||
using ResolveProxyCallback = base::OnceCallback<void(std::string)>;
|
using ResolveProxyCallback = base::OnceCallback<void(std::string)>;
|
||||||
|
|
||||||
explicit ResolveProxyHelper(network::mojom::NetworkContext* network_context);
|
explicit ResolveProxyHelper(ElectronBrowserContext* browser_context);
|
||||||
|
|
||||||
void ResolveProxy(const GURL& url, ResolveProxyCallback callback);
|
void ResolveProxy(const GURL& url, ResolveProxyCallback callback);
|
||||||
|
|
||||||
|
@ -70,7 +71,7 @@ class ResolveProxyHelper
|
||||||
mojo::Receiver<network::mojom::ProxyLookupClient> receiver_{this};
|
mojo::Receiver<network::mojom::ProxyLookupClient> receiver_{this};
|
||||||
|
|
||||||
// Weak Ref
|
// Weak Ref
|
||||||
raw_ptr<network::mojom::NetworkContext> network_context_ = nullptr;
|
raw_ptr<ElectronBrowserContext> browser_context_;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace electron
|
} // namespace electron
|
||||||
|
|
Loading…
Reference in a new issue