| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "base/message_loop_proxy.h" | 10 #include "base/message_loop_proxy.h" |
| 11 #include "remoting/base/constants.h" | 11 #include "remoting/base/constants.h" |
| 12 #include "remoting/jingle_glue/javascript_signal_strategy.h" | 12 #include "remoting/jingle_glue/javascript_signal_strategy.h" |
| 13 #include "remoting/jingle_glue/xmpp_signal_strategy.h" | 13 #include "remoting/jingle_glue/xmpp_signal_strategy.h" |
| 14 #include "remoting/protocol/auth_token_utils.h" | 14 #include "remoting/protocol/auth_token_utils.h" |
| 15 #include "remoting/protocol/client_message_dispatcher.h" | 15 #include "remoting/protocol/client_control_dispatcher.h" |
| 16 #include "remoting/protocol/client_input_dispatcher.h" |
| 16 #include "remoting/protocol/client_stub.h" | 17 #include "remoting/protocol/client_stub.h" |
| 17 #include "remoting/protocol/host_control_sender.h" | |
| 18 #include "remoting/protocol/input_sender.h" | |
| 19 #include "remoting/protocol/jingle_session_manager.h" | 18 #include "remoting/protocol/jingle_session_manager.h" |
| 20 #include "remoting/protocol/pepper_session_manager.h" | 19 #include "remoting/protocol/pepper_session_manager.h" |
| 21 #include "remoting/protocol/video_reader.h" | 20 #include "remoting/protocol/video_reader.h" |
| 22 #include "remoting/protocol/video_stub.h" | 21 #include "remoting/protocol/video_stub.h" |
| 23 #include "remoting/protocol/util.h" | 22 #include "remoting/protocol/util.h" |
| 24 | 23 |
| 25 namespace remoting { | 24 namespace remoting { |
| 26 namespace protocol { | 25 namespace protocol { |
| 27 | 26 |
| 28 ConnectionToHost::ConnectionToHost( | 27 ConnectionToHost::ConnectionToHost( |
| (...skipping 10 matching lines...) Expand all Loading... |
| 39 error_(OK), | 38 error_(OK), |
| 40 control_connected_(false), | 39 control_connected_(false), |
| 41 input_connected_(false), | 40 input_connected_(false), |
| 42 video_connected_(false) { | 41 video_connected_(false) { |
| 43 } | 42 } |
| 44 | 43 |
| 45 ConnectionToHost::~ConnectionToHost() { | 44 ConnectionToHost::~ConnectionToHost() { |
| 46 } | 45 } |
| 47 | 46 |
| 48 InputStub* ConnectionToHost::input_stub() { | 47 InputStub* ConnectionToHost::input_stub() { |
| 49 return input_sender_.get(); | 48 return input_dispatcher_.get(); |
| 50 } | 49 } |
| 51 | 50 |
| 52 HostStub* ConnectionToHost::host_stub() { | 51 HostStub* ConnectionToHost::host_stub() { |
| 53 return host_control_sender_.get(); | 52 return control_dispatcher_.get(); |
| 54 } | 53 } |
| 55 | 54 |
| 56 void ConnectionToHost::Connect(scoped_refptr<XmppProxy> xmpp_proxy, | 55 void ConnectionToHost::Connect(scoped_refptr<XmppProxy> xmpp_proxy, |
| 57 const std::string& your_jid, | 56 const std::string& your_jid, |
| 58 const std::string& host_jid, | 57 const std::string& host_jid, |
| 59 const std::string& host_public_key, | 58 const std::string& host_public_key, |
| 60 const std::string& access_code, | 59 const std::string& access_code, |
| 61 HostEventCallback* event_callback, | 60 HostEventCallback* event_callback, |
| 62 ClientStub* client_stub, | 61 ClientStub* client_stub, |
| 63 VideoStub* video_stub) { | 62 VideoStub* video_stub) { |
| (...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 193 case Session::CONNECTED: | 192 case Session::CONNECTED: |
| 194 video_reader_.reset( | 193 video_reader_.reset( |
| 195 VideoReader::Create(message_loop_, session_->config())); | 194 VideoReader::Create(message_loop_, session_->config())); |
| 196 video_reader_->Init( | 195 video_reader_->Init( |
| 197 session_.get(), video_stub_, | 196 session_.get(), video_stub_, |
| 198 base::Bind(&ConnectionToHost::OnVideoChannelInitialized, | 197 base::Bind(&ConnectionToHost::OnVideoChannelInitialized, |
| 199 base::Unretained(this))); | 198 base::Unretained(this))); |
| 200 break; | 199 break; |
| 201 | 200 |
| 202 case Session::CONNECTED_CHANNELS: | 201 case Session::CONNECTED_CHANNELS: |
| 203 host_control_sender_.reset( | 202 control_dispatcher_.reset( |
| 204 new HostControlSender(message_loop_, session_->control_channel())); | 203 new ClientControlDispatcher(message_loop_)); |
| 205 input_sender_.reset( | 204 control_dispatcher_->Init(session_.get(), client_stub_); |
| 206 new InputSender(message_loop_, session_->event_channel())); | 205 input_dispatcher_.reset( |
| 207 dispatcher_.reset(new ClientMessageDispatcher()); | 206 new ClientInputDispatcher(message_loop_)); |
| 208 dispatcher_->Initialize(session_.get(), client_stub_); | 207 input_dispatcher_->Init(session_.get()); |
| 209 | 208 |
| 210 control_connected_ = true; | 209 control_connected_ = true; |
| 211 input_connected_ = true; | 210 input_connected_ = true; |
| 212 NotifyIfChannelsReady(); | 211 NotifyIfChannelsReady(); |
| 213 break; | 212 break; |
| 214 | 213 |
| 215 default: | 214 default: |
| 216 // Ignore the other states by default. | 215 // Ignore the other states by default. |
| 217 break; | 216 break; |
| 218 } | 217 } |
| (...skipping 17 matching lines...) Expand all Loading... |
| 236 SetState(AUTHENTICATED, OK); | 235 SetState(AUTHENTICATED, OK); |
| 237 } | 236 } |
| 238 } | 237 } |
| 239 | 238 |
| 240 void ConnectionToHost::CloseOnError(Error error) { | 239 void ConnectionToHost::CloseOnError(Error error) { |
| 241 CloseChannels(); | 240 CloseChannels(); |
| 242 SetState(FAILED, error); | 241 SetState(FAILED, error); |
| 243 } | 242 } |
| 244 | 243 |
| 245 void ConnectionToHost::CloseChannels() { | 244 void ConnectionToHost::CloseChannels() { |
| 246 if (input_sender_.get()) | 245 control_dispatcher_.reset(); |
| 247 input_sender_->Close(); | 246 input_dispatcher_.reset(); |
| 248 | |
| 249 if (host_control_sender_.get()) | |
| 250 host_control_sender_->Close(); | |
| 251 | |
| 252 video_reader_.reset(); | 247 video_reader_.reset(); |
| 253 } | 248 } |
| 254 | 249 |
| 255 void ConnectionToHost::SetState(State state, Error error) { | 250 void ConnectionToHost::SetState(State state, Error error) { |
| 256 DCHECK(message_loop_->BelongsToCurrentThread()); | 251 DCHECK(message_loop_->BelongsToCurrentThread()); |
| 257 // |error| should be specified only when |state| is set to FAILED. | 252 // |error| should be specified only when |state| is set to FAILED. |
| 258 DCHECK(state == FAILED || error == OK); | 253 DCHECK(state == FAILED || error == OK); |
| 259 | 254 |
| 260 if (state != state_) { | 255 if (state != state_) { |
| 261 state_ = state; | 256 state_ = state; |
| 262 error_ = error; | 257 error_ = error; |
| 263 event_callback_->OnConnectionState(state_, error_); | 258 event_callback_->OnConnectionState(state_, error_); |
| 264 } | 259 } |
| 265 } | 260 } |
| 266 | 261 |
| 267 } // namespace protocol | 262 } // namespace protocol |
| 268 } // namespace remoting | 263 } // namespace remoting |
| OLD | NEW |