| Index: content/browser/renderer_host/p2p/socket_host_tcp.cc
|
| ===================================================================
|
| --- content/browser/renderer_host/p2p/socket_host_tcp.cc (revision 207812)
|
| +++ content/browser/renderer_host/p2p/socket_host_tcp.cc (working copy)
|
| @@ -8,10 +8,12 @@
|
| #include "content/common/p2p_messages.h"
|
| #include "ipc/ipc_sender.h"
|
| #include "jingle/glue/fake_ssl_client_socket.h"
|
| +#include "jingle/glue/proxy_resolving_client_socket.h"
|
| #include "net/base/io_buffer.h"
|
| #include "net/base/net_errors.h"
|
| #include "net/base/net_util.h"
|
| #include "net/socket/tcp_client_socket.h"
|
| +#include "net/url_request/url_request_context_getter.h"
|
|
|
| namespace {
|
|
|
| @@ -30,13 +32,14 @@
|
|
|
| namespace content {
|
|
|
| -P2PSocketHostTcpBase::P2PSocketHostTcpBase(IPC::Sender* message_sender,
|
| - int id,
|
| - P2PSocketType type)
|
| +P2PSocketHostTcpBase::P2PSocketHostTcpBase(
|
| + IPC::Sender* message_sender, int id,
|
| + P2PSocketType type, net::URLRequestContextGetter* url_context)
|
| : P2PSocketHost(message_sender, id),
|
| write_pending_(false),
|
| connected_(false),
|
| - type_(type) {
|
| + type_(type),
|
| + url_context_(url_context) {
|
| }
|
|
|
| P2PSocketHostTcpBase::~P2PSocketHostTcpBase() {
|
| @@ -60,28 +63,43 @@
|
| }
|
|
|
| bool P2PSocketHostTcpBase::Init(const net::IPEndPoint& local_address,
|
| - const net::IPEndPoint& remote_address) {
|
| + const net::IPEndPoint& remote_address) {
|
| DCHECK_EQ(state_, STATE_UNINITIALIZED);
|
|
|
| remote_address_ = remote_address;
|
| state_ = STATE_CONNECTING;
|
| - scoped_ptr<net::TCPClientSocket> tcp_socket(new net::TCPClientSocket(
|
| - net::AddressList(remote_address),
|
| - NULL, net::NetLog::Source()));
|
| - if (tcp_socket->Bind(local_address) != net::OK) {
|
| - OnError();
|
| - return false;
|
| - }
|
| +
|
| + net::HostPortPair dest_host_port_pair =
|
| + net::HostPortPair::FromIPEndPoint(remote_address);
|
| + // TODO(mallinath) - We are ignoring local_address altogether. We should
|
| + // find a way to inject this into ProxyResolvingClientSocket. This could be
|
| + // a problem on multi-homed host.
|
| +
|
| + // The default SSLConfig is good enough for us for now.
|
| + const net::SSLConfig ssl_config;
|
| + socket_.reset(new jingle_glue::ProxyResolvingClientSocket(
|
| + NULL, // Default socket pool provided by the net::Proxy.
|
| + url_context_,
|
| + ssl_config,
|
| + dest_host_port_pair));
|
| if (IsSslClientSocket(type_)) {
|
| - socket_.reset(new jingle_glue::FakeSSLClientSocket(tcp_socket.release()));
|
| - } else {
|
| - socket_ = tcp_socket.PassAs<net::StreamSocket>();
|
| + socket_.reset(new jingle_glue::FakeSSLClientSocket(socket_.release()));
|
| }
|
|
|
| - int result = socket_->Connect(
|
| - base::Bind(&P2PSocketHostTcp::OnConnected, base::Unretained(this)));
|
| - if (result != net::ERR_IO_PENDING) {
|
| - OnConnected(result);
|
| + int status = socket_->Connect(
|
| + base::Bind(&P2PSocketHostTcpBase::OnConnected,
|
| + base::Unretained(this)));
|
| + if (status != net::ERR_IO_PENDING) {
|
| + // We defer execution of ProcessConnectDone instead of calling it
|
| + // directly here as the caller may not expect an error/close to
|
| + // happen here. This is okay, as from the caller's point of view,
|
| + // the connect always happens asynchronously.
|
| + base::MessageLoop* message_loop = base::MessageLoop::current();
|
| + CHECK(message_loop);
|
| + message_loop->PostTask(
|
| + FROM_HERE,
|
| + base::Bind(&P2PSocketHostTcpBase::OnConnected,
|
| + base::Unretained(this), status));
|
| }
|
|
|
| return state_ != STATE_ERROR;
|
| @@ -285,10 +303,10 @@
|
| }
|
| }
|
|
|
| -P2PSocketHostTcp::P2PSocketHostTcp(IPC::Sender* message_sender,
|
| - int id,
|
| - P2PSocketType type)
|
| - : P2PSocketHostTcpBase(message_sender, id, type) {
|
| +P2PSocketHostTcp::P2PSocketHostTcp(
|
| + IPC::Sender* message_sender, int id,
|
| + P2PSocketType type, net::URLRequestContextGetter* url_context)
|
| + : P2PSocketHostTcpBase(message_sender, id, type, url_context) {
|
| DCHECK(type == P2P_SOCKET_TCP_CLIENT || type == P2P_SOCKET_SSLTCP_CLIENT);
|
| }
|
|
|
| @@ -322,10 +340,10 @@
|
| }
|
|
|
| // P2PSocketHostStunTcp
|
| -P2PSocketHostStunTcp::P2PSocketHostStunTcp(IPC::Sender* message_sender,
|
| - int id,
|
| - P2PSocketType type)
|
| - : P2PSocketHostTcpBase(message_sender, id, type) {
|
| +P2PSocketHostStunTcp::P2PSocketHostStunTcp(
|
| + IPC::Sender* message_sender, int id,
|
| + P2PSocketType type, net::URLRequestContextGetter* url_context)
|
| + : P2PSocketHostTcpBase(message_sender, id, type, url_context) {
|
| DCHECK(type == P2P_SOCKET_STUN_TCP_CLIENT ||
|
| type == P2P_SOCKET_STUN_SSLTCP_CLIENT);
|
| }
|
|
|