diff options
Diffstat (limited to 'remoting')
-rw-r--r-- | remoting/host/chromoting_host.cc | 23 | ||||
-rw-r--r-- | remoting/protocol/connection_to_client.cc | 18 |
2 files changed, 31 insertions, 10 deletions
diff --git a/remoting/host/chromoting_host.cc b/remoting/host/chromoting_host.cc index c713384..34ec893 100644 --- a/remoting/host/chromoting_host.cc +++ b/remoting/host/chromoting_host.cc @@ -200,25 +200,34 @@ void ChromotingHost::OnClientDisconnected(ConnectionToClient* connection) { //////////////////////////////////////////////////////////////////////////// // protocol::ConnectionToClient::EventHandler implementations void ChromotingHost::OnConnectionOpened(ConnectionToClient* connection) { - DCHECK_EQ(context_->main_message_loop(), MessageLoop::current()); + DCHECK_EQ(context_->network_message_loop(), MessageLoop::current()); // Completes the connection to the client. VLOG(1) << "Connection to client established."; - OnClientConnected(connection_.get()); + context_->main_message_loop()->PostTask( + FROM_HERE, + NewRunnableMethod(this, &ChromotingHost::OnClientConnected, + connection_.get())); } void ChromotingHost::OnConnectionClosed(ConnectionToClient* connection) { - DCHECK_EQ(context_->main_message_loop(), MessageLoop::current()); + DCHECK_EQ(context_->network_message_loop(), MessageLoop::current()); VLOG(1) << "Connection to client closed."; - OnClientDisconnected(connection_.get()); + context_->main_message_loop()->PostTask( + FROM_HERE, + NewRunnableMethod(this, &ChromotingHost::OnClientDisconnected, + connection_.get())); } void ChromotingHost::OnConnectionFailed(ConnectionToClient* connection) { - DCHECK_EQ(context_->main_message_loop(), MessageLoop::current()); + DCHECK_EQ(context_->network_message_loop(), MessageLoop::current()); LOG(ERROR) << "Connection failed unexpectedly."; - OnClientDisconnected(connection_.get()); + context_->main_message_loop()->PostTask( + FROM_HERE, + NewRunnableMethod(this, &ChromotingHost::OnClientDisconnected, + connection_.get())); } //////////////////////////////////////////////////////////////////////////// @@ -293,7 +302,7 @@ void ChromotingHost::OnNewClientSession( // If we accept the connected then create a client object and set the // callback. - connection_ = new ConnectionToClient(context_->main_message_loop(), + connection_ = new ConnectionToClient(context_->network_message_loop(), this, host_stub_.get(), input_stub_.get()); connection_->Init(session); diff --git a/remoting/protocol/connection_to_client.cc b/remoting/protocol/connection_to_client.cc index 7d9fb17..3b4bd3f 100644 --- a/remoting/protocol/connection_to_client.cc +++ b/remoting/protocol/connection_to_client.cc @@ -49,7 +49,13 @@ protocol::Session* ConnectionToClient::session() { } void ConnectionToClient::Disconnect() { - DCHECK_EQ(loop_, MessageLoop::current()); + // This method can be called from main thread so perform threading switching. + if (MessageLoop::current() != loop_) { + loop_->PostTask( + FROM_HERE, + NewRunnableMethod(this, &ConnectionToClient::Disconnect)); + return; + } // If there is a channel then close it and release the reference. if (session_) { @@ -80,8 +86,14 @@ void ConnectionToClient::OnSessionStateChange(protocol::Session::State state) { dispatcher_->Initialize(session_.get(), host_stub_, input_stub_); } - loop_->PostTask(FROM_HERE, - NewRunnableMethod(this, &ConnectionToClient::StateChangeTask, state)); + // This method can be called from main thread so perform threading switching. + if (MessageLoop::current() != loop_) { + loop_->PostTask( + FROM_HERE, + NewRunnableMethod(this, &ConnectionToClient::StateChangeTask, state)); + } else { + StateChangeTask(state); + } } void ConnectionToClient::StateChangeTask(protocol::Session::State state) { |