network_service_proxy_delegate.h 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. // Copyright 2018 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #ifndef SERVICES_NETWORK_NETWORK_SERVICE_PROXY_DELEGATE_H_
  5. #define SERVICES_NETWORK_NETWORK_SERVICE_PROXY_DELEGATE_H_
  6. #include <deque>
  7. #include "base/component_export.h"
  8. #include "base/memory/raw_ptr.h"
  9. #include "mojo/public/cpp/bindings/receiver.h"
  10. #include "mojo/public/cpp/bindings/remote.h"
  11. #include "net/base/proxy_delegate.h"
  12. #include "services/network/public/mojom/network_context.mojom.h"
  13. namespace net {
  14. class HttpRequestHeaders;
  15. class ProxyResolutionService;
  16. } // namespace net
  17. namespace network {
  18. // NetworkServiceProxyDelegate is used to support the custom proxy
  19. // configuration, which can be set in
  20. // NetworkContextParams.custom_proxy_config_client_receiver.
  21. class COMPONENT_EXPORT(NETWORK_SERVICE) NetworkServiceProxyDelegate
  22. : public net::ProxyDelegate,
  23. public mojom::CustomProxyConfigClient {
  24. public:
  25. NetworkServiceProxyDelegate(
  26. mojom::CustomProxyConfigPtr initial_config,
  27. mojo::PendingReceiver<mojom::CustomProxyConfigClient>
  28. config_client_receiver,
  29. mojo::PendingRemote<mojom::CustomProxyConnectionObserver>
  30. observer_remote);
  31. NetworkServiceProxyDelegate(const NetworkServiceProxyDelegate&) = delete;
  32. NetworkServiceProxyDelegate& operator=(const NetworkServiceProxyDelegate&) =
  33. delete;
  34. ~NetworkServiceProxyDelegate() override;
  35. void SetProxyResolutionService(
  36. net::ProxyResolutionService* proxy_resolution_service) {
  37. proxy_resolution_service_ = proxy_resolution_service;
  38. }
  39. // net::ProxyDelegate implementation:
  40. void OnResolveProxy(const GURL& url,
  41. const std::string& method,
  42. const net::ProxyRetryInfoMap& proxy_retry_info,
  43. net::ProxyInfo* result) override;
  44. void OnFallback(const net::ProxyServer& bad_proxy, int net_error) override;
  45. void OnBeforeTunnelRequest(const net::ProxyServer& proxy_server,
  46. net::HttpRequestHeaders* extra_headers) override;
  47. net::Error OnTunnelHeadersReceived(
  48. const net::ProxyServer& proxy_server,
  49. const net::HttpResponseHeaders& response_headers) override;
  50. private:
  51. // Checks whether |proxy_server| is present in the current proxy config.
  52. bool IsInProxyConfig(const net::ProxyServer& proxy_server) const;
  53. // Whether the current config may proxy |url|.
  54. bool MayProxyURL(const GURL& url) const;
  55. // Whether the HTTP |method| with current |proxy_info| is eligible to be
  56. // proxied.
  57. bool EligibleForProxy(const net::ProxyInfo& proxy_info,
  58. const std::string& method) const;
  59. void OnObserverDisconnect();
  60. // mojom::CustomProxyConfigClient implementation:
  61. void OnCustomProxyConfigUpdated(
  62. mojom::CustomProxyConfigPtr proxy_config,
  63. OnCustomProxyConfigUpdatedCallback callback) override;
  64. void MarkProxiesAsBad(base::TimeDelta bypass_duration,
  65. const net::ProxyList& bad_proxies,
  66. MarkProxiesAsBadCallback callback) override;
  67. void ClearBadProxiesCache() override;
  68. mojom::CustomProxyConfigPtr proxy_config_;
  69. mojo::Receiver<mojom::CustomProxyConfigClient> receiver_;
  70. mojo::Remote<mojom::CustomProxyConnectionObserver> observer_;
  71. raw_ptr<net::ProxyResolutionService> proxy_resolution_service_ = nullptr;
  72. };
  73. } // namespace network
  74. #endif // SERVICES_NETWORK_NETWORK_SERVICE_PROXY_DELEGATE_H_