| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "net/socket/client_socket_factory.h" | 5 #include "net/socket/client_socket_factory.h" |
| 6 | 6 |
| 7 #include "base/singleton.h" | 7 #include "base/singleton.h" |
| 8 #include "build/build_config.h" | 8 #include "build/build_config.h" |
| 9 #include "net/socket/client_socket_handle.h" | 9 #include "net/socket/client_socket_handle.h" |
| 10 #if defined(OS_WIN) | 10 #if defined(OS_WIN) |
| 11 #include "net/socket/ssl_client_socket_win.h" | 11 #include "net/socket/ssl_client_socket_win.h" |
| 12 #elif defined(USE_NSS) | 12 #elif defined(USE_NSS) |
| 13 #include "net/socket/ssl_client_socket_nss.h" | 13 #include "net/socket/ssl_client_socket_nss.h" |
| 14 #elif defined(OS_MACOSX) | 14 #elif defined(OS_MACOSX) |
| 15 #include "net/socket/ssl_client_socket_mac.h" | 15 #include "net/socket/ssl_client_socket_mac.h" |
| 16 #include "net/socket/ssl_client_socket_nss.h" | 16 #include "net/socket/ssl_client_socket_nss.h" |
| 17 #endif | 17 #endif |
| 18 #include "net/socket/tcp_client_socket.h" | 18 #include "net/socket/tcp_client_socket.h" |
| 19 | 19 |
| 20 namespace net { | 20 namespace net { |
| 21 | 21 |
| 22 namespace { | 22 namespace { |
| 23 | 23 |
| 24 SSLClientSocket* DefaultSSLClientSocketFactory( | 24 SSLClientSocket* DefaultSSLClientSocketFactory( |
| 25 ClientSocketHandle* transport_socket, | 25 ClientSocketHandle* transport_socket, |
| 26 const std::string& hostname, | 26 const HostPortPair& host_port_pair, |
| 27 const SSLConfig& ssl_config) { | 27 const SSLConfig& ssl_config) { |
| 28 #if defined(OS_WIN) | 28 #if defined(OS_WIN) |
| 29 return new SSLClientSocketWin(transport_socket, hostname, ssl_config); | 29 return new SSLClientSocketWin(transport_socket, host_port_pair, ssl_config); |
| 30 #elif defined(USE_NSS) | 30 #elif defined(USE_NSS) |
| 31 return new SSLClientSocketNSS(transport_socket, hostname, ssl_config); | 31 return new SSLClientSocketNSS(transport_socket, host_port_pair, ssl_config); |
| 32 #elif defined(OS_MACOSX) | 32 #elif defined(OS_MACOSX) |
| 33 // TODO(wtc): SSLClientSocketNSS can't do SSL client authentication using | 33 // TODO(wtc): SSLClientSocketNSS can't do SSL client authentication using |
| 34 // Mac OS X CDSA/CSSM yet (http://crbug.com/45369), so fall back on | 34 // Mac OS X CDSA/CSSM yet (http://crbug.com/45369), so fall back on |
| 35 // SSLClientSocketMac. | 35 // SSLClientSocketMac. |
| 36 if (ssl_config.client_cert) | 36 if (ssl_config.client_cert) |
| 37 return new SSLClientSocketMac(transport_socket, hostname, ssl_config); | 37 return new SSLClientSocketMac(transport_socket, host_port_pair, ssl_config); |
| 38 | 38 |
| 39 return new SSLClientSocketNSS(transport_socket, hostname, ssl_config); | 39 return new SSLClientSocketNSS(transport_socket, host_port_pair, ssl_config); |
| 40 #else | 40 #else |
| 41 NOTIMPLEMENTED(); | 41 NOTIMPLEMENTED(); |
| 42 return NULL; | 42 return NULL; |
| 43 #endif | 43 #endif |
| 44 } | 44 } |
| 45 | 45 |
| 46 SSLClientSocketFactory g_ssl_factory = DefaultSSLClientSocketFactory; | 46 SSLClientSocketFactory g_ssl_factory = DefaultSSLClientSocketFactory; |
| 47 | 47 |
| 48 class DefaultClientSocketFactory : public ClientSocketFactory { | 48 class DefaultClientSocketFactory : public ClientSocketFactory { |
| 49 public: | 49 public: |
| 50 virtual ClientSocket* CreateTCPClientSocket( | 50 virtual ClientSocket* CreateTCPClientSocket( |
| 51 const AddressList& addresses, NetLog* net_log) { | 51 const AddressList& addresses, NetLog* net_log) { |
| 52 return new TCPClientSocket(addresses, net_log); | 52 return new TCPClientSocket(addresses, net_log); |
| 53 } | 53 } |
| 54 | 54 |
| 55 virtual SSLClientSocket* CreateSSLClientSocket( | 55 virtual SSLClientSocket* CreateSSLClientSocket( |
| 56 ClientSocketHandle* transport_socket, | 56 ClientSocketHandle* transport_socket, |
| 57 const std::string& hostname, | 57 const HostPortPair& host_port_pair, |
| 58 const SSLConfig& ssl_config) { | 58 const SSLConfig& ssl_config) { |
| 59 return g_ssl_factory(transport_socket, hostname, ssl_config); | 59 return g_ssl_factory(transport_socket, host_port_pair, ssl_config); |
| 60 } | 60 } |
| 61 }; | 61 }; |
| 62 | 62 |
| 63 } // namespace | 63 } // namespace |
| 64 | 64 |
| 65 // static | 65 // static |
| 66 ClientSocketFactory* ClientSocketFactory::GetDefaultFactory() { | 66 ClientSocketFactory* ClientSocketFactory::GetDefaultFactory() { |
| 67 return Singleton<DefaultClientSocketFactory>::get(); | 67 return Singleton<DefaultClientSocketFactory>::get(); |
| 68 } | 68 } |
| 69 | 69 |
| 70 // static | 70 // static |
| 71 void ClientSocketFactory::SetSSLClientSocketFactory( | 71 void ClientSocketFactory::SetSSLClientSocketFactory( |
| 72 SSLClientSocketFactory factory) { | 72 SSLClientSocketFactory factory) { |
| 73 g_ssl_factory = factory; | 73 g_ssl_factory = factory; |
| 74 } | 74 } |
| 75 | 75 |
| 76 // Deprecated function (http://crbug.com/37810) that takes a ClientSocket. | 76 // Deprecated function (http://crbug.com/37810) that takes a ClientSocket. |
| 77 SSLClientSocket* ClientSocketFactory::CreateSSLClientSocket( | 77 SSLClientSocket* ClientSocketFactory::CreateSSLClientSocket( |
| 78 ClientSocket* transport_socket, | 78 ClientSocket* transport_socket, |
| 79 const std::string& hostname, | 79 const HostPortPair& host_port_pair, |
| 80 const SSLConfig& ssl_config) { | 80 const SSLConfig& ssl_config) { |
| 81 ClientSocketHandle* socket_handle = new ClientSocketHandle(); | 81 ClientSocketHandle* socket_handle = new ClientSocketHandle(); |
| 82 socket_handle->set_socket(transport_socket); | 82 socket_handle->set_socket(transport_socket); |
| 83 return CreateSSLClientSocket(socket_handle, hostname, ssl_config); | 83 return CreateSSLClientSocket(socket_handle, host_port_pair, ssl_config); |
| 84 } | 84 } |
| 85 | 85 |
| 86 } // namespace net | 86 } // namespace net |
| OLD | NEW |