| 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 #if defined(OS_WIN) | 10 #if defined(OS_WIN) |
| 10 #include "net/socket/ssl_client_socket_win.h" | 11 #include "net/socket/ssl_client_socket_win.h" |
| 11 #elif defined(USE_NSS) | 12 #elif defined(USE_NSS) |
| 12 #include "net/socket/ssl_client_socket_nss.h" | 13 #include "net/socket/ssl_client_socket_nss.h" |
| 13 #elif defined(OS_MACOSX) | 14 #elif defined(OS_MACOSX) |
| 14 #include "net/socket/ssl_client_socket_mac.h" | 15 #include "net/socket/ssl_client_socket_mac.h" |
| 15 #include "net/socket/ssl_client_socket_nss.h" | 16 #include "net/socket/ssl_client_socket_nss.h" |
| 16 #endif | 17 #endif |
| 17 #include "net/socket/tcp_client_socket.h" | 18 #include "net/socket/tcp_client_socket.h" |
| 18 | 19 |
| 19 namespace net { | 20 namespace net { |
| 20 | 21 |
| 21 namespace { | 22 namespace { |
| 22 | 23 |
| 23 SSLClientSocket* DefaultSSLClientSocketFactory( | 24 SSLClientSocket* DefaultSSLClientSocketFactory( |
| 24 ClientSocket* transport_socket, | 25 ClientSocketHandle* transport_socket, |
| 25 const std::string& hostname, | 26 const std::string& hostname, |
| 26 const SSLConfig& ssl_config) { | 27 const SSLConfig& ssl_config) { |
| 27 #if defined(OS_WIN) | 28 #if defined(OS_WIN) |
| 28 return new SSLClientSocketWin(transport_socket, hostname, ssl_config); | 29 return new SSLClientSocketWin(transport_socket, hostname, ssl_config); |
| 29 #elif defined(USE_NSS) | 30 #elif defined(USE_NSS) |
| 30 return new SSLClientSocketNSS(transport_socket, hostname, ssl_config); | 31 return new SSLClientSocketNSS(transport_socket, hostname, ssl_config); |
| 31 #elif defined(OS_MACOSX) | 32 #elif defined(OS_MACOSX) |
| 32 // TODO(wtc): SSLClientSocketNSS can't do SSL client authentication using | 33 // TODO(wtc): SSLClientSocketNSS can't do SSL client authentication using |
| 33 // 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 |
| 34 // SSLClientSocketMac. | 35 // SSLClientSocketMac. |
| (...skipping 10 matching lines...) Expand all Loading... |
| 45 SSLClientSocketFactory g_ssl_factory = DefaultSSLClientSocketFactory; | 46 SSLClientSocketFactory g_ssl_factory = DefaultSSLClientSocketFactory; |
| 46 | 47 |
| 47 class DefaultClientSocketFactory : public ClientSocketFactory { | 48 class DefaultClientSocketFactory : public ClientSocketFactory { |
| 48 public: | 49 public: |
| 49 virtual ClientSocket* CreateTCPClientSocket( | 50 virtual ClientSocket* CreateTCPClientSocket( |
| 50 const AddressList& addresses, NetLog* net_log) { | 51 const AddressList& addresses, NetLog* net_log) { |
| 51 return new TCPClientSocket(addresses, net_log); | 52 return new TCPClientSocket(addresses, net_log); |
| 52 } | 53 } |
| 53 | 54 |
| 54 virtual SSLClientSocket* CreateSSLClientSocket( | 55 virtual SSLClientSocket* CreateSSLClientSocket( |
| 55 ClientSocket* transport_socket, | 56 ClientSocketHandle* transport_socket, |
| 56 const std::string& hostname, | 57 const std::string& hostname, |
| 57 const SSLConfig& ssl_config) { | 58 const SSLConfig& ssl_config) { |
| 58 return g_ssl_factory(transport_socket, hostname, ssl_config); | 59 return g_ssl_factory(transport_socket, hostname, ssl_config); |
| 59 } | 60 } |
| 60 }; | 61 }; |
| 61 | 62 |
| 62 } // namespace | 63 } // namespace |
| 63 | 64 |
| 64 // static | 65 // static |
| 65 ClientSocketFactory* ClientSocketFactory::GetDefaultFactory() { | 66 ClientSocketFactory* ClientSocketFactory::GetDefaultFactory() { |
| 66 return Singleton<DefaultClientSocketFactory>::get(); | 67 return Singleton<DefaultClientSocketFactory>::get(); |
| 67 } | 68 } |
| 68 | 69 |
| 69 // static | 70 // static |
| 70 void ClientSocketFactory::SetSSLClientSocketFactory( | 71 void ClientSocketFactory::SetSSLClientSocketFactory( |
| 71 SSLClientSocketFactory factory) { | 72 SSLClientSocketFactory factory) { |
| 72 g_ssl_factory = factory; | 73 g_ssl_factory = factory; |
| 73 } | 74 } |
| 74 | 75 |
| 76 // Deprecated function (http://crbug.com/37810) that takes a ClientSocket. |
| 77 SSLClientSocket* ClientSocketFactory::CreateSSLClientSocket( |
| 78 ClientSocket* transport_socket, |
| 79 const std::string& hostname, |
| 80 const SSLConfig& ssl_config) { |
| 81 ClientSocketHandle* socket_handle = new ClientSocketHandle(); |
| 82 socket_handle->set_socket(transport_socket); |
| 83 return CreateSSLClientSocket(socket_handle, hostname, ssl_config); |
| 84 } |
| 85 |
| 75 } // namespace net | 86 } // namespace net |
| OLD | NEW |