Index: remoting/protocol/ice_connection_to_client.cc |
diff --git a/remoting/protocol/ice_connection_to_client.cc b/remoting/protocol/ice_connection_to_client.cc |
index 7210fc5606c685bca272e15d2dad07005e2ad443..9fc20819276b8bf214d6ce6a7738b9e503e7a5da 100644 |
--- a/remoting/protocol/ice_connection_to_client.cc |
+++ b/remoting/protocol/ice_connection_to_client.cc |
@@ -17,6 +17,7 @@ |
#include "remoting/protocol/host_stub.h" |
#include "remoting/protocol/host_video_dispatcher.h" |
#include "remoting/protocol/input_stub.h" |
+#include "remoting/protocol/transport_context.h" |
#include "remoting/protocol/video_frame_pump.h" |
namespace remoting { |
@@ -44,14 +45,17 @@ scoped_ptr<VideoEncoder> CreateVideoEncoder( |
IceConnectionToClient::IceConnectionToClient( |
scoped_ptr<protocol::Session> session, |
+ scoped_refptr<TransportContext> transport_context, |
scoped_refptr<base::SingleThreadTaskRunner> video_encode_task_runner) |
: event_handler_(nullptr), |
session_(std::move(session)), |
video_encode_task_runner_(video_encode_task_runner), |
+ transport_(transport_context, this), |
control_dispatcher_(new HostControlDispatcher()), |
event_dispatcher_(new HostEventDispatcher()), |
video_dispatcher_(new HostVideoDispatcher()) { |
session_->SetEventHandler(this); |
+ session_->SetTransport(&transport_); |
} |
IceConnectionToClient::~IceConnectionToClient() {} |
@@ -70,8 +74,6 @@ protocol::Session* IceConnectionToClient::session() { |
void IceConnectionToClient::Disconnect(ErrorCode error) { |
DCHECK(thread_checker_.CalledOnValidThread()); |
- CloseChannels(); |
- |
// This should trigger OnConnectionClosed() event and this object |
// may be destroyed as the result. |
session_->Close(error); |
@@ -134,7 +136,6 @@ void IceConnectionToClient::OnSessionStateChange(Session::State state) { |
case Session::CONNECTING: |
case Session::ACCEPTING: |
case Session::ACCEPTED: |
- case Session::CONNECTED: |
// Don't care about these events. |
break; |
case Session::AUTHENTICATING: |
@@ -142,23 +143,19 @@ void IceConnectionToClient::OnSessionStateChange(Session::State state) { |
break; |
case Session::AUTHENTICATED: |
// Initialize channels. |
- control_dispatcher_->Init( |
- session_->GetTransport()->GetMultiplexedChannelFactory(), this); |
+ control_dispatcher_->Init(transport_.GetMultiplexedChannelFactory(), |
+ this); |
- event_dispatcher_->Init( |
- session_->GetTransport()->GetMultiplexedChannelFactory(), this); |
+ event_dispatcher_->Init(transport_.GetMultiplexedChannelFactory(), this); |
event_dispatcher_->set_on_input_event_callback( |
base::Bind(&IceConnectionToClient::OnInputEventReceived, |
base::Unretained(this))); |
- video_dispatcher_->Init( |
- session_->GetTransport()->GetStreamChannelFactory(), this); |
+ video_dispatcher_->Init(transport_.GetStreamChannelFactory(), this); |
audio_writer_ = AudioWriter::Create(session_->config()); |
- if (audio_writer_.get()) { |
- audio_writer_->Init( |
- session_->GetTransport()->GetMultiplexedChannelFactory(), this); |
- } |
+ if (audio_writer_) |
+ audio_writer_->Init(transport_.GetMultiplexedChannelFactory(), this); |
// Notify the handler after initializing the channels, so that |
// ClientSession can get a client clipboard stub. |
@@ -166,21 +163,27 @@ void IceConnectionToClient::OnSessionStateChange(Session::State state) { |
break; |
case Session::CLOSED: |
- Close(OK); |
- break; |
- |
case Session::FAILED: |
- Close(session_->error()); |
+ CloseChannels(); |
+ event_handler_->OnConnectionClosed( |
+ this, state == Session::FAILED ? session_->error() : OK); |
break; |
} |
} |
-void IceConnectionToClient::OnSessionRouteChange( |
+ |
+void IceConnectionToClient::OnIceTransportRouteChange( |
const std::string& channel_name, |
const TransportRoute& route) { |
event_handler_->OnRouteChange(this, channel_name, route); |
} |
+void IceConnectionToClient::OnIceTransportError(ErrorCode error) { |
+ DCHECK(thread_checker_.CalledOnValidThread()); |
+ |
+ Disconnect(error); |
+} |
+ |
void IceConnectionToClient::OnChannelInitialized( |
ChannelDispatcherBase* channel_dispatcher) { |
DCHECK(thread_checker_.CalledOnValidThread()); |
@@ -195,7 +198,7 @@ void IceConnectionToClient::OnChannelError( |
LOG(ERROR) << "Failed to connect channel " |
<< channel_dispatcher->channel_name(); |
- Close(CHANNEL_CONNECTION_ERROR); |
+ Disconnect(error); |
} |
void IceConnectionToClient::NotifyIfChannelsReady() { |
@@ -214,11 +217,6 @@ void IceConnectionToClient::NotifyIfChannelsReady() { |
event_handler_->OnConnectionChannelsConnected(this); |
} |
-void IceConnectionToClient::Close(ErrorCode error) { |
- CloseChannels(); |
- event_handler_->OnConnectionClosed(this, error); |
-} |
- |
void IceConnectionToClient::CloseChannels() { |
control_dispatcher_.reset(); |
event_dispatcher_.reset(); |