blob: 2ebb69fdd9ae26571088c2212779631ab2ee9545 [file] [log] [blame]
Avi Drissman4e1b7bc32022-09-15 14:03:501// Copyright 2022 The Chromium Authors
Max Currancc1ab0c2022-09-12 22:03:112// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
Peter Conn38164602025-08-06 14:41:195#include "content/browser/preloading/proxy_lookup_client_impl.h"
Max Currancc1ab0c2022-09-12 22:03:116
Avi Drissmanadac21992023-01-11 23:46:397#include "base/functional/bind.h"
Max Currancc1ab0c2022-09-12 22:03:118#include "content/public/browser/browser_thread.h"
Lingqi Chia8e39ed52024-08-29 05:20:379#include "net/base/net_errors.h"
10#include "net/base/network_anonymization_key.h"
11#include "net/base/schemeful_site.h"
Max Currancc1ab0c2022-09-12 22:03:1112#include "net/proxy_resolution/proxy_info.h"
13#include "services/network/public/mojom/network_context.mojom.h"
14#include "url/gurl.h"
15
16namespace content {
17
18ProxyLookupClientImpl::ProxyLookupClientImpl(
19 const GURL& url,
Peter E Conn2352ee62025-07-30 17:12:3820 const net::NetworkAnonymizationKey network_anonymization_key,
Max Currancc1ab0c2022-09-12 22:03:1121 ProxyLookupCallback callback,
22 network::mojom::NetworkContext* network_context)
23 : callback_(std::move(callback)) {
24 DCHECK(network_context);
25 DCHECK_CURRENTLY_ON(BrowserThread::UI);
Brianna Goldsteind22b0642022-10-11 16:30:5026 network_context->LookUpProxyForURL(url, network_anonymization_key,
Max Currancc1ab0c2022-09-12 22:03:1127 receiver_.BindNewPipeAndPassRemote());
28 receiver_.set_disconnect_handler(
29 base::BindOnce(&ProxyLookupClientImpl::OnProxyLookupComplete,
Arthur Sonzognic686e8f2024-01-11 08:36:3730 base::Unretained(this), net::ERR_ABORTED, std::nullopt));
Max Currancc1ab0c2022-09-12 22:03:1131}
32
Peter E Conn2352ee62025-07-30 17:12:3833ProxyLookupClientImpl::ProxyLookupClientImpl(
34 const GURL& url,
35 ProxyLookupCallback callback,
36 network::mojom::NetworkContext* network_context)
37 : ProxyLookupClientImpl(
38 url,
39 net::NetworkAnonymizationKey::CreateSameSite(net::SchemefulSite(url)),
40 std::move(callback),
41 network_context) {}
42
Max Currancc1ab0c2022-09-12 22:03:1143ProxyLookupClientImpl::~ProxyLookupClientImpl() = default;
44
45void ProxyLookupClientImpl::OnProxyLookupComplete(
46 int32_t net_error,
Arthur Sonzognic686e8f2024-01-11 08:36:3747 const std::optional<net::ProxyInfo>& proxy_info) {
Max Currancc1ab0c2022-09-12 22:03:1148 bool has_proxy = proxy_info.has_value() && !proxy_info->is_direct();
49 std::move(callback_).Run(has_proxy);
50}
51
52} // namespace content