Avi Drissman | 4e1b7bc3 | 2022-09-15 14:03:50 | [diff] [blame] | 1 | // Copyright 2022 The Chromium Authors |
Max Curran | cc1ab0c | 2022-09-12 22:03:11 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
Peter Conn | 3816460 | 2025-08-06 14:41:19 | [diff] [blame] | 5 | #include "content/browser/preloading/proxy_lookup_client_impl.h" |
Max Curran | cc1ab0c | 2022-09-12 22:03:11 | [diff] [blame] | 6 | |
Avi Drissman | adac2199 | 2023-01-11 23:46:39 | [diff] [blame] | 7 | #include "base/functional/bind.h" |
Max Curran | cc1ab0c | 2022-09-12 22:03:11 | [diff] [blame] | 8 | #include "content/public/browser/browser_thread.h" |
Lingqi Chi | a8e39ed5 | 2024-08-29 05:20:37 | [diff] [blame] | 9 | #include "net/base/net_errors.h" |
| 10 | #include "net/base/network_anonymization_key.h" |
| 11 | #include "net/base/schemeful_site.h" |
Max Curran | cc1ab0c | 2022-09-12 22:03:11 | [diff] [blame] | 12 | #include "net/proxy_resolution/proxy_info.h" |
| 13 | #include "services/network/public/mojom/network_context.mojom.h" |
| 14 | #include "url/gurl.h" |
| 15 | |
| 16 | namespace content { |
| 17 | |
| 18 | ProxyLookupClientImpl::ProxyLookupClientImpl( |
| 19 | const GURL& url, |
Peter E Conn | 2352ee6 | 2025-07-30 17:12:38 | [diff] [blame] | 20 | const net::NetworkAnonymizationKey network_anonymization_key, |
Max Curran | cc1ab0c | 2022-09-12 22:03:11 | [diff] [blame] | 21 | ProxyLookupCallback callback, |
| 22 | network::mojom::NetworkContext* network_context) |
| 23 | : callback_(std::move(callback)) { |
| 24 | DCHECK(network_context); |
| 25 | DCHECK_CURRENTLY_ON(BrowserThread::UI); |
Brianna Goldstein | d22b064 | 2022-10-11 16:30:50 | [diff] [blame] | 26 | network_context->LookUpProxyForURL(url, network_anonymization_key, |
Max Curran | cc1ab0c | 2022-09-12 22:03:11 | [diff] [blame] | 27 | receiver_.BindNewPipeAndPassRemote()); |
| 28 | receiver_.set_disconnect_handler( |
| 29 | base::BindOnce(&ProxyLookupClientImpl::OnProxyLookupComplete, |
Arthur Sonzogni | c686e8f | 2024-01-11 08:36:37 | [diff] [blame] | 30 | base::Unretained(this), net::ERR_ABORTED, std::nullopt)); |
Max Curran | cc1ab0c | 2022-09-12 22:03:11 | [diff] [blame] | 31 | } |
| 32 | |
Peter E Conn | 2352ee6 | 2025-07-30 17:12:38 | [diff] [blame] | 33 | ProxyLookupClientImpl::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 Curran | cc1ab0c | 2022-09-12 22:03:11 | [diff] [blame] | 43 | ProxyLookupClientImpl::~ProxyLookupClientImpl() = default; |
| 44 | |
| 45 | void ProxyLookupClientImpl::OnProxyLookupComplete( |
| 46 | int32_t net_error, |
Arthur Sonzogni | c686e8f | 2024-01-11 08:36:37 | [diff] [blame] | 47 | const std::optional<net::ProxyInfo>& proxy_info) { |
Max Curran | cc1ab0c | 2022-09-12 22:03:11 | [diff] [blame] | 48 | bool has_proxy = proxy_info.has_value() && !proxy_info->is_direct(); |
| 49 | std::move(callback_).Run(has_proxy); |
| 50 | } |
| 51 | |
| 52 | } // namespace content |