Commit 2bfebfd4 authored by sergeyu@chromium.org's avatar sergeyu@chromium.org

Fix DCHECK in P2PSocketClient.

P2PSocketClient may DCHECK in Close() if Close() is called immediately after Init() because delegate_message_loop_ is initialized on the IPC thread. Initialize it in the constructor instead.

BUG=None
TEST=None

Review URL: http://codereview.chromium.org/7584011

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@95697 0039d316-1c4b-4281-b951-d872f2087c98
parent 14edde99
...@@ -124,8 +124,7 @@ bool IpcPacketSocket::Init(P2PSocketType type, P2PSocketClient* client, ...@@ -124,8 +124,7 @@ bool IpcPacketSocket::Init(P2PSocketType type, P2PSocketClient* client,
return false; return false;
} }
client_->Init(type, local_endpoint, remote_endpoint, this, client_->Init(type, local_endpoint, remote_endpoint, this);
base::MessageLoopProxy::CreateForCurrentThread());
return true; return true;
} }
......
...@@ -11,7 +11,7 @@ ...@@ -11,7 +11,7 @@
P2PSocketClient::P2PSocketClient(P2PSocketDispatcher* dispatcher) P2PSocketClient::P2PSocketClient(P2PSocketDispatcher* dispatcher)
: dispatcher_(dispatcher), : dispatcher_(dispatcher),
ipc_message_loop_(dispatcher->message_loop()), ipc_message_loop_(dispatcher->message_loop()),
delegate_message_loop_(NULL), delegate_message_loop_(base::MessageLoopProxy::CreateForCurrentThread()),
socket_id_(0), delegate_(NULL), socket_id_(0), delegate_(NULL),
state_(STATE_UNINITIALIZED) { state_(STATE_UNINITIALIZED) {
} }
...@@ -21,21 +21,21 @@ P2PSocketClient::~P2PSocketClient() { ...@@ -21,21 +21,21 @@ P2PSocketClient::~P2PSocketClient() {
} }
void P2PSocketClient::Init( void P2PSocketClient::Init(
P2PSocketType type, const net::IPEndPoint& local_address, P2PSocketType type,
const net::IPEndPoint& remote_address, P2PSocketClient::Delegate* delegate, const net::IPEndPoint& local_address,
scoped_refptr<base::MessageLoopProxy> delegate_loop) { const net::IPEndPoint& remote_address,
P2PSocketClient::Delegate* delegate) {
if (!ipc_message_loop_->BelongsToCurrentThread()) { if (!ipc_message_loop_->BelongsToCurrentThread()) {
ipc_message_loop_->PostTask( ipc_message_loop_->PostTask(
FROM_HERE, NewRunnableMethod( FROM_HERE, NewRunnableMethod(
this, &P2PSocketClient::Init, type, local_address, remote_address, this, &P2PSocketClient::Init, type, local_address,
delegate, delegate_loop)); remote_address, delegate));
return; return;
} }
DCHECK_EQ(state_, STATE_UNINITIALIZED); DCHECK_EQ(state_, STATE_UNINITIALIZED);
state_ = STATE_OPENING; state_ = STATE_OPENING;
delegate_ = delegate; delegate_ = delegate;
delegate_message_loop_ = delegate_loop;
socket_id_ = dispatcher_->RegisterClient(this); socket_id_ = dispatcher_->RegisterClient(this);
dispatcher_->SendP2PMessage(new P2PHostMsg_CreateSocket( dispatcher_->SendP2PMessage(new P2PHostMsg_CreateSocket(
0, type, socket_id_, local_address, remote_address)); 0, type, socket_id_, local_address, remote_address));
......
...@@ -46,8 +46,7 @@ class P2PSocketClient : public base::RefCountedThreadSafe<P2PSocketClient> { ...@@ -46,8 +46,7 @@ class P2PSocketClient : public base::RefCountedThreadSafe<P2PSocketClient> {
void Init(P2PSocketType type, void Init(P2PSocketType type,
const net::IPEndPoint& local_address, const net::IPEndPoint& local_address,
const net::IPEndPoint& remote_address, const net::IPEndPoint& remote_address,
Delegate* delegate, Delegate* delegate);
scoped_refptr<base::MessageLoopProxy> delegate_loop);
// Send the |data| to the |address|. // Send the |data| to the |address|.
void Send(const net::IPEndPoint& address, const std::vector<char>& data); void Send(const net::IPEndPoint& address, const std::vector<char>& data);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment