blob: c46422ec6a3a90efde45f97c21d486e5d6959c29 [file] [log] [blame]
Avi Drissman4a8573c2022-09-09 19:35:541// Copyright 2018 The Chromium Authors
Alexandr Ilin5b417db2018-08-17 18:34:002// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
Peter E Conn2352ee62025-07-30 17:12:385#ifndef CONTENT_BROWSER_PRELOADING_RESOLVE_HOST_CLIENT_IMPL_H_
6#define CONTENT_BROWSER_PRELOADING_RESOLVE_HOST_CLIENT_IMPL_H_
Alexandr Ilin5b417db2018-08-17 18:34:007
Arthur Sonzognife132ee2024-01-15 11:01:048#include <optional>
9
Avi Drissman9269d4ed2023-01-07 01:38:0610#include "base/functional/bind.h"
Gabriel Charetted87f10f2022-03-31 00:44:2211#include "base/time/time.h"
Miyoung Shin5e36fee2019-10-15 01:59:5312#include "mojo/public/cpp/bindings/receiver.h"
Alexandr Ilin5b417db2018-08-17 18:34:0013#include "net/base/address_list.h"
Yoichiro Hibaracf4081df2022-09-12 13:15:4214#include "net/dns/public/host_resolver_results.h"
Eric Orthcf81ba12019-01-16 18:56:3415#include "services/network/public/cpp/resolve_host_client_base.h"
Gyuyoung Kim7b80f7a2020-02-19 02:06:1216#include "services/network/public/mojom/host_resolver.mojom-forward.h"
Alexandr Ilin5b417db2018-08-17 18:34:0017
18class GURL;
19
Matt Menkebdcaff702019-12-05 19:01:1620namespace net {
Brianna Goldsteind22b0642022-10-11 16:30:5021class NetworkAnonymizationKey;
Yoichiro Hibaracf4081df2022-09-12 13:15:4222} // namespace net
Matt Menkebdcaff702019-12-05 19:01:1623
Peter E Conn2352ee62025-07-30 17:12:3824namespace network::mojom {
Alexandr Ilin5b417db2018-08-17 18:34:0025class NetworkContext;
Peter E Conn2352ee62025-07-30 17:12:3826} // namespace network::mojom
Alexandr Ilin5b417db2018-08-17 18:34:0027
Peter E Conn2352ee62025-07-30 17:12:3828namespace content {
Alexandr Ilin5b417db2018-08-17 18:34:0029
30using ResolveHostCallback = base::OnceCallback<void(bool success)>;
31
32// This class helps perform the host resolution using the NetworkContext.
33// An instance of this class must be deleted after the callback is invoked.
Eric Orthcf81ba12019-01-16 18:56:3434class ResolveHostClientImpl : public network::ResolveHostClientBase {
Alexandr Ilin5b417db2018-08-17 18:34:0035 public:
36 // Starts the host resolution for |url|. |callback| is called when the host is
37 // resolved or when an error occurs.
Brianna Goldsteind22b0642022-10-11 16:30:5038 ResolveHostClientImpl(
39 const GURL& url,
Brianna Goldstein581e2af82022-10-20 13:56:3040 const net::NetworkAnonymizationKey& network_anonymization_key,
Brianna Goldsteind22b0642022-10-11 16:30:5041 ResolveHostCallback callback,
42 network::mojom::NetworkContext* network_context);
Peter Boström53c6c5952021-09-17 09:41:2643
44 ResolveHostClientImpl(const ResolveHostClientImpl&) = delete;
45 ResolveHostClientImpl& operator=(const ResolveHostClientImpl&) = delete;
46
Alexandr Ilin5b417db2018-08-17 18:34:0047 // Cancels the request if it hasn't been completed yet.
48 ~ResolveHostClientImpl() override;
49
50 // network::mojom::ResolveHostClient:
David Benjamin1627af92025-07-22 11:13:3851 void OnComplete(
52 int result,
53 const net::ResolveErrorInfo& resolve_error_info,
54 const net::AddressList& resolved_addresses,
55 const net::HostResolverEndpointResults& alternative_endpoints) override;
Alexandr Ilin5b417db2018-08-17 18:34:0056
57 void OnConnectionError();
58
59 private:
Colin Blundelle7e33112022-03-16 10:18:3860 base::TimeTicks resolve_host_start_time_;
Miyoung Shin5e36fee2019-10-15 01:59:5361 mojo::Receiver<network::mojom::ResolveHostClient> receiver_{this};
Alexandr Ilin5b417db2018-08-17 18:34:0062 ResolveHostCallback callback_;
Alexandr Ilin5b417db2018-08-17 18:34:0063};
64
Peter E Conn2352ee62025-07-30 17:12:3865} // namespace content
Alexandr Ilin5b417db2018-08-17 18:34:0066
Peter E Conn2352ee62025-07-30 17:12:3867#endif // CONTENT_BROWSER_PRELOADING_RESOLVE_HOST_CLIENT_IMPL_H_