diff options
author | jhawkins@chromium.org <jhawkins@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-12-20 23:22:41 +0000 |
---|---|---|
committer | jhawkins@chromium.org <jhawkins@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-12-20 23:22:41 +0000 |
commit | 49639fa94a527376c0e9b93d4c54c1b8c835c041 (patch) | |
tree | dd03b9fd758c7b19b25e9934f9de9def738cdc33 /net/spdy | |
parent | 5fc2429ede8409759abf8d0c23ef5076e8e31fcf (diff) | |
download | chromium_src-49639fa94a527376c0e9b93d4c54c1b8c835c041.zip chromium_src-49639fa94a527376c0e9b93d4c54c1b8c835c041.tar.gz chromium_src-49639fa94a527376c0e9b93d4c54c1b8c835c041.tar.bz2 |
base::Bind: Convert most of net/http.
BUG=none
TEST=none
R=csilv
Review URL: http://codereview.chromium.org/8990001
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@115220 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net/spdy')
-rw-r--r-- | net/spdy/spdy_http_stream.cc | 46 | ||||
-rw-r--r-- | net/spdy/spdy_http_stream.h | 14 | ||||
-rw-r--r-- | net/spdy/spdy_http_stream_unittest.cc | 22 | ||||
-rw-r--r-- | net/spdy/spdy_network_transaction_unittest.cc | 364 | ||||
-rw-r--r-- | net/spdy/spdy_proxy_client_socket.cc | 11 | ||||
-rw-r--r-- | net/spdy/spdy_proxy_client_socket.h | 1 | ||||
-rw-r--r-- | net/spdy/spdy_proxy_client_socket_unittest.cc | 29 | ||||
-rw-r--r-- | net/spdy/spdy_session.cc | 12 | ||||
-rw-r--r-- | net/spdy/spdy_session.h | 22 | ||||
-rw-r--r-- | net/spdy/spdy_session_unittest.cc | 85 | ||||
-rw-r--r-- | net/spdy/spdy_stream_unittest.cc | 3 | ||||
-rw-r--r-- | net/spdy/spdy_websocket_stream.cc | 9 | ||||
-rw-r--r-- | net/spdy/spdy_websocket_stream.h | 2 |
13 files changed, 327 insertions, 293 deletions
diff --git a/net/spdy/spdy_http_stream.cc b/net/spdy/spdy_http_stream.cc index 1a562ce..fcdcd3e 100644 --- a/net/spdy/spdy_http_stream.cc +++ b/net/spdy/spdy_http_stream.cc @@ -31,7 +31,6 @@ SpdyHttpStream::SpdyHttpStream(SpdySession* spdy_session, response_info_(NULL), download_finished_(false), response_headers_received_(false), - user_callback_(NULL), user_buffer_len_(0), buffered_read_callback_pending_(false), more_read_data_pending_(false), @@ -50,7 +49,7 @@ SpdyHttpStream::~SpdyHttpStream() { int SpdyHttpStream::InitializeStream(const HttpRequestInfo* request_info, const BoundNetLog& stream_net_log, - OldCompletionCallback* callback) { + const CompletionCallback& callback) { DCHECK(!stream_.get()); if (spdy_session_->IsClosed()) return ERR_CONNECTION_CLOSED; @@ -82,8 +81,8 @@ uint64 SpdyHttpStream::GetUploadProgress() const { return request_body_stream_->position(); } -int SpdyHttpStream::ReadResponseHeaders(OldCompletionCallback* callback) { - CHECK(callback); +int SpdyHttpStream::ReadResponseHeaders(const CompletionCallback& callback) { + CHECK(!callback.is_null()); CHECK(!stream_->cancelled()); if (stream_->closed()) @@ -96,17 +95,17 @@ int SpdyHttpStream::ReadResponseHeaders(OldCompletionCallback* callback) { } // Still waiting for the response, return IO_PENDING. - CHECK(!user_callback_); - user_callback_ = callback; + CHECK(callback_.is_null()); + callback_ = callback; return ERR_IO_PENDING; } int SpdyHttpStream::ReadResponseBody( - IOBuffer* buf, int buf_len, OldCompletionCallback* callback) { + IOBuffer* buf, int buf_len, const CompletionCallback& callback) { CHECK(stream_->is_idle()); CHECK(buf); CHECK(buf_len); - CHECK(callback); + CHECK(!callback.is_null()); // If we have data buffered, complete the IO immediately. if (!response_body_.empty()) { @@ -135,11 +134,11 @@ int SpdyHttpStream::ReadResponseBody( return stream_->response_status(); } - CHECK(!user_callback_); + CHECK(callback_.is_null()); CHECK(!user_buffer_); CHECK_EQ(0, user_buffer_len_); - user_callback_ = callback; + callback_ = callback; user_buffer_ = buf; user_buffer_len_ = buf_len; return ERR_IO_PENDING; @@ -190,7 +189,7 @@ void SpdyHttpStream::set_chunk_callback(ChunkCallback* callback) { int SpdyHttpStream::SendRequest(const HttpRequestHeaders& request_headers, UploadDataStream* request_body, HttpResponseInfo* response, - OldCompletionCallback* callback) { + const CompletionCallback& callback) { base::Time request_time = base::Time::Now(); CHECK(stream_.get()); @@ -216,7 +215,7 @@ int SpdyHttpStream::SendRequest(const HttpRequestHeaders& request_headers, delete request_body; } - CHECK(callback); + CHECK(!callback.is_null()); CHECK(!stream_->cancelled()); CHECK(response); @@ -252,8 +251,8 @@ int SpdyHttpStream::SendRequest(const HttpRequestHeaders& request_headers, bool has_upload_data = request_body_stream_.get() != NULL; result = stream_->SendRequest(has_upload_data); if (result == ERR_IO_PENDING) { - CHECK(!user_callback_); - user_callback_ = callback; + CHECK(callback_.is_null()); + callback_ = callback; } return result; } @@ -261,13 +260,13 @@ int SpdyHttpStream::SendRequest(const HttpRequestHeaders& request_headers, void SpdyHttpStream::Cancel() { if (spdy_session_) spdy_session_->CancelPendingCreateStreams(&stream_); - user_callback_ = NULL; + callback_.Reset(); if (stream_) stream_->Cancel(); } bool SpdyHttpStream::OnSendHeadersComplete(int status) { - if (user_callback_) + if (!callback_.is_null()) DoCallback(status); return request_body_stream_.get() == NULL; } @@ -344,8 +343,9 @@ int SpdyHttpStream::OnResponseReceived(const spdy::SpdyHeaderBlock& response, // frame has been received and processed. Move to framer? response_info_->response_time = response_time; - if (user_callback_) + if (!callback_.is_null()) DoCallback(status); + return status; } @@ -385,7 +385,7 @@ void SpdyHttpStream::OnClose(int status) { // We need to complete any pending buffered read now. invoked_callback = DoBufferedReadCallback(); } - if (!invoked_callback && user_callback_) + if (!invoked_callback && !callback_.is_null()) DoCallback(status); } @@ -441,7 +441,7 @@ bool SpdyHttpStream::DoBufferedReadCallback() { int rv = 0; if (user_buffer_) { - rv = ReadResponseBody(user_buffer_, user_buffer_len_, user_callback_); + rv = ReadResponseBody(user_buffer_, user_buffer_len_, callback_); CHECK_NE(rv, ERR_IO_PENDING); user_buffer_ = NULL; user_buffer_len_ = 0; @@ -453,12 +453,12 @@ bool SpdyHttpStream::DoBufferedReadCallback() { void SpdyHttpStream::DoCallback(int rv) { CHECK_NE(rv, ERR_IO_PENDING); - CHECK(user_callback_); + CHECK(!callback_.is_null()); // Since Run may result in being called back, clear user_callback_ in advance. - OldCompletionCallback* c = user_callback_; - user_callback_ = NULL; - c->Run(rv); + CompletionCallback c = callback_; + callback_.Reset(); + c.Run(rv); } void SpdyHttpStream::GetSSLInfo(SSLInfo* ssl_info) { diff --git a/net/spdy/spdy_http_stream.h b/net/spdy/spdy_http_stream.h index 2d25f17..e44f79c 100644 --- a/net/spdy/spdy_http_stream.h +++ b/net/spdy/spdy_http_stream.h @@ -43,20 +43,20 @@ class NET_EXPORT_PRIVATE SpdyHttpStream : public SpdyStream::Delegate, // Cancels any callbacks from being invoked and deletes the stream. void Cancel(); - // HttpStream methods: + // HttpStream implementation. virtual int InitializeStream(const HttpRequestInfo* request_info, const BoundNetLog& net_log, - OldCompletionCallback* callback) OVERRIDE; + const CompletionCallback& callback) OVERRIDE; virtual int SendRequest(const HttpRequestHeaders& headers, UploadDataStream* request_body, HttpResponseInfo* response, - OldCompletionCallback* callback) OVERRIDE; + const CompletionCallback& callback) OVERRIDE; virtual uint64 GetUploadProgress() const OVERRIDE; - virtual int ReadResponseHeaders(OldCompletionCallback* callback) OVERRIDE; + virtual int ReadResponseHeaders(const CompletionCallback& callback) OVERRIDE; virtual const HttpResponseInfo* GetResponseInfo() const OVERRIDE; virtual int ReadResponseBody(IOBuffer* buf, int buf_len, - OldCompletionCallback* callback) OVERRIDE; + const CompletionCallback& callback) OVERRIDE; virtual void Close(bool not_reusable) OVERRIDE; virtual HttpStream* RenewStreamForAuth() OVERRIDE; virtual bool IsResponseBodyComplete() const OVERRIDE; @@ -72,7 +72,7 @@ class NET_EXPORT_PRIVATE SpdyHttpStream : public SpdyStream::Delegate, virtual void LogNumRttVsBytesMetrics() const OVERRIDE {} virtual void Drain(HttpNetworkSession* session) OVERRIDE; - // SpdyStream::Delegate methods: + // SpdyStream::Delegate implementation. virtual bool OnSendHeadersComplete(int status) OVERRIDE; virtual int OnSendBody() OVERRIDE; virtual int OnSendBodyComplete(int status, bool* eof) OVERRIDE; @@ -119,7 +119,7 @@ class NET_EXPORT_PRIVATE SpdyHttpStream : public SpdyStream::Delegate, // TODO(mbelshe): is this infinite buffering? std::list<scoped_refptr<IOBufferWithSize> > response_body_; - OldCompletionCallback* user_callback_; + CompletionCallback callback_; // User provided buffer for the ReadResponseBody() response. scoped_refptr<IOBuffer> user_buffer_; diff --git a/net/spdy/spdy_http_stream_unittest.cc b/net/spdy/spdy_http_stream_unittest.cc index b67a02b..e2c7f8e 100644 --- a/net/spdy/spdy_http_stream_unittest.cc +++ b/net/spdy/spdy_http_stream_unittest.cc @@ -73,7 +73,7 @@ TEST_F(SpdyHttpStreamTest, SendRequest) { HttpRequestInfo request; request.method = "GET"; request.url = GURL("http://www.google.com/"); - TestOldCompletionCallback callback; + TestCompletionCallback callback; HttpResponseInfo response; HttpRequestHeaders headers; BoundNetLog net_log; @@ -81,10 +81,10 @@ TEST_F(SpdyHttpStreamTest, SendRequest) { new SpdyHttpStream(session_.get(), true)); ASSERT_EQ( OK, - http_stream->InitializeStream(&request, net_log, NULL)); + http_stream->InitializeStream(&request, net_log, CompletionCallback())); - EXPECT_EQ(ERR_IO_PENDING, - http_stream->SendRequest(headers, NULL, &response, &callback)); + EXPECT_EQ(ERR_IO_PENDING, http_stream->SendRequest(headers, NULL, &response, + callback.callback())); EXPECT_TRUE(http_session_->spdy_session_pool()->HasSession(pair)); // This triggers the MockWrite and read 2 @@ -133,19 +133,19 @@ TEST_F(SpdyHttpStreamTest, SendChunkedPost) { request.upload_data->set_is_chunked(true); request.upload_data->AppendChunk(kUploadData, kUploadDataSize, false); request.upload_data->AppendChunk(kUploadData, kUploadDataSize, true); - TestOldCompletionCallback callback; + TestCompletionCallback callback; HttpResponseInfo response; HttpRequestHeaders headers; BoundNetLog net_log; SpdyHttpStream http_stream(session_.get(), true); ASSERT_EQ( OK, - http_stream.InitializeStream(&request, net_log, NULL)); + http_stream.InitializeStream(&request, net_log, CompletionCallback())); UploadDataStream* upload_stream = UploadDataStream::Create(request.upload_data, NULL); EXPECT_EQ(ERR_IO_PENDING, http_stream.SendRequest( - headers, upload_stream, &response, &callback)); + headers, upload_stream, &response, callback.callback())); EXPECT_TRUE(http_session_->spdy_session_pool()->HasSession(pair)); // This triggers the MockWrite and read 2 @@ -187,17 +187,17 @@ TEST_F(SpdyHttpStreamTest, SpdyURLTest) { HttpRequestInfo request; request.method = "GET"; request.url = GURL(full_url); - TestOldCompletionCallback callback; + TestCompletionCallback callback; HttpResponseInfo response; HttpRequestHeaders headers; BoundNetLog net_log; scoped_ptr<SpdyHttpStream> http_stream(new SpdyHttpStream(session_, true)); ASSERT_EQ( OK, - http_stream->InitializeStream(&request, net_log, NULL)); + http_stream->InitializeStream(&request, net_log, CompletionCallback())); - EXPECT_EQ(ERR_IO_PENDING, - http_stream->SendRequest(headers, NULL, &response, &callback)); + EXPECT_EQ(ERR_IO_PENDING, http_stream->SendRequest(headers, NULL, &response, + callback.callback())); spdy::SpdyHeaderBlock* spdy_header = http_stream->stream()->spdy_headers().get(); diff --git a/net/spdy/spdy_network_transaction_unittest.cc b/net/spdy/spdy_network_transaction_unittest.cc index 7c2c369..eb47f40 100644 --- a/net/spdy/spdy_network_transaction_unittest.cc +++ b/net/spdy/spdy_network_transaction_unittest.cc @@ -7,6 +7,8 @@ #include <string> #include <vector> +#include "base/bind.h" +#include "base/bind_helpers.h" #include "net/base/auth.h" #include "net/base/net_log_unittest.h" #include "net/http/http_network_session_peer.h" @@ -57,9 +59,6 @@ class SpdyNetworkTransactionTest spdy::SpdyFramer::set_enable_compression_default(enabled); } - class StartTransactionCallback; - class DeleteSessionCallback; - // A helper class that handles all the initial npn/ssl setup. class NormalSpdyTransactionHelper { public: @@ -150,7 +149,7 @@ class SpdyNetworkTransactionTest // Start the transaction, read some data, finish. void RunDefaultTest() { - output_.rv = trans_->Start(&request_, &callback, log_); + output_.rv = trans_->Start(&request_, callback.callback(), log_); // We expect an IO Pending or some sort of error. EXPECT_LT(output_.rv, 0); @@ -326,7 +325,7 @@ class SpdyNetworkTransactionTest TransactionHelperResult output_; scoped_ptr<StaticSocketDataProvider> first_transaction_; SSLVector ssl_vector_; - TestOldCompletionCallback callback; + TestCompletionCallback callback; scoped_ptr<HttpNetworkTransaction> trans_; scoped_ptr<HttpNetworkTransaction> trans_http_; DataVector data_vector_; @@ -410,9 +409,9 @@ class SpdyNetworkTransactionTest int bytes_read = 0; scoped_refptr<net::IOBufferWithSize> buf(new net::IOBufferWithSize(kSize)); - TestOldCompletionCallback callback; + TestCompletionCallback callback; while (true) { - int rv = trans->Read(buf, kSize, &callback); + int rv = trans->Read(buf, kSize, callback.callback()); if (rv == ERR_IO_PENDING) { // Multiple transactions may be in the data set. Keep pulling off // reads until we complete our callback. @@ -460,15 +459,17 @@ class SpdyNetworkTransactionTest HttpNetworkTransaction* trans = helper.trans(); // Start the transaction with basic parameters. - TestOldCompletionCallback callback; - int rv = trans->Start(&CreateGetRequest(), &callback, BoundNetLog()); + TestCompletionCallback callback; + int rv = trans->Start( + &CreateGetRequest(), callback.callback(), BoundNetLog()); EXPECT_EQ(ERR_IO_PENDING, rv); rv = callback.WaitForResult(); // Request the pushed path. scoped_ptr<HttpNetworkTransaction> trans2( new HttpNetworkTransaction(helper.session())); - rv = trans2->Start(&CreateGetPushRequest(), &callback, BoundNetLog()); + rv = trans2->Start( + &CreateGetPushRequest(), callback.callback(), BoundNetLog()); EXPECT_EQ(ERR_IO_PENDING, rv); MessageLoop::current()->RunAllPending(); @@ -500,6 +501,26 @@ class SpdyNetworkTransactionTest VerifyStreamsClosed(helper); } + static void DeleteSessionCallback(NormalSpdyTransactionHelper* helper, + int result) { + helper->ResetTrans(); + } + + static void StartTransactionCallback( + const scoped_refptr<HttpNetworkSession>& session, + int result) { + scoped_ptr<HttpNetworkTransaction> trans( + new HttpNetworkTransaction(session)); + TestCompletionCallback callback; + HttpRequestInfo request; + request.method = "GET"; + request.url = GURL("http://www.google.com/"); + request.load_flags = 0; + int rv = trans->Start(&request, callback.callback(), BoundNetLog()); + EXPECT_EQ(ERR_IO_PENDING, rv); + callback.WaitForResult(); + } + private: bool google_get_request_initialized_; bool google_post_request_initialized_; @@ -672,19 +693,19 @@ TEST_P(SpdyNetworkTransactionTest, ThreeGets) { scoped_ptr<HttpNetworkTransaction> trans3( new HttpNetworkTransaction(helper.session())); - TestOldCompletionCallback callback1; - TestOldCompletionCallback callback2; - TestOldCompletionCallback callback3; + TestCompletionCallback callback1; + TestCompletionCallback callback2; + TestCompletionCallback callback3; HttpRequestInfo httpreq1 = CreateGetRequest(); HttpRequestInfo httpreq2 = CreateGetRequest(); HttpRequestInfo httpreq3 = CreateGetRequest(); - out.rv = trans1->Start(&httpreq1, &callback1, log); + out.rv = trans1->Start(&httpreq1, callback1.callback(), log); ASSERT_EQ(ERR_IO_PENDING, out.rv); - out.rv = trans2->Start(&httpreq2, &callback2, log); + out.rv = trans2->Start(&httpreq2, callback2.callback(), log); ASSERT_EQ(ERR_IO_PENDING, out.rv); - out.rv = trans3->Start(&httpreq3, &callback3, log); + out.rv = trans3->Start(&httpreq3, callback3.callback(), log); ASSERT_EQ(ERR_IO_PENDING, out.rv); out.rv = callback1.WaitForResult(); @@ -757,15 +778,15 @@ TEST_P(SpdyNetworkTransactionTest, TwoGetsLateBinding) { scoped_ptr<HttpNetworkTransaction> trans2( new HttpNetworkTransaction(helper.session())); - TestOldCompletionCallback callback1; - TestOldCompletionCallback callback2; + TestCompletionCallback callback1; + TestCompletionCallback callback2; HttpRequestInfo httpreq1 = CreateGetRequest(); HttpRequestInfo httpreq2 = CreateGetRequest(); - out.rv = trans1->Start(&httpreq1, &callback1, log); + out.rv = trans1->Start(&httpreq1, callback1.callback(), log); ASSERT_EQ(ERR_IO_PENDING, out.rv); - out.rv = trans2->Start(&httpreq2, &callback2, log); + out.rv = trans2->Start(&httpreq2, callback2.callback(), log); ASSERT_EQ(ERR_IO_PENDING, out.rv); out.rv = callback1.WaitForResult(); @@ -846,8 +867,8 @@ TEST_P(SpdyNetworkTransactionTest, TwoGetsLateBindingFromPreconnect) { scoped_ptr<HttpNetworkTransaction> trans2( new HttpNetworkTransaction(helper.session())); - TestOldCompletionCallback callback1; - TestOldCompletionCallback callback2; + TestCompletionCallback callback1; + TestCompletionCallback callback2; HttpRequestInfo httpreq = CreateGetRequest(); @@ -863,9 +884,9 @@ TEST_P(SpdyNetworkTransactionTest, TwoGetsLateBindingFromPreconnect) { http_stream_factory->PreconnectStreams( 1, httpreq, preconnect_ssl_config, preconnect_ssl_config, log); - out.rv = trans1->Start(&httpreq, &callback1, log); + out.rv = trans1->Start(&httpreq, callback1.callback(), log); ASSERT_EQ(ERR_IO_PENDING, out.rv); - out.rv = trans2->Start(&httpreq, &callback2, log); + out.rv = trans2->Start(&httpreq, callback2.callback(), log); ASSERT_EQ(ERR_IO_PENDING, out.rv); out.rv = callback1.WaitForResult(); @@ -971,24 +992,24 @@ TEST_P(SpdyNetworkTransactionTest, ThreeGetsWithMaxConcurrent) { scoped_ptr<HttpNetworkTransaction> trans3( new HttpNetworkTransaction(helper.session())); - TestOldCompletionCallback callback1; - TestOldCompletionCallback callback2; - TestOldCompletionCallback callback3; + TestCompletionCallback callback1; + TestCompletionCallback callback2; + TestCompletionCallback callback3; HttpRequestInfo httpreq1 = CreateGetRequest(); HttpRequestInfo httpreq2 = CreateGetRequest(); HttpRequestInfo httpreq3 = CreateGetRequest(); - out.rv = trans1->Start(&httpreq1, &callback1, log); + out.rv = trans1->Start(&httpreq1, callback1.callback(), log); ASSERT_EQ(out.rv, ERR_IO_PENDING); // run transaction 1 through quickly to force a read of our SETTINGS // frame out.rv = callback1.WaitForResult(); ASSERT_EQ(OK, out.rv); - out.rv = trans2->Start(&httpreq2, &callback2, log); + out.rv = trans2->Start(&httpreq2, callback2.callback(), log); ASSERT_EQ(out.rv, ERR_IO_PENDING); - out.rv = trans3->Start(&httpreq3, &callback3, log); + out.rv = trans3->Start(&httpreq3, callback3.callback(), log); ASSERT_EQ(out.rv, ERR_IO_PENDING); out.rv = callback2.WaitForResult(); ASSERT_EQ(OK, out.rv); @@ -1113,10 +1134,10 @@ TEST_P(SpdyNetworkTransactionTest, FourGetsWithMaxConcurrentPriority) { scoped_ptr<HttpNetworkTransaction> trans4( new HttpNetworkTransaction(helper.session())); - TestOldCompletionCallback callback1; - TestOldCompletionCallback callback2; - TestOldCompletionCallback callback3; - TestOldCompletionCallback callback4; + TestCompletionCallback callback1; + TestCompletionCallback callback2; + TestCompletionCallback callback3; + TestCompletionCallback callback4; HttpRequestInfo httpreq1 = CreateGetRequest(); HttpRequestInfo httpreq2 = CreateGetRequest(); @@ -1124,18 +1145,18 @@ TEST_P(SpdyNetworkTransactionTest, FourGetsWithMaxConcurrentPriority) { HttpRequestInfo httpreq4 = CreateGetRequest(); httpreq4.priority = HIGHEST; - out.rv = trans1->Start(&httpreq1, &callback1, log); + out.rv = trans1->Start(&httpreq1, callback1.callback(), log); ASSERT_EQ(ERR_IO_PENDING, out.rv); // run transaction 1 through quickly to force a read of our SETTINGS // frame out.rv = callback1.WaitForResult(); ASSERT_EQ(OK, out.rv); - out.rv = trans2->Start(&httpreq2, &callback2, log); + out.rv = trans2->Start(&httpreq2, callback2.callback(), log); ASSERT_EQ(ERR_IO_PENDING, out.rv); - out.rv = trans3->Start(&httpreq3, &callback3, log); + out.rv = trans3->Start(&httpreq3, callback3.callback(), log); ASSERT_EQ(ERR_IO_PENDING, out.rv); - out.rv = trans4->Start(&httpreq4, &callback4, log); + out.rv = trans4->Start(&httpreq4, callback4.callback(), log); ASSERT_EQ(ERR_IO_PENDING, out.rv); out.rv = callback2.WaitForResult(); @@ -1247,24 +1268,24 @@ TEST_P(SpdyNetworkTransactionTest, ThreeGetsWithMaxConcurrentDelete) { scoped_ptr<HttpNetworkTransaction> trans3( new HttpNetworkTransaction(helper.session())); - TestOldCompletionCallback callback1; - TestOldCompletionCallback callback2; - TestOldCompletionCallback callback3; + TestCompletionCallback callback1; + TestCompletionCallback callback2; + TestCompletionCallback callback3; HttpRequestInfo httpreq1 = CreateGetRequest(); HttpRequestInfo httpreq2 = CreateGetRequest(); HttpRequestInfo httpreq3 = CreateGetRequest(); - out.rv = trans1->Start(&httpreq1, &callback1, log); + out.rv = trans1->Start(&httpreq1, callback1.callback(), log); ASSERT_EQ(out.rv, ERR_IO_PENDING); // run transaction 1 through quickly to force a read of our SETTINGS // frame out.rv = callback1.WaitForResult(); ASSERT_EQ(OK, out.rv); - out.rv = trans2->Start(&httpreq2, &callback2, log); + out.rv = trans2->Start(&httpreq2, callback2.callback(), log); ASSERT_EQ(out.rv, ERR_IO_PENDING); - out.rv = trans3->Start(&httpreq3, &callback3, log); + out.rv = trans3->Start(&httpreq3, callback3.callback(), log); delete trans3.release(); ASSERT_EQ(out.rv, ERR_IO_PENDING); out.rv = callback2.WaitForResult(); @@ -1297,19 +1318,28 @@ TEST_P(SpdyNetworkTransactionTest, ThreeGetsWithMaxConcurrentDelete) { // The KillerCallback will delete the transaction on error as part of the // callback. -class KillerCallback : public TestOldCompletionCallback { +class KillerCallback : public TestCompletionCallbackBase { public: explicit KillerCallback(HttpNetworkTransaction* transaction) - : transaction_(transaction) {} + : transaction_(transaction), + ALLOW_THIS_IN_INITIALIZER_LIST(callback_( + base::Bind(&KillerCallback::OnComplete, base::Unretained(this)))) { + } + + virtual ~KillerCallback() {} + + const CompletionCallback& callback() const { return callback_; } - virtual void RunWithParams(const Tuple1<int>& params) { - if (params.a < 0) + private: + void OnComplete(int result) { + if (result < 0) delete transaction_; - TestOldCompletionCallback::RunWithParams(params); + + SetResult(result); } - private: HttpNetworkTransaction* transaction_; + CompletionCallback callback_; }; // Similar to ThreeGetsMaxConcurrrentDelete above, however, this test @@ -1365,24 +1395,24 @@ TEST_P(SpdyNetworkTransactionTest, ThreeGetsWithMaxConcurrentSocketClose) { HttpNetworkTransaction trans2(helper.session()); HttpNetworkTransaction* trans3(new HttpNetworkTransaction(helper.session())); - TestOldCompletionCallback callback1; - TestOldCompletionCallback callback2; + TestCompletionCallback callback1; + TestCompletionCallback callback2; KillerCallback callback3(trans3); HttpRequestInfo httpreq1 = CreateGetRequest(); HttpRequestInfo httpreq2 = CreateGetRequest(); HttpRequestInfo httpreq3 = CreateGetRequest(); - out.rv = trans1.Start(&httpreq1, &callback1, log); + out.rv = trans1.Start(&httpreq1, callback1.callback(), log); ASSERT_EQ(out.rv, ERR_IO_PENDING); // run transaction 1 through quickly to force a read of our SETTINGS // frame out.rv = callback1.WaitForResult(); ASSERT_EQ(OK, out.rv); - out.rv = trans2.Start(&httpreq2, &callback2, log); + out.rv = trans2.Start(&httpreq2, callback2.callback(), log); ASSERT_EQ(out.rv, ERR_IO_PENDING); - out.rv = trans3->Start(&httpreq3, &callback3, log); + out.rv = trans3->Start(&httpreq3, callback3.callback(), log); ASSERT_EQ(out.rv, ERR_IO_PENDING); out.rv = callback3.WaitForResult(); ASSERT_EQ(ERR_ABORTED, out.rv); @@ -1759,8 +1789,9 @@ TEST_P(SpdyNetworkTransactionTest, SocketWriteReturnsZero) { helper.AddDeterministicData(data.get()); HttpNetworkTransaction* trans = helper.trans(); - TestOldCompletionCallback callback; - int rv = trans->Start(&CreateGetRequest(), &callback, BoundNetLog()); + TestCompletionCallback callback; + int rv = trans->Start( + &CreateGetRequest(), callback.callback(), BoundNetLog()); EXPECT_EQ(ERR_IO_PENDING, rv); data->SetStop(2); @@ -1815,8 +1846,8 @@ TEST_P(SpdyNetworkTransactionTest, ResponseWithTwoSynReplies) { HttpNetworkTransaction* trans = helper.trans(); - TestOldCompletionCallback callback; - int rv = trans->Start(&helper.request(), &callback, BoundNetLog()); + TestCompletionCallback callback; + int rv = trans->Start(&helper.request(), callback.callback(), BoundNetLog()); EXPECT_EQ(ERR_IO_PENDING, rv); rv = callback.WaitForResult(); EXPECT_EQ(OK, rv); @@ -1910,8 +1941,8 @@ TEST_P(SpdyNetworkTransactionTest, WindowUpdateReceived) { HttpNetworkTransaction* trans = helper.trans(); - TestOldCompletionCallback callback; - int rv = trans->Start(&helper.request(), &callback, BoundNetLog()); + TestCompletionCallback callback; + int rv = trans->Start(&helper.request(), callback.callback(), BoundNetLog()); EXPECT_EQ(ERR_IO_PENDING, rv); rv = callback.WaitForResult(); @@ -1967,8 +1998,8 @@ TEST_P(SpdyNetworkTransactionTest, WindowUpdateSent) { helper.RunPreTestSetup(); HttpNetworkTransaction* trans = helper.trans(); - TestOldCompletionCallback callback; - int rv = trans->Start(&helper.request(), &callback, BoundNetLog()); + TestCompletionCallback callback; + int rv = trans->Start(&helper.request(), callback.callback(), BoundNetLog()); EXPECT_EQ(ERR_IO_PENDING, rv); rv = callback.WaitForResult(); @@ -1992,7 +2023,7 @@ TEST_P(SpdyNetworkTransactionTest, WindowUpdateSent) { // Issue a read which will cause a WINDOW_UPDATE to be sent and window // size increased to default. scoped_refptr<net::IOBuffer> buf(new net::IOBuffer(kUploadDataSize)); - rv = trans->Read(buf, kUploadDataSize, NULL); + rv = trans->Read(buf, kUploadDataSize, CompletionCallback()); EXPECT_EQ(kUploadDataSize, rv); std::string content(buf->data(), buf->data()+kUploadDataSize); EXPECT_STREQ(kUploadData, content.c_str()); @@ -2073,8 +2104,8 @@ TEST_P(SpdyNetworkTransactionTest, WindowUpdateOverflow) { HttpNetworkTransaction* trans = helper.trans(); - TestOldCompletionCallback callback; - int rv = trans->Start(&helper.request(), &callback, BoundNetLog()); + TestCompletionCallback callback; + int rv = trans->Start(&helper.request(), callback.callback(), BoundNetLog()); EXPECT_EQ(ERR_IO_PENDING, rv); rv = callback.WaitForResult(); @@ -2181,8 +2212,8 @@ TEST_P(SpdyNetworkTransactionTest, FlowControlStallResume) { HttpNetworkTransaction* trans = helper.trans(); - TestOldCompletionCallback callback; - int rv = trans->Start(&helper.request(), &callback, BoundNetLog()); + TestCompletionCallback callback; + int rv = trans->Start(&helper.request(), callback.callback(), BoundNetLog()); EXPECT_EQ(ERR_IO_PENDING, rv); MessageLoop::current()->RunAllPending(); // Write as much as we can. @@ -2226,8 +2257,9 @@ TEST_P(SpdyNetworkTransactionTest, CancelledTransaction) { helper.AddData(&data); HttpNetworkTransaction* trans = helper.trans(); - TestOldCompletionCallback callback; - int rv = trans->Start(&CreateGetRequest(), &callback, BoundNetLog()); + TestCompletionCallback callback; + int rv = trans->Start( + &CreateGetRequest(), callback.callback(), BoundNetLog()); EXPECT_EQ(ERR_IO_PENDING, rv); helper.ResetTrans(); // Cancel the transaction. @@ -2265,9 +2297,10 @@ TEST_P(SpdyNetworkTransactionTest, CancelledTransactionSendRst) { helper.AddDeterministicData(data.get()); HttpNetworkTransaction* trans = helper.trans(); - TestOldCompletionCallback callback; + TestCompletionCallback callback; - int rv = trans->Start(&CreateGetRequest(), &callback, BoundNetLog()); + int rv = trans->Start( + &CreateGetRequest(), callback.callback(), BoundNetLog()); EXPECT_EQ(ERR_IO_PENDING, rv); data->SetStop(2); @@ -2279,33 +2312,6 @@ TEST_P(SpdyNetworkTransactionTest, CancelledTransactionSendRst) { helper.VerifyDataConsumed(); } -class SpdyNetworkTransactionTest::StartTransactionCallback - : public CallbackRunner< Tuple1<int> > { - public: - explicit StartTransactionCallback( - const scoped_refptr<HttpNetworkSession>& session, - NormalSpdyTransactionHelper& helper) - : session_(session), helper_(helper) {} - - // We try to start another transaction, which should succeed. - virtual void RunWithParams(const Tuple1<int>& params) { - scoped_ptr<HttpNetworkTransaction> trans( - new HttpNetworkTransaction(session_)); - TestOldCompletionCallback callback; - HttpRequestInfo request; - request.method = "GET"; - request.url = GURL("http://www.google.com/"); - request.load_flags = 0; - int rv = trans->Start(&request, &callback, BoundNetLog()); - EXPECT_EQ(ERR_IO_PENDING, rv); - rv = callback.WaitForResult(); - } - - private: - const scoped_refptr<HttpNetworkSession>& session_; - NormalSpdyTransactionHelper& helper_; -}; - // Verify that the client can correctly deal with the user callback attempting // to start another transaction on a session that is closing down. See // http://crbug.com/47455 @@ -2352,15 +2358,17 @@ TEST_P(SpdyNetworkTransactionTest, StartTransactionOnReadCallback) { HttpNetworkTransaction* trans = helper.trans(); // Start the transaction with basic parameters. - TestOldCompletionCallback callback; - int rv = trans->Start(&helper.request(), &callback, BoundNetLog()); + TestCompletionCallback callback; + int rv = trans->Start(&helper.request(), callback.callback(), BoundNetLog()); EXPECT_EQ(ERR_IO_PENDING, rv); rv = callback.WaitForResult(); - StartTransactionCallback callback2(helper.session(), helper); const int kSize = 3000; scoped_refptr<net::IOBuffer> buf(new net::IOBuffer(kSize)); - rv = trans->Read(buf, kSize, &callback2); + rv = trans->Read( + buf, kSize, + base::Bind(&SpdyNetworkTransactionTest::StartTransactionCallback, + helper.session())); // This forces an err_IO_pending, which sets the callback. data->CompleteRead(); // This finishes the read. @@ -2368,21 +2376,6 @@ TEST_P(SpdyNetworkTransactionTest, StartTransactionOnReadCallback) { helper.VerifyDataConsumed(); } -class SpdyNetworkTransactionTest::DeleteSessionCallback - : public CallbackRunner< Tuple1<int> > { - public: - explicit DeleteSessionCallback(NormalSpdyTransactionHelper& helper) : - helper_(helper) {} - - // We kill the transaction, which deletes the session and stream. - virtual void RunWithParams(const Tuple1<int>& params) { - helper_.ResetTrans(); - } - - private: - NormalSpdyTransactionHelper& helper_; -}; - // Verify that the client can correctly deal with the user callback deleting the // transaction. Failures will usually be valgrind errors. See // http://crbug.com/46925 @@ -2410,17 +2403,19 @@ TEST_P(SpdyNetworkTransactionTest, DeleteSessionOnReadCallback) { HttpNetworkTransaction* trans = helper.trans(); // Start the transaction with basic parameters. - TestOldCompletionCallback callback; - int rv = trans->Start(&helper.request(), &callback, BoundNetLog()); + TestCompletionCallback callback; + int rv = trans->Start(&helper.request(), callback.callback(), BoundNetLog()); EXPECT_EQ(ERR_IO_PENDING, rv); rv = callback.WaitForResult(); // Setup a user callback which will delete the session, and clear out the // memory holding the stream object. Note that the callback deletes trans. - DeleteSessionCallback callback2(helper); const int kSize = 3000; scoped_refptr<net::IOBuffer> buf(new net::IOBuffer(kSize)); - rv = trans->Read(buf, kSize, &callback2); + rv = trans->Read( + buf, kSize, + base::Bind(&SpdyNetworkTransactionTest::DeleteSessionCallback, + base::Unretained(&helper))); ASSERT_EQ(ERR_IO_PENDING, rv); data->CompleteRead(); @@ -2817,8 +2812,9 @@ TEST_P(SpdyNetworkTransactionTest, ServerPushServerAborted) { HttpNetworkTransaction* trans = helper.trans(); // Start the transaction with basic parameters. - TestOldCompletionCallback callback; - int rv = trans->Start(&CreateGetRequest(), &callback, BoundNetLog()); + TestCompletionCallback callback; + int rv = trans->Start( + &CreateGetRequest(), callback.callback(), BoundNetLog()); EXPECT_EQ(ERR_IO_PENDING, rv); rv = callback.WaitForResult(); EXPECT_EQ(OK, rv); @@ -3071,8 +3067,9 @@ TEST_P(SpdyNetworkTransactionTest, ServerPushInvalidAssociatedStreamID0) { HttpNetworkTransaction* trans = helper.trans(); // Start the transaction with basic parameters. - TestOldCompletionCallback callback; - int rv = trans->Start(&CreateGetRequest(), &callback, BoundNetLog()); + TestCompletionCallback callback; + int rv = trans->Start( + &CreateGetRequest(), callback.callback(), BoundNetLog()); EXPECT_EQ(ERR_IO_PENDING, rv); rv = callback.WaitForResult(); EXPECT_EQ(OK, rv); @@ -3132,8 +3129,9 @@ TEST_P(SpdyNetworkTransactionTest, ServerPushInvalidAssociatedStreamID9) { HttpNetworkTransaction* trans = helper.trans(); // Start the transaction with basic parameters. - TestOldCompletionCallback callback; - int rv = trans->Start(&CreateGetRequest(), &callback, BoundNetLog()); + TestCompletionCallback callback; + int rv = trans->Start( + &CreateGetRequest(), callback.callback(), BoundNetLog()); EXPECT_EQ(ERR_IO_PENDING, rv); rv = callback.WaitForResult(); EXPECT_EQ(OK, rv); @@ -3189,8 +3187,9 @@ TEST_P(SpdyNetworkTransactionTest, ServerPushNoURL) { HttpNetworkTransaction* trans = helper.trans(); // Start the transaction with basic parameters. - TestOldCompletionCallback callback; - int rv = trans->Start(&CreateGetRequest(), &callback, BoundNetLog()); + TestCompletionCallback callback; + int rv = trans->Start( + &CreateGetRequest(), callback.callback(), BoundNetLog()); EXPECT_EQ(ERR_IO_PENDING, rv); rv = callback.WaitForResult(); EXPECT_EQ(OK, rv); @@ -3780,14 +3779,15 @@ TEST_P(SpdyNetworkTransactionTest, BufferFull) { writes, arraysize(writes))); - TestOldCompletionCallback callback; + TestCompletionCallback callback; NormalSpdyTransactionHelper helper(CreateGetRequest(), BoundNetLog(), GetParam()); helper.RunPreTestSetup(); helper.AddData(data.get()); HttpNetworkTransaction* trans = helper.trans(); - int rv = trans->Start(&CreateGetRequest(), &callback, BoundNetLog()); + int rv = trans->Start( + &CreateGetRequest(), callback.callback(), BoundNetLog()); EXPECT_EQ(ERR_IO_PENDING, rv); TransactionHelperResult out = helper.output(); @@ -3801,14 +3801,14 @@ TEST_P(SpdyNetworkTransactionTest, BufferFull) { out.response_info = *response; // Make a copy so we can verify. // Read Data - TestOldCompletionCallback read_callback; + TestCompletionCallback read_callback; std::string content; do { // Read small chunks at a time. const int kSmallReadSize = 3; scoped_refptr<net::IOBuffer> buf(new net::IOBuffer(kSmallReadSize)); - rv = trans->Read(buf, kSmallReadSize, &read_callback); + rv = trans->Read(buf, kSmallReadSize, read_callback.callback()); if (rv == net::ERR_IO_PENDING) { data->CompleteRead(); rv = read_callback.WaitForResult(); @@ -3877,8 +3877,9 @@ TEST_P(SpdyNetworkTransactionTest, Buffering) { helper.AddData(data.get()); HttpNetworkTransaction* trans = helper.trans(); - TestOldCompletionCallback callback; - int rv = trans->Start(&CreateGetRequest(), &callback, BoundNetLog()); + TestCompletionCallback callback; + int rv = trans->Start( + &CreateGetRequest(), callback.callback(), BoundNetLog()); EXPECT_EQ(ERR_IO_PENDING, rv); TransactionHelperResult out = helper.output(); @@ -3892,7 +3893,7 @@ TEST_P(SpdyNetworkTransactionTest, Buffering) { out.response_info = *response; // Make a copy so we can verify. // Read Data - TestOldCompletionCallback read_callback; + TestCompletionCallback read_callback; std::string content; int reads_completed = 0; @@ -3900,7 +3901,7 @@ TEST_P(SpdyNetworkTransactionTest, Buffering) { // Read small chunks at a time. const int kSmallReadSize = 14; scoped_refptr<net::IOBuffer> buf(new net::IOBuffer(kSmallReadSize)); - rv = trans->Read(buf, kSmallReadSize, &read_callback); + rv = trans->Read(buf, kSmallReadSize, read_callback.callback()); if (rv == net::ERR_IO_PENDING) { data->CompleteRead(); rv = read_callback.WaitForResult(); @@ -3972,8 +3973,9 @@ TEST_P(SpdyNetworkTransactionTest, BufferedAll) { helper.AddData(data.get()); HttpNetworkTransaction* trans = helper.trans(); - TestOldCompletionCallback callback; - int rv = trans->Start(&CreateGetRequest(), &callback, BoundNetLog()); + TestCompletionCallback callback; + int rv = trans->Start( + &CreateGetRequest(), callback.callback(), BoundNetLog()); EXPECT_EQ(ERR_IO_PENDING, rv); TransactionHelperResult out = helper.output(); @@ -3987,7 +3989,7 @@ TEST_P(SpdyNetworkTransactionTest, BufferedAll) { out.response_info = *response; // Make a copy so we can verify. // Read Data - TestOldCompletionCallback read_callback; + TestCompletionCallback read_callback; std::string content; int reads_completed = 0; @@ -3995,7 +3997,7 @@ TEST_P(SpdyNetworkTransactionTest, BufferedAll) { // Read small chunks at a time. const int kSmallReadSize = 14; scoped_refptr<net::IOBuffer> buf(new net::IOBuffer(kSmallReadSize)); - rv = trans->Read(buf, kSmallReadSize, &read_callback); + rv = trans->Read(buf, kSmallReadSize, read_callback.callback()); if (rv > 0) { EXPECT_EQ(kSmallReadSize, rv); content.append(buf->data(), rv); @@ -4060,9 +4062,10 @@ TEST_P(SpdyNetworkTransactionTest, BufferedClosed) { helper.AddData(data.get()); HttpNetworkTransaction* trans = helper.trans(); - TestOldCompletionCallback callback; + TestCompletionCallback callback; - int rv = trans->Start(&CreateGetRequest(), &callback, BoundNetLog()); + int rv = trans->Start( + &CreateGetRequest(), callback.callback(), BoundNetLog()); EXPECT_EQ(ERR_IO_PENDING, rv); TransactionHelperResult out = helper.output(); @@ -4076,7 +4079,7 @@ TEST_P(SpdyNetworkTransactionTest, BufferedClosed) { out.response_info = *response; // Make a copy so we can verify. // Read Data - TestOldCompletionCallback read_callback; + TestCompletionCallback read_callback; std::string content; int reads_completed = 0; @@ -4084,7 +4087,7 @@ TEST_P(SpdyNetworkTransactionTest, BufferedClosed) { // Read small chunks at a time. const int kSmallReadSize = 14; scoped_refptr<net::IOBuffer> buf(new net::IOBuffer(kSmallReadSize)); - rv = trans->Read(buf, kSmallReadSize, &read_callback); + rv = trans->Read(buf, kSmallReadSize, read_callback.callback()); if (rv == net::ERR_IO_PENDING) { data->CompleteRead(); rv = read_callback.WaitForResult(); @@ -4139,9 +4142,10 @@ TEST_P(SpdyNetworkTransactionTest, BufferedCancelled) { helper.RunPreTestSetup(); helper.AddData(data.get()); HttpNetworkTransaction* trans = helper.trans(); - TestOldCompletionCallback callback; + TestCompletionCallback callback; - int rv = trans->Start(&CreateGetRequest(), &callback, BoundNetLog()); + int rv = trans->Start( + &CreateGetRequest(), callback.callback(), BoundNetLog()); EXPECT_EQ(ERR_IO_PENDING, rv); TransactionHelperResult out = helper.output(); @@ -4155,12 +4159,12 @@ TEST_P(SpdyNetworkTransactionTest, BufferedCancelled) { out.response_info = *response; // Make a copy so we can verify. // Read Data - TestOldCompletionCallback read_callback; + TestCompletionCallback read_callback; do { const int kReadSize = 256; scoped_refptr<net::IOBuffer> buf(new net::IOBuffer(kReadSize)); - rv = trans->Read(buf, kReadSize, &read_callback); + rv = trans->Read(buf, kReadSize, read_callback.callback()); if (rv == net::ERR_IO_PENDING) { // Complete the read now, which causes buffering to start. data->CompleteRead(); @@ -4451,9 +4455,9 @@ TEST_P(SpdyNetworkTransactionTest, CloseWithActiveStream) { helper.AddData(data.get()); HttpNetworkTransaction* trans = helper.trans(); - TestOldCompletionCallback callback; + TestCompletionCallback callback; TransactionHelperResult out; - out.rv = trans->Start(&CreateGetRequest(), &callback, log); + out.rv = trans->Start(&CreateGetRequest(), callback.callback(), log); EXPECT_EQ(out.rv, ERR_IO_PENDING); out.rv = callback.WaitForResult(); @@ -4544,9 +4548,10 @@ TEST_P(SpdyNetworkTransactionTest, ProxyConnect) { } helper.AddData(data.get()); - TestOldCompletionCallback callback; + TestCompletionCallback callback; - int rv = trans->Start(&CreateGetRequest(), &callback, BoundNetLog()); + int rv = trans->Start( + &CreateGetRequest(), callback.callback(), BoundNetLog()); EXPECT_EQ(ERR_IO_PENDING, rv); rv = callback.WaitForResult(); @@ -4604,9 +4609,10 @@ TEST_P(SpdyNetworkTransactionTest, DirectConnectProxyReconnect) { helper.AddData(data.get()); HttpNetworkTransaction* trans = helper.trans(); - TestOldCompletionCallback callback; + TestCompletionCallback callback; TransactionHelperResult out; - out.rv = trans->Start(&CreateGetRequest(), &callback, BoundNetLog()); + out.rv = trans->Start( + &CreateGetRequest(), callback.callback(), BoundNetLog()); EXPECT_EQ(out.rv, ERR_IO_PENDING); out.rv = callback.WaitForResult(); @@ -4720,8 +4726,9 @@ TEST_P(SpdyNetworkTransactionTest, DirectConnectProxyReconnect) { helper_proxy.AddData(data_proxy.get()); HttpNetworkTransaction* trans_proxy = helper_proxy.trans(); - TestOldCompletionCallback callback_proxy; - int rv = trans_proxy->Start(&request_proxy, &callback_proxy, BoundNetLog()); + TestCompletionCallback callback_proxy; + int rv = trans_proxy->Start( + &request_proxy, callback_proxy.callback(), BoundNetLog()); EXPECT_EQ(ERR_IO_PENDING, rv); rv = callback_proxy.WaitForResult(); EXPECT_EQ(0, rv); @@ -4788,8 +4795,9 @@ TEST_P(SpdyNetworkTransactionTest, VerifyRetryOnConnectionReset) { scoped_ptr<HttpNetworkTransaction> trans( new HttpNetworkTransaction(helper.session())); - TestOldCompletionCallback callback; - int rv = trans->Start(&helper.request(), &callback, BoundNetLog()); + TestCompletionCallback callback; + int rv = trans->Start( + &helper.request(), callback.callback(), BoundNetLog()); EXPECT_EQ(ERR_IO_PENDING, rv); // On the second transaction, we trigger the RST. if (i == 1) { @@ -4926,10 +4934,10 @@ TEST_P(SpdyNetworkTransactionTest, SpdyBasicAuth) { helper.RunPreTestSetup(); helper.AddData(data.get()); HttpNetworkTransaction* trans = helper.trans(); - TestOldCompletionCallback callback_start; - const int rv_start = trans->Start(&request, &callback_start, net_log); + TestCompletionCallback callback; + const int rv_start = trans->Start(&request, callback.callback(), net_log); EXPECT_EQ(ERR_IO_PENDING, rv_start); - const int rv_start_complete = callback_start.WaitForResult(); + const int rv_start_complete = callback.WaitForResult(); EXPECT_EQ(OK, rv_start_complete); // Make sure the response has an auth challenge. @@ -4946,8 +4954,9 @@ TEST_P(SpdyNetworkTransactionTest, SpdyBasicAuth) { // Restart with a username/password. AuthCredentials credentials(ASCIIToUTF16("foo"), ASCIIToUTF16("bar")); - TestOldCompletionCallback callback_restart; - const int rv_restart = trans->RestartWithAuth(credentials, &callback_restart); + TestCompletionCallback callback_restart; + const int rv_restart = trans->RestartWithAuth( + credentials, callback_restart.callback()); EXPECT_EQ(ERR_IO_PENDING, rv_restart); const int rv_restart_complete = callback_restart.WaitForResult(); EXPECT_EQ(OK, rv_restart_complete); @@ -5128,8 +5137,9 @@ TEST_P(SpdyNetworkTransactionTest, ServerPushClaimBeforeHeaders) { data->SetStop(3); // Start the transaction. - TestOldCompletionCallback callback; - int rv = trans->Start(&CreateGetRequest(), &callback, BoundNetLog()); + TestCompletionCallback callback; + int rv = trans->Start( + &CreateGetRequest(), callback.callback(), BoundNetLog()); EXPECT_EQ(ERR_IO_PENDING, rv); data->Run(); rv = callback.WaitForResult(); @@ -5139,7 +5149,8 @@ TEST_P(SpdyNetworkTransactionTest, ServerPushClaimBeforeHeaders) { // headers are not yet complete. scoped_ptr<HttpNetworkTransaction> trans2( new HttpNetworkTransaction(helper.session())); - rv = trans2->Start(&CreateGetPushRequest(), &callback, BoundNetLog()); + rv = trans2->Start( + &CreateGetPushRequest(), callback.callback(), BoundNetLog()); EXPECT_EQ(ERR_IO_PENDING, rv); data->RunFor(3); MessageLoop::current()->RunAllPending(); @@ -5277,8 +5288,9 @@ TEST_P(SpdyNetworkTransactionTest, ServerPushWithTwoHeaderFrames) { data->SetStop(4); // Start the transaction. - TestOldCompletionCallback callback; - int rv = trans->Start(&CreateGetRequest(), &callback, BoundNetLog()); + TestCompletionCallback callback; + int rv = trans->Start( + &CreateGetRequest(), callback.callback(), BoundNetLog()); EXPECT_EQ(ERR_IO_PENDING, rv); data->Run(); rv = callback.WaitForResult(); @@ -5288,7 +5300,8 @@ TEST_P(SpdyNetworkTransactionTest, ServerPushWithTwoHeaderFrames) { // headers are not yet complete. scoped_ptr<HttpNetworkTransaction> trans2( new HttpNetworkTransaction(helper.session())); - rv = trans2->Start(&CreateGetPushRequest(), &callback, BoundNetLog()); + rv = trans2->Start( + &CreateGetPushRequest(), callback.callback(), BoundNetLog()); EXPECT_EQ(ERR_IO_PENDING, rv); data->RunFor(3); MessageLoop::current()->RunAllPending(); @@ -5591,9 +5604,9 @@ TEST_P(SpdyNetworkTransactionTest, ServerPushCrossOriginCorrectness) { HttpNetworkTransaction* trans = helper.trans(); // Start the transaction with basic parameters. - TestOldCompletionCallback callback; + TestCompletionCallback callback; - int rv = trans->Start(&request, &callback, BoundNetLog()); + int rv = trans->Start(&request, callback.callback(), BoundNetLog()); EXPECT_EQ(ERR_IO_PENDING, rv); rv = callback.WaitForResult(); @@ -5649,8 +5662,9 @@ TEST_P(SpdyNetworkTransactionTest, RetryAfterRefused) { HttpNetworkTransaction* trans = helper.trans(); // Start the transaction with basic parameters. - TestOldCompletionCallback callback; - int rv = trans->Start(&CreateGetRequest(), &callback, BoundNetLog()); + TestCompletionCallback callback; + int rv = trans->Start( + &CreateGetRequest(), callback.callback(), BoundNetLog()); EXPECT_EQ(ERR_IO_PENDING, rv); rv = callback.WaitForResult(); EXPECT_EQ(OK, rv); diff --git a/net/spdy/spdy_proxy_client_socket.cc b/net/spdy/spdy_proxy_client_socket.cc index 22b63d4..7267fef 100644 --- a/net/spdy/spdy_proxy_client_socket.cc +++ b/net/spdy/spdy_proxy_client_socket.cc @@ -6,6 +6,8 @@ #include <algorithm> // min +#include "base/bind.h" +#include "base/bind_helpers.h" #include "base/logging.h" #include "base/string_util.h" #include "googleurl/src/gurl.h" @@ -29,9 +31,7 @@ SpdyProxyClientSocket::SpdyProxyClientSocket( const HostPortPair& proxy_server, HttpAuthCache* auth_cache, HttpAuthHandlerFactory* auth_handler_factory) - : ALLOW_THIS_IN_INITIALIZER_LIST( - io_callback_(this, &SpdyProxyClientSocket::OnIOComplete)), - next_state_(STATE_DISCONNECTED), + : next_state_(STATE_DISCONNECTED), spdy_stream_(spdy_stream), endpoint_(endpoint), auth_( @@ -304,7 +304,10 @@ int SpdyProxyClientSocket::DoLoop(int last_io_result) { int SpdyProxyClientSocket::DoGenerateAuthToken() { next_state_ = STATE_GENERATE_AUTH_TOKEN_COMPLETE; - return auth_->MaybeGenerateAuthToken(&request_, &io_callback_, net_log_); + return auth_->MaybeGenerateAuthToken( + &request_, + base::Bind(&SpdyProxyClientSocket::OnIOComplete, base::Unretained(this)), + net_log_); } int SpdyProxyClientSocket::DoGenerateAuthTokenComplete(int result) { diff --git a/net/spdy/spdy_proxy_client_socket.h b/net/spdy/spdy_proxy_client_socket.h index 2d594f1..b969499 100644 --- a/net/spdy/spdy_proxy_client_socket.h +++ b/net/spdy/spdy_proxy_client_socket.h @@ -128,7 +128,6 @@ class NET_EXPORT_PRIVATE SpdyProxyClientSocket : public ProxyClientSocket, // and returns the number of bytes read. int PopulateUserReadBuffer(); - OldCompletionCallbackImpl<SpdyProxyClientSocket> io_callback_; State next_state_; // Pointer to the SPDY Stream that this sits on top of. diff --git a/net/spdy/spdy_proxy_client_socket_unittest.cc b/net/spdy/spdy_proxy_client_socket_unittest.cc index 5ae0271..1357b7d 100644 --- a/net/spdy/spdy_proxy_client_socket_unittest.cc +++ b/net/spdy/spdy_proxy_client_socket_unittest.cc @@ -4,6 +4,8 @@ #include "net/spdy/spdy_proxy_client_socket.h" +#include "base/bind.h" +#include "base/bind_helpers.h" #include "base/utf_string_conversions.h" #include "net/base/address_list.h" #include "net/base/net_log.h" @@ -100,7 +102,6 @@ class SpdyProxyClientSocketTest : public PlatformTest { scoped_ptr<SpdyProxyClientSocket> sock_; TestCompletionCallback read_callback_; - TestOldCompletionCallback read_callback_old_; TestCompletionCallback write_callback_; scoped_refptr<DeterministicSocketData> data_; @@ -192,7 +193,7 @@ void SpdyProxyClientSocketTest::Initialize(MockRead* reads, ASSERT_EQ( OK, spdy_session_->CreateStream(url_, LOWEST, &spdy_stream_, BoundNetLog(), - NULL)); + CompletionCallback())); // Create the SpdyProxyClientSocket sock_.reset( @@ -864,7 +865,7 @@ TEST_F(SpdyProxyClientSocketTest, ReadErrorResponseBody) { sock_->Read(NULL, 1, CompletionCallback())); scoped_refptr<IOBuffer> buf(new IOBuffer(kLen1 + kLen2)); scoped_ptr<HttpStream> stream(sock_->CreateConnectResponseStream()); - stream->ReadResponseBody(buf, kLen1 + kLen2, &read_callback_old_); + stream->ReadResponseBody(buf, kLen1 + kLen2, read_callback_.callback()); } // ----------- Reads and Writes @@ -1230,22 +1231,30 @@ TEST_F(SpdyProxyClientSocketTest, RstWithReadAndWritePending) { // CompletionCallback that causes the SpdyProxyClientSocket to be // deleted when Run is invoked. -class DeleteSockCallback : public TestOldCompletionCallback { +class DeleteSockCallback : public TestCompletionCallbackBase { public: explicit DeleteSockCallback(scoped_ptr<SpdyProxyClientSocket>* sock) - : sock_(sock) { + : sock_(sock), + ALLOW_THIS_IN_INITIALIZER_LIST(callback_( + base::Bind(&DeleteSockCallback::OnComplete, + base::Unretained(this)))) { } virtual ~DeleteSockCallback() { } - virtual void RunWithParams(const Tuple1<int>& params) OVERRIDE { + const CompletionCallback& callback() const { return callback_; } + + private: + void OnComplete(int result) { sock_->reset(NULL); - TestOldCompletionCallback::RunWithParams(params); + SetResult(result); } - private: scoped_ptr<SpdyProxyClientSocket>* sock_; + CompletionCallback callback_; + + DISALLOW_COPY_AND_ASSIGN(DeleteSockCallback); }; // If the socket is Reset when both a read and write are pending, and the @@ -1275,9 +1284,7 @@ TEST_F(SpdyProxyClientSocketTest, RstWithReadAndWritePendingDelete) { scoped_refptr<IOBuffer> read_buf(new IOBuffer(kLen1)); ASSERT_EQ(ERR_IO_PENDING, - sock_->Read(read_buf, kLen1, - base::Bind(&OldCompletionCallbackAdapter, - &read_callback))); + sock_->Read(read_buf, kLen1, read_callback.callback())); scoped_refptr<IOBufferWithSize> write_buf(CreateBuffer(kMsg1, kLen1)); EXPECT_EQ(ERR_IO_PENDING, sock_->Write(write_buf, write_buf->size(), diff --git a/net/spdy/spdy_session.cc b/net/spdy/spdy_session.cc index b3a883b..596d569 100644 --- a/net/spdy/spdy_session.cc +++ b/net/spdy/spdy_session.cc @@ -300,6 +300,10 @@ SpdySession::SpdySession(const HostPortProxyPair& host_port_proxy_pair, SendSettings(); } +SpdySession::PendingCreateStream::~PendingCreateStream() {} + +SpdySession::CallbackResultPair::~CallbackResultPair() {} + SpdySession::~SpdySession() { if (state_ != CLOSED) { state_ = CLOSED; @@ -402,7 +406,7 @@ int SpdySession::CreateStream( RequestPriority priority, scoped_refptr<SpdyStream>* spdy_stream, const BoundNetLog& stream_net_log, - OldCompletionCallback* callback) { + const CompletionCallback& callback) { if (!max_concurrent_streams_ || active_streams_.size() < max_concurrent_streams_) { return CreateStreamImpl(url, priority, spdy_stream, stream_net_log); @@ -892,7 +896,7 @@ void SpdySession::CloseAllStreams(net::Error status) { while (!create_stream_queues_[i].empty()) { PendingCreateStream pending_create = create_stream_queues_[i].front(); create_stream_queues_[i].pop(); - pending_create.callback->Run(ERR_ABORTED); + pending_create.callback.Run(ERR_ABORTED); } } @@ -1770,10 +1774,10 @@ void SpdySession::InvokeUserStreamCreationCallback( if (it == pending_callback_map_.end()) return; - OldCompletionCallback* callback = it->second.callback; + CompletionCallback callback = it->second.callback; int result = it->second.result; pending_callback_map_.erase(it); - callback->Run(result); + callback.Run(result); } } // namespace net diff --git a/net/spdy/spdy_session.h b/net/spdy/spdy_session.h index d79603a..139b6ef 100644 --- a/net/spdy/spdy_session.h +++ b/net/spdy/spdy_session.h @@ -86,7 +86,7 @@ class NET_EXPORT SpdySession : public base::RefCounted<SpdySession>, RequestPriority priority, scoped_refptr<SpdyStream>* spdy_stream, const BoundNetLog& stream_net_log, - OldCompletionCallback* callback); + const CompletionCallback& callback); // Remove PendingCreateStream objects on transaction deletion void CancelPendingCreateStreams(const scoped_refptr<SpdyStream>* spdy_stream); @@ -237,11 +237,12 @@ class NET_EXPORT SpdySession : public base::RefCounted<SpdySession>, int GetPeerAddress(AddressList* address) const; int GetLocalAddress(IPEndPoint* address) const; - // LayeredPool methods: + // LayeredPool implementation. virtual bool CloseOneIdleConnection() OVERRIDE; private: friend class base::RefCounted<SpdySession>; + // Allow tests to access our innards for testing purposes. FRIEND_TEST_ALL_PREFIXES(SpdySessionTest, Ping); FRIEND_TEST_ALL_PREFIXES(SpdySessionTest, FailedPing); @@ -251,15 +252,19 @@ class NET_EXPORT SpdySession : public base::RefCounted<SpdySession>, PendingCreateStream(const GURL& url, RequestPriority priority, scoped_refptr<SpdyStream>* spdy_stream, const BoundNetLog& stream_net_log, - OldCompletionCallback* callback) - : url(&url), priority(priority), spdy_stream(spdy_stream), - stream_net_log(&stream_net_log), callback(callback) { } + const CompletionCallback& callback) + : url(&url), + priority(priority), + spdy_stream(spdy_stream), + stream_net_log(&stream_net_log), + callback(callback) {} + ~PendingCreateStream(); const GURL* url; RequestPriority priority; scoped_refptr<SpdyStream>* spdy_stream; const BoundNetLog* stream_net_log; - OldCompletionCallback* callback; + CompletionCallback callback; }; typedef std::queue<PendingCreateStream, std::list< PendingCreateStream> > PendingCreateStreamQueue; @@ -270,10 +275,11 @@ class NET_EXPORT SpdySession : public base::RefCounted<SpdySession>, struct CallbackResultPair { CallbackResultPair() : result(OK) {} - CallbackResultPair(OldCompletionCallback* callback_in, int result_in) + CallbackResultPair(const CompletionCallback& callback_in, int result_in) : callback(callback_in), result(result_in) {} + ~CallbackResultPair(); - OldCompletionCallback* callback; + CompletionCallback callback; int result; }; diff --git a/net/spdy/spdy_session_unittest.cc b/net/spdy/spdy_session_unittest.cc index 5aaf6bd..fbacb02 100644 --- a/net/spdy/spdy_session_unittest.cc +++ b/net/spdy/spdy_session_unittest.cc @@ -29,7 +29,7 @@ class SpdySessionTest : public PlatformTest { class TestSpdyStreamDelegate : public net::SpdyStream::Delegate { public: - explicit TestSpdyStreamDelegate(OldCompletionCallback* callback) + explicit TestSpdyStreamDelegate(const CompletionCallback& callback) : callback_(callback) {} virtual ~TestSpdyStreamDelegate() {} @@ -56,18 +56,17 @@ class TestSpdyStreamDelegate : public net::SpdyStream::Delegate { } virtual void OnClose(int status) { - OldCompletionCallback* callback = callback_; - callback_ = NULL; - callback->Run(OK); + CompletionCallback callback = callback_; + callback_.Reset(); + callback.Run(OK); } virtual void set_chunk_callback(net::ChunkCallback *) {} private: - OldCompletionCallback* callback_; + CompletionCallback callback_; }; - // Test the SpdyIOBuffer class. TEST_F(SpdySessionTest, SpdyIOBuffer) { std::priority_queue<SpdyIOBuffer> queue_; @@ -219,14 +218,14 @@ TEST_F(SpdySessionTest, Ping) { EXPECT_EQ(OK, session->InitializeWithSocket(connection.release(), false, OK)); scoped_refptr<SpdyStream> spdy_stream1; - TestOldCompletionCallback callback1; + TestCompletionCallback callback1; EXPECT_EQ(OK, session->CreateStream(url, MEDIUM, &spdy_stream1, BoundNetLog(), - &callback1)); + callback1.callback())); scoped_ptr<TestSpdyStreamDelegate> delegate( - new TestSpdyStreamDelegate(&callback1)); + new TestSpdyStreamDelegate(callback1.callback())); spdy_stream1->SetDelegate(delegate.get()); base::TimeTicks before_ping_time = base::TimeTicks::Now(); @@ -307,14 +306,14 @@ TEST_F(SpdySessionTest, FailedPing) { EXPECT_EQ(OK, session->InitializeWithSocket(connection.release(), false, OK)); scoped_refptr<SpdyStream> spdy_stream1; - TestOldCompletionCallback callback1; + TestCompletionCallback callback1; EXPECT_EQ(OK, session->CreateStream(url, MEDIUM, &spdy_stream1, BoundNetLog(), - &callback1)); + callback1.callback())); scoped_ptr<TestSpdyStreamDelegate> delegate( - new TestSpdyStreamDelegate(&callback1)); + new TestSpdyStreamDelegate(callback1.callback())); spdy_stream1->SetDelegate(delegate.get()); // Enable sending of PING. @@ -349,32 +348,38 @@ TEST_F(SpdySessionTest, FailedPing) { session = NULL; } -class StreamReleaserCallback : public CallbackRunner<Tuple1<int> > { +class StreamReleaserCallback : public TestCompletionCallbackBase { public: StreamReleaserCallback(SpdySession* session, SpdyStream* first_stream) - : session_(session), first_stream_(first_stream) {} - ~StreamReleaserCallback() {} + : session_(session), + first_stream_(first_stream), + ALLOW_THIS_IN_INITIALIZER_LIST(callback_( + base::Bind(&StreamReleaserCallback::OnComplete, + base::Unretained(this)))) { + } - int WaitForResult() { return callback_.WaitForResult(); } + virtual ~StreamReleaserCallback() {} + + scoped_refptr<SpdyStream>* stream() { return &stream_; } - virtual void RunWithParams(const Tuple1<int>& params) { + const CompletionCallback& callback() const { return callback_; } + + private: + void OnComplete(int result) { session_->CloseSessionOnError(ERR_FAILED, false); session_ = NULL; first_stream_->Cancel(); first_stream_ = NULL; stream_->Cancel(); stream_ = NULL; - callback_.RunWithParams(params); + SetResult(result); } - scoped_refptr<SpdyStream>* stream() { return &stream_; } - - private: scoped_refptr<SpdySession> session_; scoped_refptr<SpdyStream> first_stream_; scoped_refptr<SpdyStream> stream_; - TestOldCompletionCallback callback_; + CompletionCallback callback_; }; // TODO(kristianm): Could also test with more sessions where some are idle, @@ -392,13 +397,13 @@ TEST_F(SpdySessionTest, CloseIdleSessions) { scoped_refptr<SpdySession> session1 = spdy_session_pool->Get(pair1, BoundNetLog()); scoped_refptr<SpdyStream> spdy_stream1; - TestOldCompletionCallback callback1; + TestCompletionCallback callback1; GURL url1(kTestHost1); EXPECT_EQ(OK, session1->CreateStream(url1, MEDIUM, /* priority, not important */ &spdy_stream1, BoundNetLog(), - &callback1)); + callback1.callback())); // Set up session 2 const std::string kTestHost2("http://www.b.com"); @@ -407,13 +412,11 @@ TEST_F(SpdySessionTest, CloseIdleSessions) { scoped_refptr<SpdySession> session2 = spdy_session_pool->Get(pair2, BoundNetLog()); scoped_refptr<SpdyStream> spdy_stream2; - TestOldCompletionCallback callback2; + TestCompletionCallback callback2; GURL url2(kTestHost2); - EXPECT_EQ(OK, session2->CreateStream(url2, - MEDIUM, /* priority, not important */ - &spdy_stream2, - BoundNetLog(), - &callback2)); + EXPECT_EQ(OK, session2->CreateStream( + url2, MEDIUM, /* priority, not important */ + &spdy_stream2, BoundNetLog(), callback2.callback())); // Set up session 3 const std::string kTestHost3("http://www.c.com"); @@ -422,13 +425,11 @@ TEST_F(SpdySessionTest, CloseIdleSessions) { scoped_refptr<SpdySession> session3 = spdy_session_pool->Get(pair3, BoundNetLog()); scoped_refptr<SpdyStream> spdy_stream3; - TestOldCompletionCallback callback3; + TestCompletionCallback callback3; GURL url3(kTestHost3); - EXPECT_EQ(OK, session3->CreateStream(url3, - MEDIUM, /* priority, not important */ - &spdy_stream3, - BoundNetLog(), - &callback3)); + EXPECT_EQ(OK, session3->CreateStream( + url3, MEDIUM, /* priority, not important */ + &spdy_stream3, BoundNetLog(), callback3.callback())); // All sessions are active and not closed EXPECT_TRUE(session1->is_active()); @@ -551,14 +552,14 @@ TEST_F(SpdySessionTest, OnSettings) { // Create 2 streams. First will succeed. Second will be pending. scoped_refptr<SpdyStream> spdy_stream1; - TestOldCompletionCallback callback1; + TestCompletionCallback callback1; GURL url("http://www.google.com"); EXPECT_EQ(OK, session->CreateStream(url, MEDIUM, /* priority, not important */ &spdy_stream1, BoundNetLog(), - &callback1)); + callback1.callback())); StreamReleaserCallback stream_releaser(session, spdy_stream1); @@ -567,7 +568,7 @@ TEST_F(SpdySessionTest, OnSettings) { MEDIUM, /* priority, not important */ stream_releaser.stream(), BoundNetLog(), - &stream_releaser)); + stream_releaser.callback())); // Make sure |stream_releaser| holds the last refs. session = NULL; @@ -635,7 +636,7 @@ TEST_F(SpdySessionTest, CancelPendingCreateStream) { // Use scoped_ptr to let us invalidate the memory when we want to, to trigger // a valgrind error if the callback is invoked when it's not supposed to be. - scoped_ptr<TestOldCompletionCallback> callback(new TestOldCompletionCallback); + scoped_ptr<TestCompletionCallback> callback(new TestCompletionCallback); // Create 2 streams. First will succeed. Second will be pending. scoped_refptr<SpdyStream> spdy_stream1; @@ -645,7 +646,7 @@ TEST_F(SpdySessionTest, CancelPendingCreateStream) { MEDIUM, /* priority, not important */ &spdy_stream1, BoundNetLog(), - callback.get())); + callback->callback())); scoped_refptr<SpdyStream> spdy_stream2; ASSERT_EQ(ERR_IO_PENDING, @@ -653,7 +654,7 @@ TEST_F(SpdySessionTest, CancelPendingCreateStream) { MEDIUM, /* priority, not important */ &spdy_stream2, BoundNetLog(), - callback.get())); + callback->callback())); // Release the first one, this will allow the second to be created. spdy_stream1->Cancel(); diff --git a/net/spdy/spdy_stream_unittest.cc b/net/spdy/spdy_stream_unittest.cc index 4ebe693..bb47dce 100644 --- a/net/spdy/spdy_stream_unittest.cc +++ b/net/spdy/spdy_stream_unittest.cc @@ -196,7 +196,8 @@ TEST_F(SpdyStreamTest, SendDataAfterOpen) { scoped_refptr<SpdyStream> stream; ASSERT_EQ( OK, - session->CreateStream(url, LOWEST, &stream, BoundNetLog(), NULL)); + session->CreateStream(url, LOWEST, &stream, BoundNetLog(), + CompletionCallback())); scoped_refptr<IOBufferWithSize> buf(new IOBufferWithSize(8)); memcpy(buf->data(), "\0hello!\xff", 8); TestOldCompletionCallback callback; diff --git a/net/spdy/spdy_websocket_stream.cc b/net/spdy/spdy_websocket_stream.cc index fcbb31e..0ea15c5 100644 --- a/net/spdy/spdy_websocket_stream.cc +++ b/net/spdy/spdy_websocket_stream.cc @@ -4,6 +4,8 @@ #include "net/spdy/spdy_websocket_stream.h" +#include "base/bind.h" +#include "base/bind_helpers.h" #include "googleurl/src/gurl.h" #include "net/base/net_errors.h" #include "net/base/io_buffer.h" @@ -18,9 +20,7 @@ SpdyWebSocketStream::SpdyWebSocketStream( SpdySession* spdy_session, Delegate* delegate) : stream_(NULL), spdy_session_(spdy_session), - delegate_(delegate), - ALLOW_THIS_IN_INITIALIZER_LIST(spdy_stream_created_callback_( - this, &SpdyWebSocketStream::OnSpdyStreamCreated)) { + delegate_(delegate) { DCHECK(spdy_session_); DCHECK(delegate_); } @@ -44,7 +44,8 @@ int SpdyWebSocketStream::InitializeStream(const GURL& url, int result = spdy_session_->CreateStream( url, request_priority, &stream_, net_log, - &spdy_stream_created_callback_); + base::Bind(&SpdyWebSocketStream::OnSpdyStreamCreated, + base::Unretained(this))); if (result == OK) { DCHECK(stream_); diff --git a/net/spdy/spdy_websocket_stream.h b/net/spdy/spdy_websocket_stream.h index 1f0839e..d39c97c 100644 --- a/net/spdy/spdy_websocket_stream.h +++ b/net/spdy/spdy_websocket_stream.h @@ -89,8 +89,6 @@ class NET_EXPORT_PRIVATE SpdyWebSocketStream scoped_refptr<SpdySession> spdy_session_; Delegate* delegate_; - OldCompletionCallbackImpl<SpdyWebSocketStream> spdy_stream_created_callback_; - DISALLOW_COPY_AND_ASSIGN(SpdyWebSocketStream); }; |