summaryrefslogtreecommitdiffstats
path: root/content/browser/renderer_host/p2p
diff options
context:
space:
mode:
Diffstat (limited to 'content/browser/renderer_host/p2p')
-rw-r--r--content/browser/renderer_host/p2p/socket_host_tcp.cc17
-rw-r--r--content/browser/renderer_host/p2p/socket_host_tcp.h4
-rw-r--r--content/browser/renderer_host/p2p/socket_host_test_utils.h41
-rw-r--r--content/browser/renderer_host/p2p/socket_host_udp.cc13
-rw-r--r--content/browser/renderer_host/p2p/socket_host_udp.h3
-rw-r--r--content/browser/renderer_host/p2p/socket_host_udp_unittest.cc18
6 files changed, 27 insertions, 69 deletions
diff --git a/content/browser/renderer_host/p2p/socket_host_tcp.cc b/content/browser/renderer_host/p2p/socket_host_tcp.cc
index f88ff4a..db94edc 100644
--- a/content/browser/renderer_host/p2p/socket_host_tcp.cc
+++ b/content/browser/renderer_host/p2p/socket_host_tcp.cc
@@ -21,13 +21,7 @@ namespace content {
P2PSocketHostTcp::P2PSocketHostTcp(IPC::Message::Sender* message_sender,
int routing_id, int id)
: P2PSocketHost(message_sender, routing_id, id),
- connected_(false),
- ALLOW_THIS_IN_INITIALIZER_LIST(
- connect_callback_(this, &P2PSocketHostTcp::OnConnected)),
- ALLOW_THIS_IN_INITIALIZER_LIST(
- read_callback_(this, &P2PSocketHostTcp::OnRead)),
- ALLOW_THIS_IN_INITIALIZER_LIST(
- write_callback_(this, &P2PSocketHostTcp::OnWritten)) {
+ connected_(false) {
}
P2PSocketHostTcp::~P2PSocketHostTcp() {
@@ -68,7 +62,8 @@ bool P2PSocketHostTcp::Init(const net::IPEndPoint& local_address,
if (socket_->SetSendBufferSize(kMaxSendBufferSize))
LOG(WARNING) << "Failed to set send buffer size for TCP socket.";
- int result = socket_->Connect(&connect_callback_);
+ int result = socket_->Connect(
+ base::Bind(&P2PSocketHostTcp::OnConnected, base::Unretained(this)));
if (result != net::ERR_IO_PENDING) {
OnConnected(result);
}
@@ -125,7 +120,8 @@ void P2PSocketHostTcp::DoRead() {
read_buffer_->RemainingCapacity());
}
result = socket_->Read(read_buffer_, read_buffer_->RemainingCapacity(),
- &read_callback_);
+ base::Bind(&P2PSocketHostTcp::OnRead,
+ base::Unretained(this)));
DidCompleteRead(result);
} while (result > 0);
}
@@ -232,7 +228,8 @@ void P2PSocketHostTcp::Send(const net::IPEndPoint& to,
void P2PSocketHostTcp::DoWrite() {
while (true) {
int result = socket_->Write(write_buffer_, write_buffer_->BytesRemaining(),
- &write_callback_);
+ base::Bind(&P2PSocketHostTcp::OnWritten,
+ base::Unretained(this)));
if (result >= 0) {
write_buffer_->DidConsume(result);
if (write_buffer_->BytesRemaining() == 0) {
diff --git a/content/browser/renderer_host/p2p/socket_host_tcp.h b/content/browser/renderer_host/p2p/socket_host_tcp.h
index 3c50f82..b24630a 100644
--- a/content/browser/renderer_host/p2p/socket_host_tcp.h
+++ b/content/browser/renderer_host/p2p/socket_host_tcp.h
@@ -66,10 +66,6 @@ class CONTENT_EXPORT P2PSocketHostTcp : public P2PSocketHost {
bool connected_;
- net::OldCompletionCallbackImpl<P2PSocketHostTcp> connect_callback_;
- net::OldCompletionCallbackImpl<P2PSocketHostTcp> read_callback_;
- net::OldCompletionCallbackImpl<P2PSocketHostTcp> write_callback_;
-
DISALLOW_COPY_AND_ASSIGN(P2PSocketHostTcp);
};
diff --git a/content/browser/renderer_host/p2p/socket_host_test_utils.h b/content/browser/renderer_host/p2p/socket_host_test_utils.h
index 0f1aeb4..0ea8c1c 100644
--- a/content/browser/renderer_host/p2p/socket_host_test_utils.h
+++ b/content/browser/renderer_host/p2p/socket_host_test_utils.h
@@ -57,14 +57,11 @@ class FakeSocket : public net::StreamSocket {
// net::Socket implementation.
virtual int Read(net::IOBuffer* buf, int buf_len,
- net::OldCompletionCallback* callback) OVERRIDE;
- virtual int Read(net::IOBuffer* buf, int buf_len,
const net::CompletionCallback& callback) OVERRIDE;
virtual int Write(net::IOBuffer* buf, int buf_len,
- net::OldCompletionCallback* callback) OVERRIDE;
+ const net::CompletionCallback& callback) OVERRIDE;
virtual bool SetReceiveBufferSize(int32 size) OVERRIDE;
virtual bool SetSendBufferSize(int32 size) OVERRIDE;
- virtual int Connect(net::OldCompletionCallback* callback) OVERRIDE;
virtual int Connect(const net::CompletionCallback& callback) OVERRIDE;
virtual void Disconnect() OVERRIDE;
virtual bool IsConnected() const OVERRIDE;
@@ -83,7 +80,6 @@ class FakeSocket : public net::StreamSocket {
bool read_pending_;
scoped_refptr<net::IOBuffer> read_buffer_;
int read_buffer_size_;
- net::OldCompletionCallback* old_read_callback_;
net::CompletionCallback read_callback_;
std::string* written_data_;
@@ -115,15 +111,9 @@ void FakeSocket::AppendInputData(const char* data, int data_size) {
memcpy(read_buffer_->data(), &input_data_[0] + input_pos_, result);
input_pos_ += result;
read_buffer_ = NULL;
- if (old_read_callback_) {
- net::OldCompletionCallback* cb = old_read_callback_;
- old_read_callback_ = NULL;
- cb->Run(result);
- } else {
- net::CompletionCallback cb = read_callback_;
- read_callback_.Reset();
- cb.Run(result);
- }
+ net::CompletionCallback cb = read_callback_;
+ read_callback_.Reset();
+ cb.Run(result);
}
}
@@ -136,23 +126,6 @@ void FakeSocket::SetLocalAddress(const net::IPEndPoint& local_address) {
}
int FakeSocket::Read(net::IOBuffer* buf, int buf_len,
- net::OldCompletionCallback* callback) {
- DCHECK(buf);
- if (input_pos_ < static_cast<int>(input_data_.size())){
- int result = std::min(buf_len,
- static_cast<int>(input_data_.size()) - input_pos_);
- memcpy(buf->data(), &(*input_data_.begin()) + input_pos_, result);
- input_pos_ += result;
- return result;
- } else {
- read_pending_ = true;
- read_buffer_ = buf;
- read_buffer_size_ = buf_len;
- old_read_callback_ = callback;
- return net::ERR_IO_PENDING;
- }
-}
-int FakeSocket::Read(net::IOBuffer* buf, int buf_len,
const net::CompletionCallback& callback) {
DCHECK(buf);
if (input_pos_ < static_cast<int>(input_data_.size())){
@@ -171,7 +144,7 @@ int FakeSocket::Read(net::IOBuffer* buf, int buf_len,
}
int FakeSocket::Write(net::IOBuffer* buf, int buf_len,
- net::OldCompletionCallback* callback) {
+ const net::CompletionCallback& callback) {
DCHECK(buf);
if (written_data_) {
written_data_->insert(written_data_->end(),
@@ -190,10 +163,6 @@ bool FakeSocket::SetSendBufferSize(int32 size) {
return false;
}
-int FakeSocket::Connect(net::OldCompletionCallback* callback) {
- return 0;
-}
-
int FakeSocket::Connect(const net::CompletionCallback& callback) {
return 0;
}
diff --git a/content/browser/renderer_host/p2p/socket_host_udp.cc b/content/browser/renderer_host/p2p/socket_host_udp.cc
index f85e80d..e5c4b01 100644
--- a/content/browser/renderer_host/p2p/socket_host_udp.cc
+++ b/content/browser/renderer_host/p2p/socket_host_udp.cc
@@ -4,6 +4,7 @@
#include "content/browser/renderer_host/p2p/socket_host_udp.h"
+#include "base/bind.h"
#include "content/common/p2p_messages.h"
#include "net/base/io_buffer.h"
#include "net/base/net_errors.h"
@@ -34,11 +35,7 @@ P2PSocketHostUdp::P2PSocketHostUdp(IPC::Message::Sender* message_sender,
: P2PSocketHost(message_sender, routing_id, id),
socket_(new net::UDPServerSocket(NULL, net::NetLog::Source())),
send_queue_bytes_(0),
- send_pending_(false),
- ALLOW_THIS_IN_INITIALIZER_LIST(
- recv_callback_(this, &P2PSocketHostUdp::OnRecv)),
- ALLOW_THIS_IN_INITIALIZER_LIST(
- send_callback_(this, &P2PSocketHostUdp::OnSend)) {
+ send_pending_(false) {
}
P2PSocketHostUdp::~P2PSocketHostUdp() {
@@ -93,7 +90,8 @@ void P2PSocketHostUdp::DoRead() {
int result;
do {
result = socket_->RecvFrom(recv_buffer_, kReadBufferSize, &recv_address_,
- &recv_callback_);
+ base::Bind(&P2PSocketHostUdp::OnRecv,
+ base::Unretained(this)));
DidCompleteRead(result);
} while (result > 0);
}
@@ -167,7 +165,8 @@ void P2PSocketHostUdp::Send(const net::IPEndPoint& to,
void P2PSocketHostUdp::DoSend(const PendingPacket& packet) {
int result = socket_->SendTo(packet.data, packet.size, packet.to,
- &send_callback_);
+ base::Bind(&P2PSocketHostUdp::OnSend,
+ base::Unretained(this)));
if (result == net::ERR_IO_PENDING) {
send_pending_ = true;
} else if (result < 0) {
diff --git a/content/browser/renderer_host/p2p/socket_host_udp.h b/content/browser/renderer_host/p2p/socket_host_udp.h
index 6925b54..d46c790 100644
--- a/content/browser/renderer_host/p2p/socket_host_udp.h
+++ b/content/browser/renderer_host/p2p/socket_host_udp.h
@@ -69,9 +69,6 @@ class CONTENT_EXPORT P2PSocketHostUdp : public P2PSocketHost {
// response or relay allocation request or response.
ConnectedPeerSet connected_peers_;
- net::OldCompletionCallbackImpl<P2PSocketHostUdp> recv_callback_;
- net::OldCompletionCallbackImpl<P2PSocketHostUdp> send_callback_;
-
DISALLOW_COPY_AND_ASSIGN(P2PSocketHostUdp);
};
diff --git a/content/browser/renderer_host/p2p/socket_host_udp_unittest.cc b/content/browser/renderer_host/p2p/socket_host_udp_unittest.cc
index a33bc83..02cc3b2 100644
--- a/content/browser/renderer_host/p2p/socket_host_udp_unittest.cc
+++ b/content/browser/renderer_host/p2p/socket_host_udp_unittest.cc
@@ -30,7 +30,7 @@ class FakeDatagramServerSocket : public net::DatagramServerSocket {
// P2PSocketHostUdp destroyes a socket on errors so sent packets
// need to be stored outside of this object.
explicit FakeDatagramServerSocket(std::deque<UDPPacket>* sent_packets)
- : sent_packets_(sent_packets), recv_callback_(NULL) {
+ : sent_packets_(sent_packets) {
}
virtual void Close() OVERRIDE {
@@ -53,8 +53,8 @@ class FakeDatagramServerSocket : public net::DatagramServerSocket {
virtual int RecvFrom(net::IOBuffer* buf, int buf_len,
net::IPEndPoint* address,
- net::OldCompletionCallback* callback) OVERRIDE {
- CHECK(!recv_callback_);
+ const net::CompletionCallback& callback) OVERRIDE {
+ CHECK(recv_callback_.is_null());
if (incoming_packets_.size() > 0) {
scoped_refptr<net::IOBuffer> buffer(buf);
int size = std::min(
@@ -74,7 +74,7 @@ class FakeDatagramServerSocket : public net::DatagramServerSocket {
virtual int SendTo(net::IOBuffer* buf, int buf_len,
const net::IPEndPoint& address,
- net::OldCompletionCallback* callback) OVERRIDE {
+ const net::CompletionCallback& callback) OVERRIDE {
scoped_refptr<net::IOBuffer> buffer(buf);
std::vector<char> data_vector(buffer->data(), buffer->data() + buf_len);
sent_packets_->push_back(UDPPacket(address, data_vector));
@@ -90,14 +90,14 @@ class FakeDatagramServerSocket : public net::DatagramServerSocket {
}
void ReceivePacket(const net::IPEndPoint& address, std::vector<char> data) {
- if (recv_callback_) {
+ if (!recv_callback_.is_null()) {
int size = std::min(recv_size_, static_cast<int>(data.size()));
memcpy(recv_buffer_->data(), &*data.begin(), size);
*recv_address_ = address;
- net::OldCompletionCallback* cb = recv_callback_;
- recv_callback_ = NULL;
+ net::CompletionCallback cb = recv_callback_;
+ recv_callback_.Reset();
recv_buffer_ = NULL;
- cb->Run(size);
+ cb.Run(size);
} else {
incoming_packets_.push_back(UDPPacket(address, data));
}
@@ -116,7 +116,7 @@ class FakeDatagramServerSocket : public net::DatagramServerSocket {
scoped_refptr<net::IOBuffer> recv_buffer_;
net::IPEndPoint* recv_address_;
int recv_size_;
- net::OldCompletionCallback* recv_callback_;
+ net::CompletionCallback recv_callback_;
};
} // namespace