#ifndef CONTENT_BROWSER_PRELOADING_PREFETCH_PREFETCH_PROXY_CONFIGURATOR_H_
#define CONTENT_BROWSER_PRELOADING_PREFETCH_PREFETCH_PROXY_CONFIGURATOR_H_
#include <optional>
#include "base/memory/raw_ptr.h"
#include "base/sequence_checker.h"
#include "base/time/time.h"
#include "content/common/content_export.h"
#include "mojo/public/cpp/bindings/pending_remote.h"
#include "mojo/public/cpp/bindings/receiver_set.h"
#include "mojo/public/cpp/bindings/remote_set.h"
#include "net/base/proxy_chain.h"
#include "net/http/http_request_headers.h"
#include "services/network/public/mojom/network_context.mojom.h"
namespace content {
class CONTENT_EXPORT PrefetchProxyConfigurator
: public network::mojom::CustomProxyConnectionObserver {
public:
static std::unique_ptr<PrefetchProxyConfigurator>
MaybeCreatePrefetchProxyConfigurator(const GURL& proxy_url,
const std::string& api_key);
PrefetchProxyConfigurator(const GURL& proxy_url, const std::string& api_key);
~PrefetchProxyConfigurator() override;
PrefetchProxyConfigurator(const PrefetchProxyConfigurator&) = delete;
const PrefetchProxyConfigurator operator=(const PrefetchProxyConfigurator&) =
delete;
void AddCustomProxyConfigClient(
mojo::Remote<network::mojom::CustomProxyConfigClient> config_client,
base::OnceCallback<void()> callback);
void UpdateCustomProxyConfig(base::OnceCallback<void()> callback);
network::mojom::CustomProxyConfigPtr CreateCustomProxyConfig() const;
mojo::PendingRemote<network::mojom::CustomProxyConnectionObserver>
NewProxyConnectionObserverRemote();
bool IsPrefetchProxyAvailable() const;
void SetClockForTesting(const base::Clock* clock);
void OnFallback(const net::ProxyChain& bad_chain, int net_error) override;
void OnTunnelHeadersReceived(
const net::ProxyChain& proxy_chain,
uint64_t chain_index,
const scoped_refptr<net::HttpResponseHeaders>& response_headers) override;
#if BUILDFLAG(ARKWEB_EX_FALLBACK_PROXY)
void OnTunnelHeadersReceivedWithToken(
const net::ProxyChain& proxy_chain,
const scoped_refptr<net::HttpResponseHeaders>& response_headers,
const std::string& token) override {}
void OnProxyConnectResult(const net::ProxyChain& proxy_chain,
int error_code) override {}
#endif
private:
void OnTunnelProxyConnectionError(std::optional<base::TimeDelta> retry_after);
net::HttpRequestHeaders connect_tunnel_headers_;
const net::ProxyChain prefetch_proxy_chain_;
raw_ptr<const base::Clock> clock_;
std::optional<base::Time> prefetch_proxy_not_available_until_;
mojo::RemoteSet<network::mojom::CustomProxyConfigClient>
proxy_config_clients_;
mojo::ReceiverSet<network::mojom::CustomProxyConnectionObserver>
observer_receivers_;
SEQUENCE_CHECKER(sequence_checker_);
};
}
#endif