summaryrefslogtreecommitdiff
path: root/chromium/jingle/glue/xmpp_client_socket_factory.cc
blob: 4823ee5d9bd98fff76e3dca3ae4fd94ce61fa6d4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "jingle/glue/xmpp_client_socket_factory.h"

#include "base/logging.h"
#include "jingle/glue/fake_ssl_client_socket.h"
#include "jingle/glue/proxy_resolving_client_socket.h"
#include "net/socket/client_socket_factory.h"
#include "net/socket/client_socket_handle.h"
#include "net/socket/ssl_client_socket.h"
#include "net/url_request/url_request_context.h"
#include "net/url_request/url_request_context_getter.h"

namespace jingle_glue {

XmppClientSocketFactory::XmppClientSocketFactory(
    net::ClientSocketFactory* client_socket_factory,
    const net::SSLConfig& ssl_config,
    const scoped_refptr<net::URLRequestContextGetter>& request_context_getter,
    bool use_fake_ssl_client_socket)
    : client_socket_factory_(client_socket_factory),
      request_context_getter_(request_context_getter),
      ssl_config_(ssl_config),
      use_fake_ssl_client_socket_(use_fake_ssl_client_socket) {
  CHECK(client_socket_factory_);
}

XmppClientSocketFactory::~XmppClientSocketFactory() {}

scoped_ptr<net::StreamSocket>
XmppClientSocketFactory::CreateTransportClientSocket(
    const net::HostPortPair& host_and_port) {
  // TODO(akalin): Use socket pools.
  scoped_ptr<net::StreamSocket> transport_socket(
      new ProxyResolvingClientSocket(
          NULL,
          request_context_getter_,
          ssl_config_,
          host_and_port));
  return (use_fake_ssl_client_socket_ ?
          scoped_ptr<net::StreamSocket>(
              new FakeSSLClientSocket(transport_socket.Pass())) :
          transport_socket.Pass());
}

scoped_ptr<net::SSLClientSocket>
XmppClientSocketFactory::CreateSSLClientSocket(
    scoped_ptr<net::ClientSocketHandle> transport_socket,
    const net::HostPortPair& host_and_port) {
  net::SSLClientSocketContext context;
  context.cert_verifier =
      request_context_getter_->GetURLRequestContext()->cert_verifier();
  context.transport_security_state = request_context_getter_->
      GetURLRequestContext()->transport_security_state();
  DCHECK(context.transport_security_state);
  // TODO(rkn): context.server_bound_cert_service is NULL because the
  // ServerBoundCertService class is not thread safe.
  return client_socket_factory_->CreateSSLClientSocket(
      transport_socket.Pass(), host_and_port, ssl_config_, context);
}


}  // namespace jingle_glue