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

Unified Diff: content/renderer/p2p/socket_client.cc

Issue 10962010: Fix asan test failure in P2PSocketClient::Init. Make sure P2PSocketClient::Init only access |deleg… (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Fix init. Created 8 years, 3 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 | « content/renderer/p2p/socket_client.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: content/renderer/p2p/socket_client.cc
diff --git a/content/renderer/p2p/socket_client.cc b/content/renderer/p2p/socket_client.cc
index 76357cd2b45fdc0bc08f1d654e74118fbd38eb10..9a99d55e8cc1f4ed3a4c10598dd02fd6208ed25b 100644
--- a/content/renderer/p2p/socket_client.cc
+++ b/content/renderer/p2p/socket_client.cc
@@ -28,16 +28,21 @@ void P2PSocketClient::Init(
const net::IPEndPoint& local_address,
const net::IPEndPoint& remote_address,
P2PSocketClient::Delegate* delegate) {
- if (!ipc_message_loop_->BelongsToCurrentThread()) {
- ipc_message_loop_->PostTask(
- FROM_HERE, base::Bind(&P2PSocketClient::Init, this, type, local_address,
- remote_address, delegate));
- return;
- }
+ DCHECK(delegate_message_loop_->BelongsToCurrentThread());
+ // |delegate_| is only accessesed on |delegate_message_loop_|.
+ delegate_ = delegate;
tommi (sloooow) - chröme 2012/09/20 13:47:46 maybe first DCHECK(!delegate_) or is it OK for del
+ ipc_message_loop_->PostTask(
+ FROM_HERE, base::Bind(&P2PSocketClient::DoInit, this, type, local_address,
+ remote_address));
+}
+
+void P2PSocketClient::DoInit(P2PSocketType type,
+ const net::IPEndPoint& local_address,
+ const net::IPEndPoint& remote_address) {
DCHECK_EQ(state_, STATE_UNINITIALIZED);
+ DCHECK(delegate_);
state_ = STATE_OPENING;
- delegate_ = delegate;
socket_id_ = dispatcher_->RegisterClient(this);
dispatcher_->SendP2PMessage(new P2PHostMsg_CreateSocket(
type, socket_id_, local_address, remote_address));
@@ -68,6 +73,7 @@ void P2PSocketClient::Close() {
}
void P2PSocketClient::DoClose() {
+ DCHECK(ipc_message_loop_->BelongsToCurrentThread());
if (dispatcher_) {
if (state_ == STATE_OPEN || state_ == STATE_OPENING ||
state_ == STATE_ERROR) {
@@ -95,6 +101,7 @@ void P2PSocketClient::OnSocketCreated(const net::IPEndPoint& address) {
}
void P2PSocketClient::DeliverOnSocketCreated(const net::IPEndPoint& address) {
+ DCHECK(delegate_message_loop_->BelongsToCurrentThread());
if (delegate_)
delegate_->OnOpen(address);
}
@@ -118,6 +125,7 @@ void P2PSocketClient::OnIncomingTcpConnection(const net::IPEndPoint& address) {
void P2PSocketClient::DeliverOnIncomingTcpConnection(
const net::IPEndPoint& address, scoped_refptr<P2PSocketClient> new_client) {
+ DCHECK(delegate_message_loop_->BelongsToCurrentThread());
if (delegate_)
delegate_->OnIncomingTcpConnection(address, new_client);
}
@@ -131,6 +139,7 @@ void P2PSocketClient::OnError() {
}
void P2PSocketClient::DeliverOnError() {
+ DCHECK(delegate_message_loop_->BelongsToCurrentThread());
if (delegate_)
delegate_->OnError();
}
@@ -146,6 +155,7 @@ void P2PSocketClient::OnDataReceived(const net::IPEndPoint& address,
void P2PSocketClient::DeliverOnDataReceived(const net::IPEndPoint& address,
const std::vector<char>& data) {
+ DCHECK(delegate_message_loop_->BelongsToCurrentThread());
if (delegate_)
delegate_->OnDataReceived(address, data);
}
« no previous file with comments | « content/renderer/p2p/socket_client.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698