blob: 6a3a4ccfdbac5042e2b082111e990890accc978b [file] [log] [blame]
license.botbf09a502008-08-24 00:55:551// 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.
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"
9#if defined(OS_WIN)
[email protected]f7984fc62009-06-22 23:26:4410#include "net/socket/ssl_client_socket_win.h"
[email protected]1a157302010-01-29 03:36:4511#elif defined(USE_NSS)
[email protected]f7984fc62009-06-22 23:26:4412#include "net/socket/ssl_client_socket_nss.h"
[email protected]b75523f2008-10-17 14:49:0713#elif defined(OS_MACOSX)
[email protected]f7984fc62009-06-22 23:26:4414#include "net/socket/ssl_client_socket_mac.h"
[email protected]68bf9152008-09-25 19:47:3015#endif
[email protected]f7984fc62009-06-22 23:26:4416#include "net/socket/tcp_client_socket.h"
initial.commit586acc5fe2008-07-26 22:42:5217
18namespace net {
19
[email protected]abe48d32010-02-03 02:09:3620namespace {
21
22SSLClientSocket* 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.
39SSLClientSocketFactory g_ssl_factory = DefaultSSLClientSocketFactory;
40
initial.commit586acc5fe2008-07-26 22:42:5241class DefaultClientSocketFactory : public ClientSocketFactory {
42 public:
43 virtual ClientSocket* CreateTCPClientSocket(
44 const AddressList& addresses) {
45 return new TCPClientSocket(addresses);
46 }
47
[email protected]aaead502008-10-15 00:20:1148 virtual SSLClientSocket* CreateSSLClientSocket(
initial.commit586acc5fe2008-07-26 22:42:5249 ClientSocket* transport_socket,
[email protected]c5949a32008-10-08 17:28:2350 const std::string& hostname,
[email protected]aaead502008-10-15 00:20:1151 const SSLConfig& ssl_config) {
[email protected]abe48d32010-02-03 02:09:3652 return g_ssl_factory(transport_socket, hostname, ssl_config);
initial.commit586acc5fe2008-07-26 22:42:5253 }
54};
55
[email protected]abe48d32010-02-03 02:09:3656} // namespace
57
initial.commit586acc5fe2008-07-26 22:42:5258// static
59ClientSocketFactory* ClientSocketFactory::GetDefaultFactory() {
60 return Singleton<DefaultClientSocketFactory>::get();
61}
62
[email protected]abe48d32010-02-03 02:09:3663// static
64void ClientSocketFactory::SetSSLClientSocketFactory(
65 SSLClientSocketFactory factory) {
66 g_ssl_factory = factory;
67}
68
initial.commit586acc5fe2008-07-26 22:42:5269} // namespace net