client_socket_factory.h 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. // Copyright (c) 2011 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 NET_SOCKET_CLIENT_SOCKET_FACTORY_H_
  5. #define NET_SOCKET_CLIENT_SOCKET_FACTORY_H_
  6. #include <memory>
  7. #include <string>
  8. #include "net/base/net_export.h"
  9. #include "net/http/proxy_client_socket.h"
  10. #include "net/socket/datagram_socket.h"
  11. #include "net/socket/socket_performance_watcher.h"
  12. #include "net/socket/transport_client_socket.h"
  13. #include "net/traffic_annotation/network_traffic_annotation.h"
  14. namespace net {
  15. class AddressList;
  16. class DatagramClientSocket;
  17. class HostPortPair;
  18. class NetLog;
  19. struct NetLogSource;
  20. class SSLClientContext;
  21. class SSLClientSocket;
  22. struct SSLConfig;
  23. class NetworkQualityEstimator;
  24. // An interface used to instantiate StreamSocket objects. Used to facilitate
  25. // testing code with mock socket implementations.
  26. class NET_EXPORT ClientSocketFactory {
  27. public:
  28. virtual ~ClientSocketFactory() = default;
  29. // |source| is the NetLogSource for the entity trying to create the socket,
  30. // if it has one.
  31. virtual std::unique_ptr<DatagramClientSocket> CreateDatagramClientSocket(
  32. DatagramSocket::BindType bind_type,
  33. NetLog* net_log,
  34. const NetLogSource& source) = 0;
  35. // |network_quality_estimator| is optional. If not specified, the network
  36. // quality will not be considered when determining TCP connect handshake
  37. // timeouts, or when histogramming the handshake duration.
  38. virtual std::unique_ptr<TransportClientSocket> CreateTransportClientSocket(
  39. const AddressList& addresses,
  40. std::unique_ptr<SocketPerformanceWatcher> socket_performance_watcher,
  41. NetworkQualityEstimator* network_quality_estimator,
  42. NetLog* net_log,
  43. const NetLogSource& source) = 0;
  44. // It is allowed to pass in a StreamSocket that is not obtained from a
  45. // socket pool. The caller could create a StreamSocket directly.
  46. virtual std::unique_ptr<SSLClientSocket> CreateSSLClientSocket(
  47. SSLClientContext* context,
  48. std::unique_ptr<StreamSocket> stream_socket,
  49. const HostPortPair& host_and_port,
  50. const SSLConfig& ssl_config) = 0;
  51. // Returns the default ClientSocketFactory.
  52. static ClientSocketFactory* GetDefaultFactory();
  53. };
  54. } // namespace net
  55. #endif // NET_SOCKET_CLIENT_SOCKET_FACTORY_H_