Home | History | Annotate | Download | only in socket
      1 // Copyright (c) 2006-2008 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 
      5 #include "net/socket/client_socket_factory.h"
      6 
      7 #include "base/singleton.h"
      8 #include "build/build_config.h"
      9 #if defined(OS_WIN)
     10 #include "net/socket/ssl_client_socket_win.h"
     11 #elif defined(USE_NSS)
     12 #include "net/socket/ssl_client_socket_nss.h"
     13 #elif defined(OS_MACOSX)
     14 #include "net/socket/ssl_client_socket_mac.h"
     15 #endif
     16 #include "net/socket/tcp_client_socket.h"
     17 
     18 namespace net {
     19 
     20 namespace {
     21 
     22 SSLClientSocket* DefaultSSLClientSocketFactory(
     23     ClientSocket* transport_socket,
     24     const std::string& hostname,
     25     const SSLConfig& ssl_config) {
     26 #if defined(OS_WIN)
     27   return new SSLClientSocketWin(transport_socket, hostname, ssl_config);
     28 #elif defined(USE_NSS)
     29   return new SSLClientSocketNSS(transport_socket, hostname, ssl_config);
     30 #elif defined(OS_MACOSX)
     31   return new SSLClientSocketMac(transport_socket, hostname, ssl_config);
     32 #else
     33   NOTIMPLEMENTED();
     34   return NULL;
     35 #endif
     36 }
     37 
     38 // True if we should use NSS instead of the system SSL library for SSL.
     39 SSLClientSocketFactory g_ssl_factory = DefaultSSLClientSocketFactory;
     40 
     41 class DefaultClientSocketFactory : public ClientSocketFactory {
     42  public:
     43   virtual ClientSocket* CreateTCPClientSocket(
     44       const AddressList& addresses) {
     45     return new TCPClientSocket(addresses);
     46   }
     47 
     48   virtual SSLClientSocket* CreateSSLClientSocket(
     49       ClientSocket* transport_socket,
     50       const std::string& hostname,
     51       const SSLConfig& ssl_config) {
     52     return g_ssl_factory(transport_socket, hostname, ssl_config);
     53   }
     54 };
     55 
     56 }  // namespace
     57 
     58 // static
     59 ClientSocketFactory* ClientSocketFactory::GetDefaultFactory() {
     60   return Singleton<DefaultClientSocketFactory>::get();
     61 }
     62 
     63 // static
     64 void ClientSocketFactory::SetSSLClientSocketFactory(
     65     SSLClientSocketFactory factory) {
     66   g_ssl_factory = factory;
     67 }
     68 
     69 }  // namespace net
     70