diff options
Diffstat (limited to 'net')
32 files changed, 620 insertions, 634 deletions
diff --git a/net/base/test_completion_callback.cc b/net/base/test_completion_callback.cc index 6851a7c..aa04d22 100644 --- a/net/base/test_completion_callback.cc +++ b/net/base/test_completion_callback.cc @@ -5,54 +5,57 @@ #include "net/base/test_completion_callback.h" #include "base/bind.h" +#include "base/bind_helpers.h" #include "base/compiler_specific.h" #include "base/message_loop.h" #include "net/base/net_errors.h" -TestOldCompletionCallback::TestOldCompletionCallback() - : result_(0), - have_result_(false), - waiting_for_result_(false) { +void TestCompletionCallbackBase::SetResult(int result) { + result_ = result; + have_result_ = true; + if (waiting_for_result_) + MessageLoop::current()->Quit(); } -TestOldCompletionCallback::~TestOldCompletionCallback() {} - -int TestOldCompletionCallback::WaitForResult() { +int TestCompletionCallbackBase::WaitForResult() { DCHECK(!waiting_for_result_); + while (!have_result_) { waiting_for_result_ = true; MessageLoop::current()->Run(); waiting_for_result_ = false; } - have_result_ = false; // auto-reset for next callback + + have_result_ = false; // Auto-reset for next callback. return result_; } -int TestOldCompletionCallback::GetResult(int result) { +int TestCompletionCallbackBase::GetResult(int result) { if (net::ERR_IO_PENDING != result) return result; + return WaitForResult(); } +TestCompletionCallbackBase::TestCompletionCallbackBase() + : result_(0), + have_result_(false), + waiting_for_result_(false) { +} + void TestOldCompletionCallback::RunWithParams(const Tuple1<int>& params) { - result_ = params.a; - have_result_ = true; - if (waiting_for_result_) - MessageLoop::current()->Quit(); + SetResult(params.a); } namespace net { TestCompletionCallback::TestCompletionCallback() : ALLOW_THIS_IN_INITIALIZER_LIST(callback_( - base::Bind(&TestCompletionCallback::OnComplete, + base::Bind(&TestCompletionCallback::SetResult, base::Unretained(this)))) { } TestCompletionCallback::~TestCompletionCallback() {} -void TestCompletionCallback::OnComplete(int result) { - old_callback_impl_.RunWithParams(Tuple1<int>(result)); -} } // namespace net diff --git a/net/base/test_completion_callback.h b/net/base/test_completion_callback.h index a192194..5dff389 100644 --- a/net/base/test_completion_callback.h +++ b/net/base/test_completion_callback.h @@ -22,45 +22,51 @@ // there could be other side-effects resulting from WaitForResult. For this // reason, this class is probably not ideal for a general application. // -class TestOldCompletionCallback : public CallbackRunner< Tuple1<int> > { - public: - TestOldCompletionCallback(); - virtual ~TestOldCompletionCallback(); +// Base class overridden by custom implementations of TestCompletionCallback. +class TestCompletionCallbackBase { + public: + void SetResult(int result); int WaitForResult(); - int GetResult(int result); - bool have_result() const { return have_result_; } - virtual void RunWithParams(const Tuple1<int>& params) OVERRIDE; + protected: + TestCompletionCallbackBase(); - private: int result_; bool have_result_; bool waiting_for_result_; + + private: + DISALLOW_COPY_AND_ASSIGN(TestCompletionCallbackBase); +}; + +class TestOldCompletionCallback : public TestCompletionCallbackBase, + public CallbackRunner<Tuple1<int> > { + public: + TestOldCompletionCallback() {}; + virtual ~TestOldCompletionCallback() {} + + virtual void RunWithParams(const Tuple1<int>& params) OVERRIDE; + + private: + DISALLOW_COPY_AND_ASSIGN(TestOldCompletionCallback); }; namespace net { -class TestCompletionCallback { +class TestCompletionCallback : public TestCompletionCallbackBase { public: TestCompletionCallback(); ~TestCompletionCallback(); - int WaitForResult() { return old_callback_impl_.WaitForResult(); } - - int GetResult(int result) { return old_callback_impl_.GetResult(result); } - - bool have_result() const { return old_callback_impl_.have_result(); } - const CompletionCallback& callback() const { return callback_; } private: - void OnComplete(int result); - const CompletionCallback callback_; - TestOldCompletionCallback old_callback_impl_; + + DISALLOW_COPY_AND_ASSIGN(TestCompletionCallback); }; } // namespace net diff --git a/net/http/http_network_transaction_unittest.cc b/net/http/http_network_transaction_unittest.cc index 82dc571..fd0a4c4 100644 --- a/net/http/http_network_transaction_unittest.cc +++ b/net/http/http_network_transaction_unittest.cc @@ -7312,10 +7312,10 @@ TEST_F(HttpNetworkTransactionTest, connection->Init(host_port_pair.ToString(), transport_params, LOWEST, - &callback_old, + callback.callback(), session->GetTransportSocketPool(), BoundNetLog())); - EXPECT_EQ(OK, callback_old.WaitForResult()); + EXPECT_EQ(OK, callback.WaitForResult()); SSLConfig ssl_config; session->ssl_config_service()->GetSSLConfig(&ssl_config); @@ -8567,12 +8567,13 @@ TEST_F(HttpNetworkTransactionTest, PreconnectWithExistingSpdySession) { session->spdy_session_pool()->Get(pair, BoundNetLog()); scoped_refptr<TransportSocketParams> transport_params( new TransportSocketParams(host_port_pair, MEDIUM, false, false)); - TestOldCompletionCallback callback; + TestOldCompletionCallback old_callback; + TestCompletionCallback callback; scoped_ptr<ClientSocketHandle> connection(new ClientSocketHandle); EXPECT_EQ(ERR_IO_PENDING, connection->Init(host_port_pair.ToString(), transport_params, - LOWEST, &callback, + LOWEST, callback.callback(), session->GetTransportSocketPool(), BoundNetLog())); EXPECT_EQ(OK, callback.WaitForResult()); spdy_session->InitializeWithSocket(connection.release(), false, OK); @@ -8587,9 +8588,9 @@ TEST_F(HttpNetworkTransactionTest, PreconnectWithExistingSpdySession) { scoped_ptr<HttpNetworkTransaction> trans(new HttpNetworkTransaction(session)); - int rv = trans->Start(&request, &callback, BoundNetLog()); + int rv = trans->Start(&request, &old_callback, BoundNetLog()); EXPECT_EQ(ERR_IO_PENDING, rv); - EXPECT_EQ(OK, callback.WaitForResult()); + EXPECT_EQ(OK, old_callback.WaitForResult()); } // Given a net error, cause that error to be returned from the first Write() diff --git a/net/http/http_pipelined_connection_impl_unittest.cc b/net/http/http_pipelined_connection_impl_unittest.cc index 2c0d2df..eb7eb78 100644 --- a/net/http/http_pipelined_connection_impl_unittest.cc +++ b/net/http/http_pipelined_connection_impl_unittest.cc @@ -86,7 +86,8 @@ class HttpPipelinedConnectionImplTest : public testing::Test { factory_.AddSocketDataProvider(data_.get()); scoped_refptr<DummySocketParams> params; ClientSocketHandle* connection = new ClientSocketHandle; - connection->Init("a", params, MEDIUM, NULL, &pool_, BoundNetLog()); + connection->Init("a", params, MEDIUM, CompletionCallback(), &pool_, + BoundNetLog()); pipeline_.reset(new HttpPipelinedConnectionImpl(connection, &delegate_, ssl_config_, proxy_info_, BoundNetLog(), false)); diff --git a/net/http/http_proxy_client_socket_pool.cc b/net/http/http_proxy_client_socket_pool.cc index f210cc8..7b1f960 100644 --- a/net/http/http_proxy_client_socket_pool.cc +++ b/net/http/http_proxy_client_socket_pool.cc @@ -174,12 +174,9 @@ int HttpProxyConnectJob::DoTransportConnect() { next_state_ = STATE_TCP_CONNECT_COMPLETE; transport_socket_handle_.reset(new ClientSocketHandle()); return transport_socket_handle_->Init( - group_name(), - params_->transport_params(), - params_->transport_params()->destination().priority(), - &callback_old_, - transport_pool_, - net_log()); + group_name(), params_->transport_params(), + params_->transport_params()->destination().priority(), callback_, + transport_pool_, net_log()); } int HttpProxyConnectJob::DoTransportConnectComplete(int result) { @@ -211,7 +208,7 @@ int HttpProxyConnectJob::DoSSLConnect() { return transport_socket_handle_->Init( group_name(), params_->ssl_params(), params_->ssl_params()->transport_params()->destination().priority(), - &callback_old_, ssl_pool_, net_log()); + callback_, ssl_pool_, net_log()); } int HttpProxyConnectJob::DoSSLConnectComplete(int result) { diff --git a/net/http/http_proxy_client_socket_pool_unittest.cc b/net/http/http_proxy_client_socket_pool_unittest.cc index d9c51a6..4c589e9 100644 --- a/net/http/http_proxy_client_socket_pool_unittest.cc +++ b/net/http/http_proxy_client_socket_pool_unittest.cc @@ -216,7 +216,7 @@ class HttpProxyClientSocketPoolTest : public TestWithHttpParam { scoped_refptr<DeterministicSocketData> data_; HttpProxyClientSocketPool pool_; ClientSocketHandle handle_; - TestOldCompletionCallback callback_; + TestCompletionCallback callback_; }; //----------------------------------------------------------------------------- @@ -229,8 +229,8 @@ INSTANTIATE_TEST_CASE_P(HttpProxyClientSocketPoolTests, TEST_P(HttpProxyClientSocketPoolTest, NoTunnel) { Initialize(false, NULL, 0, NULL, 0, NULL, 0, NULL, 0); - int rv = handle_.Init("a", GetNoTunnelParams(), LOW, NULL, &pool_, - BoundNetLog()); + int rv = handle_.Init("a", GetNoTunnelParams(), LOW, CompletionCallback(), + &pool_, BoundNetLog()); EXPECT_EQ(OK, rv); EXPECT_TRUE(handle_.is_initialized()); ASSERT_TRUE(handle_.socket()); @@ -271,8 +271,8 @@ TEST_P(HttpProxyClientSocketPoolTest, NeedAuth) { arraysize(spdy_writes)); data_->StopAfter(4); - int rv = handle_.Init("a", GetTunnelParams(), LOW, &callback_, &pool_, - BoundNetLog()); + int rv = handle_.Init("a", GetTunnelParams(), LOW, callback_.callback(), + &pool_, BoundNetLog()); EXPECT_EQ(ERR_IO_PENDING, rv); EXPECT_FALSE(handle_.is_initialized()); EXPECT_FALSE(handle_.socket()); @@ -296,7 +296,7 @@ TEST_P(HttpProxyClientSocketPoolTest, NeedAuth) { } TEST_P(HttpProxyClientSocketPoolTest, HaveAuth) { - // It's pretty much impossible to make the SPDY case becave synchronously + // It's pretty much impossible to make the SPDY case behave synchronously // so we skip this test for SPDY if (GetParam() == SPDY) return; @@ -315,8 +315,8 @@ TEST_P(HttpProxyClientSocketPoolTest, HaveAuth) { NULL, 0); AddAuthToCache(); - int rv = handle_.Init("a", GetTunnelParams(), LOW, &callback_, &pool_, - BoundNetLog()); + int rv = handle_.Init("a", GetTunnelParams(), LOW, callback_.callback(), + &pool_, BoundNetLog()); EXPECT_EQ(OK, rv); EXPECT_TRUE(handle_.is_initialized()); ASSERT_TRUE(handle_.socket()); @@ -352,8 +352,8 @@ TEST_P(HttpProxyClientSocketPoolTest, AsyncHaveAuth) { arraysize(spdy_writes)); AddAuthToCache(); - int rv = handle_.Init("a", GetTunnelParams(), LOW, &callback_, &pool_, - BoundNetLog()); + int rv = handle_.Init("a", GetTunnelParams(), LOW, callback_.callback(), + &pool_, BoundNetLog()); EXPECT_EQ(ERR_IO_PENDING, rv); EXPECT_FALSE(handle_.is_initialized()); EXPECT_FALSE(handle_.socket()); @@ -374,8 +374,8 @@ TEST_P(HttpProxyClientSocketPoolTest, TCPError) { socket_factory().AddSocketDataProvider(data_.get()); - int rv = handle_.Init("a", GetTunnelParams(), LOW, &callback_, &pool_, - BoundNetLog()); + int rv = handle_.Init("a", GetTunnelParams(), LOW, callback_.callback(), + &pool_, BoundNetLog()); EXPECT_EQ(ERR_IO_PENDING, rv); EXPECT_FALSE(handle_.is_initialized()); EXPECT_FALSE(handle_.socket()); @@ -399,8 +399,8 @@ TEST_P(HttpProxyClientSocketPoolTest, SSLError) { } socket_factory().AddSSLSocketDataProvider(ssl_data_.get()); - int rv = handle_.Init("a", GetTunnelParams(), LOW, &callback_, &pool_, - BoundNetLog()); + int rv = handle_.Init("a", GetTunnelParams(), LOW, callback_.callback(), + &pool_, BoundNetLog()); EXPECT_EQ(ERR_IO_PENDING, rv); EXPECT_FALSE(handle_.is_initialized()); EXPECT_FALSE(handle_.socket()); @@ -424,8 +424,8 @@ TEST_P(HttpProxyClientSocketPoolTest, SslClientAuth) { } socket_factory().AddSSLSocketDataProvider(ssl_data_.get()); - int rv = handle_.Init("a", GetTunnelParams(), LOW, &callback_, &pool_, - BoundNetLog()); + int rv = handle_.Init("a", GetTunnelParams(), LOW, callback_.callback(), + &pool_, BoundNetLog()); EXPECT_EQ(ERR_IO_PENDING, rv); EXPECT_FALSE(handle_.is_initialized()); EXPECT_FALSE(handle_.socket()); @@ -462,8 +462,8 @@ TEST_P(HttpProxyClientSocketPoolTest, TunnelUnexpectedClose) { arraysize(spdy_writes)); AddAuthToCache(); - int rv = handle_.Init("a", GetTunnelParams(), LOW, &callback_, &pool_, - BoundNetLog()); + int rv = handle_.Init("a", GetTunnelParams(), LOW, callback_.callback(), + &pool_, BoundNetLog()); EXPECT_EQ(ERR_IO_PENDING, rv); EXPECT_FALSE(handle_.is_initialized()); EXPECT_FALSE(handle_.socket()); @@ -503,8 +503,8 @@ TEST_P(HttpProxyClientSocketPoolTest, TunnelSetupError) { arraysize(spdy_writes)); AddAuthToCache(); - int rv = handle_.Init("a", GetTunnelParams(), LOW, &callback_, &pool_, - BoundNetLog()); + int rv = handle_.Init("a", GetTunnelParams(), LOW, callback_.callback(), + &pool_, BoundNetLog()); EXPECT_EQ(ERR_IO_PENDING, rv); EXPECT_FALSE(handle_.is_initialized()); EXPECT_FALSE(handle_.socket()); diff --git a/net/http/http_stream_factory_impl_job.cc b/net/http/http_stream_factory_impl_job.cc index 4bd782c..8a1f69f 100644 --- a/net/http/http_stream_factory_impl_job.cc +++ b/net/http/http_stream_factory_impl_job.cc @@ -5,6 +5,7 @@ #include "net/http/http_stream_factory_impl_job.h" #include "base/bind.h" +#include "base/bind_helpers.h" #include "base/logging.h" #include "base/stl_util.h" #include "base/string_util.h" @@ -114,7 +115,10 @@ HttpStreamFactoryImpl::Job::Job(HttpStreamFactoryImpl* stream_factory, proxy_ssl_config_(proxy_ssl_config), net_log_(BoundNetLog::Make(net_log.net_log(), NetLog::SOURCE_HTTP_STREAM_JOB)), - ALLOW_THIS_IN_INITIALIZER_LIST(io_callback_(this, &Job::OnIOComplete)), + ALLOW_THIS_IN_INITIALIZER_LIST(old_io_callback_( + this, &Job::OnIOComplete)), + ALLOW_THIS_IN_INITIALIZER_LIST(io_callback_( + base::Bind(&Job::OnIOComplete, base::Unretained(this)))), connection_(new ClientSocketHandle), session_(session), stream_factory_(stream_factory), @@ -572,8 +576,7 @@ int HttpStreamFactoryImpl::Job::DoResolveProxy() { } return session_->proxy_service()->ResolveProxy( - request_info_.url, &proxy_info_, &io_callback_, &pac_request_, - net_log_); + request_info_.url, &proxy_info_, io_callback_, &pac_request_, net_log_); } int HttpStreamFactoryImpl::Job::DoResolveProxyComplete(int result) { @@ -715,19 +718,10 @@ int HttpStreamFactoryImpl::Job::DoInitConnection() { num_streams_); } else { return InitSocketHandleForHttpRequest( - origin_url_, - request_info_.extra_headers, - request_info_.load_flags, - request_info_.priority, - session_, - proxy_info_, - ShouldForceSpdySSL(), - want_spdy_over_npn, - server_ssl_config_, - proxy_ssl_config_, - net_log_, - connection_.get(), - &io_callback_); + origin_url_, request_info_.extra_headers, request_info_.load_flags, + request_info_.priority, session_, proxy_info_, ShouldForceSpdySSL(), + want_spdy_over_npn, server_ssl_config_, proxy_ssl_config_, net_log_, + connection_.get(), io_callback_); } } @@ -956,7 +950,7 @@ int HttpStreamFactoryImpl::Job::DoRestartTunnelAuth() { next_state_ = STATE_RESTART_TUNNEL_AUTH_COMPLETE; HttpProxyClientSocket* http_proxy_socket = static_cast<HttpProxyClientSocket*>(connection_->socket()); - return http_proxy_socket->RestartWithAuth(&io_callback_); + return http_proxy_socket->RestartWithAuth(&old_io_callback_); } int HttpStreamFactoryImpl::Job::DoRestartTunnelAuthComplete(int result) { @@ -1090,8 +1084,7 @@ int HttpStreamFactoryImpl::Job::ReconsiderProxyAfterError(int error) { } int rv = session_->proxy_service()->ReconsiderProxyAfterError( - request_info_.url, &proxy_info_, &io_callback_, &pac_request_, - net_log_); + request_info_.url, &proxy_info_, io_callback_, &pac_request_, net_log_); if (rv == OK || rv == ERR_IO_PENDING) { // If the error was during connection setup, there is no socket to // disconnect. diff --git a/net/http/http_stream_factory_impl_job.h b/net/http/http_stream_factory_impl_job.h index f705ed9..2c771ff 100644 --- a/net/http/http_stream_factory_impl_job.h +++ b/net/http/http_stream_factory_impl_job.h @@ -207,7 +207,8 @@ class HttpStreamFactoryImpl::Job { SSLConfig proxy_ssl_config_; const BoundNetLog net_log_; - OldCompletionCallbackImpl<Job> io_callback_; + OldCompletionCallbackImpl<Job> old_io_callback_; + CompletionCallback io_callback_; scoped_ptr<ClientSocketHandle> connection_; HttpNetworkSession* const session_; HttpStreamFactoryImpl* const stream_factory_; diff --git a/net/proxy/proxy_service.cc b/net/proxy/proxy_service.cc index 67a3e05..647718b 100644 --- a/net/proxy/proxy_service.cc +++ b/net/proxy/proxy_service.cc @@ -6,6 +6,8 @@ #include <algorithm> +#include "base/bind.h" +#include "base/bind_helpers.h" #include "base/compiler_specific.h" #include "base/logging.h" #include "base/message_loop.h" @@ -67,7 +69,7 @@ const size_t kDefaultNumPacThreads = 4; // Now by the time we run the proxy-autoconfig there is a lower chance of // getting transient DNS / connect failures. // -// Admitedly this is a hack. Ideally we would have NetworkChangeNotifier +// Admittedly this is a hack. Ideally we would have NetworkChangeNotifier // deliver a reliable signal indicating that the network has changed AND is // ready for action... But until then, we can reduce the likelihood of users // getting wedged because of proxy detection failures on network switch. @@ -84,7 +86,7 @@ const size_t kDefaultNumPacThreads = 4; // The specific hard-coded wait time below is arbitrary. // Basically I ran some experiments switching between wireless networks on // a Linux Ubuntu (Lucid) laptop, and experimentally found this timeout fixes -// things. It is entirely possible that the value is insuficient for other +// things. It is entirely possible that the value is insufficient for other // setups. const int64 kNumMillisToStallAfterNetworkChanges = 2000; @@ -777,7 +779,7 @@ int ProxyService::ResolveProxy(const GURL& raw_url, DCHECK(!ContainsPendingRequest(req)); pending_requests_.push_back(req); - // Completion will be notifed through |callback|, unless the caller cancels + // Completion will be notified through |callback|, unless the caller cancels // the request using |pac_request|. if (pac_request) *pac_request = req.get(); @@ -960,7 +962,7 @@ void ProxyService::OnInitProxyResolverComplete(int result) { int ProxyService::ReconsiderProxyAfterError(const GURL& url, ProxyInfo* result, - OldCompletionCallback* callback, + const CompletionCallback& callback, PacRequest** pac_request, const BoundNetLog& net_log) { DCHECK(CalledOnValidThread()); @@ -1262,7 +1264,8 @@ SyncProxyServiceHelper::SyncProxyServiceHelper(MessageLoop* io_message_loop, proxy_service_(proxy_service), event_(false, false), ALLOW_THIS_IN_INITIALIZER_LIST(callback_( - this, &SyncProxyServiceHelper::OnCompletion)) { + base::Bind(&SyncProxyServiceHelper::OnCompletion, + base::Unretained(this)))) { DCHECK(io_message_loop_ != MessageLoop::current()); } @@ -1302,7 +1305,7 @@ SyncProxyServiceHelper::~SyncProxyServiceHelper() {} void SyncProxyServiceHelper::StartAsyncResolve(const GURL& url, const BoundNetLog& net_log) { result_ = proxy_service_->ResolveProxy( - url, &proxy_info_, &callback_, NULL, net_log); + url, &proxy_info_, callback_, NULL, net_log); if (result_ != net::ERR_IO_PENDING) { OnCompletion(result_); } @@ -1311,7 +1314,7 @@ void SyncProxyServiceHelper::StartAsyncResolve(const GURL& url, void SyncProxyServiceHelper::StartAsyncReconsider(const GURL& url, const BoundNetLog& net_log) { result_ = proxy_service_->ReconsiderProxyAfterError( - url, &proxy_info_, &callback_, NULL, net_log); + url, &proxy_info_, callback_, NULL, net_log); if (result_ != net::ERR_IO_PENDING) { OnCompletion(result_); } diff --git a/net/proxy/proxy_service.h b/net/proxy/proxy_service.h index 4db51b8..0e011c5 100644 --- a/net/proxy/proxy_service.h +++ b/net/proxy/proxy_service.h @@ -99,7 +99,7 @@ class NET_EXPORT ProxyService : public NetworkChangeNotifier::IPAddressObserver, // Profiling information for the request is saved to |net_log| if non-NULL. int ReconsiderProxyAfterError(const GURL& url, ProxyInfo* results, - OldCompletionCallback* callback, + const CompletionCallback& callback, PacRequest** pac_request, const BoundNetLog& net_log); @@ -404,7 +404,7 @@ class NET_EXPORT SyncProxyServiceHelper ProxyService* proxy_service_; base::WaitableEvent event_; - OldCompletionCallbackImpl<SyncProxyServiceHelper> callback_; + CompletionCallback callback_; ProxyInfo proxy_info_; int result_; }; diff --git a/net/proxy/proxy_service_unittest.cc b/net/proxy/proxy_service_unittest.cc index 361a473..e602216 100644 --- a/net/proxy/proxy_service_unittest.cc +++ b/net/proxy/proxy_service_unittest.cc @@ -212,8 +212,8 @@ TEST(ProxyServiceTest, PAC_FailoverWithoutDirect) { // Now, imagine that connecting to foopy:8080 fails: there is nothing // left to fallback to, since our proxy list was NOT terminated by // DIRECT. - TestOldCompletionCallback callback2; - rv = service.ReconsiderProxyAfterError(url, &info, &callback2, NULL, + TestCompletionCallback callback2; + rv = service.ReconsiderProxyAfterError(url, &info, callback2.callback(), NULL, BoundNetLog()); // ReconsiderProxyAfterError returns error indicating nothing left. EXPECT_EQ(ERR_FAILED, rv); @@ -267,31 +267,31 @@ TEST(ProxyServiceTest, PAC_FailoverAfterDirect) { EXPECT_TRUE(info.is_direct()); // Fallback 1. - TestOldCompletionCallback callback2; - rv = service.ReconsiderProxyAfterError(url, &info, &callback2, NULL, + TestCompletionCallback callback2; + rv = service.ReconsiderProxyAfterError(url, &info, callback2.callback(), NULL, BoundNetLog()); EXPECT_EQ(OK, rv); EXPECT_FALSE(info.is_direct()); EXPECT_EQ("foobar:10", info.proxy_server().ToURI()); // Fallback 2. - TestOldCompletionCallback callback3; - rv = service.ReconsiderProxyAfterError(url, &info, &callback3, NULL, + TestCompletionCallback callback3; + rv = service.ReconsiderProxyAfterError(url, &info, callback3.callback(), NULL, BoundNetLog()); EXPECT_EQ(OK, rv); EXPECT_TRUE(info.is_direct()); // Fallback 3. - TestOldCompletionCallback callback4; - rv = service.ReconsiderProxyAfterError(url, &info, &callback4, NULL, + TestCompletionCallback callback4; + rv = service.ReconsiderProxyAfterError(url, &info, callback4.callback(), NULL, BoundNetLog()); EXPECT_EQ(OK, rv); EXPECT_FALSE(info.is_direct()); EXPECT_EQ("foobar:20", info.proxy_server().ToURI()); // Fallback 4 -- Nothing to fall back to! - TestOldCompletionCallback callback5; - rv = service.ReconsiderProxyAfterError(url, &info, &callback5, NULL, + TestCompletionCallback callback5; + rv = service.ReconsiderProxyAfterError(url, &info, callback5.callback(), NULL, BoundNetLog()); EXPECT_EQ(ERR_FAILED, rv); EXPECT_TRUE(info.is_empty()); @@ -532,8 +532,8 @@ TEST(ProxyServiceTest, ProxyFallback) { EXPECT_EQ("foopy1:8080", info.proxy_server().ToURI()); // Fake an error on the proxy. - TestOldCompletionCallback callback2; - rv = service.ReconsiderProxyAfterError(url, &info, &callback2, NULL, + TestCompletionCallback callback2; + rv = service.ReconsiderProxyAfterError(url, &info, callback2.callback(), NULL, BoundNetLog()); EXPECT_EQ(OK, rv); @@ -561,8 +561,8 @@ TEST(ProxyServiceTest, ProxyFallback) { EXPECT_EQ("foopy3:7070", info.proxy_server().ToURI()); // We fake another error. It should now try the third one. - TestOldCompletionCallback callback4; - rv = service.ReconsiderProxyAfterError(url, &info, &callback4, NULL, + TestCompletionCallback callback4; + rv = service.ReconsiderProxyAfterError(url, &info, callback4.callback(), NULL, BoundNetLog()); EXPECT_EQ(OK, rv); EXPECT_EQ("foopy2:9090", info.proxy_server().ToURI()); @@ -570,24 +570,25 @@ TEST(ProxyServiceTest, ProxyFallback) { // We fake another error. At this point we have tried all of the // proxy servers we thought were valid; next we try the proxy server // that was in our bad proxies map (foopy1:8080). - TestOldCompletionCallback callback5; - rv = service.ReconsiderProxyAfterError(url, &info, &callback5, NULL, + TestCompletionCallback callback5; + rv = service.ReconsiderProxyAfterError(url, &info, callback5.callback(), NULL, BoundNetLog()); EXPECT_EQ(OK, rv); EXPECT_EQ("foopy1:8080", info.proxy_server().ToURI()); // Fake another error, the last proxy is gone, the list should now be empty, // so there is nothing left to try. - TestOldCompletionCallback callback6; - rv = service.ReconsiderProxyAfterError(url, &info, &callback6, NULL, + TestCompletionCallback callback6; + rv = service.ReconsiderProxyAfterError(url, &info, callback6.callback(), NULL, BoundNetLog()); EXPECT_EQ(ERR_FAILED, rv); EXPECT_FALSE(info.is_direct()); EXPECT_TRUE(info.is_empty()); // Look up proxies again - TestOldCompletionCallback callback7; - rv = service.ResolveProxy(url, &info, &callback7, NULL, BoundNetLog()); + TestCompletionCallback callback7; + rv = service.ResolveProxy(url, &info, callback7.callback(), NULL, + BoundNetLog()); EXPECT_EQ(ERR_IO_PENDING, rv); ASSERT_EQ(1u, resolver->pending_requests().size()); @@ -643,8 +644,8 @@ TEST(ProxyServiceTest, ProxyFallbackToDirect) { EXPECT_EQ("foopy1:8080", info.proxy_server().ToURI()); // Fake an error on the proxy. - TestOldCompletionCallback callback2; - rv = service.ReconsiderProxyAfterError(url, &info, &callback2, NULL, + TestCompletionCallback callback2; + rv = service.ReconsiderProxyAfterError(url, &info, callback2.callback(), NULL, BoundNetLog()); EXPECT_EQ(OK, rv); @@ -652,8 +653,8 @@ TEST(ProxyServiceTest, ProxyFallbackToDirect) { EXPECT_EQ("foopy2:9090", info.proxy_server().ToURI()); // Fake an error on this proxy as well. - TestOldCompletionCallback callback3; - rv = service.ReconsiderProxyAfterError(url, &info, &callback3, NULL, + TestCompletionCallback callback3; + rv = service.ReconsiderProxyAfterError(url, &info, callback3.callback(), NULL, BoundNetLog()); EXPECT_EQ(OK, rv); @@ -661,8 +662,8 @@ TEST(ProxyServiceTest, ProxyFallbackToDirect) { EXPECT_TRUE(info.is_direct()); // Now we tell the proxy service that even DIRECT failed. - TestOldCompletionCallback callback4; - rv = service.ReconsiderProxyAfterError(url, &info, &callback4, NULL, + TestCompletionCallback callback4; + rv = service.ReconsiderProxyAfterError(url, &info, callback4.callback(), NULL, BoundNetLog()); // There was nothing left to try after DIRECT, so we are out of // choices. @@ -708,8 +709,8 @@ TEST(ProxyServiceTest, ProxyFallback_NewSettings) { config_service->SetConfig( ProxyConfig::CreateFromCustomPacURL(GURL("http://foopy-new/proxy.pac"))); - TestOldCompletionCallback callback2; - rv = service.ReconsiderProxyAfterError(url, &info, &callback2, NULL, + TestCompletionCallback callback2; + rv = service.ReconsiderProxyAfterError(url, &info, callback2.callback(), NULL, BoundNetLog()); EXPECT_EQ(ERR_IO_PENDING, rv); @@ -729,8 +730,8 @@ TEST(ProxyServiceTest, ProxyFallback_NewSettings) { EXPECT_EQ("foopy1:8080", info.proxy_server().ToURI()); // We fake another error. It should now ignore the first one. - TestOldCompletionCallback callback3; - rv = service.ReconsiderProxyAfterError(url, &info, &callback3, NULL, + TestCompletionCallback callback3; + rv = service.ReconsiderProxyAfterError(url, &info, callback3.callback(), NULL, BoundNetLog()); EXPECT_EQ(OK, rv); EXPECT_EQ("foopy2:9090", info.proxy_server().ToURI()); @@ -741,8 +742,8 @@ TEST(ProxyServiceTest, ProxyFallback_NewSettings) { GURL("http://foopy-new2/proxy.pac"))); // We fake another error. It should go back to the first proxy. - TestOldCompletionCallback callback4; - rv = service.ReconsiderProxyAfterError(url, &info, &callback4, NULL, + TestCompletionCallback callback4; + rv = service.ReconsiderProxyAfterError(url, &info, callback4.callback(), NULL, BoundNetLog()); EXPECT_EQ(ERR_IO_PENDING, rv); @@ -795,8 +796,8 @@ TEST(ProxyServiceTest, ProxyFallback_BadConfig) { EXPECT_EQ("foopy1:8080", info.proxy_server().ToURI()); // Fake a proxy error. - TestOldCompletionCallback callback2; - rv = service.ReconsiderProxyAfterError(url, &info, &callback2, NULL, + TestCompletionCallback callback2; + rv = service.ReconsiderProxyAfterError(url, &info, callback2.callback(), NULL, BoundNetLog()); EXPECT_EQ(OK, rv); @@ -826,9 +827,9 @@ TEST(ProxyServiceTest, ProxyFallback_BadConfig) { // proxy list. Since we have not marked the configuration as bad, it should // "just work" the next time we call it. ProxyInfo info3; - TestOldCompletionCallback callback4; - rv = service.ReconsiderProxyAfterError(url, &info3, &callback4, NULL, - BoundNetLog()); + TestCompletionCallback callback4; + rv = service.ReconsiderProxyAfterError(url, &info3, callback4.callback(), + NULL, BoundNetLog()); EXPECT_EQ(ERR_IO_PENDING, rv); ASSERT_EQ(1u, resolver->pending_requests().size()); @@ -882,8 +883,8 @@ TEST(ProxyServiceTest, ProxyFallback_BadConfigMandatory) { EXPECT_EQ("foopy1:8080", info.proxy_server().ToURI()); // Fake a proxy error. - TestOldCompletionCallback callback2; - rv = service.ReconsiderProxyAfterError(url, &info, &callback2, NULL, + TestCompletionCallback callback2; + rv = service.ReconsiderProxyAfterError(url, &info, callback2.callback(), NULL, BoundNetLog()); EXPECT_EQ(OK, rv); @@ -914,9 +915,9 @@ TEST(ProxyServiceTest, ProxyFallback_BadConfigMandatory) { // proxy list. Since we have not marked the configuration as bad, it should // "just work" the next time we call it. ProxyInfo info3; - TestOldCompletionCallback callback4; - rv = service.ReconsiderProxyAfterError(url, &info3, &callback4, NULL, - BoundNetLog()); + TestCompletionCallback callback4; + rv = service.ReconsiderProxyAfterError(url, &info3, callback4.callback(), + NULL, BoundNetLog()); EXPECT_EQ(ERR_IO_PENDING, rv); ASSERT_EQ(1u, resolver->pending_requests().size()); diff --git a/net/socket/client_socket_handle.cc b/net/socket/client_socket_handle.cc index e093ec9..6d3e4e9 100644 --- a/net/socket/client_socket_handle.cc +++ b/net/socket/client_socket_handle.cc @@ -50,7 +50,7 @@ void ClientSocketHandle::ResetInternal(bool cancel) { is_initialized_ = false; group_name_.clear(); is_reused_ = false; - user_callback_ = NULL; + user_callback_.Reset(); if (layered_pool_) { pool_->RemoveLayeredPool(layered_pool_); layered_pool_ = NULL; @@ -92,10 +92,10 @@ void ClientSocketHandle::AddLayeredPool(LayeredPool* layered_pool) { } void ClientSocketHandle::OnIOComplete(int result) { - OldCompletionCallback* callback = user_callback_; - user_callback_ = NULL; + CompletionCallback callback = user_callback_; + user_callback_.Reset(); HandleInitCompletion(result); - callback->Run(result); + callback.Run(result); } void ClientSocketHandle::HandleInitCompletion(int result) { diff --git a/net/socket/client_socket_handle.h b/net/socket/client_socket_handle.h index 23fc5cf..003730c 100644 --- a/net/socket/client_socket_handle.h +++ b/net/socket/client_socket_handle.h @@ -74,7 +74,7 @@ class NET_EXPORT ClientSocketHandle { int Init(const std::string& group_name, const scoped_refptr<SocketParams>& socket_params, RequestPriority priority, - OldCompletionCallback* callback, + const CompletionCallback& callback, PoolType* pool, const BoundNetLog& net_log); @@ -173,7 +173,7 @@ class NET_EXPORT ClientSocketHandle { std::string group_name_; bool is_reused_; OldCompletionCallbackImpl<ClientSocketHandle> callback_; - OldCompletionCallback* user_callback_; + CompletionCallback user_callback_; base::TimeDelta idle_time_; int pool_id_; // See ClientSocketPool::ReleaseSocket() for an explanation. bool is_ssl_error_; @@ -192,7 +192,7 @@ template <typename SocketParams, typename PoolType> int ClientSocketHandle::Init(const std::string& group_name, const scoped_refptr<SocketParams>& socket_params, RequestPriority priority, - OldCompletionCallback* callback, + const CompletionCallback& callback, PoolType* pool, const BoundNetLog& net_log) { requesting_source_ = net_log.source(); diff --git a/net/socket/client_socket_pool_base_unittest.cc b/net/socket/client_socket_pool_base_unittest.cc index 1aac330..3520127 100644 --- a/net/socket/client_socket_pool_base_unittest.cc +++ b/net/socket/client_socket_pool_base_unittest.cc @@ -4,6 +4,8 @@ #include "net/socket/client_socket_pool_base.h" +#include "base/bind.h" +#include "base/bind_helpers.h" #include "base/callback.h" #include "base/compiler_specific.h" #include "base/memory/ref_counted.h" @@ -785,7 +787,7 @@ TEST_F(ClientSocketPoolBaseTest, ConnectJob_TimedOut) { TEST_F(ClientSocketPoolBaseTest, BasicSynchronous) { CreatePool(kDefaultMaxSockets, kDefaultMaxSocketsPerGroup); - TestOldCompletionCallback callback; + TestCompletionCallback callback; ClientSocketHandle handle; CapturingBoundNetLog log(CapturingNetLog::kUnbounded); @@ -793,7 +795,7 @@ TEST_F(ClientSocketPoolBaseTest, BasicSynchronous) { handle.Init("a", params_, kDefaultPriority, - &callback, + callback.callback(), pool_.get(), log.bound())); EXPECT_TRUE(handle.is_initialized()); @@ -823,7 +825,7 @@ TEST_F(ClientSocketPoolBaseTest, InitConnectionFailure) { CapturingBoundNetLog log(CapturingNetLog::kUnbounded); ClientSocketHandle handle; - TestOldCompletionCallback callback; + TestCompletionCallback callback; // Set the additional error state members to ensure that they get cleared. handle.set_is_ssl_error(true); HttpResponseInfo info; @@ -833,7 +835,7 @@ TEST_F(ClientSocketPoolBaseTest, InitConnectionFailure) { handle.Init("a", params_, kDefaultPriority, - &callback, + callback.callback(), pool_.get(), log.bound())); EXPECT_FALSE(handle.socket()); @@ -1067,23 +1069,23 @@ TEST_F(ClientSocketPoolBaseTest, StallAndThenCancelAndTriggerAvailableSocket) { connect_job_factory_->set_job_type(TestConnectJob::kMockPendingJob); ClientSocketHandle handle; - TestOldCompletionCallback callback; + TestCompletionCallback callback; EXPECT_EQ(ERR_IO_PENDING, handle.Init("a", params_, kDefaultPriority, - &callback, + callback.callback(), pool_.get(), BoundNetLog())); ClientSocketHandle handles[4]; for (size_t i = 0; i < arraysize(handles); ++i) { - TestOldCompletionCallback callback; + TestCompletionCallback callback; EXPECT_EQ(ERR_IO_PENDING, handles[i].Init("b", params_, kDefaultPriority, - &callback, + callback.callback(), pool_.get(), BoundNetLog())); } @@ -1101,23 +1103,23 @@ TEST_F(ClientSocketPoolBaseTest, CancelStalledSocketAtSocketLimit) { { ClientSocketHandle handles[kDefaultMaxSockets]; - TestOldCompletionCallback callbacks[kDefaultMaxSockets]; + TestCompletionCallback callbacks[kDefaultMaxSockets]; for (int i = 0; i < kDefaultMaxSockets; ++i) { EXPECT_EQ(OK, handles[i].Init(base::IntToString(i), params_, kDefaultPriority, - &callbacks[i], + callbacks[i].callback(), pool_.get(), BoundNetLog())); } // Force a stalled group. ClientSocketHandle stalled_handle; - TestOldCompletionCallback callback; + TestCompletionCallback callback; EXPECT_EQ(ERR_IO_PENDING, stalled_handle.Init("foo", params_, kDefaultPriority, - &callback, + callback.callback(), pool_.get(), BoundNetLog())); @@ -1141,11 +1143,11 @@ TEST_F(ClientSocketPoolBaseTest, CancelPendingSocketAtSocketLimit) { { ClientSocketHandle handles[kDefaultMaxSockets]; for (int i = 0; i < kDefaultMaxSockets; ++i) { - TestOldCompletionCallback callback; + TestCompletionCallback callback; EXPECT_EQ(ERR_IO_PENDING, handles[i].Init(base::IntToString(i), params_, kDefaultPriority, - &callback, + callback.callback(), pool_.get(), BoundNetLog())); } @@ -1153,11 +1155,11 @@ TEST_F(ClientSocketPoolBaseTest, CancelPendingSocketAtSocketLimit) { // Force a stalled group. connect_job_factory_->set_job_type(TestConnectJob::kMockPendingJob); ClientSocketHandle stalled_handle; - TestOldCompletionCallback callback; + TestCompletionCallback callback; EXPECT_EQ(ERR_IO_PENDING, stalled_handle.Init("foo", params_, kDefaultPriority, - &callback, + callback.callback(), pool_.get(), BoundNetLog())); @@ -1189,17 +1191,17 @@ TEST_F(ClientSocketPoolBaseTest, WaitForStalledSocketAtSocketLimit) { connect_job_factory_->set_job_type(TestConnectJob::kMockJob); ClientSocketHandle stalled_handle; - TestOldCompletionCallback callback; + TestCompletionCallback callback; { EXPECT_FALSE(pool_->IsStalled()); ClientSocketHandle handles[kDefaultMaxSockets]; for (int i = 0; i < kDefaultMaxSockets; ++i) { - TestOldCompletionCallback callback; + TestCompletionCallback callback; EXPECT_EQ(OK, handles[i].Init(base::StringPrintf( "Take 2: %d", i), params_, kDefaultPriority, - &callback, + callback.callback(), pool_.get(), BoundNetLog())); } @@ -1212,7 +1214,7 @@ TEST_F(ClientSocketPoolBaseTest, WaitForStalledSocketAtSocketLimit) { EXPECT_EQ(ERR_IO_PENDING, stalled_handle.Init("foo", params_, kDefaultPriority, - &callback, + callback.callback(), pool_.get(), BoundNetLog())); EXPECT_TRUE(pool_->IsStalled()); @@ -1236,11 +1238,11 @@ TEST_F(ClientSocketPoolBaseTest, CloseIdleSocketAtSocketLimitDeleteGroup) { for (int i = 0; i < kDefaultMaxSockets; ++i) { ClientSocketHandle handle; - TestOldCompletionCallback callback; + TestCompletionCallback callback; EXPECT_EQ(OK, handle.Init(base::IntToString(i), params_, kDefaultPriority, - &callback, + callback.callback(), pool_.get(), BoundNetLog())); } @@ -1252,7 +1254,7 @@ TEST_F(ClientSocketPoolBaseTest, CloseIdleSocketAtSocketLimitDeleteGroup) { // reuse a socket. connect_job_factory_->set_job_type(TestConnectJob::kMockPendingJob); ClientSocketHandle handle; - TestOldCompletionCallback callback; + TestCompletionCallback callback; // "0" is special here, since it should be the first entry in the sorted map, // which is the one which we would close an idle socket for. We shouldn't @@ -1260,7 +1262,7 @@ TEST_F(ClientSocketPoolBaseTest, CloseIdleSocketAtSocketLimitDeleteGroup) { EXPECT_EQ(OK, handle.Init("0", params_, kDefaultPriority, - &callback, + callback.callback(), pool_.get(), BoundNetLog())); @@ -1330,11 +1332,11 @@ TEST_F(ClientSocketPoolBaseTest, CancelRequestClearGroup) { connect_job_factory_->set_job_type(TestConnectJob::kMockPendingJob); ClientSocketHandle handle; - TestOldCompletionCallback callback; + TestCompletionCallback callback; EXPECT_EQ(ERR_IO_PENDING, handle.Init("a", params_, kDefaultPriority, - &callback, + callback.callback(), pool_.get(), BoundNetLog())); handle.Reset(); @@ -1345,23 +1347,23 @@ TEST_F(ClientSocketPoolBaseTest, ConnectCancelConnect) { connect_job_factory_->set_job_type(TestConnectJob::kMockPendingJob); ClientSocketHandle handle; - TestOldCompletionCallback callback; + TestCompletionCallback callback; EXPECT_EQ(ERR_IO_PENDING, handle.Init("a", params_, kDefaultPriority, - &callback, + callback.callback(), pool_.get(), BoundNetLog())); handle.Reset(); - TestOldCompletionCallback callback2; + TestCompletionCallback callback2; EXPECT_EQ(ERR_IO_PENDING, handle.Init("a", params_, kDefaultPriority, - &callback2, + callback2.callback(), pool_.get(), BoundNetLog())); @@ -1407,7 +1409,7 @@ TEST_F(ClientSocketPoolBaseTest, CancelRequest) { EXPECT_EQ(ClientSocketPoolTest::kIndexOutOfBounds, GetOrderOfRequest(8)); } -class RequestSocketCallback : public CallbackRunner< Tuple1<int> > { +class RequestSocketCallback : public TestCompletionCallbackBase { public: RequestSocketCallback(ClientSocketHandle* handle, TestClientSocketPool* pool, @@ -1417,11 +1419,20 @@ class RequestSocketCallback : public CallbackRunner< Tuple1<int> > { pool_(pool), within_callback_(false), test_connect_job_factory_(test_connect_job_factory), - next_job_type_(next_job_type) {} + next_job_type_(next_job_type), + ALLOW_THIS_IN_INITIALIZER_LIST(callback_( + base::Bind(&RequestSocketCallback::OnComplete, + base::Unretained(this)))) { + } + + virtual ~RequestSocketCallback() {} + + const CompletionCallback& callback() const { return callback_; } - virtual void RunWithParams(const Tuple1<int>& params) { - callback_.RunWithParams(params); - ASSERT_EQ(OK, params.a); + private: + void OnComplete(int result) { + SetResult(result); + ASSERT_EQ(OK, result); if (!within_callback_) { test_connect_job_factory_->set_job_type(next_job_type_); @@ -1436,12 +1447,12 @@ class RequestSocketCallback : public CallbackRunner< Tuple1<int> > { MessageLoop::current()->RunAllPending(); } within_callback_ = true; - TestOldCompletionCallback next_job_callback; + TestCompletionCallback next_job_callback; scoped_refptr<TestSocketParams> params(new TestSocketParams()); int rv = handle_->Init("a", params, kDefaultPriority, - &next_job_callback, + next_job_callback.callback(), pool_, BoundNetLog()); switch (next_job_type_) { @@ -1471,17 +1482,12 @@ class RequestSocketCallback : public CallbackRunner< Tuple1<int> > { } } - int WaitForResult() { - return callback_.WaitForResult(); - } - - private: ClientSocketHandle* const handle_; TestClientSocketPool* const pool_; bool within_callback_; TestConnectJobFactory* const test_connect_job_factory_; TestConnectJob::JobType next_job_type_; - TestOldCompletionCallback callback_; + CompletionCallback callback_; }; TEST_F(ClientSocketPoolBaseTest, RequestPendingJobTwice) { @@ -1495,7 +1501,7 @@ TEST_F(ClientSocketPoolBaseTest, RequestPendingJobTwice) { int rv = handle.Init("a", params_, kDefaultPriority, - &callback, + callback.callback(), pool_.get(), BoundNetLog()); ASSERT_EQ(ERR_IO_PENDING, rv); @@ -1513,7 +1519,7 @@ TEST_F(ClientSocketPoolBaseTest, RequestPendingJobThenSynchronous) { int rv = handle.Init("a", params_, kDefaultPriority, - &callback, + callback.callback(), pool_.get(), BoundNetLog()); ASSERT_EQ(ERR_IO_PENDING, rv); @@ -1577,11 +1583,11 @@ TEST_F(ClientSocketPoolBaseTest, CancelActiveRequestThenRequestSocket) { connect_job_factory_->set_job_type(TestConnectJob::kMockPendingJob); ClientSocketHandle handle; - TestOldCompletionCallback callback; + TestCompletionCallback callback; int rv = handle.Init("a", params_, kDefaultPriority, - &callback, + callback.callback(), pool_.get(), BoundNetLog()); EXPECT_EQ(ERR_IO_PENDING, rv); @@ -1592,7 +1598,7 @@ TEST_F(ClientSocketPoolBaseTest, CancelActiveRequestThenRequestSocket) { rv = handle.Init("a", params_, kDefaultPriority, - &callback, + callback.callback(), pool_.get(), BoundNetLog()); EXPECT_EQ(ERR_IO_PENDING, rv); @@ -1643,12 +1649,12 @@ TEST_F(ClientSocketPoolBaseTest, BasicAsynchronous) { connect_job_factory_->set_job_type(TestConnectJob::kMockPendingJob); ClientSocketHandle handle; - TestOldCompletionCallback callback; + TestCompletionCallback callback; CapturingBoundNetLog log(CapturingNetLog::kUnbounded); int rv = handle.Init("a", params_, LOWEST, - &callback, + callback.callback(), pool_.get(), log.bound()); EXPECT_EQ(ERR_IO_PENDING, rv); @@ -1680,7 +1686,7 @@ TEST_F(ClientSocketPoolBaseTest, connect_job_factory_->set_job_type(TestConnectJob::kMockPendingFailingJob); ClientSocketHandle handle; - TestOldCompletionCallback callback; + TestCompletionCallback callback; CapturingBoundNetLog log(CapturingNetLog::kUnbounded); // Set the additional error state members to ensure that they get cleared. handle.set_is_ssl_error(true); @@ -1690,7 +1696,7 @@ TEST_F(ClientSocketPoolBaseTest, EXPECT_EQ(ERR_IO_PENDING, handle.Init("a", params_, kDefaultPriority, - &callback, + callback.callback(), pool_.get(), log.bound())); EXPECT_EQ(LOAD_STATE_CONNECTING, pool_->GetLoadState("a", &handle)); @@ -1718,15 +1724,15 @@ TEST_F(ClientSocketPoolBaseTest, TwoRequestsCancelOne) { connect_job_factory_->set_job_type(TestConnectJob::kMockPendingJob); ClientSocketHandle handle; - TestOldCompletionCallback callback; + TestCompletionCallback callback; ClientSocketHandle handle2; - TestOldCompletionCallback callback2; + TestCompletionCallback callback2; EXPECT_EQ(ERR_IO_PENDING, handle.Init("a", params_, kDefaultPriority, - &callback, + callback.callback(), pool_.get(), BoundNetLog())); CapturingBoundNetLog log2(CapturingNetLog::kUnbounded); @@ -1734,7 +1740,7 @@ TEST_F(ClientSocketPoolBaseTest, TwoRequestsCancelOne) { handle2.Init("a", params_, kDefaultPriority, - &callback2, + callback2.callback(), pool_.get(), BoundNetLog())); @@ -1786,7 +1792,7 @@ TEST_F(ClientSocketPoolBaseTest, ReleaseSockets) { int rv = req1.handle()->Init("a", params_, kDefaultPriority, - &req1, pool_.get(), + req1.callback(), pool_.get(), BoundNetLog()); EXPECT_EQ(ERR_IO_PENDING, rv); EXPECT_EQ(OK, req1.WaitForResult()); @@ -1799,7 +1805,7 @@ TEST_F(ClientSocketPoolBaseTest, ReleaseSockets) { rv = req2.handle()->Init("a", params_, kDefaultPriority, - &req2, + req2.callback(), pool_.get(), BoundNetLog()); EXPECT_EQ(ERR_IO_PENDING, rv); @@ -1807,7 +1813,7 @@ TEST_F(ClientSocketPoolBaseTest, ReleaseSockets) { rv = req3.handle()->Init("a", params_, kDefaultPriority, - &req3, + req3.callback(), pool_.get(), BoundNetLog()); EXPECT_EQ(ERR_IO_PENDING, rv); @@ -1845,7 +1851,7 @@ TEST_F(ClientSocketPoolBaseTest, PendingJobCompletionOrder) { int rv = req1.handle()->Init("a", params_, kDefaultPriority, - &req1, + req1.callback(), pool_.get(), BoundNetLog()); EXPECT_EQ(ERR_IO_PENDING, rv); @@ -1854,7 +1860,7 @@ TEST_F(ClientSocketPoolBaseTest, PendingJobCompletionOrder) { rv = req2.handle()->Init("a", params_, kDefaultPriority, - &req2, + req2.callback(), pool_.get(), BoundNetLog()); EXPECT_EQ(ERR_IO_PENDING, rv); @@ -1866,7 +1872,7 @@ TEST_F(ClientSocketPoolBaseTest, PendingJobCompletionOrder) { rv = req3.handle()->Init("a", params_, kDefaultPriority, - &req3, + req3.callback(), pool_.get(), BoundNetLog()); EXPECT_EQ(ERR_IO_PENDING, rv); @@ -1887,11 +1893,11 @@ TEST_F(ClientSocketPoolBaseTest, LoadState) { TestConnectJob::kMockAdvancingLoadStateJob); ClientSocketHandle handle; - TestOldCompletionCallback callback; + TestCompletionCallback callback; int rv = handle.Init("a", params_, kDefaultPriority, - &callback, + callback.callback(), pool_.get(), BoundNetLog()); EXPECT_EQ(ERR_IO_PENDING, rv); @@ -1900,12 +1906,9 @@ TEST_F(ClientSocketPoolBaseTest, LoadState) { MessageLoop::current()->RunAllPending(); ClientSocketHandle handle2; - TestOldCompletionCallback callback2; - rv = handle2.Init("a", - params_, - kDefaultPriority, - &callback2, pool_.get(), - BoundNetLog()); + TestCompletionCallback callback2; + rv = handle2.Init("a", params_, kDefaultPriority, callback2.callback(), + pool_.get(), BoundNetLog()); EXPECT_EQ(ERR_IO_PENDING, rv); EXPECT_NE(LOAD_STATE_IDLE, handle.GetLoadState()); EXPECT_NE(LOAD_STATE_IDLE, handle2.GetLoadState()); @@ -1916,12 +1919,10 @@ TEST_F(ClientSocketPoolBaseTest, Recoverable) { connect_job_factory_->set_job_type(TestConnectJob::kMockRecoverableJob); ClientSocketHandle handle; - TestOldCompletionCallback callback; - EXPECT_EQ(ERR_PROXY_AUTH_REQUESTED, handle.Init("a", - params_, - kDefaultPriority, - &callback, pool_.get(), - BoundNetLog())); + TestCompletionCallback callback; + EXPECT_EQ(ERR_PROXY_AUTH_REQUESTED, + handle.Init("a", params_, kDefaultPriority, callback.callback(), + pool_.get(), BoundNetLog())); EXPECT_TRUE(handle.is_initialized()); EXPECT_TRUE(handle.socket()); } @@ -1932,12 +1933,12 @@ TEST_F(ClientSocketPoolBaseTest, AsyncRecoverable) { connect_job_factory_->set_job_type( TestConnectJob::kMockPendingRecoverableJob); ClientSocketHandle handle; - TestOldCompletionCallback callback; + TestCompletionCallback callback; EXPECT_EQ(ERR_IO_PENDING, handle.Init("a", params_, kDefaultPriority, - &callback, + callback.callback(), pool_.get(), BoundNetLog())); EXPECT_EQ(LOAD_STATE_CONNECTING, pool_->GetLoadState("a", &handle)); @@ -1952,12 +1953,12 @@ TEST_F(ClientSocketPoolBaseTest, AdditionalErrorStateSynchronous) { TestConnectJob::kMockAdditionalErrorStateJob); ClientSocketHandle handle; - TestOldCompletionCallback callback; + TestCompletionCallback callback; EXPECT_EQ(ERR_CONNECTION_FAILED, handle.Init("a", params_, kDefaultPriority, - &callback, + callback.callback(), pool_.get(), BoundNetLog())); EXPECT_FALSE(handle.is_initialized()); @@ -1972,12 +1973,12 @@ TEST_F(ClientSocketPoolBaseTest, AdditionalErrorStateAsynchronous) { connect_job_factory_->set_job_type( TestConnectJob::kMockPendingAdditionalErrorStateJob); ClientSocketHandle handle; - TestOldCompletionCallback callback; + TestCompletionCallback callback; EXPECT_EQ(ERR_IO_PENDING, handle.Init("a", params_, kDefaultPriority, - &callback, + callback.callback(), pool_.get(), BoundNetLog())); EXPECT_EQ(LOAD_STATE_CONNECTING, pool_->GetLoadState("a", &handle)); @@ -2002,22 +2003,22 @@ TEST_F(ClientSocketPoolBaseTest, DisableCleanupTimer) { // Startup two mock pending connect jobs, which will sit in the MessageLoop. ClientSocketHandle handle; - TestOldCompletionCallback callback; + TestCompletionCallback callback; int rv = handle.Init("a", params_, LOWEST, - &callback, + callback.callback(), pool_.get(), BoundNetLog()); EXPECT_EQ(ERR_IO_PENDING, rv); EXPECT_EQ(LOAD_STATE_CONNECTING, pool_->GetLoadState("a", &handle)); ClientSocketHandle handle2; - TestOldCompletionCallback callback2; + TestCompletionCallback callback2; rv = handle2.Init("a", params_, LOWEST, - &callback2, + callback2.callback(), pool_.get(), BoundNetLog()); EXPECT_EQ(ERR_IO_PENDING, rv); @@ -2044,14 +2045,15 @@ TEST_F(ClientSocketPoolBaseTest, DisableCleanupTimer) { // Request a new socket. This should cleanup the unused and timed out ones. // A new socket will be created rather than reusing the idle one. CapturingBoundNetLog log(CapturingNetLog::kUnbounded); + TestCompletionCallback callback3; rv = handle.Init("a", params_, LOWEST, - &callback, + callback3.callback(), pool_.get(), log.bound()); EXPECT_EQ(ERR_IO_PENDING, rv); - EXPECT_EQ(OK, callback.WaitForResult()); + EXPECT_EQ(OK, callback3.WaitForResult()); EXPECT_FALSE(handle.is_reused()); // Make sure the idle socket is closed @@ -2076,22 +2078,22 @@ TEST_F(ClientSocketPoolBaseTest, CleanupTimedOutIdleSockets) { // Startup two mock pending connect jobs, which will sit in the MessageLoop. ClientSocketHandle handle; - TestOldCompletionCallback callback; + TestCompletionCallback callback; int rv = handle.Init("a", params_, LOWEST, - &callback, + callback.callback(), pool_.get(), BoundNetLog()); EXPECT_EQ(ERR_IO_PENDING, rv); EXPECT_EQ(LOAD_STATE_CONNECTING, pool_->GetLoadState("a", &handle)); ClientSocketHandle handle2; - TestOldCompletionCallback callback2; + TestCompletionCallback callback2; rv = handle2.Init("a", params_, LOWEST, - &callback2, + callback2.callback(), pool_.get(), BoundNetLog()); EXPECT_EQ(ERR_IO_PENDING, rv); @@ -2125,7 +2127,7 @@ TEST_F(ClientSocketPoolBaseTest, CleanupTimedOutIdleSockets) { rv = handle.Init("a", params_, LOWEST, - &callback, + callback.callback(), pool_.get(), log.bound()); EXPECT_EQ(OK, rv); @@ -2150,41 +2152,41 @@ TEST_F(ClientSocketPoolBaseTest, MultipleReleasingDisconnectedSockets) { // Startup 4 connect jobs. Two of them will be pending. ClientSocketHandle handle; - TestOldCompletionCallback callback; + TestCompletionCallback callback; int rv = handle.Init("a", params_, LOWEST, - &callback, + callback.callback(), pool_.get(), BoundNetLog()); EXPECT_EQ(OK, rv); ClientSocketHandle handle2; - TestOldCompletionCallback callback2; + TestCompletionCallback callback2; rv = handle2.Init("a", params_, LOWEST, - &callback2, + callback2.callback(), pool_.get(), BoundNetLog()); EXPECT_EQ(OK, rv); ClientSocketHandle handle3; - TestOldCompletionCallback callback3; + TestCompletionCallback callback3; rv = handle3.Init("a", params_, LOWEST, - &callback3, + callback3.callback(), pool_.get(), BoundNetLog()); EXPECT_EQ(ERR_IO_PENDING, rv); ClientSocketHandle handle4; - TestOldCompletionCallback callback4; + TestCompletionCallback callback4; rv = handle4.Init("a", params_, LOWEST, - &callback4, + callback4.callback(), pool_.get(), BoundNetLog()); EXPECT_EQ(ERR_IO_PENDING, rv); @@ -2216,21 +2218,21 @@ TEST_F(ClientSocketPoolBaseTest, SocketLimitReleasingSockets) { // Max out the socket limit with 2 per group. ClientSocketHandle handle_a[4]; - TestOldCompletionCallback callback_a[4]; + TestCompletionCallback callback_a[4]; ClientSocketHandle handle_b[4]; - TestOldCompletionCallback callback_b[4]; + TestCompletionCallback callback_b[4]; for (int i = 0; i < 2; ++i) { EXPECT_EQ(OK, handle_a[i].Init("a", params_, LOWEST, - &callback_a[i], + callback_a[i].callback(), pool_.get(), BoundNetLog())); EXPECT_EQ(OK, handle_b[i].Init("b", params_, LOWEST, - &callback_b[i], + callback_b[i].callback(), pool_.get(), BoundNetLog())); } @@ -2242,14 +2244,14 @@ TEST_F(ClientSocketPoolBaseTest, SocketLimitReleasingSockets) { handle_a[i].Init("a", params_, LOWEST, - &callback_a[i], + callback_a[i].callback(), pool_.get(), BoundNetLog())); EXPECT_EQ(ERR_IO_PENDING, handle_b[i].Init("b", params_, LOWEST, - &callback_b[i], + callback_b[i].callback(), pool_.get(), BoundNetLog())); } @@ -2310,42 +2312,44 @@ TEST_F(ClientSocketPoolBaseTest, EXPECT_EQ(ClientSocketPoolTest::kIndexOutOfBounds, GetOrderOfRequest(5)); } -class TestReleasingSocketRequest : public CallbackRunner< Tuple1<int> > { +class TestReleasingSocketRequest : public TestCompletionCallbackBase { public: TestReleasingSocketRequest(TestClientSocketPool* pool, int expected_result, bool reset_releasing_handle) : pool_(pool), expected_result_(expected_result), - reset_releasing_handle_(reset_releasing_handle) {} + reset_releasing_handle_(reset_releasing_handle), + ALLOW_THIS_IN_INITIALIZER_LIST(callback_( + base::Bind(&TestReleasingSocketRequest::OnComplete, + base::Unretained(this)))) { + } + + virtual ~TestReleasingSocketRequest() {} ClientSocketHandle* handle() { return &handle_; } - int WaitForResult() { - return callback_.WaitForResult(); - } + const CompletionCallback& callback() const { return callback_; } - virtual void RunWithParams(const Tuple1<int>& params) { - callback_.RunWithParams(params); + private: + void OnComplete(int result) { + SetResult(result); if (reset_releasing_handle_) - handle_.Reset(); + handle_.Reset(); + scoped_refptr<TestSocketParams> con_params(new TestSocketParams()); - EXPECT_EQ(expected_result_, handle2_.Init("a", - con_params, - kDefaultPriority, - &callback2_, - pool_, - BoundNetLog())); + EXPECT_EQ(expected_result_, + handle2_.Init("a", con_params, kDefaultPriority, + callback2_.callback(), pool_, BoundNetLog())); } - private: TestClientSocketPool* const pool_; int expected_result_; bool reset_releasing_handle_; ClientSocketHandle handle_; ClientSocketHandle handle2_; - TestOldCompletionCallback callback_; - TestOldCompletionCallback callback2_; + CompletionCallback callback_; + TestCompletionCallback callback2_; }; @@ -2363,12 +2367,8 @@ TEST_F(ClientSocketPoolBaseTest, AdditionalErrorSocketsDontUseSlot) { TestConnectJob::kMockPendingAdditionalErrorStateJob); TestReleasingSocketRequest req(pool_.get(), OK, false); EXPECT_EQ(ERR_IO_PENDING, - req.handle()->Init("a", - params_, - kDefaultPriority, - &req, - pool_.get(), - BoundNetLog())); + req.handle()->Init("a", params_, kDefaultPriority, req.callback(), + pool_.get(), BoundNetLog())); // The next job should complete synchronously connect_job_factory_->set_job_type(TestConnectJob::kMockJob); @@ -2392,11 +2392,11 @@ TEST_F(ClientSocketPoolBaseTest, CallbackThatReleasesPool) { connect_job_factory_->set_job_type(TestConnectJob::kMockPendingFailingJob); ClientSocketHandle handle; - TestOldCompletionCallback callback; + TestCompletionCallback callback; EXPECT_EQ(ERR_IO_PENDING, handle.Init("a", params_, kDefaultPriority, - &callback, + callback.callback(), pool_.get(), BoundNetLog())); @@ -2411,11 +2411,11 @@ TEST_F(ClientSocketPoolBaseTest, DoNotReuseSocketAfterFlush) { connect_job_factory_->set_job_type(TestConnectJob::kMockPendingJob); ClientSocketHandle handle; - TestOldCompletionCallback callback; + TestCompletionCallback callback; EXPECT_EQ(ERR_IO_PENDING, handle.Init("a", params_, kDefaultPriority, - &callback, + callback.callback(), pool_.get(), BoundNetLog())); EXPECT_EQ(OK, callback.WaitForResult()); @@ -2429,49 +2429,55 @@ TEST_F(ClientSocketPoolBaseTest, DoNotReuseSocketAfterFlush) { EXPECT_EQ(ERR_IO_PENDING, handle.Init("a", params_, kDefaultPriority, - &callback, + callback.callback(), pool_.get(), BoundNetLog())); EXPECT_EQ(OK, callback.WaitForResult()); EXPECT_EQ(ClientSocketHandle::UNUSED, handle.reuse_type()); } -class ConnectWithinCallback : public CallbackRunner< Tuple1<int> > { +class ConnectWithinCallback : public TestCompletionCallbackBase { public: ConnectWithinCallback( const std::string& group_name, const scoped_refptr<TestSocketParams>& params, TestClientSocketPool* pool) - : group_name_(group_name), params_(params), pool_(pool) {} + : group_name_(group_name), + params_(params), + pool_(pool), + ALLOW_THIS_IN_INITIALIZER_LIST(callback_( + base::Bind(&ConnectWithinCallback::OnComplete, + base::Unretained(this)))) { + } + + virtual ~ConnectWithinCallback() {} + + int WaitForNestedResult() { + return nested_callback_.WaitForResult(); + } - ~ConnectWithinCallback() {} + const CompletionCallback& callback() const { return callback_; } - virtual void RunWithParams(const Tuple1<int>& params) { - callback_.RunWithParams(params); + private: + void OnComplete(int result) { + SetResult(result); EXPECT_EQ(ERR_IO_PENDING, handle_.Init(group_name_, params_, kDefaultPriority, - &nested_callback_, + nested_callback_.callback(), pool_, BoundNetLog())); } - int WaitForResult() { - return callback_.WaitForResult(); - } - - int WaitForNestedResult() { - return nested_callback_.WaitForResult(); - } - - private: const std::string group_name_; const scoped_refptr<TestSocketParams> params_; TestClientSocketPool* const pool_; ClientSocketHandle handle_; - TestOldCompletionCallback callback_; - TestOldCompletionCallback nested_callback_; + CompletionCallback callback_; + TestCompletionCallback nested_callback_; + + DISALLOW_COPY_AND_ASSIGN(ConnectWithinCallback); }; TEST_F(ClientSocketPoolBaseTest, AbortAllRequestsOnFlush) { @@ -2485,7 +2491,7 @@ TEST_F(ClientSocketPoolBaseTest, AbortAllRequestsOnFlush) { EXPECT_EQ(ERR_IO_PENDING, handle.Init("a", params_, kDefaultPriority, - &callback, + callback.callback(), pool_.get(), BoundNetLog())); @@ -2508,11 +2514,11 @@ TEST_F(ClientSocketPoolBaseTest, BackupSocketCancelAtMaxSockets) { // timer. connect_job_factory_->set_job_type(TestConnectJob::kMockWaitingJob); ClientSocketHandle handle; - TestOldCompletionCallback callback; + TestCompletionCallback callback; EXPECT_EQ(ERR_IO_PENDING, handle.Init("bar", params_, kDefaultPriority, - &callback, + callback.callback(), pool_.get(), BoundNetLog())); @@ -2520,11 +2526,11 @@ TEST_F(ClientSocketPoolBaseTest, BackupSocketCancelAtMaxSockets) { connect_job_factory_->set_job_type(TestConnectJob::kMockJob); ClientSocketHandle handles[kDefaultMaxSockets]; for (int i = 1; i < kDefaultMaxSockets; ++i) { - TestOldCompletionCallback callback; + TestCompletionCallback callback; EXPECT_EQ(OK, handles[i].Init("bar", params_, kDefaultPriority, - &callback, + callback.callback(), pool_.get(), BoundNetLog())); } @@ -2550,11 +2556,11 @@ TEST_F(ClientSocketPoolBaseTest, CancelBackupSocketAfterCancelingAllRequests) { // timer. connect_job_factory_->set_job_type(TestConnectJob::kMockWaitingJob); ClientSocketHandle handle; - TestOldCompletionCallback callback; + TestCompletionCallback callback; EXPECT_EQ(ERR_IO_PENDING, handle.Init("bar", params_, kDefaultPriority, - &callback, + callback.callback(), pool_.get(), BoundNetLog())); ASSERT_TRUE(pool_->HasGroup("bar")); @@ -2579,20 +2585,20 @@ TEST_F(ClientSocketPoolBaseTest, CancelBackupSocketAfterFinishingAllRequests) { // timer. connect_job_factory_->set_job_type(TestConnectJob::kMockWaitingJob); ClientSocketHandle handle; - TestOldCompletionCallback callback; + TestCompletionCallback callback; EXPECT_EQ(ERR_IO_PENDING, handle.Init("bar", params_, kDefaultPriority, - &callback, + callback.callback(), pool_.get(), BoundNetLog())); connect_job_factory_->set_job_type(TestConnectJob::kMockPendingJob); ClientSocketHandle handle2; - TestOldCompletionCallback callback2; + TestCompletionCallback callback2; EXPECT_EQ(ERR_IO_PENDING, handle2.Init("bar", params_, kDefaultPriority, - &callback2, + callback2.callback(), pool_.get(), BoundNetLog())); ASSERT_TRUE(pool_->HasGroup("bar")); @@ -2617,12 +2623,12 @@ TEST_F(ClientSocketPoolBaseTest, DelayedSocketBindingWaitingForConnect) { connect_job_factory_->set_job_type(TestConnectJob::kMockPendingJob); ClientSocketHandle handle1; - TestOldCompletionCallback callback; + TestCompletionCallback callback; EXPECT_EQ(ERR_IO_PENDING, handle1.Init("a", params_, kDefaultPriority, - &callback, + callback.callback(), pool_.get(), BoundNetLog())); EXPECT_EQ(OK, callback.WaitForResult()); @@ -2638,7 +2644,7 @@ TEST_F(ClientSocketPoolBaseTest, DelayedSocketBindingWaitingForConnect) { handle2.Init("a", params_, kDefaultPriority, - &callback, + callback.callback(), pool_.get(), BoundNetLog())); // No idle sockets, and one connecting job. @@ -2675,12 +2681,12 @@ TEST_F(ClientSocketPoolBaseTest, DelayedSocketBindingAtGroupCapacity) { connect_job_factory_->set_job_type(TestConnectJob::kMockPendingJob); ClientSocketHandle handle1; - TestOldCompletionCallback callback; + TestCompletionCallback callback; EXPECT_EQ(ERR_IO_PENDING, handle1.Init("a", params_, kDefaultPriority, - &callback, + callback.callback(), pool_.get(), BoundNetLog())); EXPECT_EQ(OK, callback.WaitForResult()); @@ -2696,7 +2702,7 @@ TEST_F(ClientSocketPoolBaseTest, DelayedSocketBindingAtGroupCapacity) { handle2.Init("a", params_, kDefaultPriority, - &callback, + callback.callback(), pool_.get(), BoundNetLog())); // No idle sockets, and one connecting job. @@ -2735,12 +2741,12 @@ TEST_F(ClientSocketPoolBaseTest, DelayedSocketBindingAtStall) { connect_job_factory_->set_job_type(TestConnectJob::kMockPendingJob); ClientSocketHandle handle1; - TestOldCompletionCallback callback; + TestCompletionCallback callback; EXPECT_EQ(ERR_IO_PENDING, handle1.Init("a", params_, kDefaultPriority, - &callback, + callback.callback(), pool_.get(), BoundNetLog())); EXPECT_EQ(OK, callback.WaitForResult()); @@ -2756,7 +2762,7 @@ TEST_F(ClientSocketPoolBaseTest, DelayedSocketBindingAtStall) { handle2.Init("a", params_, kDefaultPriority, - &callback, + callback.callback(), pool_.get(), BoundNetLog())); // No idle sockets, and one connecting job. @@ -2798,12 +2804,12 @@ TEST_F(ClientSocketPoolBaseTest, SynchronouslyProcessOnePendingRequest) { connect_job_factory_->set_job_type(TestConnectJob::kMockPendingFailingJob); ClientSocketHandle handle1; - TestOldCompletionCallback callback1; + TestCompletionCallback callback1; EXPECT_EQ(ERR_IO_PENDING, handle1.Init("a", params_, kDefaultPriority, - &callback1, + callback1.callback(), pool_.get(), BoundNetLog())); EXPECT_EQ(1, pool_->NumConnectJobsInGroup("a")); @@ -2812,14 +2818,14 @@ TEST_F(ClientSocketPoolBaseTest, SynchronouslyProcessOnePendingRequest) { // empty. connect_job_factory_->set_job_type(TestConnectJob::kMockFailingJob); ClientSocketHandle handle2; - TestOldCompletionCallback callback2; + TestCompletionCallback callback2; // It'll be ERR_IO_PENDING now, but the TestConnectJob will synchronously fail // when created. EXPECT_EQ(ERR_IO_PENDING, handle2.Init("a", params_, kDefaultPriority, - &callback2, + callback2.callback(), pool_.get(), BoundNetLog())); @@ -2836,28 +2842,28 @@ TEST_F(ClientSocketPoolBaseTest, PreferUsedSocketToUnusedSocket) { connect_job_factory_->set_job_type(TestConnectJob::kMockPendingJob); ClientSocketHandle handle1; - TestOldCompletionCallback callback1; + TestCompletionCallback callback1; EXPECT_EQ(ERR_IO_PENDING, handle1.Init("a", params_, kDefaultPriority, - &callback1, + callback1.callback(), pool_.get(), BoundNetLog())); ClientSocketHandle handle2; - TestOldCompletionCallback callback2; + TestCompletionCallback callback2; EXPECT_EQ(ERR_IO_PENDING, handle2.Init("a", params_, kDefaultPriority, - &callback2, + callback2.callback(), pool_.get(), BoundNetLog())); ClientSocketHandle handle3; - TestOldCompletionCallback callback3; + TestCompletionCallback callback3; EXPECT_EQ(ERR_IO_PENDING, handle3.Init("a", params_, kDefaultPriority, - &callback3, + callback3.callback(), pool_.get(), BoundNetLog())); @@ -2876,19 +2882,19 @@ TEST_F(ClientSocketPoolBaseTest, PreferUsedSocketToUnusedSocket) { EXPECT_EQ(OK, handle1.Init("a", params_, kDefaultPriority, - &callback1, + callback1.callback(), pool_.get(), BoundNetLog())); EXPECT_EQ(OK, handle2.Init("a", params_, kDefaultPriority, - &callback2, + callback2.callback(), pool_.get(), BoundNetLog())); EXPECT_EQ(OK, handle3.Init("a", params_, kDefaultPriority, - &callback3, + callback3.callback(), pool_.get(), BoundNetLog())); @@ -2908,20 +2914,20 @@ TEST_F(ClientSocketPoolBaseTest, RequestSockets) { EXPECT_EQ(0, pool_->IdleSocketCountInGroup("a")); ClientSocketHandle handle1; - TestOldCompletionCallback callback1; + TestCompletionCallback callback1; EXPECT_EQ(ERR_IO_PENDING, handle1.Init("a", params_, kDefaultPriority, - &callback1, + callback1.callback(), pool_.get(), BoundNetLog())); ClientSocketHandle handle2; - TestOldCompletionCallback callback2; + TestCompletionCallback callback2; EXPECT_EQ(ERR_IO_PENDING, handle2.Init("a", params_, kDefaultPriority, - &callback2, + callback2.callback(), pool_.get(), BoundNetLog())); @@ -2942,11 +2948,11 @@ TEST_F(ClientSocketPoolBaseTest, RequestSocketsWhenAlreadyHaveAConnectJob) { connect_job_factory_->set_job_type(TestConnectJob::kMockPendingJob); ClientSocketHandle handle1; - TestOldCompletionCallback callback1; + TestCompletionCallback callback1; EXPECT_EQ(ERR_IO_PENDING, handle1.Init("a", params_, kDefaultPriority, - &callback1, + callback1.callback(), pool_.get(), BoundNetLog())); @@ -2960,11 +2966,11 @@ TEST_F(ClientSocketPoolBaseTest, RequestSocketsWhenAlreadyHaveAConnectJob) { EXPECT_EQ(0, pool_->IdleSocketCountInGroup("a")); ClientSocketHandle handle2; - TestOldCompletionCallback callback2; + TestCompletionCallback callback2; EXPECT_EQ(ERR_IO_PENDING, handle2.Init("a", params_, kDefaultPriority, - &callback2, + callback2.callback(), pool_.get(), BoundNetLog())); @@ -2986,29 +2992,29 @@ TEST_F(ClientSocketPoolBaseTest, connect_job_factory_->set_job_type(TestConnectJob::kMockPendingJob); ClientSocketHandle handle1; - TestOldCompletionCallback callback1; + TestCompletionCallback callback1; EXPECT_EQ(ERR_IO_PENDING, handle1.Init("a", params_, kDefaultPriority, - &callback1, + callback1.callback(), pool_.get(), BoundNetLog())); ClientSocketHandle handle2; - TestOldCompletionCallback callback2; + TestCompletionCallback callback2; EXPECT_EQ(ERR_IO_PENDING, handle2.Init("a", params_, kDefaultPriority, - &callback2, + callback2.callback(), pool_.get(), BoundNetLog())); ClientSocketHandle handle3; - TestOldCompletionCallback callback3; + TestCompletionCallback callback3; EXPECT_EQ(ERR_IO_PENDING, handle3.Init("a", params_, kDefaultPriority, - &callback3, + callback3.callback(), pool_.get(), BoundNetLog())); @@ -3080,11 +3086,11 @@ TEST_F(ClientSocketPoolBaseTest, RequestSocketsCountIdleSockets) { connect_job_factory_->set_job_type(TestConnectJob::kMockPendingJob); ClientSocketHandle handle1; - TestOldCompletionCallback callback1; + TestCompletionCallback callback1; EXPECT_EQ(ERR_IO_PENDING, handle1.Init("a", params_, kDefaultPriority, - &callback1, + callback1.callback(), pool_.get(), BoundNetLog())); ASSERT_EQ(OK, callback1.WaitForResult()); @@ -3105,11 +3111,11 @@ TEST_F(ClientSocketPoolBaseTest, RequestSocketsCountActiveSockets) { connect_job_factory_->set_job_type(TestConnectJob::kMockPendingJob); ClientSocketHandle handle1; - TestOldCompletionCallback callback1; + TestCompletionCallback callback1; EXPECT_EQ(ERR_IO_PENDING, handle1.Init("a", params_, kDefaultPriority, - &callback1, + callback1.callback(), pool_.get(), BoundNetLog())); ASSERT_EQ(OK, callback1.WaitForResult()); @@ -3176,21 +3182,21 @@ TEST_F(ClientSocketPoolBaseTest, RequestSocketsMultipleTimesDoesNothing) { EXPECT_EQ(0, pool_->IdleSocketCountInGroup("a")); ClientSocketHandle handle1; - TestOldCompletionCallback callback1; + TestCompletionCallback callback1; EXPECT_EQ(ERR_IO_PENDING, handle1.Init("a", params_, kDefaultPriority, - &callback1, + callback1.callback(), pool_.get(), BoundNetLog())); ASSERT_EQ(OK, callback1.WaitForResult()); ClientSocketHandle handle2; - TestOldCompletionCallback callback2; + TestCompletionCallback callback2; int rv = handle2.Init("a", params_, kDefaultPriority, - &callback2, + callback2.callback(), pool_.get(), BoundNetLog()); if (rv != OK) { @@ -3242,11 +3248,11 @@ TEST_F(ClientSocketPoolBaseTest, PreconnectJobsTakenByNormalRequests) { EXPECT_EQ(0, pool_->IdleSocketCountInGroup("a")); ClientSocketHandle handle1; - TestOldCompletionCallback callback1; + TestCompletionCallback callback1; EXPECT_EQ(ERR_IO_PENDING, handle1.Init("a", params_, kDefaultPriority, - &callback1, + callback1.callback(), pool_.get(), BoundNetLog())); @@ -3272,11 +3278,11 @@ TEST_F(ClientSocketPoolBaseTest, PreconnectClosesIdleSocketRemovesGroup) { // Set up one idle socket in "a". ClientSocketHandle handle1; - TestOldCompletionCallback callback1; + TestCompletionCallback callback1; EXPECT_EQ(ERR_IO_PENDING, handle1.Init("a", params_, kDefaultPriority, - &callback1, + callback1.callback(), pool_.get(), BoundNetLog())); @@ -3286,17 +3292,17 @@ TEST_F(ClientSocketPoolBaseTest, PreconnectClosesIdleSocketRemovesGroup) { // Set up two active sockets in "b". ClientSocketHandle handle2; - TestOldCompletionCallback callback2; + TestCompletionCallback callback2; EXPECT_EQ(ERR_IO_PENDING, handle1.Init("b", params_, kDefaultPriority, - &callback1, + callback1.callback(), pool_.get(), BoundNetLog())); EXPECT_EQ(ERR_IO_PENDING, handle2.Init("b", params_, kDefaultPriority, - &callback2, + callback2.callback(), pool_.get(), BoundNetLog())); @@ -3371,11 +3377,11 @@ TEST_F(ClientSocketPoolBaseTest, PreconnectWithBackupJob) { // Make the backup job be a pending job, so it completes normally. connect_job_factory_->set_job_type(TestConnectJob::kMockPendingJob); ClientSocketHandle handle; - TestOldCompletionCallback callback; + TestCompletionCallback callback; EXPECT_EQ(ERR_IO_PENDING, handle.Init("a", params_, kDefaultPriority, - &callback, + callback.callback(), pool_.get(), BoundNetLog())); // Timer has started, but the backup connect job shouldn't be created yet. @@ -3406,14 +3412,14 @@ class MockLayeredPool : public LayeredPool { } int RequestSocket(TestClientSocketPool* pool) { - return handle_.Init(group_name_, params_, kDefaultPriority, &callback_, - pool, BoundNetLog()); + return handle_.Init(group_name_, params_, kDefaultPriority, + callback_.callback(), pool, BoundNetLog()); } int RequestSocketWithoutLimits(TestClientSocketPool* pool) { params_->set_ignore_limits(true); - return handle_.Init(group_name_, params_, kDefaultPriority, &callback_, - pool, BoundNetLog()); + return handle_.Init(group_name_, params_, kDefaultPriority, + callback_.callback(), pool, BoundNetLog()); } bool ReleaseOneConnection() { @@ -3431,7 +3437,7 @@ class MockLayeredPool : public LayeredPool { TestClientSocketPool* const pool_; scoped_refptr<TestSocketParams> params_; ClientSocketHandle handle_; - TestOldCompletionCallback callback_; + TestCompletionCallback callback_; const std::string group_name_; }; @@ -3468,11 +3474,11 @@ TEST_F(ClientSocketPoolBaseTest, CloseIdleSocketsHeldByLayeredPoolWhenNeeded) { .WillOnce(Invoke(&mock_layered_pool, &MockLayeredPool::ReleaseOneConnection)); ClientSocketHandle handle; - TestOldCompletionCallback callback; + TestCompletionCallback callback; EXPECT_EQ(OK, handle.Init("a", params_, kDefaultPriority, - &callback, + callback.callback(), pool_.get(), BoundNetLog())); } @@ -3493,11 +3499,11 @@ TEST_F(ClientSocketPoolBaseTest, .WillRepeatedly(Invoke(&mock_layered_pool2, &MockLayeredPool::ReleaseOneConnection)); ClientSocketHandle handle; - TestOldCompletionCallback callback; + TestCompletionCallback callback; EXPECT_EQ(OK, handle.Init("a", params_, kDefaultPriority, - &callback, + callback.callback(), pool_.get(), BoundNetLog())); } diff --git a/net/socket/client_socket_pool_manager.cc b/net/socket/client_socket_pool_manager.cc index 54ad7d8..7098864 100644 --- a/net/socket/client_socket_pool_manager.cc +++ b/net/socket/client_socket_pool_manager.cc @@ -52,7 +52,7 @@ int InitSocketPoolHelper(const GURL& request_url, const BoundNetLog& net_log, int num_preconnect_streams, ClientSocketHandle* socket_handle, - OldCompletionCallback* callback) { + const CompletionCallback& callback) { scoped_refptr<TransportSocketParams> tcp_params; scoped_refptr<HttpProxySocketParams> http_proxy_params; scoped_refptr<SOCKSSocketParams> socks_params; @@ -289,23 +289,13 @@ int InitSocketHandleForHttpRequest( const SSLConfig& ssl_config_for_proxy, const BoundNetLog& net_log, ClientSocketHandle* socket_handle, - OldCompletionCallback* callback) { + const CompletionCallback& callback) { DCHECK(socket_handle); - return InitSocketPoolHelper(request_url, - request_extra_headers, - request_load_flags, - request_priority, - session, - proxy_info, - force_spdy_over_ssl, - want_spdy_over_npn, - ssl_config_for_origin, - ssl_config_for_proxy, - false, - net_log, - 0, - socket_handle, - callback); + return InitSocketPoolHelper( + request_url, request_extra_headers, request_load_flags, request_priority, + session, proxy_info, force_spdy_over_ssl, want_spdy_over_npn, + ssl_config_for_origin, ssl_config_for_proxy, false, net_log, 0, + socket_handle, callback); } int InitSocketHandleForRawConnect( @@ -316,7 +306,7 @@ int InitSocketHandleForRawConnect( const SSLConfig& ssl_config_for_proxy, const BoundNetLog& net_log, ClientSocketHandle* socket_handle, - OldCompletionCallback* callback) { + const CompletionCallback& callback) { DCHECK(socket_handle); // Synthesize an HttpRequestInfo. GURL request_url = GURL("http://" + host_port_pair.ToString()); @@ -324,21 +314,10 @@ int InitSocketHandleForRawConnect( int request_load_flags = 0; RequestPriority request_priority = MEDIUM; - return InitSocketPoolHelper(request_url, - request_extra_headers, - request_load_flags, - request_priority, - session, - proxy_info, - false, - false, - ssl_config_for_origin, - ssl_config_for_proxy, - true, - net_log, - 0, - socket_handle, - callback); + return InitSocketPoolHelper( + request_url, request_extra_headers, request_load_flags, request_priority, + session, proxy_info, false, false, ssl_config_for_origin, + ssl_config_for_proxy, true, net_log, 0, socket_handle, callback); } int PreconnectSocketsForHttpRequest( @@ -354,21 +333,11 @@ int PreconnectSocketsForHttpRequest( const SSLConfig& ssl_config_for_proxy, const BoundNetLog& net_log, int num_preconnect_streams) { - return InitSocketPoolHelper(request_url, - request_extra_headers, - request_load_flags, - request_priority, - session, - proxy_info, - force_spdy_over_ssl, - want_spdy_over_npn, - ssl_config_for_origin, - ssl_config_for_proxy, - false, - net_log, - num_preconnect_streams, - NULL, - NULL); + return InitSocketPoolHelper( + request_url, request_extra_headers, request_load_flags, request_priority, + session, proxy_info, force_spdy_over_ssl, want_spdy_over_npn, + ssl_config_for_origin, ssl_config_for_proxy, false, net_log, + num_preconnect_streams, NULL, CompletionCallback()); } } // namespace net diff --git a/net/socket/client_socket_pool_manager.h b/net/socket/client_socket_pool_manager.h index 2c51761..7c1f865 100644 --- a/net/socket/client_socket_pool_manager.h +++ b/net/socket/client_socket_pool_manager.h @@ -88,7 +88,7 @@ int InitSocketHandleForHttpRequest( const SSLConfig& ssl_config_for_proxy, const BoundNetLog& net_log, ClientSocketHandle* socket_handle, - OldCompletionCallback* callback); + const CompletionCallback& callback); // A helper method that uses the passed in proxy information to initialize a // ClientSocketHandle with the relevant socket pool. Use this method for @@ -102,7 +102,7 @@ NET_EXPORT int InitSocketHandleForRawConnect( const SSLConfig& ssl_config_for_proxy, const BoundNetLog& net_log, ClientSocketHandle* socket_handle, - OldCompletionCallback* callback); + const CompletionCallback& callback); // Similar to InitSocketHandleForHttpRequest except that it initiates the // desired number of preconnect streams from the relevant socket pool. diff --git a/net/socket/deterministic_socket_data_unittest.cc b/net/socket/deterministic_socket_data_unittest.cc index 8740c8d..ee0539e 100644 --- a/net/socket/deterministic_socket_data_unittest.cc +++ b/net/socket/deterministic_socket_data_unittest.cc @@ -93,7 +93,7 @@ void DeterministicSocketDataTest::Initialize(MockRead* reads, connection_.Init(endpoint_.ToString(), tcp_params_, LOWEST, - NULL, + CompletionCallback(), reinterpret_cast<TransportClientSocketPool*>(&socket_pool_), BoundNetLog())); sock_ = connection_.socket(); diff --git a/net/socket/socket_test_util.cc b/net/socket/socket_test_util.cc index ff8bc50..9e437aa 100644 --- a/net/socket/socket_test_util.cc +++ b/net/socket/socket_test_util.cc @@ -1344,10 +1344,11 @@ void MockUDPClientSocket::RunCallback(const CompletionCallback& callback, } TestSocketRequest::TestSocketRequest( - std::vector<TestSocketRequest*>* request_order, - size_t* completion_count) + std::vector<TestSocketRequest*>* request_order, size_t* completion_count) : request_order_(request_order), - completion_count_(completion_count) { + completion_count_(completion_count), + ALLOW_THIS_IN_INITIALIZER_LIST(callback_( + base::Bind(&TestSocketRequest::OnComplete, base::Unretained(this)))) { DCHECK(request_order); DCHECK(completion_count); } @@ -1355,12 +1356,8 @@ TestSocketRequest::TestSocketRequest( TestSocketRequest::~TestSocketRequest() { } -int TestSocketRequest::WaitForResult() { - return callback_.WaitForResult(); -} - -void TestSocketRequest::RunWithParams(const Tuple1<int>& params) { - callback_.RunWithParams(params); +void TestSocketRequest::OnComplete(int result) { + SetResult(result); (*completion_count_)++; request_order_->push_back(this); } diff --git a/net/socket/socket_test_util.h b/net/socket/socket_test_util.h index e4909c5..adb8ea9 100644 --- a/net/socket/socket_test_util.h +++ b/net/socket/socket_test_util.h @@ -832,23 +832,25 @@ class MockUDPClientSocket : public DatagramClientSocket, DISALLOW_COPY_AND_ASSIGN(MockUDPClientSocket); }; -class TestSocketRequest : public CallbackRunner< Tuple1<int> > { +class TestSocketRequest : public TestCompletionCallbackBase { public: - TestSocketRequest( - std::vector<TestSocketRequest*>* request_order, - size_t* completion_count); + TestSocketRequest(std::vector<TestSocketRequest*>* request_order, + size_t* completion_count); virtual ~TestSocketRequest(); ClientSocketHandle* handle() { return &handle_; } - int WaitForResult(); - virtual void RunWithParams(const Tuple1<int>& params) OVERRIDE; + const net::CompletionCallback& callback() const { return callback_; } private: + void OnComplete(int result); + ClientSocketHandle handle_; std::vector<TestSocketRequest*>* request_order_; size_t* completion_count_; - TestOldCompletionCallback callback_; + CompletionCallback callback_; + + DISALLOW_COPY_AND_ASSIGN(TestSocketRequest); }; class ClientSocketPoolTest { @@ -876,7 +878,7 @@ class ClientSocketPoolTest { &completion_count_); requests_.push_back(request); int rv = request->handle()->Init( - group_name, socket_params, priority, request, + group_name, socket_params, priority, request->callback(), socket_pool, BoundNetLog()); if (rv != ERR_IO_PENDING) request_order_.push_back(request); diff --git a/net/socket/socks_client_socket_pool.cc b/net/socket/socks_client_socket_pool.cc index 2602a3e..ec47341 100644 --- a/net/socket/socks_client_socket_pool.cc +++ b/net/socket/socks_client_socket_pool.cc @@ -4,6 +4,8 @@ #include "net/socket/socks_client_socket_pool.h" +#include "base/bind.h" +#include "base/bind_helpers.h" #include "base/time.h" #include "base/values.h" #include "net/base/net_errors.h" @@ -50,8 +52,8 @@ SOCKSConnectJob::SOCKSConnectJob( socks_params_(socks_params), transport_pool_(transport_pool), resolver_(host_resolver), - ALLOW_THIS_IN_INITIALIZER_LIST( - callback_old_(this, &SOCKSConnectJob::OnIOComplete)) { + ALLOW_THIS_IN_INITIALIZER_LIST(callback_( + base::Bind(&SOCKSConnectJob::OnIOComplete, base::Unretained(this)))) { } SOCKSConnectJob::~SOCKSConnectJob() { @@ -115,12 +117,10 @@ int SOCKSConnectJob::DoLoop(int result) { int SOCKSConnectJob::DoTransportConnect() { next_state_ = STATE_TRANSPORT_CONNECT_COMPLETE; transport_socket_handle_.reset(new ClientSocketHandle()); - return transport_socket_handle_->Init(group_name(), - socks_params_->transport_params(), - socks_params_->destination().priority(), - &callback_old_, - transport_pool_, - net_log()); + return transport_socket_handle_->Init( + group_name(), socks_params_->transport_params(), + socks_params_->destination().priority(), callback_, transport_pool_, + net_log()); } int SOCKSConnectJob::DoTransportConnectComplete(int result) { diff --git a/net/socket/socks_client_socket_pool.h b/net/socket/socks_client_socket_pool.h index 422b772..cacf7af 100644 --- a/net/socket/socks_client_socket_pool.h +++ b/net/socket/socks_client_socket_pool.h @@ -98,7 +98,7 @@ class SOCKSConnectJob : public ConnectJob { HostResolver* const resolver_; State next_state_; - OldCompletionCallbackImpl<SOCKSConnectJob> callback_old_; + CompletionCallback callback_; scoped_ptr<ClientSocketHandle> transport_socket_handle_; scoped_ptr<StreamSocket> socket_; diff --git a/net/socket/socks_client_socket_pool_unittest.cc b/net/socket/socks_client_socket_pool_unittest.cc index 148cb5b..28706ea 100644 --- a/net/socket/socks_client_socket_pool_unittest.cc +++ b/net/socket/socks_client_socket_pool_unittest.cc @@ -101,8 +101,8 @@ TEST_F(SOCKSClientSocketPoolTest, Simple) { transport_client_socket_factory_.AddSocketDataProvider(data.data_provider()); ClientSocketHandle handle; - int rv = handle.Init("a", ignored_socket_params_, LOW, NULL, &pool_, - BoundNetLog()); + int rv = handle.Init("a", ignored_socket_params_, LOW, CompletionCallback(), + &pool_, BoundNetLog()); EXPECT_EQ(OK, rv); EXPECT_TRUE(handle.is_initialized()); EXPECT_TRUE(handle.socket()); @@ -112,10 +112,10 @@ TEST_F(SOCKSClientSocketPoolTest, Async) { SOCKS5MockData data(true); transport_client_socket_factory_.AddSocketDataProvider(data.data_provider()); - TestOldCompletionCallback callback; + TestCompletionCallback callback; ClientSocketHandle handle; - int rv = handle.Init("a", ignored_socket_params_, LOW, &callback, &pool_, - BoundNetLog()); + int rv = handle.Init("a", ignored_socket_params_, LOW, callback.callback(), + &pool_, BoundNetLog()); EXPECT_EQ(ERR_IO_PENDING, rv); EXPECT_FALSE(handle.is_initialized()); EXPECT_FALSE(handle.socket()); @@ -131,8 +131,8 @@ TEST_F(SOCKSClientSocketPoolTest, TransportConnectError) { transport_client_socket_factory_.AddSocketDataProvider(socket_data.get()); ClientSocketHandle handle; - int rv = handle.Init("a", ignored_socket_params_, LOW, NULL, &pool_, - BoundNetLog()); + int rv = handle.Init("a", ignored_socket_params_, LOW, CompletionCallback(), + &pool_, BoundNetLog()); EXPECT_EQ(ERR_PROXY_CONNECTION_FAILED, rv); EXPECT_FALSE(handle.is_initialized()); EXPECT_FALSE(handle.socket()); @@ -143,10 +143,10 @@ TEST_F(SOCKSClientSocketPoolTest, AsyncTransportConnectError) { socket_data->set_connect_data(MockConnect(true, ERR_CONNECTION_REFUSED)); transport_client_socket_factory_.AddSocketDataProvider(socket_data.get()); - TestOldCompletionCallback callback; + TestCompletionCallback callback; ClientSocketHandle handle; - int rv = handle.Init("a", ignored_socket_params_, LOW, &callback, &pool_, - BoundNetLog()); + int rv = handle.Init("a", ignored_socket_params_, LOW, callback.callback(), + &pool_, BoundNetLog()); EXPECT_EQ(ERR_IO_PENDING, rv); EXPECT_FALSE(handle.is_initialized()); EXPECT_FALSE(handle.socket()); @@ -167,8 +167,8 @@ TEST_F(SOCKSClientSocketPoolTest, SOCKSConnectError) { ClientSocketHandle handle; EXPECT_EQ(0, transport_socket_pool_.release_count()); - int rv = handle.Init("a", ignored_socket_params_, LOW, NULL, &pool_, - BoundNetLog()); + int rv = handle.Init("a", ignored_socket_params_, LOW, CompletionCallback(), + &pool_, BoundNetLog()); EXPECT_EQ(ERR_SOCKS_CONNECTION_FAILED, rv); EXPECT_FALSE(handle.is_initialized()); EXPECT_FALSE(handle.socket()); @@ -184,11 +184,11 @@ TEST_F(SOCKSClientSocketPoolTest, AsyncSOCKSConnectError) { socket_data->set_connect_data(MockConnect(false, 0)); transport_client_socket_factory_.AddSocketDataProvider(socket_data.get()); - TestOldCompletionCallback callback; + TestCompletionCallback callback; ClientSocketHandle handle; EXPECT_EQ(0, transport_socket_pool_.release_count()); - int rv = handle.Init("a", ignored_socket_params_, LOW, &callback, &pool_, - BoundNetLog()); + int rv = handle.Init("a", ignored_socket_params_, LOW, callback.callback(), + &pool_, BoundNetLog()); EXPECT_EQ(ERR_IO_PENDING, rv); EXPECT_FALSE(handle.is_initialized()); EXPECT_FALSE(handle.socket()); diff --git a/net/socket/ssl_client_socket_pool.cc b/net/socket/ssl_client_socket_pool.cc index 744eb38..fb91d07 100644 --- a/net/socket/ssl_client_socket_pool.cc +++ b/net/socket/ssl_client_socket_pool.cc @@ -4,6 +4,8 @@ #include "net/socket/ssl_client_socket_pool.h" +#include "base/bind.h" +#include "base/bind_helpers.h" #include "base/metrics/field_trial.h" #include "base/metrics/histogram.h" #include "base/values.h" @@ -95,9 +97,7 @@ SSLConnectJob::SSLConnectJob(const std::string& group_name, context_(context), ALLOW_THIS_IN_INITIALIZER_LIST( callback_(base::Bind(&SSLConnectJob::OnIOComplete, - base::Unretained(this)))), - ALLOW_THIS_IN_INITIALIZER_LIST( - callback_old_(this, &SSLConnectJob::OnIOComplete)) {} + base::Unretained(this)))) {} SSLConnectJob::~SSLConnectJob() {} @@ -207,10 +207,9 @@ int SSLConnectJob::DoTransportConnect() { scoped_refptr<TransportSocketParams> transport_params = params_->transport_params(); return transport_socket_handle_->Init( - group_name(), - transport_params, - transport_params->destination().priority(), - &callback_old_, transport_pool_, net_log()); + group_name(), transport_params, + transport_params->destination().priority(), callback_, transport_pool_, + net_log()); } int SSLConnectJob::DoTransportConnectComplete(int result) { @@ -225,9 +224,9 @@ int SSLConnectJob::DoSOCKSConnect() { next_state_ = STATE_SOCKS_CONNECT_COMPLETE; transport_socket_handle_.reset(new ClientSocketHandle()); scoped_refptr<SOCKSSocketParams> socks_params = params_->socks_params(); - return transport_socket_handle_->Init(group_name(), socks_params, - socks_params->destination().priority(), - &callback_old_, socks_pool_, net_log()); + return transport_socket_handle_->Init( + group_name(), socks_params, socks_params->destination().priority(), + callback_, socks_pool_, net_log()); } int SSLConnectJob::DoSOCKSConnectComplete(int result) { @@ -246,8 +245,8 @@ int SSLConnectJob::DoTunnelConnect() { params_->http_proxy_params(); return transport_socket_handle_->Init( group_name(), http_proxy_params, - http_proxy_params->destination().priority(), &callback_old_, - http_proxy_pool_, net_log()); + http_proxy_params->destination().priority(), callback_, http_proxy_pool_, + net_log()); } int SSLConnectJob::DoTunnelConnectComplete(int result) { diff --git a/net/socket/ssl_client_socket_pool.h b/net/socket/ssl_client_socket_pool.h index 6b4de78..907c6e5 100644 --- a/net/socket/ssl_client_socket_pool.h +++ b/net/socket/ssl_client_socket_pool.h @@ -153,7 +153,6 @@ class SSLConnectJob : public ConnectJob { State next_state_; CompletionCallback callback_; - OldCompletionCallbackImpl<SSLConnectJob> callback_old_; scoped_ptr<ClientSocketHandle> transport_socket_handle_; scoped_ptr<SSLClientSocket> ssl_socket_; scoped_ptr<SSLHostInfo> ssl_host_info_; diff --git a/net/socket/ssl_client_socket_pool_unittest.cc b/net/socket/ssl_client_socket_pool_unittest.cc index 05dd93d..673fa22 100644 --- a/net/socket/ssl_client_socket_pool_unittest.cc +++ b/net/socket/ssl_client_socket_pool_unittest.cc @@ -183,7 +183,8 @@ TEST_F(SSLClientSocketPoolTest, TCPFail) { false); ClientSocketHandle handle; - int rv = handle.Init("a", params, MEDIUM, NULL, pool_.get(), BoundNetLog()); + int rv = handle.Init("a", params, MEDIUM, CompletionCallback(), pool_.get(), + BoundNetLog()); EXPECT_EQ(ERR_CONNECTION_FAILED, rv); EXPECT_FALSE(handle.is_initialized()); EXPECT_FALSE(handle.socket()); @@ -200,9 +201,9 @@ TEST_F(SSLClientSocketPoolTest, TCPFailAsync) { false); ClientSocketHandle handle; - TestOldCompletionCallback callback; + TestCompletionCallback callback; int rv = handle.Init( - "a", params, MEDIUM, &callback, pool_.get(), BoundNetLog()); + "a", params, MEDIUM, callback.callback(), pool_.get(), BoundNetLog()); EXPECT_EQ(ERR_IO_PENDING, rv); EXPECT_FALSE(handle.is_initialized()); EXPECT_FALSE(handle.socket()); @@ -225,9 +226,9 @@ TEST_F(SSLClientSocketPoolTest, BasicDirect) { false); ClientSocketHandle handle; - TestOldCompletionCallback callback; + TestCompletionCallback callback; int rv = handle.Init( - "a", params, MEDIUM, &callback, pool_.get(), BoundNetLog()); + "a", params, MEDIUM, callback.callback(), pool_.get(), BoundNetLog()); EXPECT_EQ(OK, rv); EXPECT_TRUE(handle.is_initialized()); EXPECT_TRUE(handle.socket()); @@ -244,9 +245,9 @@ TEST_F(SSLClientSocketPoolTest, BasicDirectAsync) { false); ClientSocketHandle handle; - TestOldCompletionCallback callback; + TestCompletionCallback callback; int rv = handle.Init( - "a", params, MEDIUM, &callback, pool_.get(), BoundNetLog()); + "a", params, MEDIUM, callback.callback(), pool_.get(), BoundNetLog()); EXPECT_EQ(ERR_IO_PENDING, rv); EXPECT_FALSE(handle.is_initialized()); EXPECT_FALSE(handle.socket()); @@ -267,9 +268,9 @@ TEST_F(SSLClientSocketPoolTest, DirectCertError) { false); ClientSocketHandle handle; - TestOldCompletionCallback callback; + TestCompletionCallback callback; int rv = handle.Init( - "a", params, MEDIUM, &callback, pool_.get(), BoundNetLog()); + "a", params, MEDIUM, callback.callback(), pool_.get(), BoundNetLog()); EXPECT_EQ(ERR_IO_PENDING, rv); EXPECT_FALSE(handle.is_initialized()); EXPECT_FALSE(handle.socket()); @@ -290,9 +291,9 @@ TEST_F(SSLClientSocketPoolTest, DirectSSLError) { false); ClientSocketHandle handle; - TestOldCompletionCallback callback; + TestCompletionCallback callback; int rv = handle.Init( - "a", params, MEDIUM, &callback, pool_.get(), BoundNetLog()); + "a", params, MEDIUM, callback.callback(), pool_.get(), BoundNetLog()); EXPECT_EQ(ERR_IO_PENDING, rv); EXPECT_FALSE(handle.is_initialized()); EXPECT_FALSE(handle.socket()); @@ -316,9 +317,9 @@ TEST_F(SSLClientSocketPoolTest, DirectWithNPN) { false); ClientSocketHandle handle; - TestOldCompletionCallback callback; + TestCompletionCallback callback; int rv = handle.Init( - "a", params, MEDIUM, &callback, pool_.get(), BoundNetLog()); + "a", params, MEDIUM, callback.callback(), pool_.get(), BoundNetLog()); EXPECT_EQ(ERR_IO_PENDING, rv); EXPECT_FALSE(handle.is_initialized()); EXPECT_FALSE(handle.socket()); @@ -343,9 +344,9 @@ TEST_F(SSLClientSocketPoolTest, DirectNoSPDY) { true); ClientSocketHandle handle; - TestOldCompletionCallback callback; + TestCompletionCallback callback; int rv = handle.Init( - "a", params, MEDIUM, &callback, pool_.get(), BoundNetLog()); + "a", params, MEDIUM, callback.callback(), pool_.get(), BoundNetLog()); EXPECT_EQ(ERR_IO_PENDING, rv); EXPECT_FALSE(handle.is_initialized()); EXPECT_FALSE(handle.socket()); @@ -369,9 +370,9 @@ TEST_F(SSLClientSocketPoolTest, DirectGotSPDY) { true); ClientSocketHandle handle; - TestOldCompletionCallback callback; + TestCompletionCallback callback; int rv = handle.Init( - "a", params, MEDIUM, &callback, pool_.get(), BoundNetLog()); + "a", params, MEDIUM, callback.callback(), pool_.get(), BoundNetLog()); EXPECT_EQ(ERR_IO_PENDING, rv); EXPECT_FALSE(handle.is_initialized()); EXPECT_FALSE(handle.socket()); @@ -402,9 +403,9 @@ TEST_F(SSLClientSocketPoolTest, DirectGotBonusSPDY) { true); ClientSocketHandle handle; - TestOldCompletionCallback callback; + TestCompletionCallback callback; int rv = handle.Init( - "a", params, MEDIUM, &callback, pool_.get(), BoundNetLog()); + "a", params, MEDIUM, callback.callback(), pool_.get(), BoundNetLog()); EXPECT_EQ(ERR_IO_PENDING, rv); EXPECT_FALSE(handle.is_initialized()); EXPECT_FALSE(handle.socket()); @@ -432,9 +433,9 @@ TEST_F(SSLClientSocketPoolTest, SOCKSFail) { false); ClientSocketHandle handle; - TestOldCompletionCallback callback; + TestCompletionCallback callback; int rv = handle.Init( - "a", params, MEDIUM, &callback, pool_.get(), BoundNetLog()); + "a", params, MEDIUM, callback.callback(), pool_.get(), BoundNetLog()); EXPECT_EQ(ERR_CONNECTION_FAILED, rv); EXPECT_FALSE(handle.is_initialized()); EXPECT_FALSE(handle.socket()); @@ -451,9 +452,9 @@ TEST_F(SSLClientSocketPoolTest, SOCKSFailAsync) { false); ClientSocketHandle handle; - TestOldCompletionCallback callback; + TestCompletionCallback callback; int rv = handle.Init( - "a", params, MEDIUM, &callback, pool_.get(), BoundNetLog()); + "a", params, MEDIUM, callback.callback(), pool_.get(), BoundNetLog()); EXPECT_EQ(ERR_IO_PENDING, rv); EXPECT_FALSE(handle.is_initialized()); EXPECT_FALSE(handle.socket()); @@ -476,9 +477,9 @@ TEST_F(SSLClientSocketPoolTest, SOCKSBasic) { false); ClientSocketHandle handle; - TestOldCompletionCallback callback; + TestCompletionCallback callback; int rv = handle.Init( - "a", params, MEDIUM, &callback, pool_.get(), BoundNetLog()); + "a", params, MEDIUM, callback.callback(), pool_.get(), BoundNetLog()); EXPECT_EQ(OK, rv); EXPECT_TRUE(handle.is_initialized()); EXPECT_TRUE(handle.socket()); @@ -495,9 +496,9 @@ TEST_F(SSLClientSocketPoolTest, SOCKSBasicAsync) { false); ClientSocketHandle handle; - TestOldCompletionCallback callback; + TestCompletionCallback callback; int rv = handle.Init( - "a", params, MEDIUM, &callback, pool_.get(), BoundNetLog()); + "a", params, MEDIUM, callback.callback(), pool_.get(), BoundNetLog()); EXPECT_EQ(ERR_IO_PENDING, rv); EXPECT_FALSE(handle.is_initialized()); EXPECT_FALSE(handle.socket()); @@ -517,9 +518,9 @@ TEST_F(SSLClientSocketPoolTest, HttpProxyFail) { false); ClientSocketHandle handle; - TestOldCompletionCallback callback; + TestCompletionCallback callback; int rv = handle.Init( - "a", params, MEDIUM, &callback, pool_.get(), BoundNetLog()); + "a", params, MEDIUM, callback.callback(), pool_.get(), BoundNetLog()); EXPECT_EQ(ERR_PROXY_CONNECTION_FAILED, rv); EXPECT_FALSE(handle.is_initialized()); EXPECT_FALSE(handle.socket()); @@ -536,9 +537,9 @@ TEST_F(SSLClientSocketPoolTest, HttpProxyFailAsync) { false); ClientSocketHandle handle; - TestOldCompletionCallback callback; + TestCompletionCallback callback; int rv = handle.Init( - "a", params, MEDIUM, &callback, pool_.get(), BoundNetLog()); + "a", params, MEDIUM, callback.callback(), pool_.get(), BoundNetLog()); EXPECT_EQ(ERR_IO_PENDING, rv); EXPECT_FALSE(handle.is_initialized()); EXPECT_FALSE(handle.socket()); @@ -573,9 +574,9 @@ TEST_F(SSLClientSocketPoolTest, HttpProxyBasic) { false); ClientSocketHandle handle; - TestOldCompletionCallback callback; + TestCompletionCallback callback; int rv = handle.Init( - "a", params, MEDIUM, &callback, pool_.get(), BoundNetLog()); + "a", params, MEDIUM, callback.callback(), pool_.get(), BoundNetLog()); EXPECT_EQ(OK, rv); EXPECT_TRUE(handle.is_initialized()); EXPECT_TRUE(handle.socket()); @@ -603,9 +604,9 @@ TEST_F(SSLClientSocketPoolTest, HttpProxyBasicAsync) { false); ClientSocketHandle handle; - TestOldCompletionCallback callback; + TestCompletionCallback callback; int rv = handle.Init( - "a", params, MEDIUM, &callback, pool_.get(), BoundNetLog()); + "a", params, MEDIUM, callback.callback(), pool_.get(), BoundNetLog()); EXPECT_EQ(ERR_IO_PENDING, rv); EXPECT_FALSE(handle.is_initialized()); EXPECT_FALSE(handle.socket()); @@ -638,9 +639,9 @@ TEST_F(SSLClientSocketPoolTest, NeedProxyAuth) { false); ClientSocketHandle handle; - TestOldCompletionCallback callback; + TestCompletionCallback callback; int rv = handle.Init( - "a", params, MEDIUM, &callback, pool_.get(), BoundNetLog()); + "a", params, MEDIUM, callback.callback(), pool_.get(), BoundNetLog()); EXPECT_EQ(ERR_IO_PENDING, rv); EXPECT_FALSE(handle.is_initialized()); EXPECT_FALSE(handle.socket()); @@ -703,9 +704,9 @@ TEST_F(SSLClientSocketPoolTest, IPPooling) { true); scoped_ptr<ClientSocketHandle> handle(new ClientSocketHandle()); - TestOldCompletionCallback callback; + TestCompletionCallback callback; int rv = handle->Init( - "a", params, MEDIUM, &callback, pool_.get(), BoundNetLog()); + "a", params, MEDIUM, callback.callback(), pool_.get(), BoundNetLog()); EXPECT_EQ(ERR_IO_PENDING, rv); EXPECT_FALSE(handle->is_initialized()); EXPECT_FALSE(handle->socket()); @@ -756,7 +757,6 @@ TEST_F(SSLClientSocketPoolTest, IPPoolingClientCert) { }; TestCompletionCallback callback; - TestOldCompletionCallback old_callback; int rv; for (size_t i = 0; i < ARRAYSIZE_UNSAFE(test_hosts); i++) { host_resolver_.rules()->AddIPLiteralRule(test_hosts[i].name, @@ -793,12 +793,12 @@ TEST_F(SSLClientSocketPoolTest, IPPoolingClientCert) { scoped_ptr<ClientSocketHandle> handle(new ClientSocketHandle()); rv = handle->Init( - "a", params, MEDIUM, &old_callback, pool_.get(), BoundNetLog()); + "a", params, MEDIUM, callback.callback(), pool_.get(), BoundNetLog()); EXPECT_EQ(ERR_IO_PENDING, rv); EXPECT_FALSE(handle->is_initialized()); EXPECT_FALSE(handle->socket()); - EXPECT_EQ(OK, old_callback.WaitForResult()); + EXPECT_EQ(OK, callback.WaitForResult()); EXPECT_TRUE(handle->is_initialized()); EXPECT_TRUE(handle->socket()); diff --git a/net/socket/transport_client_socket_pool_unittest.cc b/net/socket/transport_client_socket_pool_unittest.cc index c5d1080..d78c15e 100644 --- a/net/socket/transport_client_socket_pool_unittest.cc +++ b/net/socket/transport_client_socket_pool_unittest.cc @@ -4,6 +4,8 @@ #include "net/socket/transport_client_socket_pool.h" +#include "base/bind.h" +#include "base/bind_helpers.h" #include "base/callback.h" #include "base/compiler_specific.h" #include "base/logging.h" @@ -501,9 +503,10 @@ TEST(TransportConnectJobTest, MakeAddrListStartWithIPv4) { } TEST_F(TransportClientSocketPoolTest, Basic) { - TestOldCompletionCallback callback; + TestCompletionCallback callback; ClientSocketHandle handle; - int rv = handle.Init("a", low_params_, LOW, &callback, &pool_, BoundNetLog()); + int rv = handle.Init("a", low_params_, LOW, callback.callback(), &pool_, + BoundNetLog()); EXPECT_EQ(ERR_IO_PENDING, rv); EXPECT_FALSE(handle.is_initialized()); EXPECT_FALSE(handle.socket()); @@ -517,31 +520,32 @@ TEST_F(TransportClientSocketPoolTest, Basic) { TEST_F(TransportClientSocketPoolTest, InitHostResolutionFailure) { host_resolver_->rules()->AddSimulatedFailure("unresolvable.host.name"); - TestOldCompletionCallback callback; + TestCompletionCallback callback; ClientSocketHandle handle; HostPortPair host_port_pair("unresolvable.host.name", 80); scoped_refptr<TransportSocketParams> dest(new TransportSocketParams( host_port_pair, kDefaultPriority, false, false)); EXPECT_EQ(ERR_IO_PENDING, - handle.Init("a", dest, kDefaultPriority, &callback, &pool_, - BoundNetLog())); + handle.Init("a", dest, kDefaultPriority, callback.callback(), + &pool_, BoundNetLog())); EXPECT_EQ(ERR_NAME_NOT_RESOLVED, callback.WaitForResult()); } TEST_F(TransportClientSocketPoolTest, InitConnectionFailure) { client_socket_factory_.set_client_socket_type( MockClientSocketFactory::MOCK_FAILING_CLIENT_SOCKET); - TestOldCompletionCallback callback; + TestCompletionCallback callback; ClientSocketHandle handle; - EXPECT_EQ(ERR_IO_PENDING, handle.Init("a", params_, kDefaultPriority, - &callback, &pool_, BoundNetLog())); + EXPECT_EQ(ERR_IO_PENDING, + handle.Init("a", params_, kDefaultPriority, callback.callback(), + &pool_, BoundNetLog())); EXPECT_EQ(ERR_CONNECTION_FAILED, callback.WaitForResult()); // Make the host resolutions complete synchronously this time. host_resolver_->set_synchronous_mode(true); - EXPECT_EQ(ERR_CONNECTION_FAILED, handle.Init("a", params_, - kDefaultPriority, &callback, - &pool_, BoundNetLog())); + EXPECT_EQ(ERR_CONNECTION_FAILED, + handle.Init("a", params_, kDefaultPriority, callback.callback(), + &pool_, BoundNetLog())); } TEST_F(TransportClientSocketPoolTest, PendingRequests) { @@ -644,23 +648,26 @@ TEST_F(TransportClientSocketPoolTest, PendingRequests_NoKeepAlive) { // The pending host resolution will eventually complete, and destroy the // ClientSocketPool which will crash if the group was not cleared properly. TEST_F(TransportClientSocketPoolTest, CancelRequestClearGroup) { - TestOldCompletionCallback callback; + TestCompletionCallback callback; ClientSocketHandle handle; - EXPECT_EQ(ERR_IO_PENDING, handle.Init("a", params_, kDefaultPriority, - &callback, &pool_, BoundNetLog())); + EXPECT_EQ(ERR_IO_PENDING, + handle.Init("a", params_, kDefaultPriority, callback.callback(), + &pool_, BoundNetLog())); handle.Reset(); } TEST_F(TransportClientSocketPoolTest, TwoRequestsCancelOne) { ClientSocketHandle handle; - TestOldCompletionCallback callback; + TestCompletionCallback callback; ClientSocketHandle handle2; - TestOldCompletionCallback callback2; + TestCompletionCallback callback2; - EXPECT_EQ(ERR_IO_PENDING, handle.Init("a", params_, kDefaultPriority, - &callback, &pool_, BoundNetLog())); - EXPECT_EQ(ERR_IO_PENDING, handle2.Init("a", params_, kDefaultPriority, - &callback2, &pool_, BoundNetLog())); + EXPECT_EQ(ERR_IO_PENDING, + handle.Init("a", params_, kDefaultPriority, callback.callback(), + &pool_, BoundNetLog())); + EXPECT_EQ(ERR_IO_PENDING, + handle2.Init("a", params_, kDefaultPriority, callback2.callback(), + &pool_, BoundNetLog())); handle.Reset(); @@ -672,15 +679,17 @@ TEST_F(TransportClientSocketPoolTest, ConnectCancelConnect) { client_socket_factory_.set_client_socket_type( MockClientSocketFactory::MOCK_PENDING_CLIENT_SOCKET); ClientSocketHandle handle; - TestOldCompletionCallback callback; - EXPECT_EQ(ERR_IO_PENDING, handle.Init("a", params_, kDefaultPriority, - &callback, &pool_, BoundNetLog())); + TestCompletionCallback callback; + EXPECT_EQ(ERR_IO_PENDING, + handle.Init("a", params_, kDefaultPriority, callback.callback(), + &pool_, BoundNetLog())); handle.Reset(); - TestOldCompletionCallback callback2; - EXPECT_EQ(ERR_IO_PENDING, handle.Init("a", params_, kDefaultPriority, - &callback2, &pool_, BoundNetLog())); + TestCompletionCallback callback2; + EXPECT_EQ(ERR_IO_PENDING, + handle.Init("a", params_, kDefaultPriority, callback2.callback(), + &pool_, BoundNetLog())); host_resolver_->set_synchronous_mode(true); // At this point, handle has two ConnectingSockets out for it. Due to the @@ -757,17 +766,26 @@ TEST_F(TransportClientSocketPoolTest, CancelRequest) { EXPECT_EQ(ClientSocketPoolTest::kIndexOutOfBounds, GetOrderOfRequest(17)); } -class RequestSocketCallback : public CallbackRunner< Tuple1<int> > { +class RequestSocketCallback : public TestCompletionCallbackBase { public: RequestSocketCallback(ClientSocketHandle* handle, TransportClientSocketPool* pool) : handle_(handle), pool_(pool), - within_callback_(false) {} + within_callback_(false), + ALLOW_THIS_IN_INITIALIZER_LIST(callback_( + base::Bind(&RequestSocketCallback::OnComplete, + base::Unretained(this)))) { + } + + virtual ~RequestSocketCallback() {} - virtual void RunWithParams(const Tuple1<int>& params) { - callback_.RunWithParams(params); - ASSERT_EQ(OK, params.a); + const CompletionCallback& callback() const { return callback_; } + + private: + void OnComplete(int result) { + SetResult(result); + ASSERT_EQ(OK, result); if (!within_callback_) { // Don't allow reuse of the socket. Disconnect it and then release it and @@ -782,20 +800,18 @@ class RequestSocketCallback : public CallbackRunner< Tuple1<int> > { within_callback_ = true; scoped_refptr<TransportSocketParams> dest(new TransportSocketParams( HostPortPair("www.google.com", 80), LOWEST, false, false)); - int rv = handle_->Init("a", dest, LOWEST, this, pool_, BoundNetLog()); + int rv = handle_->Init("a", dest, LOWEST, callback(), pool_, + BoundNetLog()); EXPECT_EQ(OK, rv); } } - int WaitForResult() { - return callback_.WaitForResult(); - } - - private: ClientSocketHandle* const handle_; TransportClientSocketPool* const pool_; bool within_callback_; - TestOldCompletionCallback callback_; + CompletionCallback callback_; + + DISALLOW_COPY_AND_ASSIGN(RequestSocketCallback); }; TEST_F(TransportClientSocketPoolTest, RequestTwice) { @@ -803,7 +819,7 @@ TEST_F(TransportClientSocketPoolTest, RequestTwice) { RequestSocketCallback callback(&handle, &pool_); scoped_refptr<TransportSocketParams> dest(new TransportSocketParams( HostPortPair("www.google.com", 80), LOWEST, false, false)); - int rv = handle.Init("a", dest, LOWEST, &callback, &pool_, + int rv = handle.Init("a", dest, LOWEST, callback.callback(), &pool_, BoundNetLog()); ASSERT_EQ(ERR_IO_PENDING, rv); @@ -864,9 +880,10 @@ TEST_F(TransportClientSocketPoolTest, FailingActiveRequestWithPendingRequests) { } TEST_F(TransportClientSocketPoolTest, ResetIdleSocketsOnIPAddressChange) { - TestOldCompletionCallback callback; + TestCompletionCallback callback; ClientSocketHandle handle; - int rv = handle.Init("a", low_params_, LOW, &callback, &pool_, BoundNetLog()); + int rv = handle.Init("a", low_params_, LOW, callback.callback(), &pool_, + BoundNetLog()); EXPECT_EQ(ERR_IO_PENDING, rv); EXPECT_FALSE(handle.is_initialized()); EXPECT_FALSE(handle.socket()); @@ -919,9 +936,9 @@ TEST_F(TransportClientSocketPoolTest, BackupSocketConnect) { EXPECT_EQ(0, pool_.IdleSocketCount()); - TestOldCompletionCallback callback; + TestCompletionCallback callback; ClientSocketHandle handle; - int rv = handle.Init("b", low_params_, LOW, &callback, &pool_, + int rv = handle.Init("b", low_params_, LOW, callback.callback(), &pool_, BoundNetLog()); EXPECT_EQ(ERR_IO_PENDING, rv); EXPECT_FALSE(handle.is_initialized()); @@ -961,9 +978,9 @@ TEST_F(TransportClientSocketPoolTest, BackupSocketCancel) { for (int index = CANCEL_BEFORE_WAIT; index < CANCEL_AFTER_WAIT; ++index) { EXPECT_EQ(0, pool_.IdleSocketCount()); - TestOldCompletionCallback callback; + TestCompletionCallback callback; ClientSocketHandle handle; - int rv = handle.Init("c", low_params_, LOW, &callback, &pool_, + int rv = handle.Init("c", low_params_, LOW, callback.callback(), &pool_, BoundNetLog()); EXPECT_EQ(ERR_IO_PENDING, rv); EXPECT_FALSE(handle.is_initialized()); @@ -1006,9 +1023,10 @@ TEST_F(TransportClientSocketPoolTest, BackupSocketFailAfterStall) { EXPECT_EQ(0, pool_.IdleSocketCount()); - TestOldCompletionCallback callback; + TestCompletionCallback callback; ClientSocketHandle handle; - int rv = handle.Init("b", low_params_, LOW, &callback, &pool_, BoundNetLog()); + int rv = handle.Init("b", low_params_, LOW, callback.callback(), &pool_, + BoundNetLog()); EXPECT_EQ(ERR_IO_PENDING, rv); EXPECT_FALSE(handle.is_initialized()); EXPECT_FALSE(handle.socket()); @@ -1052,9 +1070,10 @@ TEST_F(TransportClientSocketPoolTest, BackupSocketFailAfterDelay) { EXPECT_EQ(0, pool_.IdleSocketCount()); - TestOldCompletionCallback callback; + TestCompletionCallback callback; ClientSocketHandle handle; - int rv = handle.Init("b", low_params_, LOW, &callback, &pool_, BoundNetLog()); + int rv = handle.Init("b", low_params_, LOW, callback.callback(), &pool_, + BoundNetLog()); EXPECT_EQ(ERR_IO_PENDING, rv); EXPECT_FALSE(handle.is_initialized()); EXPECT_FALSE(handle.socket()); @@ -1106,9 +1125,10 @@ TEST_F(TransportClientSocketPoolTest, IPv6FallbackSocketIPv4FinishesFirst) { host_resolver_->rules()->AddIPLiteralRule( "*", "2:abcd::3:4:ff,2.2.2.2", ""); - TestOldCompletionCallback callback; + TestCompletionCallback callback; ClientSocketHandle handle; - int rv = handle.Init("a", low_params_, LOW, &callback, &pool, BoundNetLog()); + int rv = handle.Init("a", low_params_, LOW, callback.callback(), &pool, + BoundNetLog()); EXPECT_EQ(ERR_IO_PENDING, rv); EXPECT_FALSE(handle.is_initialized()); EXPECT_FALSE(handle.socket()); @@ -1150,9 +1170,10 @@ TEST_F(TransportClientSocketPoolTest, IPv6FallbackSocketIPv6FinishesFirst) { host_resolver_->rules()->AddIPLiteralRule( "*", "2:abcd::3:4:ff,2.2.2.2", ""); - TestOldCompletionCallback callback; + TestCompletionCallback callback; ClientSocketHandle handle; - int rv = handle.Init("a", low_params_, LOW, &callback, &pool, BoundNetLog()); + int rv = handle.Init("a", low_params_, LOW, callback.callback(), &pool, + BoundNetLog()); EXPECT_EQ(ERR_IO_PENDING, rv); EXPECT_FALSE(handle.is_initialized()); EXPECT_FALSE(handle.socket()); @@ -1183,9 +1204,10 @@ TEST_F(TransportClientSocketPoolTest, IPv6NoIPv4AddressesToFallbackTo) { host_resolver_->rules()->AddIPLiteralRule( "*", "2:abcd::3:4:ff,3:abcd::3:4:ff", ""); - TestOldCompletionCallback callback; + TestCompletionCallback callback; ClientSocketHandle handle; - int rv = handle.Init("a", low_params_, LOW, &callback, &pool, BoundNetLog()); + int rv = handle.Init("a", low_params_, LOW, callback.callback(), &pool, + BoundNetLog()); EXPECT_EQ(ERR_IO_PENDING, rv); EXPECT_FALSE(handle.is_initialized()); EXPECT_FALSE(handle.socket()); @@ -1216,9 +1238,10 @@ TEST_F(TransportClientSocketPoolTest, IPv4HasNoFallback) { host_resolver_->rules()->AddIPLiteralRule( "*", "1.1.1.1", ""); - TestOldCompletionCallback callback; + TestCompletionCallback callback; ClientSocketHandle handle; - int rv = handle.Init("a", low_params_, LOW, &callback, &pool, BoundNetLog()); + int rv = handle.Init("a", low_params_, LOW, callback.callback(), &pool, + BoundNetLog()); EXPECT_EQ(ERR_IO_PENDING, rv); EXPECT_FALSE(handle.is_initialized()); EXPECT_FALSE(handle.socket()); diff --git a/net/spdy/spdy_http_stream_unittest.cc b/net/spdy/spdy_http_stream_unittest.cc index 1af0810..b67a02b 100644 --- a/net/spdy/spdy_http_stream_unittest.cc +++ b/net/spdy/spdy_http_stream_unittest.cc @@ -32,13 +32,13 @@ class SpdyHttpStreamTest : public testing::Test { session_ = http_session_->spdy_session_pool()->Get(pair, BoundNetLog()); transport_params_ = new TransportSocketParams(host_port_pair, MEDIUM, false, false); - TestOldCompletionCallback callback; + TestCompletionCallback callback; scoped_ptr<ClientSocketHandle> connection(new ClientSocketHandle); EXPECT_EQ(ERR_IO_PENDING, connection->Init(host_port_pair.ToString(), transport_params_, MEDIUM, - &callback, + callback.callback(), http_session_->GetTransportSocketPool(), BoundNetLog())); EXPECT_EQ(OK, callback.WaitForResult()); diff --git a/net/spdy/spdy_proxy_client_socket_unittest.cc b/net/spdy/spdy_proxy_client_socket_unittest.cc index d7d2626..2d2b401 100644 --- a/net/spdy/spdy_proxy_client_socket_unittest.cc +++ b/net/spdy/spdy_proxy_client_socket_unittest.cc @@ -183,8 +183,8 @@ void SpdyProxyClientSocketTest::Initialize(MockRead* reads, scoped_ptr<ClientSocketHandle> connection(new ClientSocketHandle); EXPECT_EQ(OK, connection->Init(endpoint_host_port_pair_.ToString(), - transport_params_, - LOWEST, NULL, session_->GetTransportSocketPool(), + transport_params_, LOWEST, CompletionCallback(), + session_->GetTransportSocketPool(), BoundNetLog())); spdy_session_->InitializeWithSocket(connection.release(), false, OK); diff --git a/net/spdy/spdy_session_unittest.cc b/net/spdy/spdy_session_unittest.cc index 0fc8e5c..5aaf6bd 100644 --- a/net/spdy/spdy_session_unittest.cc +++ b/net/spdy/spdy_session_unittest.cc @@ -142,11 +142,10 @@ TEST_F(SpdySessionTest, GoAway) { false, false)); scoped_ptr<ClientSocketHandle> connection(new ClientSocketHandle); - EXPECT_EQ(OK, - connection->Init(test_host_port_pair.ToString(), - transport_params, MEDIUM, - NULL, http_session->GetTransportSocketPool(), - BoundNetLog())); + EXPECT_EQ(OK, connection->Init(test_host_port_pair.ToString(), + transport_params, MEDIUM, CompletionCallback(), + http_session->GetTransportSocketPool(), + BoundNetLog())); EXPECT_EQ(OK, session->InitializeWithSocket(connection.release(), false, OK)); // Flush the SpdySession::OnReadComplete() task. @@ -213,13 +212,10 @@ TEST_F(SpdySessionTest, Ping) { false, false)); scoped_ptr<ClientSocketHandle> connection(new ClientSocketHandle); - EXPECT_EQ(OK, - connection->Init(test_host_port_pair.ToString(), - transport_params, - MEDIUM, - NULL, - http_session->GetTransportSocketPool(), - BoundNetLog())); + EXPECT_EQ(OK, connection->Init(test_host_port_pair.ToString(), + transport_params, MEDIUM, CompletionCallback(), + http_session->GetTransportSocketPool(), + BoundNetLog())); EXPECT_EQ(OK, session->InitializeWithSocket(connection.release(), false, OK)); scoped_refptr<SpdyStream> spdy_stream1; @@ -304,13 +300,10 @@ TEST_F(SpdySessionTest, FailedPing) { false, false)); scoped_ptr<ClientSocketHandle> connection(new ClientSocketHandle); - EXPECT_EQ(OK, - connection->Init(test_host_port_pair.ToString(), - transport_params, - MEDIUM, - NULL, - http_session->GetTransportSocketPool(), - BoundNetLog())); + EXPECT_EQ(OK, connection->Init(test_host_port_pair.ToString(), + transport_params, MEDIUM, CompletionCallback(), + http_session->GetTransportSocketPool(), + BoundNetLog())); EXPECT_EQ(OK, session->InitializeWithSocket(connection.release(), false, OK)); scoped_refptr<SpdyStream> spdy_stream1; @@ -550,11 +543,10 @@ TEST_F(SpdySessionTest, OnSettings) { false, false)); scoped_ptr<ClientSocketHandle> connection(new ClientSocketHandle); - EXPECT_EQ(OK, - connection->Init(test_host_port_pair.ToString(), - transport_params, MEDIUM, - NULL, http_session->GetTransportSocketPool(), - BoundNetLog())); + EXPECT_EQ(OK, connection->Init(test_host_port_pair.ToString(), + transport_params, MEDIUM, CompletionCallback(), + http_session->GetTransportSocketPool(), + BoundNetLog())); EXPECT_EQ(OK, session->InitializeWithSocket(connection.release(), false, OK)); // Create 2 streams. First will succeed. Second will be pending. @@ -635,11 +627,10 @@ TEST_F(SpdySessionTest, CancelPendingCreateStream) { false, false)); scoped_ptr<ClientSocketHandle> connection(new ClientSocketHandle); - EXPECT_EQ(OK, - connection->Init(test_host_port_pair.ToString(), - transport_params, MEDIUM, - NULL, http_session->GetTransportSocketPool(), - BoundNetLog())); + EXPECT_EQ(OK, connection->Init(test_host_port_pair.ToString(), + transport_params, MEDIUM, CompletionCallback(), + http_session->GetTransportSocketPool(), + BoundNetLog())); EXPECT_EQ(OK, session->InitializeWithSocket(connection.release(), false, OK)); // Use scoped_ptr to let us invalidate the memory when we want to, to trigger @@ -734,11 +725,10 @@ TEST_F(SpdySessionTest, SendSettingsOnNewSession) { false, false)); scoped_ptr<ClientSocketHandle> connection(new ClientSocketHandle); - EXPECT_EQ(OK, - connection->Init(test_host_port_pair.ToString(), - transport_params, MEDIUM, - NULL, http_session->GetTransportSocketPool(), - BoundNetLog())); + EXPECT_EQ(OK, connection->Init(test_host_port_pair.ToString(), + transport_params, MEDIUM, CompletionCallback(), + http_session->GetTransportSocketPool(), + BoundNetLog())); EXPECT_EQ(OK, session->InitializeWithSocket(connection.release(), false, OK)); MessageLoop::current()->RunAllPending(); EXPECT_TRUE(data.at_write_eof()); @@ -808,11 +798,10 @@ void IPPoolingTest(bool clean_via_close_current_sessions) { false, false)); scoped_ptr<ClientSocketHandle> connection(new ClientSocketHandle); - EXPECT_EQ(OK, - connection->Init(test_host_port_pair.ToString(), - transport_params, MEDIUM, - NULL, http_session->GetTransportSocketPool(), - BoundNetLog())); + EXPECT_EQ(OK, connection->Init(test_host_port_pair.ToString(), + transport_params, MEDIUM, CompletionCallback(), + http_session->GetTransportSocketPool(), + BoundNetLog())); EXPECT_EQ(OK, session->InitializeWithSocket(connection.release(), false, OK)); // TODO(rtenneti): MockClientSocket::GetPeerAddress return's 0 as the port diff --git a/net/spdy/spdy_stream_unittest.cc b/net/spdy/spdy_stream_unittest.cc index 41d3190..4ebe693 100644 --- a/net/spdy/spdy_stream_unittest.cc +++ b/net/spdy/spdy_stream_unittest.cc @@ -187,13 +187,10 @@ TEST_F(SpdyStreamTest, SendDataAfterOpen) { new TransportSocketParams(host_port_pair, LOWEST, false, false)); scoped_ptr<ClientSocketHandle> connection(new ClientSocketHandle); - EXPECT_EQ(OK, - connection->Init(host_port_pair.ToString(), - transport_params, - LOWEST, - NULL, - session_->GetTransportSocketPool(), - BoundNetLog())); + EXPECT_EQ(OK, connection->Init(host_port_pair.ToString(), transport_params, + LOWEST, CompletionCallback(), + session_->GetTransportSocketPool(), + BoundNetLog())); session->InitializeWithSocket(connection.release(), false, OK); scoped_refptr<SpdyStream> stream; diff --git a/net/spdy/spdy_websocket_stream_unittest.cc b/net/spdy/spdy_websocket_stream_unittest.cc index 03c7e93..7231bc4 100644 --- a/net/spdy/spdy_websocket_stream_unittest.cc +++ b/net/spdy/spdy_websocket_stream_unittest.cc @@ -264,11 +264,11 @@ class SpdyWebSocketStreamTest : public testing::Test { EXPECT_TRUE(spdy_session_pool->HasSession(host_port_proxy_pair_)); transport_params_ = new TransportSocketParams(host_port_pair_, MEDIUM, false, false); - TestOldCompletionCallback callback; + TestCompletionCallback callback; scoped_ptr<ClientSocketHandle> connection(new ClientSocketHandle); EXPECT_EQ(ERR_IO_PENDING, connection->Init(host_port_pair_.ToString(), transport_params_, - MEDIUM, &callback, + MEDIUM, callback.callback(), http_session_->GetTransportSocketPool(), BoundNetLog())); EXPECT_EQ(OK, callback.WaitForResult()); diff --git a/net/websockets/websocket_job_unittest.cc b/net/websockets/websocket_job_unittest.cc index 4f6bc97..2fd25d1 100644 --- a/net/websockets/websocket_job_unittest.cc +++ b/net/websockets/websocket_job_unittest.cc @@ -276,12 +276,11 @@ class MockHttpTransactionFactory : public net::HttpTransactionFactory { false, false); net::ClientSocketHandle* connection = new net::ClientSocketHandle; - EXPECT_EQ(net::OK, connection->Init(host_port_pair_.ToString(), - transport_params_, - net::MEDIUM, - NULL, - http_session_->GetTransportSocketPool(), - net::BoundNetLog())); + EXPECT_EQ(net::OK, + connection->Init(host_port_pair_.ToString(), transport_params_, + net::MEDIUM, net::CompletionCallback(), + http_session_->GetTransportSocketPool(), + net::BoundNetLog())); EXPECT_EQ(net::OK, session_->InitializeWithSocket(connection, false, net::OK)); } |