1 // Copyright (c) 2011 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.
5 #ifndef NET_SOCKET_CLIENT_SOCKET_FACTORY_H_
6 #define NET_SOCKET_CLIENT_SOCKET_FACTORY_H_
11 #include "base/basictypes.h"
12 #include "net/base/net_export.h"
13 #include "net/base/net_log.h"
14 #include "net/base/rand_callback.h"
15 #include "net/udp/datagram_socket.h"
20 class ClientSocketHandle
;
21 class DatagramClientSocket
;
23 class SSLClientSocket
;
24 struct SSLClientSocketContext
;
29 // An interface used to instantiate StreamSocket objects. Used to facilitate
30 // testing code with mock socket implementations.
31 class NET_EXPORT ClientSocketFactory
{
33 virtual ~ClientSocketFactory() {}
35 // |source| is the NetLog::Source for the entity trying to create the socket,
37 virtual DatagramClientSocket
* CreateDatagramClientSocket(
38 DatagramSocket::BindType bind_type
,
39 const RandIntCallback
& rand_int_cb
,
41 const NetLog::Source
& source
) = 0;
43 virtual StreamSocket
* CreateTransportClientSocket(
44 const AddressList
& addresses
,
46 const NetLog::Source
& source
) = 0;
48 // It is allowed to pass in a |transport_socket| that is not obtained from a
49 // socket pool. The caller could create a ClientSocketHandle directly and call
50 // set_socket() on it to set a valid StreamSocket instance.
51 virtual SSLClientSocket
* CreateSSLClientSocket(
52 ClientSocketHandle
* transport_socket
,
53 const HostPortPair
& host_and_port
,
54 const SSLConfig
& ssl_config
,
55 SSLHostInfo
* ssl_host_info
,
56 const SSLClientSocketContext
& context
) = 0;
58 // Deprecated function (http://crbug.com/37810) that takes a StreamSocket.
59 virtual SSLClientSocket
* CreateSSLClientSocket(
60 StreamSocket
* transport_socket
,
61 const HostPortPair
& host_and_port
,
62 const SSLConfig
& ssl_config
,
63 SSLHostInfo
* ssl_host_info
,
64 const SSLClientSocketContext
& context
);
66 // Clears cache used for SSL session resumption.
67 virtual void ClearSSLSessionCache() = 0;
69 // Returns the default ClientSocketFactory.
70 static ClientSocketFactory
* GetDefaultFactory();
72 // Instructs the default ClientSocketFactory to use the system SSL library.
73 static void UseSystemSSL();
78 #endif // NET_SOCKET_CLIENT_SOCKET_FACTORY_H_