summaryrefslogtreecommitdiffstats
path: root/remoting
diff options
context:
space:
mode:
authorsergeyu@chromium.org <sergeyu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-08-31 02:07:06 +0000
committersergeyu@chromium.org <sergeyu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-08-31 02:07:06 +0000
commite70eedc3b4909f76b5bc8411e62786851a8c5313 (patch)
treeac79911b38d6b47b87aef174d6ce47f36ef6ac54 /remoting
parentfb0acfd33377c1f40627677a58c352dad84088b0 (diff)
downloadchromium_src-e70eedc3b4909f76b5bc8411e62786851a8c5313.zip
chromium_src-e70eedc3b4909f76b5bc8411e62786851a8c5313.tar.gz
chromium_src-e70eedc3b4909f76b5bc8411e62786851a8c5313.tar.bz2
Merge 153972 - Fix UdpPacketSocket to handle callbacks after the socket is destroyed.
PPB_UDPSocket_Private doesn't make guarantees about callbacks not being called after Close() - we may still get some callbacks asynchronously with error codes different from PP_ERROR_ABORTED. UdpPacketSocket wasn't handling this case properly. BUG=143839 Review URL: https://chromiumcodereview.appspot.com/10900028 TBR=sergeyu@chromium.org Review URL: https://chromiumcodereview.appspot.com/10908030 git-svn-id: svn://svn.chromium.org/chrome/branches/1229/src@154349 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'remoting')
-rw-r--r--remoting/client/plugin/pepper_packet_socket_factory.cc17
1 files changed, 11 insertions, 6 deletions
diff --git a/remoting/client/plugin/pepper_packet_socket_factory.cc b/remoting/client/plugin/pepper_packet_socket_factory.cc
index 80ae0bd..29428ff 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);
}