Roll src/third_party/skia 0dacc67:eeff8bb
[chromium-blink-merge.git] / jingle / glue / xmpp_client_socket_factory.cc
blob4f7ac4ca05787163d079f1e8642c0d9c87390e60
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.
5 #include "jingle/glue/xmpp_client_socket_factory.h"
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"
16 namespace jingle_glue {
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_);
30 XmppClientSocketFactory::~XmppClientSocketFactory() {}
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());
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.channel_id_service is NULL because the
59 // ChannelIDService class is not thread safe.
60 return client_socket_factory_->CreateSSLClientSocket(
61 transport_socket.Pass(), host_and_port, ssl_config_, context);
65 } // namespace jingle_glue