diff options
author | yutak@chromium.org <yutak@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-12-01 06:47:32 +0000 |
---|---|---|
committer | yutak@chromium.org <yutak@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-12-01 06:47:32 +0000 |
commit | 056df82a008ff3120c4fda5d84b0fbc645fd73e0 (patch) | |
tree | f808bd7db875ea06fd067d28b4244e954f2fb1e1 /net/socket_stream | |
parent | 41517b9911563e2a62647aba006118a2b9757718 (diff) | |
download | chromium_src-056df82a008ff3120c4fda5d84b0fbc645fd73e0.zip chromium_src-056df82a008ff3120c4fda5d84b0fbc645fd73e0.tar.gz chromium_src-056df82a008ff3120c4fda5d84b0fbc645fd73e0.tar.bz2 |
Replace OldCompletionCallback in SocketStream::Delegate.
BUG=105683
TEST=none
Review URL: http://codereview.chromium.org/8747013
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@112414 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net/socket_stream')
-rw-r--r-- | net/socket_stream/socket_stream.cc | 33 | ||||
-rw-r--r-- | net/socket_stream/socket_stream.h | 9 | ||||
-rw-r--r-- | net/socket_stream/socket_stream_unittest.cc | 36 |
3 files changed, 43 insertions, 35 deletions
diff --git a/net/socket_stream/socket_stream.cc b/net/socket_stream/socket_stream.cc index 254935a..e948570 100644 --- a/net/socket_stream/socket_stream.cc +++ b/net/socket_stream/socket_stream.cc @@ -10,6 +10,8 @@ #include <set> #include <string> +#include "base/bind.h" +#include "base/bind_helpers.h" #include "base/compiler_specific.h" #include "base/logging.h" #include "base/message_loop.h" @@ -62,12 +64,17 @@ SocketStream::SocketStream(const GURL& url, Delegate* delegate) proxy_mode_(kDirectConnection), proxy_url_(url), pac_request_(NULL), + // Unretained() is required; without it, Bind() creates a circular + // dependency and the SocketStream object will not be freed. ALLOW_THIS_IN_INITIALIZER_LIST( - io_callback_(this, &SocketStream::OnIOCompleted)), + io_callback_(base::Bind(&SocketStream::OnIOCompleted, + base::Unretained(this)))), ALLOW_THIS_IN_INITIALIZER_LIST( - read_callback_(this, &SocketStream::OnReadCompleted)), + io_callback_old_(this, &SocketStream::OnIOCompleted)), ALLOW_THIS_IN_INITIALIZER_LIST( - write_callback_(this, &SocketStream::OnWriteCompleted)), + read_callback_old_(this, &SocketStream::OnReadCompleted)), + ALLOW_THIS_IN_INITIALIZER_LIST( + write_callback_old_(this, &SocketStream::OnWriteCompleted)), read_buf_(NULL), write_buf_(NULL), current_write_buf_(NULL), @@ -548,7 +555,7 @@ int SocketStream::DoResolveProxy() { // Alternate-Protocol header here for ws:// or TLS NPN extension for wss:// . return proxy_service()->ResolveProxy( - proxy_url_, &proxy_info_, &io_callback_, &pac_request_, net_log_); + proxy_url_, &proxy_info_, &io_callback_old_, &pac_request_, net_log_); } int SocketStream::DoResolveProxyComplete(int result) { @@ -625,7 +632,7 @@ int SocketStream::DoResolveHostComplete(int result) { int SocketStream::DoResolveProtocol(int result) { DCHECK_EQ(OK, result); next_state_ = STATE_RESOLVE_PROTOCOL_COMPLETE; - result = delegate_->OnStartOpenConnection(this, &io_callback_); + result = delegate_->OnStartOpenConnection(this, io_callback_); if (result == ERR_IO_PENDING) metrics_->OnWaitConnection(); else if (result != OK && result != ERR_PROTOCOL_SWITCHED) @@ -661,7 +668,7 @@ int SocketStream::DoTcpConnect(int result) { net_log_.net_log(), net_log_.source())); metrics_->OnStartConnection(); - return socket_->Connect(&io_callback_); + return socket_->Connect(&io_callback_old_); } int SocketStream::DoTcpConnectComplete(int result) { @@ -754,7 +761,7 @@ int SocketStream::DoWriteTunnelHeaders() { int buf_len = static_cast<int>(tunnel_request_headers_->headers_.size() - tunnel_request_headers_bytes_sent_); DCHECK_GT(buf_len, 0); - return socket_->Write(tunnel_request_headers_, buf_len, &io_callback_); + return socket_->Write(tunnel_request_headers_, buf_len, &io_callback_old_); } int SocketStream::DoWriteTunnelHeadersComplete(int result) { @@ -791,7 +798,7 @@ int SocketStream::DoReadTunnelHeaders() { tunnel_response_headers_->SetDataOffset(tunnel_response_headers_len_); CHECK(tunnel_response_headers_->data()); - return socket_->Read(tunnel_response_headers_, buf_len, &io_callback_); + return socket_->Read(tunnel_response_headers_, buf_len, &io_callback_old_); } int SocketStream::DoReadTunnelHeadersComplete(int result) { @@ -888,7 +895,7 @@ int SocketStream::DoSOCKSConnect() { s = new SOCKSClientSocket(s, req_info, host_resolver_); socket_.reset(s); metrics_->OnCountConnectionType(SocketStreamMetrics::SOCKS_CONNECTION); - return socket_->Connect(&io_callback_); + return socket_->Connect(&io_callback_old_); } int SocketStream::DoSOCKSConnectComplete(int result) { @@ -919,7 +926,7 @@ int SocketStream::DoSecureProxyConnect() { ssl_context)); next_state_ = STATE_SECURE_PROXY_CONNECT_COMPLETE; metrics_->OnCountConnectionType(SocketStreamMetrics::SECURE_PROXY_CONNECTION); - return socket_->Connect(&io_callback_); + return socket_->Connect(&io_callback_old_); } int SocketStream::DoSecureProxyConnectComplete(int result) { @@ -949,7 +956,7 @@ int SocketStream::DoSSLConnect() { ssl_context)); next_state_ = STATE_SSL_CONNECT_COMPLETE; metrics_->OnCountConnectionType(SocketStreamMetrics::SSL_CONNECTION); - return socket_->Connect(&io_callback_); + return socket_->Connect(&io_callback_old_); } int SocketStream::DoSSLConnectComplete(int result) { @@ -994,7 +1001,7 @@ int SocketStream::DoReadWrite(int result) { if (!read_buf_) { // No read pending and server didn't close the socket. read_buf_ = new IOBuffer(kReadBufferSize); - result = socket_->Read(read_buf_, kReadBufferSize, &read_callback_); + result = socket_->Read(read_buf_, kReadBufferSize, &read_callback_old_); if (result > 0) { return DidReceiveData(result); } else if (result == 0) { @@ -1022,7 +1029,7 @@ int SocketStream::DoReadWrite(int result) { current_write_buf_->SetOffset(write_buf_offset_); result = socket_->Write(current_write_buf_, current_write_buf_->BytesRemaining(), - &write_callback_); + &write_callback_old_); if (result > 0) { return DidSendData(result); } diff --git a/net/socket_stream/socket_stream.h b/net/socket_stream/socket_stream.h index 9539ca6..501c44b 100644 --- a/net/socket_stream/socket_stream.h +++ b/net/socket_stream/socket_stream.h @@ -62,7 +62,7 @@ class NET_EXPORT SocketStream virtual ~Delegate() {} virtual int OnStartOpenConnection(SocketStream* socket, - OldCompletionCallback* callback) { + const CompletionCallback& callback) { return OK; } @@ -336,9 +336,10 @@ class NET_EXPORT SocketStream SSLConfig server_ssl_config_; SSLConfig proxy_ssl_config_; - OldCompletionCallbackImpl<SocketStream> io_callback_; - OldCompletionCallbackImpl<SocketStream> read_callback_; - OldCompletionCallbackImpl<SocketStream> write_callback_; + const CompletionCallback io_callback_; + OldCompletionCallbackImpl<SocketStream> io_callback_old_; + OldCompletionCallbackImpl<SocketStream> read_callback_old_; + OldCompletionCallbackImpl<SocketStream> write_callback_old_; scoped_refptr<IOBuffer> read_buf_; int read_buf_size_; diff --git a/net/socket_stream/socket_stream_unittest.cc b/net/socket_stream/socket_stream_unittest.cc index 3732498..dac85bc 100644 --- a/net/socket_stream/socket_stream_unittest.cc +++ b/net/socket_stream/socket_stream_unittest.cc @@ -32,7 +32,6 @@ struct SocketStreamEvent { int num, const std::string& str, net::AuthChallengeInfo* auth_challenge_info, - net::OldCompletionCallback* callback, int error) : event_type(type), socket(socket_stream), number(num), data(str), auth_info(auth_challenge_info), error_code(error) {} @@ -78,62 +77,63 @@ class SocketStreamEventRecorder : public net::SocketStream::Delegate { on_error_ = callback; } - virtual int OnStartOpenConnection(net::SocketStream* socket, - net::OldCompletionCallback* callback) { + virtual int OnStartOpenConnection( + net::SocketStream* socket, + const net::CompletionCallback& callback) OVERRIDE { connection_callback_ = callback; events_.push_back( SocketStreamEvent(SocketStreamEvent::EVENT_START_OPEN_CONNECTION, - socket, 0, std::string(), NULL, callback, net::OK)); + socket, 0, std::string(), NULL, net::OK)); if (!on_start_open_connection_.is_null()) return on_start_open_connection_.Run(&events_.back()); return net::OK; } virtual void OnConnected(net::SocketStream* socket, - int num_pending_send_allowed) { + int num_pending_send_allowed) OVERRIDE { events_.push_back( SocketStreamEvent(SocketStreamEvent::EVENT_CONNECTED, socket, num_pending_send_allowed, std::string(), - NULL, NULL, net::OK)); + NULL, net::OK)); if (!on_connected_.is_null()) on_connected_.Run(&events_.back()); } virtual void OnSentData(net::SocketStream* socket, - int amount_sent) { + int amount_sent) OVERRIDE { events_.push_back( SocketStreamEvent(SocketStreamEvent::EVENT_SENT_DATA, socket, - amount_sent, std::string(), NULL, NULL, net::OK)); + amount_sent, std::string(), NULL, net::OK)); if (!on_sent_data_.is_null()) on_sent_data_.Run(&events_.back()); } virtual void OnReceivedData(net::SocketStream* socket, - const char* data, int len) { + const char* data, int len) OVERRIDE { events_.push_back( SocketStreamEvent(SocketStreamEvent::EVENT_RECEIVED_DATA, socket, len, - std::string(data, len), NULL, NULL, net::OK)); + std::string(data, len), NULL, net::OK)); if (!on_received_data_.is_null()) on_received_data_.Run(&events_.back()); } - virtual void OnClose(net::SocketStream* socket) { + virtual void OnClose(net::SocketStream* socket) OVERRIDE { events_.push_back( SocketStreamEvent(SocketStreamEvent::EVENT_CLOSE, socket, 0, - std::string(), NULL, NULL, net::OK)); + std::string(), NULL, net::OK)); if (!on_close_.is_null()) on_close_.Run(&events_.back()); if (callback_) callback_->Run(net::OK); } virtual void OnAuthRequired(net::SocketStream* socket, - net::AuthChallengeInfo* auth_info) { + net::AuthChallengeInfo* auth_info) OVERRIDE { events_.push_back( SocketStreamEvent(SocketStreamEvent::EVENT_AUTH_REQUIRED, socket, 0, - std::string(), auth_info, NULL, net::OK)); + std::string(), auth_info, net::OK)); if (!on_auth_required_.is_null()) on_auth_required_.Run(&events_.back()); } - virtual void OnError(const net::SocketStream* socket, int error) { + virtual void OnError(const net::SocketStream* socket, int error) OVERRIDE { events_.push_back( SocketStreamEvent(SocketStreamEvent::EVENT_ERROR, NULL, 0, - std::string(), NULL, NULL, error)); + std::string(), NULL, error)); if (!on_error_.is_null()) on_error_.Run(&events_.back()); if (callback_) @@ -152,7 +152,7 @@ class SocketStreamEventRecorder : public net::SocketStream::Delegate { credentials_ = credentials; } void CompleteConnection(int result) { - connection_callback_->Run(result); + connection_callback_.Run(result); } const std::vector<SocketStreamEvent>& GetSeenEvents() const { @@ -169,7 +169,7 @@ class SocketStreamEventRecorder : public net::SocketStream::Delegate { base::Callback<void(SocketStreamEvent*)> on_auth_required_; base::Callback<void(SocketStreamEvent*)> on_error_; net::OldCompletionCallback* callback_; - net::OldCompletionCallback* connection_callback_; + net::CompletionCallback connection_callback_; net::AuthCredentials credentials_; DISALLOW_COPY_AND_ASSIGN(SocketStreamEventRecorder); |