client_socket_factory.cc 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. // Copyright (c) 2012 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. #include "net/socket/client_socket_factory.h"
  5. #include <utility>
  6. #include "base/lazy_instance.h"
  7. #include "build/build_config.h"
  8. #include "net/socket/ssl_client_socket.h"
  9. #include "net/socket/tcp_client_socket.h"
  10. #include "net/socket/udp_client_socket.h"
  11. namespace net {
  12. class X509Certificate;
  13. namespace {
  14. class DefaultClientSocketFactory : public ClientSocketFactory {
  15. public:
  16. DefaultClientSocketFactory() = default;
  17. // Note: This code never runs, as the factory is defined as a Leaky singleton.
  18. ~DefaultClientSocketFactory() override = default;
  19. std::unique_ptr<DatagramClientSocket> CreateDatagramClientSocket(
  20. DatagramSocket::BindType bind_type,
  21. NetLog* net_log,
  22. const NetLogSource& source) override {
  23. return std::make_unique<UDPClientSocket>(bind_type, net_log, source);
  24. }
  25. std::unique_ptr<TransportClientSocket> CreateTransportClientSocket(
  26. const AddressList& addresses,
  27. std::unique_ptr<SocketPerformanceWatcher> socket_performance_watcher,
  28. NetworkQualityEstimator* network_quality_estimator,
  29. NetLog* net_log,
  30. const NetLogSource& source) override {
  31. return std::make_unique<TCPClientSocket>(
  32. addresses, std::move(socket_performance_watcher),
  33. network_quality_estimator, net_log, source);
  34. }
  35. std::unique_ptr<SSLClientSocket> CreateSSLClientSocket(
  36. SSLClientContext* context,
  37. std::unique_ptr<StreamSocket> stream_socket,
  38. const HostPortPair& host_and_port,
  39. const SSLConfig& ssl_config) override {
  40. return context->CreateSSLClientSocket(std::move(stream_socket),
  41. host_and_port, ssl_config);
  42. }
  43. };
  44. static base::LazyInstance<DefaultClientSocketFactory>::Leaky
  45. g_default_client_socket_factory = LAZY_INSTANCE_INITIALIZER;
  46. } // namespace
  47. // static
  48. ClientSocketFactory* ClientSocketFactory::GetDefaultFactory() {
  49. return g_default_client_socket_factory.Pointer();
  50. }
  51. } // namespace net