Index: remoting/protocol/connection_to_client.cc |
diff --git a/remoting/protocol/connection_to_client.cc b/remoting/protocol/connection_to_client.cc |
index 4f8a46b2b2177f787b5a6b5006e39a8726f69ea7..e1c10dfba1a2264d012bbbd7884c37dfed6094b5 100644 |
--- a/remoting/protocol/connection_to_client.cc |
+++ b/remoting/protocol/connection_to_client.cc |
@@ -25,16 +25,19 @@ namespace protocol { |
static const size_t kAverageUpdateStream = 10; |
Wez
2011/11/09 01:35:07
I can't see this being used anywhere, so maybe rem
Sergey Ulanov
2011/11/09 19:26:13
Done.
|
ConnectionToClient::ConnectionToClient(base::MessageLoopProxy* message_loop, |
- EventHandler* handler) |
+ protocol::Session* session) |
: message_loop_(message_loop), |
- handler_(handler), |
+ handler_(NULL), |
host_stub_(NULL), |
input_stub_(NULL), |
+ session_(session), |
control_connected_(false), |
input_connected_(false), |
video_connected_(false) { |
DCHECK(message_loop_); |
- DCHECK(handler_); |
+ session_->SetStateChangeCallback( |
+ base::Bind(&ConnectionToClient::OnSessionStateChange, |
+ base::Unretained(this))); |
Wez
2011/11/09 01:35:07
Why not do this in SetEventHandler()? (Not saying
Sergey Ulanov
2011/11/09 19:26:13
Just because I moved |session| parameter from Init
|
} |
ConnectionToClient::~ConnectionToClient() { |
@@ -42,12 +45,9 @@ ConnectionToClient::~ConnectionToClient() { |
// connection. |
} |
-void ConnectionToClient::Init(protocol::Session* session) { |
+void ConnectionToClient::SetEventHandler(EventHandler* event_handler) { |
DCHECK(message_loop_->BelongsToCurrentThread()); |
- session_.reset(session); |
- session_->SetStateChangeCallback( |
- base::Bind(&ConnectionToClient::OnSessionStateChange, |
- base::Unretained(this))); |
+ handler_ = event_handler; |
} |
protocol::Session* ConnectionToClient::session() { |
@@ -71,7 +71,8 @@ void ConnectionToClient::Disconnect() { |
} |
void ConnectionToClient::UpdateSequenceNumber(int64 sequence_number) { |
- handler_->OnSequenceNumberUpdated(this, sequence_number); |
+ if (handler_) |
+ handler_->OnSequenceNumberUpdated(this, sequence_number); |
} |
VideoStub* ConnectionToClient::video_stub() { |
@@ -94,7 +95,6 @@ void ConnectionToClient::set_input_stub(protocol::InputStub* input_stub) { |
void ConnectionToClient::OnSessionStateChange(protocol::Session::State state) { |
DCHECK(message_loop_->BelongsToCurrentThread()); |
- DCHECK(handler_); |
switch(state) { |
case protocol::Session::CONNECTING: |
// Don't care about this message. |
@@ -121,7 +121,8 @@ void ConnectionToClient::OnSessionStateChange(protocol::Session::State state) { |
case protocol::Session::CLOSED: |
CloseChannels(); |
- handler_->OnConnectionClosed(this); |
+ if (handler_) |
+ handler_->OnConnectionClosed(this); |
break; |
case protocol::Session::FAILED: |
@@ -146,13 +147,16 @@ void ConnectionToClient::OnVideoInitialized(bool successful) { |
} |
void ConnectionToClient::NotifyIfChannelsReady() { |
- if (control_connected_ && input_connected_ && video_connected_) |
- handler_->OnConnectionOpened(this); |
+ if (control_connected_ && input_connected_ && video_connected_) { |
+ if (handler_) |
+ handler_->OnConnectionOpened(this); |
Wez
2011/11/09 01:35:07
Doesn't this mean we'll never get this notificatio
Sergey Ulanov
2011/11/09 19:26:13
Fixed it. Now SetEventHandler() is required to be
|
+ } |
} |
void ConnectionToClient::CloseOnError() { |
CloseChannels(); |
- handler_->OnConnectionFailed(this); |
+ if (handler_) |
+ handler_->OnConnectionFailed(this); |
} |
void ConnectionToClient::CloseChannels() { |