Chromium Code Reviews| Index: content/browser/renderer_host/p2p/socket_host_tcp.cc |
| =================================================================== |
| --- content/browser/renderer_host/p2p/socket_host_tcp.cc (revision 206737) |
| +++ content/browser/renderer_host/p2p/socket_host_tcp.cc (working copy) |
| @@ -7,6 +7,7 @@ |
| #include "base/sys_byteorder.h" |
| #include "content/common/p2p_messages.h" |
| #include "ipc/ipc_sender.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" |
| @@ -24,11 +25,30 @@ |
| namespace content { |
| +namespace { |
| + |
| +net::StreamSocket* CreateSocket( |
|
Sergey Ulanov
2013/06/20 01:50:02
This function is called in only one place and it j
Mallinath (Gone from Chromium)
2013/06/20 05:24:15
Done.
|
| + const net::HostPortPair& host_and_port, |
| + const scoped_refptr<net::URLRequestContextGetter>& request_context_getter) { |
| + // The default SSLConfig is good enough for us for now. |
| + const net::SSLConfig ssl_config; |
| + return new jingle_glue::ProxyResolvingClientSocket( |
| + NULL, // Default socket pool provided by the net::Proxy. |
| + request_context_getter, |
| + ssl_config, |
| + host_and_port); |
| +} |
| + |
| +} // namespace |
| + |
| P2PSocketHostTcpBase::P2PSocketHostTcpBase(IPC::Sender* message_sender, |
| - int id) |
| + int id, |
| + net::URLRequestContextGetter* getter) |
| : P2PSocketHost(message_sender, id), |
| + //weak_ptr_factory_(this), |
| write_pending_(false), |
| - connected_(false) { |
| + connected_(false), |
| + context_getter_(getter) { |
| } |
| P2PSocketHostTcpBase::~P2PSocketHostTcpBase() { |
| @@ -51,24 +71,33 @@ |
| } |
| 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; |
| - } |
| - socket_.reset(tcp_socket.release()); |
| - int result = socket_->Connect( |
| - base::Bind(&P2PSocketHostTcp::OnConnected, base::Unretained(this))); |
| - if (result != net::ERR_IO_PENDING) { |
| - OnConnected(result); |
| + 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. |
| + socket_.reset(CreateSocket(dest_host_port_pair, context_getter_)); |
| + |
| + 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; |
| @@ -272,8 +301,9 @@ |
| } |
| } |
| -P2PSocketHostTcp::P2PSocketHostTcp(IPC::Sender* message_sender, int id) |
| - : P2PSocketHostTcpBase(message_sender, id) { |
| +P2PSocketHostTcp::P2PSocketHostTcp(IPC::Sender* message_sender, int id, |
| + net::URLRequestContextGetter* getter) |
| + : P2PSocketHostTcpBase(message_sender, id, getter) { |
| } |
| P2PSocketHostTcp::~P2PSocketHostTcp() { |
| @@ -307,8 +337,9 @@ |
| // P2PSocketHostStunTcp |
| P2PSocketHostStunTcp::P2PSocketHostStunTcp(IPC::Sender* message_sender, |
| - int id) |
| - : P2PSocketHostTcpBase(message_sender, id) { |
| + int id, |
| + net::URLRequestContextGetter* getter) |
| + : P2PSocketHostTcpBase(message_sender, id, getter) { |
| } |
| P2PSocketHostStunTcp::~P2PSocketHostStunTcp() { |