#ifndef SERVICES_NETWORK_NETWORK_SERVICE_PROXY_DELEGATE_H_
#define SERVICES_NETWORK_NETWORK_SERVICE_PROXY_DELEGATE_H_
#include <deque>
#include "base/component_export.h"
#include "base/memory/raw_ptr.h"
#include "mojo/public/cpp/bindings/receiver.h"
#include "mojo/public/cpp/bindings/remote.h"
#include "net/base/proxy_delegate.h"
#include "services/network/public/mojom/network_context.mojom.h"
namespace net {
class HttpRequestHeaders;
class ProxyResolutionService;
}
namespace network {
class COMPONENT_EXPORT(NETWORK_SERVICE) NetworkServiceProxyDelegate
: public net::ProxyDelegate,
public mojom::CustomProxyConfigClient {
public:
NetworkServiceProxyDelegate(
mojom::CustomProxyConfigPtr initial_config,
mojo::PendingReceiver<mojom::CustomProxyConfigClient>
config_client_receiver,
mojo::PendingRemote<mojom::CustomProxyConnectionObserver>
observer_remote);
NetworkServiceProxyDelegate(const NetworkServiceProxyDelegate&) = delete;
NetworkServiceProxyDelegate& operator=(const NetworkServiceProxyDelegate&) =
delete;
~NetworkServiceProxyDelegate() override;
void SetProxyResolutionService(
net::ProxyResolutionService* proxy_resolution_service) {
proxy_resolution_service_ = proxy_resolution_service;
}
void OnResolveProxy(const GURL& url,
const std::string& method,
const net::ProxyRetryInfoMap& proxy_retry_info,
net::ProxyInfo* result) override;
void OnFallback(const net::ProxyServer& bad_proxy, int net_error) override;
void OnBeforeTunnelRequest(const net::ProxyServer& proxy_server,
net::HttpRequestHeaders* extra_headers) override;
net::Error OnTunnelHeadersReceived(
const net::ProxyServer& proxy_server,
const net::HttpResponseHeaders& response_headers) override;
private:
bool IsInProxyConfig(const net::ProxyServer& proxy_server) const;
bool MayProxyURL(const GURL& url) const;
bool EligibleForProxy(const net::ProxyInfo& proxy_info,
const std::string& method) const;
void MergeProxyRules(const net::ProxyList& existing_proxy_list,
net::ProxyInfo& proxy_info) const;
void OnObserverDisconnect();
void OnCustomProxyConfigUpdated(
mojom::CustomProxyConfigPtr proxy_config,
OnCustomProxyConfigUpdatedCallback callback) override;
void MarkProxiesAsBad(base::TimeDelta bypass_duration,
const net::ProxyList& bad_proxies,
MarkProxiesAsBadCallback callback) override;
void ClearBadProxiesCache() override;
mojom::CustomProxyConfigPtr proxy_config_;
mojo::Receiver<mojom::CustomProxyConfigClient> receiver_;
mojo::Remote<mojom::CustomProxyConnectionObserver> observer_;
raw_ptr<net::ProxyResolutionService, DanglingUntriaged>
proxy_resolution_service_ = nullptr;
};
}
#endif