diff options
author | jhawkins@chromium.org <jhawkins@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-12-09 01:06:19 +0000 |
---|---|---|
committer | jhawkins@chromium.org <jhawkins@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-12-09 01:06:19 +0000 |
commit | f749f9cee070a7a15107fa9cce6b89ad1d969bcf (patch) | |
tree | 0ecb3a7dd6daff154a8e2bf441ee097704651815 /jingle | |
parent | 4df3c1c675ded79c6c5d2f210a3131808ac93abd (diff) | |
download | chromium_src-f749f9cee070a7a15107fa9cce6b89ad1d969bcf.zip chromium_src-f749f9cee070a7a15107fa9cce6b89ad1d969bcf.tar.gz chromium_src-f749f9cee070a7a15107fa9cce6b89ad1d969bcf.tar.bz2 |
Revert 113699 - base::Bind: Convert Socket::Write.
BUG=none
TEST=none
R=csilv
Review URL: http://codereview.chromium.org/8831001
TBR=jhawkins@chromium.org
Review URL: http://codereview.chromium.org/8889036
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@113719 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'jingle')
-rw-r--r-- | jingle/glue/channel_socket_adapter.cc | 70 | ||||
-rw-r--r-- | jingle/glue/channel_socket_adapter.h | 5 | ||||
-rw-r--r-- | jingle/glue/pseudotcp_adapter.cc | 67 | ||||
-rw-r--r-- | jingle/glue/pseudotcp_adapter.h | 2 | ||||
-rw-r--r-- | jingle/glue/pseudotcp_adapter_unittest.cc | 14 | ||||
-rw-r--r-- | jingle/notifier/base/fake_ssl_client_socket.cc | 8 | ||||
-rw-r--r-- | jingle/notifier/base/fake_ssl_client_socket.h | 2 | ||||
-rw-r--r-- | jingle/notifier/base/fake_ssl_client_socket_unittest.cc | 2 | ||||
-rw-r--r-- | jingle/notifier/base/proxy_resolving_client_socket.cc | 7 | ||||
-rw-r--r-- | jingle/notifier/base/proxy_resolving_client_socket.h | 2 |
10 files changed, 25 insertions, 154 deletions
diff --git a/jingle/glue/channel_socket_adapter.cc b/jingle/glue/channel_socket_adapter.cc index 39b3eb45c..3e22a35 100644 --- a/jingle/glue/channel_socket_adapter.cc +++ b/jingle/glue/channel_socket_adapter.cc @@ -19,7 +19,7 @@ TransportChannelSocketAdapter::TransportChannelSocketAdapter( : message_loop_(MessageLoop::current()), channel_(channel), old_read_callback_(NULL), - old_write_callback_(NULL), + write_callback_(NULL), closed_error_code_(net::OK) { DCHECK(channel_); @@ -73,47 +73,11 @@ int TransportChannelSocketAdapter::Read( } int TransportChannelSocketAdapter::Write( - net::IOBuffer* buffer, int buffer_size, - net::OldCompletionCallback* callback) { + net::IOBuffer* buffer, int buffer_size, net::OldCompletionCallback* callback) { DCHECK_EQ(MessageLoop::current(), message_loop_); DCHECK(buffer); DCHECK(callback); - CHECK(!old_write_callback_ && write_callback_.is_null()); - - if (!channel_) { - DCHECK(closed_error_code_ != net::OK); - return closed_error_code_; - } - - int result; - if (channel_->writable()) { - result = channel_->SendPacket(buffer->data(), buffer_size); - if (result < 0) { - result = net::MapSystemError(channel_->GetError()); - - // If the underlying socket returns IO pending where it shouldn't we - // pretend the packet is dropped and return as succeeded because no - // writeable callback will happen. - if (result == net::ERR_IO_PENDING) - result = net::OK; - } - } else { - // Channel is not writable yet. - result = net::ERR_IO_PENDING; - old_write_callback_ = callback; - write_buffer_ = buffer; - write_buffer_size_ = buffer_size; - } - - return result; -} -int TransportChannelSocketAdapter::Write( - net::IOBuffer* buffer, int buffer_size, - const net::CompletionCallback& callback) { - DCHECK_EQ(MessageLoop::current(), message_loop_); - DCHECK(buffer); - DCHECK(!callback.is_null()); - CHECK(!old_write_callback_ && write_callback_.is_null()); + CHECK(!write_callback_); if (!channel_) { DCHECK(closed_error_code_ != net::OK); @@ -177,16 +141,11 @@ void TransportChannelSocketAdapter::Close(int error_code) { callback.Run(error_code); } - if (old_write_callback_) { - net::OldCompletionCallback* callback = old_write_callback_; - old_write_callback_ = NULL; + if (write_callback_) { + net::OldCompletionCallback* callback = write_callback_; + write_callback_ = NULL; write_buffer_ = NULL; callback->Run(error_code); - } else if (!write_callback_.is_null()) { - net::CompletionCallback callback = write_callback_; - write_callback_.Reset(); - write_buffer_ = NULL; - callback.Run(error_code); } } @@ -227,24 +186,17 @@ void TransportChannelSocketAdapter::OnWritableState( cricket::TransportChannel* channel) { DCHECK_EQ(MessageLoop::current(), message_loop_); // Try to send the packet if there is a pending write. - if (old_write_callback_ || !write_callback_.is_null()) { + if (write_callback_) { int result = channel_->SendPacket(write_buffer_->data(), write_buffer_size_); if (result < 0) result = net::MapSystemError(channel_->GetError()); if (result != net::ERR_IO_PENDING) { - if (old_write_callback_) { - net::OldCompletionCallback* callback = old_write_callback_; - old_write_callback_ = NULL; - write_buffer_ = NULL; - callback->Run(result); - } else { - net::CompletionCallback callback = write_callback_; - write_callback_.Reset(); - write_buffer_ = NULL; - callback.Run(result); - } + net::OldCompletionCallback* callback = write_callback_; + write_callback_ = NULL; + write_buffer_ = NULL; + callback->Run(result); } } } diff --git a/jingle/glue/channel_socket_adapter.h b/jingle/glue/channel_socket_adapter.h index 75af022..1f367e8 100644 --- a/jingle/glue/channel_socket_adapter.h +++ b/jingle/glue/channel_socket_adapter.h @@ -41,8 +41,6 @@ class TransportChannelSocketAdapter : public net::Socket, const net::CompletionCallback& callback) OVERRIDE; virtual int Write(net::IOBuffer* buf, int buf_len, net::OldCompletionCallback* callback) OVERRIDE; - virtual int Write(net::IOBuffer* buf, int buf_len, - const net::CompletionCallback& callback) OVERRIDE; virtual bool SetReceiveBufferSize(int32 size) OVERRIDE; virtual bool SetSendBufferSize(int32 size) OVERRIDE; @@ -62,8 +60,7 @@ class TransportChannelSocketAdapter : public net::Socket, scoped_refptr<net::IOBuffer> read_buffer_; int read_buffer_size_; - net::OldCompletionCallback* old_write_callback_; // Not owned. - net::CompletionCallback write_callback_; + net::OldCompletionCallback* write_callback_; // Not owned. scoped_refptr<net::IOBuffer> write_buffer_; int write_buffer_size_; diff --git a/jingle/glue/pseudotcp_adapter.cc b/jingle/glue/pseudotcp_adapter.cc index 84b0dcc..7807eed 100644 --- a/jingle/glue/pseudotcp_adapter.cc +++ b/jingle/glue/pseudotcp_adapter.cc @@ -35,8 +35,6 @@ class PseudoTcpAdapter::Core : public cricket::IPseudoTcpNotify, const net::CompletionCallback& callback); int Write(net::IOBuffer* buffer, int buffer_size, net::OldCompletionCallback* callback); - int Write(net::IOBuffer* buffer, int buffer_size, - const net::CompletionCallback& callback); int Connect(net::OldCompletionCallback* callback); int Connect(const net::CompletionCallback& callback); void Disconnect(); @@ -77,8 +75,7 @@ class PseudoTcpAdapter::Core : public cricket::IPseudoTcpNotify, net::CompletionCallback connect_callback_; net::OldCompletionCallback* old_read_callback_; net::CompletionCallback read_callback_; - net::OldCompletionCallback* old_write_callback_; - net::CompletionCallback write_callback_; + net::OldCompletionCallback* write_callback_; cricket::PseudoTcp pseudo_tcp_; scoped_ptr<net::Socket> socket_; @@ -103,7 +100,7 @@ class PseudoTcpAdapter::Core : public cricket::IPseudoTcpNotify, PseudoTcpAdapter::Core::Core(net::Socket* socket) : old_connect_callback_(NULL), old_read_callback_(NULL), - old_write_callback_(NULL), + write_callback_(NULL), ALLOW_THIS_IN_INITIALIZER_LIST(pseudo_tcp_(this, 0)), socket_(socket), socket_write_pending_(false), @@ -167,30 +164,7 @@ int PseudoTcpAdapter::Core::Read(net::IOBuffer* buffer, int buffer_size, int PseudoTcpAdapter::Core::Write(net::IOBuffer* buffer, int buffer_size, net::OldCompletionCallback* callback) { - DCHECK(!old_write_callback_ && write_callback_.is_null()); - - // Reference the Core in case a callback deletes the adapter. - scoped_refptr<Core> core(this); - - int result = pseudo_tcp_.Send(buffer->data(), buffer_size); - if (result < 0) { - result = net::MapSystemError(pseudo_tcp_.GetError()); - DCHECK(result < 0); - } - - if (result == net::ERR_IO_PENDING) { - write_buffer_ = buffer; - write_buffer_size_ = buffer_size; - old_write_callback_ = callback; - } - - AdjustClock(); - - return result; -} -int PseudoTcpAdapter::Core::Write(net::IOBuffer* buffer, int buffer_size, - const net::CompletionCallback& callback) { - DCHECK(!old_write_callback_ && write_callback_.is_null()); + DCHECK(!write_callback_); // Reference the Core in case a callback deletes the adapter. scoped_refptr<Core> core(this); @@ -257,8 +231,7 @@ void PseudoTcpAdapter::Core::Disconnect() { old_read_callback_ = NULL; read_callback_.Reset(); read_buffer_ = NULL; - old_write_callback_ = NULL; - write_callback_.Reset(); + write_callback_ = NULL; write_buffer_ = NULL; old_connect_callback_ = NULL; connect_callback_.Reset(); @@ -324,7 +297,7 @@ void PseudoTcpAdapter::Core::OnTcpReadable(PseudoTcp* tcp) { void PseudoTcpAdapter::Core::OnTcpWriteable(PseudoTcp* tcp) { DCHECK_EQ(tcp, &pseudo_tcp_); - if (!old_write_callback_ && write_callback_.is_null()) + if (!write_callback_) return; int result = pseudo_tcp_.Send(write_buffer_->data(), write_buffer_size_); @@ -337,17 +310,10 @@ void PseudoTcpAdapter::Core::OnTcpWriteable(PseudoTcp* tcp) { AdjustClock(); - if (old_write_callback_) { - net::OldCompletionCallback* callback = old_write_callback_; - old_write_callback_ = NULL; - write_buffer_ = NULL; - callback->Run(result); - } else { - net::CompletionCallback callback = write_callback_; - write_callback_.Reset(); - write_buffer_ = NULL; - callback.Run(result); - } + net::OldCompletionCallback* callback = write_callback_; + write_callback_ = NULL; + write_buffer_ = NULL; + callback->Run(result); } void PseudoTcpAdapter::Core::OnTcpClosed(PseudoTcp* tcp, uint32 error) { @@ -373,14 +339,10 @@ void PseudoTcpAdapter::Core::OnTcpClosed(PseudoTcp* tcp, uint32 error) { callback.Run(net::MapSystemError(error)); } - if (old_write_callback_) { - net::OldCompletionCallback* callback = old_write_callback_; - old_write_callback_ = NULL; + if (write_callback_) { + net::OldCompletionCallback* callback = write_callback_; + write_callback_ = NULL; callback->Run(net::MapSystemError(error)); - } else if (!write_callback_.is_null()) { - net::CompletionCallback callback = write_callback_; - write_callback_.Reset(); - callback.Run(net::MapSystemError(error)); } } @@ -518,11 +480,6 @@ int PseudoTcpAdapter::Write(net::IOBuffer* buffer, int buffer_size, DCHECK(CalledOnValidThread()); return core_->Write(buffer, buffer_size, callback); } -int PseudoTcpAdapter::Write(net::IOBuffer* buffer, int buffer_size, - const net::CompletionCallback& callback) { - DCHECK(CalledOnValidThread()); - return core_->Write(buffer, buffer_size, callback); -} bool PseudoTcpAdapter::SetReceiveBufferSize(int32 size) { DCHECK(CalledOnValidThread()); diff --git a/jingle/glue/pseudotcp_adapter.h b/jingle/glue/pseudotcp_adapter.h index 6d3cf8c..f0d27ee 100644 --- a/jingle/glue/pseudotcp_adapter.h +++ b/jingle/glue/pseudotcp_adapter.h @@ -36,8 +36,6 @@ class PseudoTcpAdapter : public net::StreamSocket, base::NonThreadSafe { const net::CompletionCallback& callback) OVERRIDE; virtual int Write(net::IOBuffer* buffer, int buffer_size, net::OldCompletionCallback* callback) OVERRIDE; - virtual int Write(net::IOBuffer* buffer, int buffer_size, - const net::CompletionCallback& callback) OVERRIDE; virtual bool SetReceiveBufferSize(int32 size) OVERRIDE; virtual bool SetSendBufferSize(int32 size) OVERRIDE; diff --git a/jingle/glue/pseudotcp_adapter_unittest.cc b/jingle/glue/pseudotcp_adapter_unittest.cc index 94b403f..6d803a5 100644 --- a/jingle/glue/pseudotcp_adapter_unittest.cc +++ b/jingle/glue/pseudotcp_adapter_unittest.cc @@ -174,20 +174,6 @@ class FakeSocket : public net::Socket { return buf_len; } - virtual int Write(net::IOBuffer* buf, int buf_len, - const net::CompletionCallback& callback) OVERRIDE { - DCHECK(buf); - if (peer_socket_) { - MessageLoop::current()->PostDelayedTask( - FROM_HERE, - base::Bind(&FakeSocket::AppendInputPacket, - base::Unretained(peer_socket_), - std::vector<char>(buf->data(), buf->data() + buf_len)), - latency_ms_); - } - - return buf_len; - } virtual bool SetReceiveBufferSize(int32 size) OVERRIDE { NOTIMPLEMENTED(); diff --git a/jingle/notifier/base/fake_ssl_client_socket.cc b/jingle/notifier/base/fake_ssl_client_socket.cc index 9c13f52..bdad879 100644 --- a/jingle/notifier/base/fake_ssl_client_socket.cc +++ b/jingle/notifier/base/fake_ssl_client_socket.cc @@ -112,13 +112,7 @@ int FakeSSLClientSocket::Read(net::IOBuffer* buf, int buf_len, } int FakeSSLClientSocket::Write(net::IOBuffer* buf, int buf_len, - net::OldCompletionCallback* callback) { - DCHECK_EQ(next_handshake_state_, STATE_NONE); - DCHECK(handshake_completed_); - return transport_socket_->Write(buf, buf_len, callback); -} -int FakeSSLClientSocket::Write(net::IOBuffer* buf, int buf_len, - const net::CompletionCallback& callback) { + net::OldCompletionCallback* callback) { DCHECK_EQ(next_handshake_state_, STATE_NONE); DCHECK(handshake_completed_); return transport_socket_->Write(buf, buf_len, callback); diff --git a/jingle/notifier/base/fake_ssl_client_socket.h b/jingle/notifier/base/fake_ssl_client_socket.h index 047923d..623e21b 100644 --- a/jingle/notifier/base/fake_ssl_client_socket.h +++ b/jingle/notifier/base/fake_ssl_client_socket.h @@ -52,8 +52,6 @@ class FakeSSLClientSocket : public net::StreamSocket { const net::CompletionCallback& callback) OVERRIDE; virtual int Write(net::IOBuffer* buf, int buf_len, net::OldCompletionCallback* callback) OVERRIDE; - virtual int Write(net::IOBuffer* buf, int buf_len, - const net::CompletionCallback& callback) OVERRIDE; virtual bool SetReceiveBufferSize(int32 size) OVERRIDE; virtual bool SetSendBufferSize(int32 size) OVERRIDE; virtual int Connect(net::OldCompletionCallback* callback) OVERRIDE; diff --git a/jingle/notifier/base/fake_ssl_client_socket_unittest.cc b/jingle/notifier/base/fake_ssl_client_socket_unittest.cc index 28ee5db..eb3ba5a 100644 --- a/jingle/notifier/base/fake_ssl_client_socket_unittest.cc +++ b/jingle/notifier/base/fake_ssl_client_socket_unittest.cc @@ -51,8 +51,6 @@ class MockClientSocket : public net::StreamSocket { MOCK_METHOD3(Read, int(net::IOBuffer*, int, const net::CompletionCallback&)); MOCK_METHOD3(Write, int(net::IOBuffer*, int, net::OldCompletionCallback*)); - MOCK_METHOD3(Write, int(net::IOBuffer*, int, - const net::CompletionCallback&)); MOCK_METHOD1(SetReceiveBufferSize, bool(int32)); MOCK_METHOD1(SetSendBufferSize, bool(int32)); MOCK_METHOD1(Connect, int(net::OldCompletionCallback*)); diff --git a/jingle/notifier/base/proxy_resolving_client_socket.cc b/jingle/notifier/base/proxy_resolving_client_socket.cc index c7d54c2..3d46ed6b 100644 --- a/jingle/notifier/base/proxy_resolving_client_socket.cc +++ b/jingle/notifier/base/proxy_resolving_client_socket.cc @@ -89,13 +89,6 @@ int ProxyResolvingClientSocket::Write(net::IOBuffer* buf, int buf_len, NOTREACHED(); return net::ERR_SOCKET_NOT_CONNECTED; } -int ProxyResolvingClientSocket::Write(net::IOBuffer* buf, int buf_len, - const net::CompletionCallback& callback) { - if (transport_.get() && transport_->socket()) - return transport_->socket()->Write(buf, buf_len, callback); - NOTREACHED(); - return net::ERR_SOCKET_NOT_CONNECTED; -} bool ProxyResolvingClientSocket::SetReceiveBufferSize(int32 size) { if (transport_.get() && transport_->socket()) diff --git a/jingle/notifier/base/proxy_resolving_client_socket.h b/jingle/notifier/base/proxy_resolving_client_socket.h index 6eae9f4..4463364 100644 --- a/jingle/notifier/base/proxy_resolving_client_socket.h +++ b/jingle/notifier/base/proxy_resolving_client_socket.h @@ -52,8 +52,6 @@ class ProxyResolvingClientSocket : public net::StreamSocket { const net::CompletionCallback& callback) OVERRIDE; virtual int Write(net::IOBuffer* buf, int buf_len, net::OldCompletionCallback* callback) OVERRIDE; - virtual int Write(net::IOBuffer* buf, int buf_len, - const net::CompletionCallback& callback) OVERRIDE; virtual bool SetReceiveBufferSize(int32 size) OVERRIDE; virtual bool SetSendBufferSize(int32 size) OVERRIDE; virtual int Connect(net::OldCompletionCallback* callback) OVERRIDE; |