electron/shell/browser/net/resolve_proxy_helper.cc
electron-roller[bot] 81c143318b
chore: bump chromium to 94.0.4590.2 (main) (#30274)
* chore: bump chromium in DEPS to 94.0.4587.0

* chore: update patches

* 2823155: fix GPU video decoding capabilities enumeration

Ref: https://chromium-review.googlesource.com/c/chromium/src/+/2823155

* 3041383: Reduce includes in url_request_mojom_traits.h

Ref: https://chromium-review.googlesource.com/c/chromium/src/+/3041383

* chore: bump chromium in DEPS to 94.0.4588.0

* chore: update patches

* chore: bump chromium in DEPS to 94.0.4589.0

* chore: update patches

* 3050633: Rename ScaleFactor to ResourceScaleFactor

Ref: https://chromium-review.googlesource.com/c/chromium/src/+/3050633

* 3048296: Create new mojo target to prevent traits header spreading

Ref: https://chromium-review.googlesource.com/c/chromium/src/+/3048296

* 3046186: Rename base::ClampToRange

Ref: https://chromium-review.googlesource.com/c/chromium/src/+/3046186

* chore: update picture-in-picture patch

Ref: https://chromium-review.googlesource.com/c/chromium/src/+/3056037

* chore: bump chromium in DEPS to 94.0.4590.0

* chore: update patches

* 3057495: Fix base::NoDestructor usage in Mac KeychainPassword

Ref: https://chromium-review.googlesource.com/c/chromium/src/+/3057495

* 3056134: Remove NetworkIsolationKey unused methods

Ref: https://chromium-review.googlesource.com/c/chromium/src/+/3056134

* 3035091: [rab/gsab] Fix gsab maxByteLength after transferring to worker

Adds a patch to v8 to disable a DCHECK that is also firing on node streams
in child processes.

Ref: https://chromium-review.googlesource.com/c/v8/v8/+/3035091

* chore: bump chromium in DEPS to 94.0.4590.2

* chore: fix mas_no_private_api.patch

Ref: https://chromium-review.googlesource.com/c/chromium/src/+/3049052

* 3049555: [views] Add CHECK to prevent fallthrough to global NativeTheme

Ref: https://chromium-review.googlesource.com/c/chromium/src/+/3049555

* chore: empty commit

* chore: fix whitespace for lint

* chore: cherry-pick chromium woa fix

* Revert "chore: cherry-pick chromium woa fix"

This reverts commit 64f3082e2d5f93ef0e2ac5d98246532a105fd4a1.

* chore: fix the build on Windows on ARM

* chore: remove commented code in printing.patch

* fixup! chore: remove commented code in printing.patch

do not remove the new weak_ptr check

* build: sync disable_use_lld_for_macos.patch

Co-authored-by: electron-roller[bot] <84116207+electron-roller[bot]@users.noreply.github.com>
Co-authored-by: VerteDinde <khammond@slack-corp.com>
Co-authored-by: PatchUp <73610968+patchup[bot]@users.noreply.github.com>
Co-authored-by: VerteDinde <keeleymhammond@gmail.com>
Co-authored-by: Charles Kerr <charles@charleskerr.com>
2021-08-11 17:04:56 -04:00

101 lines
3.2 KiB
C++

// Copyright (c) 2018 GitHub, Inc.
// Use of this source code is governed by the MIT license that can be
// found in the LICENSE file.
#include "shell/browser/net/resolve_proxy_helper.h"
#include <utility>
#include "base/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/proxy_resolution/proxy_info.h"
#include "services/network/public/mojom/network_context.mojom.h"
#include "shell/browser/electron_browser_context.h"
using content::BrowserThread;
namespace electron {
ResolveProxyHelper::ResolveProxyHelper(ElectronBrowserContext* browser_context)
: browser_context_(browser_context) {}
ResolveProxyHelper::~ResolveProxyHelper() {
DCHECK_CURRENTLY_ON(BrowserThread::UI);
DCHECK(!owned_self_);
DCHECK(!receiver_.is_bound());
// Clear all pending requests if the ProxyService is still alive.
pending_requests_.clear();
}
void ResolveProxyHelper::ResolveProxy(const GURL& url,
ResolveProxyCallback callback) {
DCHECK_CURRENTLY_ON(BrowserThread::UI);
// Enqueue the pending request.
pending_requests_.emplace_back(url, std::move(callback));
// If nothing is in progress, start.
if (!receiver_.is_bound()) {
DCHECK_EQ(1u, pending_requests_.size());
StartPendingRequest();
}
}
void ResolveProxyHelper::StartPendingRequest() {
DCHECK_CURRENTLY_ON(BrowserThread::UI);
DCHECK(!receiver_.is_bound());
DCHECK(!pending_requests_.empty());
// Start the request.
mojo::PendingRemote<network::mojom::ProxyLookupClient> proxy_lookup_client =
receiver_.BindNewPipeAndPassRemote();
receiver_.set_disconnect_handler(
base::BindOnce(&ResolveProxyHelper::OnProxyLookupComplete,
base::Unretained(this), net::ERR_ABORTED, absl::nullopt));
browser_context_->GetDefaultStoragePartition()
->GetNetworkContext()
->LookUpProxyForURL(pending_requests_.front().url,
net::NetworkIsolationKey(),
std::move(proxy_lookup_client));
}
void ResolveProxyHelper::OnProxyLookupComplete(
int32_t net_error,
const absl::optional<net::ProxyInfo>& proxy_info) {
DCHECK_CURRENTLY_ON(BrowserThread::UI);
DCHECK(!pending_requests_.empty());
receiver_.reset();
// Clear the current (completed) request.
PendingRequest completed_request = std::move(pending_requests_.front());
pending_requests_.pop_front();
std::string proxy;
if (proxy_info)
proxy = proxy_info->ToPacString();
if (!completed_request.callback.is_null())
std::move(completed_request.callback).Run(proxy);
// Start the next request.
if (!pending_requests_.empty())
StartPendingRequest();
}
ResolveProxyHelper::PendingRequest::PendingRequest(
const GURL& url,
ResolveProxyCallback callback)
: url(url), callback(std::move(callback)) {}
ResolveProxyHelper::PendingRequest::PendingRequest(
ResolveProxyHelper::PendingRequest&& pending_request) = default;
ResolveProxyHelper::PendingRequest::~PendingRequest() noexcept = default;
ResolveProxyHelper::PendingRequest&
ResolveProxyHelper::PendingRequest::operator=(
ResolveProxyHelper::PendingRequest&& pending_request) noexcept = default;
} // namespace electron