1 // Copyright (c) 2012 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 "jingle/glue/xmpp_client_socket_factory.h" 6 7 #include "base/logging.h" 8 #include "jingle/glue/fake_ssl_client_socket.h" 9 #include "jingle/glue/proxy_resolving_client_socket.h" 10 #include "net/socket/client_socket_factory.h" 11 #include "net/socket/client_socket_handle.h" 12 #include "net/socket/ssl_client_socket.h" 13 #include "net/url_request/url_request_context.h" 14 #include "net/url_request/url_request_context_getter.h" 15 16 namespace jingle_glue { 17 18 XmppClientSocketFactory::XmppClientSocketFactory( 19 net::ClientSocketFactory* client_socket_factory, 20 const net::SSLConfig& ssl_config, 21 const scoped_refptr<net::URLRequestContextGetter>& request_context_getter, 22 bool use_fake_ssl_client_socket) 23 : client_socket_factory_(client_socket_factory), 24 request_context_getter_(request_context_getter), 25 ssl_config_(ssl_config), 26 use_fake_ssl_client_socket_(use_fake_ssl_client_socket) { 27 CHECK(client_socket_factory_); 28 } 29 30 XmppClientSocketFactory::~XmppClientSocketFactory() {} 31 32 scoped_ptr<net::StreamSocket> 33 XmppClientSocketFactory::CreateTransportClientSocket( 34 const net::HostPortPair& host_and_port) { 35 // TODO(akalin): Use socket pools. 36 scoped_ptr<net::StreamSocket> transport_socket( 37 new ProxyResolvingClientSocket( 38 NULL, 39 request_context_getter_, 40 ssl_config_, 41 host_and_port)); 42 return (use_fake_ssl_client_socket_ ? 43 scoped_ptr<net::StreamSocket>( 44 new FakeSSLClientSocket(transport_socket.Pass())) : 45 transport_socket.Pass()); 46 } 47 48 scoped_ptr<net::SSLClientSocket> 49 XmppClientSocketFactory::CreateSSLClientSocket( 50 scoped_ptr<net::ClientSocketHandle> transport_socket, 51 const net::HostPortPair& host_and_port) { 52 net::SSLClientSocketContext context; 53 context.cert_verifier = 54 request_context_getter_->GetURLRequestContext()->cert_verifier(); 55 context.transport_security_state = request_context_getter_-> 56 GetURLRequestContext()->transport_security_state(); 57 DCHECK(context.transport_security_state); 58 // TODO(rkn): context.server_bound_cert_service is NULL because the 59 // ServerBoundCertService class is not thread safe. 60 return client_socket_factory_->CreateSSLClientSocket( 61 transport_socket.Pass(), host_and_port, ssl_config_, context); 62 } 63 64 65 } // namespace jingle_glue 66