Index: content/browser/renderer_host/p2p/socket_host_tcp.cc |
=================================================================== |
--- content/browser/renderer_host/p2p/socket_host_tcp.cc (revision 207453) |
+++ content/browser/renderer_host/p2p/socket_host_tcp.cc (working copy) |
@@ -7,10 +7,12 @@ |
#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" |
#include "net/socket/tcp_client_socket.h" |
+#include "net/url_request/url_request_context_getter.h" |
namespace { |
@@ -24,11 +26,14 @@ |
namespace content { |
-P2PSocketHostTcpBase::P2PSocketHostTcpBase(IPC::Sender* message_sender, |
- int id) |
+P2PSocketHostTcpBase::P2PSocketHostTcpBase( |
+ IPC::Sender* message_sender, int id, |
+ net::URLRequestContextGetter* url_context) |
: P2PSocketHost(message_sender, id), |
+ //weak_ptr_factory_(this), |
juberti
2013/06/21 04:30:35
Remove?
Mallinath (Gone from Chromium)
2013/06/21 05:46:10
Done.
|
write_pending_(false), |
- connected_(false) { |
+ connected_(false), |
+ url_context_(url_context) { |
} |
P2PSocketHostTcpBase::~P2PSocketHostTcpBase() { |
@@ -51,24 +56,40 @@ |
} |
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. |
+ |
+ // 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)); |
+ |
+ 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 +293,10 @@ |
} |
} |
-P2PSocketHostTcp::P2PSocketHostTcp(IPC::Sender* message_sender, int id) |
- : P2PSocketHostTcpBase(message_sender, id) { |
+P2PSocketHostTcp::P2PSocketHostTcp( |
+ IPC::Sender* message_sender, int id, |
+ net::URLRequestContextGetter* url_context) |
+ : P2PSocketHostTcpBase(message_sender, id, url_context) { |
} |
P2PSocketHostTcp::~P2PSocketHostTcp() { |
@@ -306,9 +329,10 @@ |
} |
// P2PSocketHostStunTcp |
-P2PSocketHostStunTcp::P2PSocketHostStunTcp(IPC::Sender* message_sender, |
- int id) |
- : P2PSocketHostTcpBase(message_sender, id) { |
+P2PSocketHostStunTcp::P2PSocketHostStunTcp( |
+ IPC::Sender* message_sender, int id, |
+ net::URLRequestContextGetter* url_context) |
+ : P2PSocketHostTcpBase(message_sender, id, url_context) { |
} |
P2PSocketHostStunTcp::~P2PSocketHostStunTcp() { |