diff options
author | akalin@chromium.org <akalin@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-08-15 00:13:44 +0000 |
---|---|---|
committer | akalin@chromium.org <akalin@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-08-15 00:13:44 +0000 |
commit | 18ccfdb7574c4868e37f53386454277e3e63bbe8 (patch) | |
tree | f1e177773e0b1cdc80deb3d755a8d7baf1233df6 /jingle/glue | |
parent | 582a8575e5259762d5cb7b517b928ed7fc75ca11 (diff) | |
download | chromium_src-18ccfdb7574c4868e37f53386454277e3e63bbe8.zip chromium_src-18ccfdb7574c4868e37f53386454277e3e63bbe8.tar.gz chromium_src-18ccfdb7574c4868e37f53386454277e3e63bbe8.tar.bz2 |
[net] Use scoped_ptr<> consistently in ClientSocketFactory and related code
This will make it easier to modify ClientSocketFactory et al. to support
reprioritization. This also fixes a few latent memory leaks in tests.
Make SocketStream use a ClientSocketHandle instead of
just a StreamSocket.
Rename {set,release}_socket() to {Set,Pass}Socket().
BUG=166689
TBR=eroman@chromium.org, rsleevi@chromium.org, sergeyu@chromium.org
Review URL: https://codereview.chromium.org/22995002
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@217707 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'jingle/glue')
-rw-r--r-- | jingle/glue/chrome_async_socket.cc | 10 | ||||
-rw-r--r-- | jingle/glue/chrome_async_socket_unittest.cc | 8 | ||||
-rw-r--r-- | jingle/glue/fake_ssl_client_socket.cc | 4 | ||||
-rw-r--r-- | jingle/glue/fake_ssl_client_socket.h | 3 | ||||
-rw-r--r-- | jingle/glue/fake_ssl_client_socket_unittest.cc | 7 | ||||
-rw-r--r-- | jingle/glue/resolving_client_socket_factory.h | 7 | ||||
-rw-r--r-- | jingle/glue/xmpp_client_socket_factory.cc | 26 | ||||
-rw-r--r-- | jingle/glue/xmpp_client_socket_factory.h | 6 |
8 files changed, 39 insertions, 32 deletions
diff --git a/jingle/glue/chrome_async_socket.cc b/jingle/glue/chrome_async_socket.cc index 39085e1..c14fb99 100644 --- a/jingle/glue/chrome_async_socket.cc +++ b/jingle/glue/chrome_async_socket.cc @@ -106,9 +106,9 @@ bool ChromeAsyncSocket::Connect(const talk_base::SocketAddress& address) { net::HostPortPair dest_host_port_pair(address.hostname(), address.port()); - transport_socket_.reset( + transport_socket_ = resolving_client_socket_factory_->CreateTransportClientSocket( - dest_host_port_pair)); + dest_host_port_pair); int status = transport_socket_->Connect( base::Bind(&ChromeAsyncSocket::ProcessConnectDone, weak_ptr_factory_.GetWeakPtr())); @@ -404,10 +404,10 @@ bool ChromeAsyncSocket::StartTls(const std::string& domain_name) { DCHECK(transport_socket_.get()); scoped_ptr<net::ClientSocketHandle> socket_handle( new net::ClientSocketHandle()); - socket_handle->set_socket(transport_socket_.release()); - transport_socket_.reset( + socket_handle->SetSocket(transport_socket_.Pass()); + transport_socket_ = resolving_client_socket_factory_->CreateSSLClientSocket( - socket_handle.release(), net::HostPortPair(domain_name, 443))); + socket_handle.Pass(), net::HostPortPair(domain_name, 443)); int status = transport_socket_->Connect( base::Bind(&ChromeAsyncSocket::ProcessSSLConnectDone, weak_ptr_factory_.GetWeakPtr())); diff --git a/jingle/glue/chrome_async_socket_unittest.cc b/jingle/glue/chrome_async_socket_unittest.cc index ebb69a2..db3d2b0 100644 --- a/jingle/glue/chrome_async_socket_unittest.cc +++ b/jingle/glue/chrome_async_socket_unittest.cc @@ -113,20 +113,20 @@ class MockXmppClientSocketFactory : public ResolvingClientSocketFactory { } // ResolvingClientSocketFactory implementation. - virtual net::StreamSocket* CreateTransportClientSocket( + virtual scoped_ptr<net::StreamSocket> CreateTransportClientSocket( const net::HostPortPair& host_and_port) OVERRIDE { return mock_client_socket_factory_->CreateTransportClientSocket( address_list_, NULL, net::NetLog::Source()); } - virtual net::SSLClientSocket* CreateSSLClientSocket( - net::ClientSocketHandle* transport_socket, + virtual scoped_ptr<net::SSLClientSocket> CreateSSLClientSocket( + scoped_ptr<net::ClientSocketHandle> transport_socket, const net::HostPortPair& host_and_port) OVERRIDE { net::SSLClientSocketContext context; context.cert_verifier = cert_verifier_.get(); context.transport_security_state = transport_security_state_.get(); return mock_client_socket_factory_->CreateSSLClientSocket( - transport_socket, host_and_port, ssl_config_, context); + transport_socket.Pass(), host_and_port, ssl_config_, context); } private: diff --git a/jingle/glue/fake_ssl_client_socket.cc b/jingle/glue/fake_ssl_client_socket.cc index bf6d12a..9d722c7 100644 --- a/jingle/glue/fake_ssl_client_socket.cc +++ b/jingle/glue/fake_ssl_client_socket.cc @@ -77,8 +77,8 @@ base::StringPiece FakeSSLClientSocket::GetSslServerHello() { } FakeSSLClientSocket::FakeSSLClientSocket( - net::StreamSocket* transport_socket) - : transport_socket_(transport_socket), + scoped_ptr<net::StreamSocket> transport_socket) + : transport_socket_(transport_socket.Pass()), next_handshake_state_(STATE_NONE), handshake_completed_(false), write_buf_(NewDrainableIOBufferWithSize(arraysize(kSslClientHello))), diff --git a/jingle/glue/fake_ssl_client_socket.h b/jingle/glue/fake_ssl_client_socket.h index 5bc4547..54a9e2f 100644 --- a/jingle/glue/fake_ssl_client_socket.h +++ b/jingle/glue/fake_ssl_client_socket.h @@ -36,8 +36,7 @@ namespace jingle_glue { class FakeSSLClientSocket : public net::StreamSocket { public: - // Takes ownership of |transport_socket|. - explicit FakeSSLClientSocket(net::StreamSocket* transport_socket); + explicit FakeSSLClientSocket(scoped_ptr<net::StreamSocket> transport_socket); virtual ~FakeSSLClientSocket(); diff --git a/jingle/glue/fake_ssl_client_socket_unittest.cc b/jingle/glue/fake_ssl_client_socket_unittest.cc index 5c061f3..f6d8fea 100644 --- a/jingle/glue/fake_ssl_client_socket_unittest.cc +++ b/jingle/glue/fake_ssl_client_socket_unittest.cc @@ -91,7 +91,7 @@ class FakeSSLClientSocketTest : public testing::Test { virtual ~FakeSSLClientSocketTest() {} - net::StreamSocket* MakeClientSocket() { + scoped_ptr<net::StreamSocket> MakeClientSocket() { return mock_client_socket_factory_.CreateTransportClientSocket( net::AddressList(), NULL, net::NetLog::Source()); } @@ -269,7 +269,7 @@ class FakeSSLClientSocketTest : public testing::Test { }; TEST_F(FakeSSLClientSocketTest, PassThroughMethods) { - MockClientSocket* mock_client_socket = new MockClientSocket(); + scoped_ptr<MockClientSocket> mock_client_socket(new MockClientSocket()); const int kReceiveBufferSize = 10; const int kSendBufferSize = 20; net::IPEndPoint ip_endpoint(net::IPAddressNumber(net::kIPv4AddressSize), 80); @@ -284,7 +284,8 @@ TEST_F(FakeSSLClientSocketTest, PassThroughMethods) { EXPECT_CALL(*mock_client_socket, SetOmniboxSpeculation()); // Takes ownership of |mock_client_socket|. - FakeSSLClientSocket fake_ssl_client_socket(mock_client_socket); + FakeSSLClientSocket fake_ssl_client_socket( + mock_client_socket.PassAs<net::StreamSocket>()); fake_ssl_client_socket.SetReceiveBufferSize(kReceiveBufferSize); fake_ssl_client_socket.SetSendBufferSize(kSendBufferSize); EXPECT_EQ(kPeerAddress, diff --git a/jingle/glue/resolving_client_socket_factory.h b/jingle/glue/resolving_client_socket_factory.h index 5be8bc8..d1b9fc1 100644 --- a/jingle/glue/resolving_client_socket_factory.h +++ b/jingle/glue/resolving_client_socket_factory.h @@ -5,6 +5,7 @@ #ifndef JINGLE_GLUE_RESOLVING_CLIENT_SOCKET_FACTORY_H_ #define JINGLE_GLUE_RESOLVING_CLIENT_SOCKET_FACTORY_H_ +#include "base/memory/scoped_ptr.h" namespace net { class ClientSocketHandle; @@ -23,11 +24,11 @@ class ResolvingClientSocketFactory { public: virtual ~ResolvingClientSocketFactory() { } // Method to create a transport socket using a HostPortPair. - virtual net::StreamSocket* CreateTransportClientSocket( + virtual scoped_ptr<net::StreamSocket> CreateTransportClientSocket( const net::HostPortPair& host_and_port) = 0; - virtual net::SSLClientSocket* CreateSSLClientSocket( - net::ClientSocketHandle* transport_socket, + virtual scoped_ptr<net::SSLClientSocket> CreateSSLClientSocket( + scoped_ptr<net::ClientSocketHandle> transport_socket, const net::HostPortPair& host_and_port) = 0; }; diff --git a/jingle/glue/xmpp_client_socket_factory.cc b/jingle/glue/xmpp_client_socket_factory.cc index b9e040d..4823ee5 100644 --- a/jingle/glue/xmpp_client_socket_factory.cc +++ b/jingle/glue/xmpp_client_socket_factory.cc @@ -8,6 +8,7 @@ #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" @@ -28,20 +29,25 @@ XmppClientSocketFactory::XmppClientSocketFactory( XmppClientSocketFactory::~XmppClientSocketFactory() {} -net::StreamSocket* XmppClientSocketFactory::CreateTransportClientSocket( +scoped_ptr<net::StreamSocket> +XmppClientSocketFactory::CreateTransportClientSocket( const net::HostPortPair& host_and_port) { // TODO(akalin): Use socket pools. - net::StreamSocket* transport_socket = new ProxyResolvingClientSocket( - NULL, - request_context_getter_, - ssl_config_, - host_and_port); + scoped_ptr<net::StreamSocket> transport_socket( + new ProxyResolvingClientSocket( + NULL, + request_context_getter_, + ssl_config_, + host_and_port)); return (use_fake_ssl_client_socket_ ? - new FakeSSLClientSocket(transport_socket) : transport_socket); + scoped_ptr<net::StreamSocket>( + new FakeSSLClientSocket(transport_socket.Pass())) : + transport_socket.Pass()); } -net::SSLClientSocket* XmppClientSocketFactory::CreateSSLClientSocket( - net::ClientSocketHandle* transport_socket, +scoped_ptr<net::SSLClientSocket> +XmppClientSocketFactory::CreateSSLClientSocket( + scoped_ptr<net::ClientSocketHandle> transport_socket, const net::HostPortPair& host_and_port) { net::SSLClientSocketContext context; context.cert_verifier = @@ -52,7 +58,7 @@ net::SSLClientSocket* XmppClientSocketFactory::CreateSSLClientSocket( // TODO(rkn): context.server_bound_cert_service is NULL because the // ServerBoundCertService class is not thread safe. return client_socket_factory_->CreateSSLClientSocket( - transport_socket, host_and_port, ssl_config_, context); + transport_socket.Pass(), host_and_port, ssl_config_, context); } diff --git a/jingle/glue/xmpp_client_socket_factory.h b/jingle/glue/xmpp_client_socket_factory.h index c2a0d6a..4204c19 100644 --- a/jingle/glue/xmpp_client_socket_factory.h +++ b/jingle/glue/xmpp_client_socket_factory.h @@ -35,11 +35,11 @@ class XmppClientSocketFactory : public ResolvingClientSocketFactory { virtual ~XmppClientSocketFactory(); // ResolvingClientSocketFactory implementation. - virtual net::StreamSocket* CreateTransportClientSocket( + virtual scoped_ptr<net::StreamSocket> CreateTransportClientSocket( const net::HostPortPair& host_and_port) OVERRIDE; - virtual net::SSLClientSocket* CreateSSLClientSocket( - net::ClientSocketHandle* transport_socket, + virtual scoped_ptr<net::SSLClientSocket> CreateSSLClientSocket( + scoped_ptr<net::ClientSocketHandle> transport_socket, const net::HostPortPair& host_and_port) OVERRIDE; private: |