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_
10 #include "base/basictypes.h"
11 #include "net/base/net_export.h"
12 #include "net/base/net_log.h"
13 #include "net/base/rand_callback.h"
14 #include "net/udp/datagram_socket.h"
19 class ClientSocketHandle
;
20 class DatagramClientSocket
;
22 class SSLClientSocket
;
23 struct SSLClientSocketContext
;
27 // An interface used to instantiate StreamSocket objects. Used to facilitate
28 // testing code with mock socket implementations.
29 class NET_EXPORT ClientSocketFactory
{
31 virtual ~ClientSocketFactory() {}
33 // |source| is the NetLog::Source for the entity trying to create the socket,
35 virtual DatagramClientSocket
* CreateDatagramClientSocket(
36 DatagramSocket::BindType bind_type
,
37 const RandIntCallback
& rand_int_cb
,
39 const NetLog::Source
& source
) = 0;
41 virtual StreamSocket
* CreateTransportClientSocket(
42 const AddressList
& addresses
,
44 const NetLog::Source
& source
) = 0;
46 // It is allowed to pass in a |transport_socket| that is not obtained from a
47 // socket pool. The caller could create a ClientSocketHandle directly and call
48 // set_socket() on it to set a valid StreamSocket instance.
49 virtual SSLClientSocket
* CreateSSLClientSocket(
50 ClientSocketHandle
* transport_socket
,
51 const HostPortPair
& host_and_port
,
52 const SSLConfig
& ssl_config
,
53 const SSLClientSocketContext
& context
) = 0;
55 // Deprecated function (http://crbug.com/37810) that takes a StreamSocket.
56 virtual SSLClientSocket
* CreateSSLClientSocket(
57 StreamSocket
* transport_socket
,
58 const HostPortPair
& host_and_port
,
59 const SSLConfig
& ssl_config
,
60 const SSLClientSocketContext
& context
);
62 // Clears cache used for SSL session resumption.
63 virtual void ClearSSLSessionCache() = 0;
65 // Returns the default ClientSocketFactory.
66 static ClientSocketFactory
* GetDefaultFactory();
71 #endif // NET_SOCKET_CLIENT_SOCKET_FACTORY_H_