Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(373)

Unified Diff: remoting/client/plugin/pepper_packet_socket_factory.cc

Issue 10900028: Fix UdpPacketSocket to handle callbacks after the socket is destroyed. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: remoting/client/plugin/pepper_packet_socket_factory.cc
diff --git a/remoting/client/plugin/pepper_packet_socket_factory.cc b/remoting/client/plugin/pepper_packet_socket_factory.cc
index 80ae0bdb3795dd4288fb19d7b7bed43835b41229..29428ff7daece985f860bf3e38120986d221713a 100644
--- a/remoting/client/plugin/pepper_packet_socket_factory.cc
+++ b/remoting/client/plugin/pepper_packet_socket_factory.cc
@@ -6,6 +6,7 @@
#include "base/bind.h"
#include "base/logging.h"
+#include "base/memory/weak_ptr.h"
#include "net/base/io_buffer.h"
#include "ppapi/cpp/private/net_address_private.h"
#include "ppapi/cpp/private/udp_socket_private.h"
@@ -31,7 +32,7 @@ class UdpPacketSocket : public talk_base::AsyncPacketSocket {
virtual ~UdpPacketSocket();
// |min_port| and |max_port| are set to zero if the port number
- // |should be assigned by the OS.
+ // should be assigned by the OS.
bool Init(const talk_base::SocketAddress& local_address,
int min_port,
int max_port);
@@ -87,6 +88,8 @@ class UdpPacketSocket : public talk_base::AsyncPacketSocket {
std::list<PendingPacket> send_queue_;
int send_queue_size_;
+ base::WeakPtrFactory<UdpPacketSocket> weak_factory_;
+
DISALLOW_COPY_AND_ASSIGN(UdpPacketSocket);
};
@@ -106,7 +109,8 @@ UdpPacketSocket::UdpPacketSocket(const pp::InstanceHandle& instance)
min_port_(0),
max_port_(0),
send_pending_(false),
- send_queue_size_(0) {
+ send_queue_size_(0),
+ ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)) {
}
UdpPacketSocket::~UdpPacketSocket() {
@@ -131,7 +135,8 @@ bool UdpPacketSocket::Init(const talk_base::SocketAddress& local_address,
}
int result = socket_.Bind(&pp_local_address, PpCompletionCallback(
- base::Bind(&UdpPacketSocket::OnBindCompleted, base::Unretained(this))));
+ base::Bind(&UdpPacketSocket::OnBindCompleted,
+ weak_factory_.GetWeakPtr())));
DCHECK_EQ(result, PP_OK_COMPLETIONPENDING);
state_ = STATE_BINDING;
@@ -169,7 +174,7 @@ void UdpPacketSocket::OnBindCompleted(int result) {
min_port_)) {
int result = socket_.Bind(&pp_local_address, PpCompletionCallback(
base::Bind(&UdpPacketSocket::OnBindCompleted,
- base::Unretained(this))));
+ weak_factory_.GetWeakPtr())));
DCHECK_EQ(result, PP_OK_COMPLETIONPENDING);
}
} else {
@@ -258,7 +263,7 @@ void UdpPacketSocket::DoSend() {
send_queue_.front().data->data(), send_queue_.front().data->size(),
&send_queue_.front().address,
PpCompletionCallback(base::Bind(&UdpPacketSocket::OnSendCompleted,
- base::Unretained(this))));
+ weak_factory_.GetWeakPtr())));
DCHECK_EQ(result, PP_OK_COMPLETIONPENDING);
send_pending_ = true;
}
@@ -305,7 +310,7 @@ void UdpPacketSocket::DoRead() {
int result = socket_.RecvFrom(
&receive_buffer_[0], receive_buffer_.size(),
PpCompletionCallback(base::Bind(&UdpPacketSocket::OnReadCompleted,
- base::Unretained(this))));
+ weak_factory_.GetWeakPtr())));
DCHECK_EQ(result, PP_OK_COMPLETIONPENDING);
}
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698