summaryrefslogtreecommitdiffstats
path: root/remoting/protocol/connection_to_client.cc
diff options
context:
space:
mode:
authorsergeyu@chromium.org <sergeyu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-08-11 02:14:35 +0000
committersergeyu@chromium.org <sergeyu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-08-11 02:14:35 +0000
commit182ec8f2c5515db4677e1ae5e6750ddbeffeeb19 (patch)
tree0d0e316403711beebfeb4fafa001855ae0a86da0 /remoting/protocol/connection_to_client.cc
parentde719a407c847bbc4c6884a5f5a07e2327e97233 (diff)
downloadchromium_src-182ec8f2c5515db4677e1ae5e6750ddbeffeeb19.zip
chromium_src-182ec8f2c5515db4677e1ae5e6750ddbeffeeb19.tar.gz
chromium_src-182ec8f2c5515db4677e1ae5e6750ddbeffeeb19.tar.bz2
Remove video_channel() from Session interface
BUG=None TEST=Unittests. Committed: http://src.chromium.org/viewvc/chrome?view=rev&revision=96089 Review URL: http://codereview.chromium.org/7508044 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@96301 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'remoting/protocol/connection_to_client.cc')
-rw-r--r--remoting/protocol/connection_to_client.cc50
1 files changed, 42 insertions, 8 deletions
diff --git a/remoting/protocol/connection_to_client.cc b/remoting/protocol/connection_to_client.cc
index f5cf592e..4330984 100644
--- a/remoting/protocol/connection_to_client.cc
+++ b/remoting/protocol/connection_to_client.cc
@@ -4,6 +4,7 @@
#include "remoting/protocol/connection_to_client.h"
+#include "base/bind.h"
#include "google/protobuf/message.h"
#include "net/base/io_buffer.h"
#include "remoting/protocol/client_control_sender.h"
@@ -26,7 +27,10 @@ ConnectionToClient::ConnectionToClient(MessageLoop* message_loop,
: loop_(message_loop),
handler_(handler),
host_stub_(NULL),
- input_stub_(NULL) {
+ input_stub_(NULL),
+ control_connected_(false),
+ input_connected_(false),
+ video_connected_(false) {
DCHECK(loop_);
DCHECK(handler_);
}
@@ -90,33 +94,63 @@ void ConnectionToClient::OnSessionStateChange(protocol::Session::State state) {
DCHECK(handler_);
switch(state) {
case protocol::Session::CONNECTING:
+ // Don't care about this message.
break;
- // Don't care about this message.
+
case protocol::Session::CONNECTED:
- client_control_sender_.reset(
- new ClientControlSender(session_->control_channel()));
video_writer_.reset(VideoWriter::Create(session_->config()));
- video_writer_->Init(session_.get());
+ video_writer_->Init(
+ session_.get(), base::Bind(&ConnectionToClient::OnVideoInitialized,
+ base::Unretained(this)));
+ break;
+ case protocol::Session::CONNECTED_CHANNELS:
+ client_control_sender_.reset(
+ new ClientControlSender(session_->control_channel()));
dispatcher_.reset(new HostMessageDispatcher());
dispatcher_->Initialize(this, host_stub_, input_stub_);
- handler_->OnConnectionOpened(this);
+ control_connected_ = true;
+ input_connected_ = true;
+ NotifyIfChannelsReady();
break;
+
case protocol::Session::CLOSED:
CloseChannels();
handler_->OnConnectionClosed(this);
break;
+
case protocol::Session::FAILED:
- CloseChannels();
- handler_->OnConnectionFailed(this);
+ CloseOnError();
break;
+
default:
// We shouldn't receive other states.
NOTREACHED();
}
}
+void ConnectionToClient::OnVideoInitialized(bool successful) {
+ if (!successful) {
+ LOG(ERROR) << "Failed to connect video channel";
+ CloseOnError();
+ return;
+ }
+
+ video_connected_ = true;
+ NotifyIfChannelsReady();
+}
+
+void ConnectionToClient::NotifyIfChannelsReady() {
+ if (control_connected_ && input_connected_ && video_connected_)
+ handler_->OnConnectionOpened(this);
+}
+
+void ConnectionToClient::CloseOnError() {
+ CloseChannels();
+ handler_->OnConnectionFailed(this);
+}
+
void ConnectionToClient::CloseChannels() {
if (video_writer_.get())
video_writer_->Close();