Index: remoting/protocol/connection_to_host.cc |
diff --git a/remoting/protocol/connection_to_host.cc b/remoting/protocol/connection_to_host.cc |
index 580f1984fbc290e80bcffd8a345d3a41ac5b9e3d..bf335c2646737c155d7ea2f887db237cbf045e72 100644 |
--- a/remoting/protocol/connection_to_host.cc |
+++ b/remoting/protocol/connection_to_host.cc |
@@ -172,8 +172,7 @@ void ConnectionToHost::OnSessionStateChange( |
switch (state) { |
case Session::FAILED: |
state_ = STATE_FAILED; |
- CloseChannels(); |
- event_callback_->OnConnectionFailed(this); |
+ CloseOnError(); |
break; |
case Session::CLOSED: |
@@ -186,7 +185,10 @@ void ConnectionToHost::OnSessionStateChange( |
state_ = STATE_CONNECTED; |
// Initialize reader and writer. |
video_reader_.reset(VideoReader::Create(session_->config())); |
- video_reader_->Init(session_.get(), video_stub_); |
+ video_reader_->Init( |
+ session_.get(), video_stub_, |
+ base::Bind(&ConnectionToHost::OnVideoChannelInitialized, |
+ base::Unretained(this))); |
host_control_sender_.reset( |
new HostControlSender(session_->control_channel())); |
dispatcher_->Initialize(session_.get(), client_stub_); |
@@ -199,12 +201,27 @@ void ConnectionToHost::OnSessionStateChange( |
} |
} |
+void ConnectionToHost::OnVideoChannelInitialized(bool successful) { |
+ if (!successful) { |
+ CloseOnError(); |
+ return; |
+ } |
+} |
+ |
+void ConnectionToHost::CloseOnError() { |
+ state_ = STATE_FAILED; |
+ CloseChannels(); |
+ event_callback_->OnConnectionFailed(this); |
+} |
+ |
void ConnectionToHost::CloseChannels() { |
if (input_sender_.get()) |
input_sender_->Close(); |
if (host_control_sender_.get()) |
host_control_sender_->Close(); |
+ |
+ video_reader_.reset(); |
} |
void ConnectionToHost::OnClientAuthenticated() { |