| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "remoting/protocol/connection_to_host.h" | 5 #include "remoting/protocol/connection_to_host.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/callback.h" | 8 #include "base/callback.h" |
| 9 #include "base/location.h" | 9 #include "base/location.h" |
| 10 #include "remoting/base/constants.h" | 10 #include "remoting/base/constants.h" |
| 11 #include "remoting/protocol/audio_reader.h" | 11 #include "remoting/protocol/audio_reader.h" |
| 12 #include "remoting/protocol/audio_stub.h" | 12 #include "remoting/protocol/audio_stub.h" |
| 13 #include "remoting/protocol/auth_util.h" | 13 #include "remoting/protocol/auth_util.h" |
| 14 #include "remoting/protocol/authenticator.h" | 14 #include "remoting/protocol/authenticator.h" |
| 15 #include "remoting/protocol/client_control_dispatcher.h" | 15 #include "remoting/protocol/client_control_dispatcher.h" |
| 16 #include "remoting/protocol/client_event_dispatcher.h" | 16 #include "remoting/protocol/client_event_dispatcher.h" |
| 17 #include "remoting/protocol/client_stub.h" | 17 #include "remoting/protocol/client_stub.h" |
| 18 #include "remoting/protocol/client_video_dispatcher.h" |
| 18 #include "remoting/protocol/clipboard_stub.h" | 19 #include "remoting/protocol/clipboard_stub.h" |
| 19 #include "remoting/protocol/errors.h" | 20 #include "remoting/protocol/errors.h" |
| 20 #include "remoting/protocol/jingle_session_manager.h" | 21 #include "remoting/protocol/jingle_session_manager.h" |
| 21 #include "remoting/protocol/transport.h" | 22 #include "remoting/protocol/transport.h" |
| 22 #include "remoting/protocol/video_reader.h" | |
| 23 #include "remoting/protocol/video_stub.h" | 23 #include "remoting/protocol/video_stub.h" |
| 24 | 24 |
| 25 namespace remoting { | 25 namespace remoting { |
| 26 namespace protocol { | 26 namespace protocol { |
| 27 | 27 |
| 28 ConnectionToHost::ConnectionToHost() | 28 ConnectionToHost::ConnectionToHost() |
| 29 : event_callback_(NULL), | 29 : event_callback_(NULL), |
| 30 client_stub_(NULL), | 30 client_stub_(NULL), |
| 31 clipboard_stub_(NULL), | 31 clipboard_stub_(NULL), |
| 32 audio_stub_(NULL), | 32 audio_stub_(NULL), |
| (...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 190 base::Unretained(this))); | 190 base::Unretained(this))); |
| 191 control_dispatcher_->set_client_stub(client_stub_); | 191 control_dispatcher_->set_client_stub(client_stub_); |
| 192 control_dispatcher_->set_clipboard_stub(clipboard_stub_); | 192 control_dispatcher_->set_clipboard_stub(clipboard_stub_); |
| 193 | 193 |
| 194 event_dispatcher_.reset(new ClientEventDispatcher()); | 194 event_dispatcher_.reset(new ClientEventDispatcher()); |
| 195 event_dispatcher_->Init( | 195 event_dispatcher_->Init( |
| 196 session_.get(), session_->config().event_config(), | 196 session_.get(), session_->config().event_config(), |
| 197 base::Bind(&ConnectionToHost::OnChannelInitialized, | 197 base::Bind(&ConnectionToHost::OnChannelInitialized, |
| 198 base::Unretained(this))); | 198 base::Unretained(this))); |
| 199 | 199 |
| 200 video_reader_ = VideoReader::Create(session_->config()); | 200 video_dispatcher_.reset( |
| 201 video_reader_->Init(session_.get(), monitored_video_stub_.get(), | 201 new ClientVideoDispatcher(monitored_video_stub_.get())); |
| 202 video_dispatcher_->Init(session_.get(), session_->config().video_config(), |
| 202 base::Bind(&ConnectionToHost::OnChannelInitialized, | 203 base::Bind(&ConnectionToHost::OnChannelInitialized, |
| 203 base::Unretained(this))); | 204 base::Unretained(this))); |
| 204 | 205 |
| 205 audio_reader_ = AudioReader::Create(session_->config()); | 206 audio_reader_ = AudioReader::Create(session_->config()); |
| 206 if (audio_reader_.get()) { | 207 if (audio_reader_.get()) { |
| 207 audio_reader_->Init(session_.get(), session_->config().audio_config(), | 208 audio_reader_->Init(session_.get(), session_->config().audio_config(), |
| 208 base::Bind(&ConnectionToHost::OnChannelInitialized, | 209 base::Bind(&ConnectionToHost::OnChannelInitialized, |
| 209 base::Unretained(this))); | 210 base::Unretained(this))); |
| 210 audio_reader_->set_audio_stub(audio_stub_); | 211 audio_reader_->set_audio_stub(audio_stub_); |
| 211 } | 212 } |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 256 } | 257 } |
| 257 | 258 |
| 258 NotifyIfChannelsReady(); | 259 NotifyIfChannelsReady(); |
| 259 } | 260 } |
| 260 | 261 |
| 261 void ConnectionToHost::NotifyIfChannelsReady() { | 262 void ConnectionToHost::NotifyIfChannelsReady() { |
| 262 if (!control_dispatcher_.get() || !control_dispatcher_->is_connected()) | 263 if (!control_dispatcher_.get() || !control_dispatcher_->is_connected()) |
| 263 return; | 264 return; |
| 264 if (!event_dispatcher_.get() || !event_dispatcher_->is_connected()) | 265 if (!event_dispatcher_.get() || !event_dispatcher_->is_connected()) |
| 265 return; | 266 return; |
| 266 if (!video_reader_.get() || !video_reader_->is_connected()) | 267 if (!video_dispatcher_.get() || !video_dispatcher_->is_connected()) |
| 267 return; | 268 return; |
| 268 if ((!audio_reader_.get() || !audio_reader_->is_connected()) && | 269 if ((!audio_reader_.get() || !audio_reader_->is_connected()) && |
| 269 session_->config().is_audio_enabled()) { | 270 session_->config().is_audio_enabled()) { |
| 270 return; | 271 return; |
| 271 } | 272 } |
| 272 if (state_ != AUTHENTICATED) | 273 if (state_ != AUTHENTICATED) |
| 273 return; | 274 return; |
| 274 | 275 |
| 275 // Start forwarding clipboard and input events. | 276 // Start forwarding clipboard and input events. |
| 276 clipboard_forwarder_.set_clipboard_stub(control_dispatcher_.get()); | 277 clipboard_forwarder_.set_clipboard_stub(control_dispatcher_.get()); |
| 277 event_forwarder_.set_input_stub(event_dispatcher_.get()); | 278 event_forwarder_.set_input_stub(event_dispatcher_.get()); |
| 278 SetState(CONNECTED, OK); | 279 SetState(CONNECTED, OK); |
| 279 } | 280 } |
| 280 | 281 |
| 281 void ConnectionToHost::CloseOnError(ErrorCode error) { | 282 void ConnectionToHost::CloseOnError(ErrorCode error) { |
| 282 CloseChannels(); | 283 CloseChannels(); |
| 283 SetState(FAILED, error); | 284 SetState(FAILED, error); |
| 284 } | 285 } |
| 285 | 286 |
| 286 void ConnectionToHost::CloseChannels() { | 287 void ConnectionToHost::CloseChannels() { |
| 287 control_dispatcher_.reset(); | 288 control_dispatcher_.reset(); |
| 288 event_dispatcher_.reset(); | 289 event_dispatcher_.reset(); |
| 289 clipboard_forwarder_.set_clipboard_stub(NULL); | 290 clipboard_forwarder_.set_clipboard_stub(NULL); |
| 290 event_forwarder_.set_input_stub(NULL); | 291 event_forwarder_.set_input_stub(NULL); |
| 291 video_reader_.reset(); | 292 video_dispatcher_.reset(); |
| 292 audio_reader_.reset(); | 293 audio_reader_.reset(); |
| 293 } | 294 } |
| 294 | 295 |
| 295 void ConnectionToHost::SetState(State state, ErrorCode error) { | 296 void ConnectionToHost::SetState(State state, ErrorCode error) { |
| 296 DCHECK(CalledOnValidThread()); | 297 DCHECK(CalledOnValidThread()); |
| 297 // |error| should be specified only when |state| is set to FAILED. | 298 // |error| should be specified only when |state| is set to FAILED. |
| 298 DCHECK(state == FAILED || error == OK); | 299 DCHECK(state == FAILED || error == OK); |
| 299 | 300 |
| 300 if (state != state_) { | 301 if (state != state_) { |
| 301 state_ = state; | 302 state_ = state; |
| 302 error_ = error; | 303 error_ = error; |
| 303 event_callback_->OnConnectionState(state_, error_); | 304 event_callback_->OnConnectionState(state_, error_); |
| 304 } | 305 } |
| 305 } | 306 } |
| 306 | 307 |
| 307 } // namespace protocol | 308 } // namespace protocol |
| 308 } // namespace remoting | 309 } // namespace remoting |
| OLD | NEW |