blob: d0793cb198d143d05a13e4e1ec141a53f4df2a05 [file] [log] [blame]
[email protected]a2006ece2010-04-23 16:44:021// Copyright (c) 2010 The Chromium Authors. All rights reserved.
license.botbf09a502008-08-24 00:55:552// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
initial.commit586acc5fe2008-07-26 22:42:524
[email protected]f7984fc62009-06-22 23:26:445#include "net/socket/client_socket_factory.h"
initial.commit586acc5fe2008-07-26 22:42:526
7#include "base/singleton.h"
[email protected]68bf9152008-09-25 19:47:308#include "build/build_config.h"
[email protected]e60e47a2010-07-14 03:37:189#include "net/socket/client_socket_handle.h"
[email protected]68bf9152008-09-25 19:47:3010#if defined(OS_WIN)
[email protected]f7984fc62009-06-22 23:26:4411#include "net/socket/ssl_client_socket_win.h"
[email protected]d518cd92010-09-29 12:27:4412#elif defined(USE_OPENSSL)
13#include "net/socket/ssl_client_socket_openssl.h"
[email protected]1a157302010-01-29 03:36:4514#elif defined(USE_NSS)
[email protected]f7984fc62009-06-22 23:26:4415#include "net/socket/ssl_client_socket_nss.h"
[email protected]b75523f2008-10-17 14:49:0716#elif defined(OS_MACOSX)
[email protected]f7984fc62009-06-22 23:26:4417#include "net/socket/ssl_client_socket_mac.h"
[email protected]fd4f139f2010-06-11 17:02:2018#include "net/socket/ssl_client_socket_nss.h"
[email protected]68bf9152008-09-25 19:47:3019#endif
[email protected]f7984fc62009-06-22 23:26:4420#include "net/socket/tcp_client_socket.h"
initial.commit586acc5fe2008-07-26 22:42:5221
22namespace net {
23
[email protected]abe48d32010-02-03 02:09:3624namespace {
25
26SSLClientSocket* DefaultSSLClientSocketFactory(
[email protected]e60e47a2010-07-14 03:37:1827 ClientSocketHandle* transport_socket,
[email protected]abe48d32010-02-03 02:09:3628 const std::string& hostname,
29 const SSLConfig& ssl_config) {
30#if defined(OS_WIN)
31 return new SSLClientSocketWin(transport_socket, hostname, ssl_config);
[email protected]d518cd92010-09-29 12:27:4432#elif defined(USE_OPENSSL)
33 return new SSLClientSocketOpenSSL(transport_socket, hostname, ssl_config);
[email protected]abe48d32010-02-03 02:09:3634#elif defined(USE_NSS)
35 return new SSLClientSocketNSS(transport_socket, hostname, ssl_config);
36#elif defined(OS_MACOSX)
[email protected]fd4f139f2010-06-11 17:02:2037 // TODO(wtc): SSLClientSocketNSS can't do SSL client authentication using
38 // Mac OS X CDSA/CSSM yet (http://crbug.com/45369), so fall back on
39 // SSLClientSocketMac.
[email protected]3c241bc2010-08-13 18:34:5340 if (ssl_config.send_client_cert)
[email protected]fd4f139f2010-06-11 17:02:2041 return new SSLClientSocketMac(transport_socket, hostname, ssl_config);
42
43 return new SSLClientSocketNSS(transport_socket, hostname, ssl_config);
[email protected]abe48d32010-02-03 02:09:3644#else
45 NOTIMPLEMENTED();
46 return NULL;
47#endif
48}
49
[email protected]abe48d32010-02-03 02:09:3650SSLClientSocketFactory g_ssl_factory = DefaultSSLClientSocketFactory;
51
initial.commit586acc5fe2008-07-26 22:42:5252class DefaultClientSocketFactory : public ClientSocketFactory {
53 public:
54 virtual ClientSocket* CreateTCPClientSocket(
[email protected]0a0b7682010-08-25 17:08:0755 const AddressList& addresses,
56 NetLog* net_log,
57 const NetLog::Source& source) {
58 return new TCPClientSocket(addresses, net_log, source);
initial.commit586acc5fe2008-07-26 22:42:5259 }
60
[email protected]aaead502008-10-15 00:20:1161 virtual SSLClientSocket* CreateSSLClientSocket(
[email protected]e60e47a2010-07-14 03:37:1862 ClientSocketHandle* transport_socket,
[email protected]c5949a32008-10-08 17:28:2363 const std::string& hostname,
[email protected]aaead502008-10-15 00:20:1164 const SSLConfig& ssl_config) {
[email protected]abe48d32010-02-03 02:09:3665 return g_ssl_factory(transport_socket, hostname, ssl_config);
initial.commit586acc5fe2008-07-26 22:42:5266 }
67};
68
[email protected]abe48d32010-02-03 02:09:3669} // namespace
70
initial.commit586acc5fe2008-07-26 22:42:5271// static
72ClientSocketFactory* ClientSocketFactory::GetDefaultFactory() {
73 return Singleton<DefaultClientSocketFactory>::get();
74}
75
[email protected]abe48d32010-02-03 02:09:3676// static
77void ClientSocketFactory::SetSSLClientSocketFactory(
78 SSLClientSocketFactory factory) {
79 g_ssl_factory = factory;
80}
81
[email protected]e60e47a2010-07-14 03:37:1882// Deprecated function (http://crbug.com/37810) that takes a ClientSocket.
83SSLClientSocket* ClientSocketFactory::CreateSSLClientSocket(
84 ClientSocket* transport_socket,
85 const std::string& hostname,
86 const SSLConfig& ssl_config) {
87 ClientSocketHandle* socket_handle = new ClientSocketHandle();
88 socket_handle->set_socket(transport_socket);
89 return CreateSSLClientSocket(socket_handle, hostname, ssl_config);
90}
91
initial.commit586acc5fe2008-07-26 22:42:5292} // namespace net