2023-04-05 14:06:14 +00:00
|
|
|
// Copyright (c) 2023 Signal Messenger, LLC
|
|
|
|
// Use of this source code is governed by the MIT license that can be
|
|
|
|
// found in the LICENSE file.
|
|
|
|
|
|
|
|
#ifndef ELECTRON_SHELL_BROWSER_NET_RESOLVE_HOST_FUNCTION_H_
|
|
|
|
#define ELECTRON_SHELL_BROWSER_NET_RESOLVE_HOST_FUNCTION_H_
|
|
|
|
|
2024-01-10 22:23:35 +00:00
|
|
|
#include <optional>
|
2023-04-05 14:06:14 +00:00
|
|
|
#include <string>
|
|
|
|
|
2023-05-11 20:07:39 +00:00
|
|
|
#include "base/memory/raw_ptr.h"
|
2023-04-05 14:06:14 +00:00
|
|
|
#include "base/memory/ref_counted.h"
|
2024-01-04 21:20:37 +00:00
|
|
|
#include "base/sequence_checker.h"
|
2023-04-05 14:06:14 +00:00
|
|
|
#include "mojo/public/cpp/bindings/receiver.h"
|
|
|
|
#include "net/base/address_list.h"
|
|
|
|
#include "net/dns/public/host_resolver_results.h"
|
|
|
|
#include "services/network/public/cpp/resolve_host_client_base.h"
|
|
|
|
#include "services/network/public/mojom/host_resolver.mojom.h"
|
|
|
|
#include "services/network/public/mojom/network_context.mojom.h"
|
|
|
|
|
|
|
|
namespace electron {
|
|
|
|
|
|
|
|
class ElectronBrowserContext;
|
|
|
|
|
|
|
|
class ResolveHostFunction
|
|
|
|
: public base::RefCountedThreadSafe<ResolveHostFunction>,
|
|
|
|
network::ResolveHostClientBase {
|
|
|
|
public:
|
2024-01-10 22:23:35 +00:00
|
|
|
using ResolveHostCallback = base::OnceCallback<
|
|
|
|
void(int64_t, const std::optional<net::AddressList>& resolved_addresses)>;
|
2023-04-05 14:06:14 +00:00
|
|
|
|
|
|
|
explicit ResolveHostFunction(ElectronBrowserContext* browser_context,
|
|
|
|
std::string host,
|
|
|
|
network::mojom::ResolveHostParametersPtr params,
|
|
|
|
ResolveHostCallback callback);
|
|
|
|
|
|
|
|
void Run();
|
|
|
|
|
|
|
|
// disable copy
|
|
|
|
ResolveHostFunction(const ResolveHostFunction&) = delete;
|
|
|
|
ResolveHostFunction& operator=(const ResolveHostFunction&) = delete;
|
|
|
|
|
|
|
|
protected:
|
|
|
|
~ResolveHostFunction() override;
|
|
|
|
|
|
|
|
private:
|
|
|
|
friend class base::RefCountedThreadSafe<ResolveHostFunction>;
|
|
|
|
|
|
|
|
// network::mojom::ResolveHostClient implementation
|
|
|
|
void OnComplete(int result,
|
|
|
|
const net::ResolveErrorInfo& resolve_error_info,
|
2024-01-10 22:23:35 +00:00
|
|
|
const std::optional<net::AddressList>& resolved_addresses,
|
|
|
|
const std::optional<net::HostResolverEndpointResults>&
|
2023-04-05 14:06:14 +00:00
|
|
|
endpoint_results_with_metadata) override;
|
|
|
|
|
2024-01-04 21:20:37 +00:00
|
|
|
SEQUENCE_CHECKER(sequence_checker_);
|
|
|
|
|
2023-04-05 14:06:14 +00:00
|
|
|
// Receiver for the currently in-progress request, if any.
|
|
|
|
mojo::Receiver<network::mojom::ResolveHostClient> receiver_{this};
|
|
|
|
|
|
|
|
// Weak Ref
|
2023-05-11 20:07:39 +00:00
|
|
|
raw_ptr<ElectronBrowserContext> browser_context_;
|
2023-04-05 14:06:14 +00:00
|
|
|
std::string host_;
|
|
|
|
network::mojom::ResolveHostParametersPtr params_;
|
|
|
|
ResolveHostCallback callback_;
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace electron
|
|
|
|
|
|
|
|
#endif // ELECTRON_SHELL_BROWSER_NET_RESOLVE_HOST_FUNCTION_H_
|