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() {
|
||||
if (!resolve_proxy_helper_) {
|
||||
resolve_proxy_helper_ = base::MakeRefCounted<electron::ResolveProxyHelper>(
|
||||
system_network_context_manager()->GetContext());
|
||||
nullptr /* browser_context */);
|
||||
}
|
||||
return resolve_proxy_helper_.get();
|
||||
}
|
||||
|
|
|
@ -609,8 +609,7 @@ ElectronBrowserContext::GetFileSystemAccessPermissionContext() {
|
|||
|
||||
ResolveProxyHelper* ElectronBrowserContext::GetResolveProxyHelper() {
|
||||
if (!resolve_proxy_helper_) {
|
||||
resolve_proxy_helper_ = base::MakeRefCounted<ResolveProxyHelper>(
|
||||
GetDefaultStoragePartition()->GetNetworkContext());
|
||||
resolve_proxy_helper_ = base::MakeRefCounted<ResolveProxyHelper>(this);
|
||||
}
|
||||
return resolve_proxy_helper_.get();
|
||||
}
|
||||
|
|
|
@ -8,17 +8,20 @@
|
|||
|
||||
#include "base/functional/bind.h"
|
||||
#include "content/public/browser/browser_thread.h"
|
||||
#include "content/public/browser/storage_partition.h"
|
||||
#include "mojo/public/cpp/bindings/pending_remote.h"
|
||||
#include "net/base/network_anonymization_key.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;
|
||||
|
||||
namespace electron {
|
||||
|
||||
ResolveProxyHelper::ResolveProxyHelper(
|
||||
network::mojom::NetworkContext* network_context)
|
||||
: network_context_(network_context) {}
|
||||
ResolveProxyHelper::ResolveProxyHelper(ElectronBrowserContext* browser_context)
|
||||
: browser_context_(browser_context) {}
|
||||
|
||||
ResolveProxyHelper::~ResolveProxyHelper() {
|
||||
DCHECK_CURRENTLY_ON(BrowserThread::UI);
|
||||
|
@ -52,9 +55,18 @@ void ResolveProxyHelper::StartPendingRequest() {
|
|||
receiver_.set_disconnect_handler(
|
||||
base::BindOnce(&ResolveProxyHelper::OnProxyLookupComplete,
|
||||
base::Unretained(this), net::ERR_ABORTED, std::nullopt));
|
||||
network_context_->LookUpProxyForURL(pending_requests_.front().url,
|
||||
net::NetworkAnonymizationKey(),
|
||||
std::move(proxy_lookup_client));
|
||||
network::mojom::NetworkContext* network_context = nullptr;
|
||||
if (browser_context_) {
|
||||
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(
|
||||
|
|
|
@ -12,19 +12,20 @@
|
|||
#include "base/memory/raw_ptr.h"
|
||||
#include "base/memory/ref_counted.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 "url/gurl.h"
|
||||
|
||||
namespace electron {
|
||||
|
||||
class ElectronBrowserContext;
|
||||
|
||||
class ResolveProxyHelper
|
||||
: public base::RefCountedThreadSafe<ResolveProxyHelper>,
|
||||
network::mojom::ProxyLookupClient {
|
||||
public:
|
||||
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);
|
||||
|
||||
|
@ -70,7 +71,7 @@ class ResolveProxyHelper
|
|||
mojo::Receiver<network::mojom::ProxyLookupClient> receiver_{this};
|
||||
|
||||
// Weak Ref
|
||||
raw_ptr<network::mojom::NetworkContext> network_context_ = nullptr;
|
||||
raw_ptr<ElectronBrowserContext> browser_context_;
|
||||
};
|
||||
|
||||
} // namespace electron
|
||||
|
|
Loading…
Reference in a new issue