| 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/jingle_glue/javascript_signal_strategy.h" | 11 #include "remoting/jingle_glue/javascript_signal_strategy.h" |
| 12 #include "remoting/jingle_glue/xmpp_signal_strategy.h" | 12 #include "remoting/jingle_glue/xmpp_signal_strategy.h" |
| 13 #include "remoting/protocol/audio_reader.h" |
| 14 #include "remoting/protocol/audio_stub.h" |
| 13 #include "remoting/protocol/auth_util.h" | 15 #include "remoting/protocol/auth_util.h" |
| 14 #include "remoting/protocol/authenticator.h" | 16 #include "remoting/protocol/authenticator.h" |
| 15 #include "remoting/protocol/client_control_dispatcher.h" | 17 #include "remoting/protocol/client_control_dispatcher.h" |
| 16 #include "remoting/protocol/client_event_dispatcher.h" | 18 #include "remoting/protocol/client_event_dispatcher.h" |
| 17 #include "remoting/protocol/client_stub.h" | 19 #include "remoting/protocol/client_stub.h" |
| 18 #include "remoting/protocol/clipboard_stub.h" | 20 #include "remoting/protocol/clipboard_stub.h" |
| 19 #include "remoting/protocol/errors.h" | 21 #include "remoting/protocol/errors.h" |
| 20 #include "remoting/protocol/jingle_session_manager.h" | 22 #include "remoting/protocol/jingle_session_manager.h" |
| 21 #include "remoting/protocol/transport.h" | 23 #include "remoting/protocol/transport.h" |
| 22 #include "remoting/protocol/video_reader.h" | 24 #include "remoting/protocol/video_reader.h" |
| 23 #include "remoting/protocol/video_stub.h" | 25 #include "remoting/protocol/video_stub.h" |
| 24 #include "remoting/protocol/util.h" | 26 #include "remoting/protocol/util.h" |
| 25 | 27 |
| 26 namespace remoting { | 28 namespace remoting { |
| 27 namespace protocol { | 29 namespace protocol { |
| 28 | 30 |
| 29 ConnectionToHost::ConnectionToHost( | 31 ConnectionToHost::ConnectionToHost( |
| 30 bool allow_nat_traversal) | 32 bool allow_nat_traversal) |
| 31 : allow_nat_traversal_(allow_nat_traversal), | 33 : allow_nat_traversal_(allow_nat_traversal), |
| 32 event_callback_(NULL), | 34 event_callback_(NULL), |
| 33 client_stub_(NULL), | 35 client_stub_(NULL), |
| 34 clipboard_stub_(NULL), | 36 clipboard_stub_(NULL), |
| 35 video_stub_(NULL), | 37 video_stub_(NULL), |
| 38 audio_stub_(NULL), |
| 36 state_(CONNECTING), | 39 state_(CONNECTING), |
| 37 error_(OK) { | 40 error_(OK) { |
| 38 } | 41 } |
| 39 | 42 |
| 40 ConnectionToHost::~ConnectionToHost() { | 43 ConnectionToHost::~ConnectionToHost() { |
| 41 } | 44 } |
| 42 | 45 |
| 43 ClipboardStub* ConnectionToHost::clipboard_stub() { | 46 ClipboardStub* ConnectionToHost::clipboard_stub() { |
| 44 return &clipboard_forwarder_; | 47 return &clipboard_forwarder_; |
| 45 } | 48 } |
| 46 | 49 |
| 47 HostStub* ConnectionToHost::host_stub() { | 50 HostStub* ConnectionToHost::host_stub() { |
| 48 // TODO(wez): Add a HostFilter class, equivalent to input filter. | 51 // TODO(wez): Add a HostFilter class, equivalent to input filter. |
| 49 return control_dispatcher_.get(); | 52 return control_dispatcher_.get(); |
| 50 } | 53 } |
| 51 | 54 |
| 52 InputStub* ConnectionToHost::input_stub() { | 55 InputStub* ConnectionToHost::input_stub() { |
| 53 return &event_forwarder_; | 56 return &event_forwarder_; |
| 54 } | 57 } |
| 55 | 58 |
| 56 void ConnectionToHost::Connect(scoped_refptr<XmppProxy> xmpp_proxy, | 59 void ConnectionToHost::Connect(scoped_refptr<XmppProxy> xmpp_proxy, |
| 57 const std::string& local_jid, | 60 const std::string& local_jid, |
| 58 const std::string& host_jid, | 61 const std::string& host_jid, |
| 59 const std::string& host_public_key, | 62 const std::string& host_public_key, |
| 60 scoped_ptr<TransportFactory> transport_factory, | 63 scoped_ptr<TransportFactory> transport_factory, |
| 61 scoped_ptr<Authenticator> authenticator, | 64 scoped_ptr<Authenticator> authenticator, |
| 62 HostEventCallback* event_callback, | 65 HostEventCallback* event_callback, |
| 63 ClientStub* client_stub, | 66 ClientStub* client_stub, |
| 64 ClipboardStub* clipboard_stub, | 67 ClipboardStub* clipboard_stub, |
| 65 VideoStub* video_stub) { | 68 VideoStub* video_stub, |
| 69 AudioStub* audio_stub) { |
| 66 event_callback_ = event_callback; | 70 event_callback_ = event_callback; |
| 67 client_stub_ = client_stub; | 71 client_stub_ = client_stub; |
| 68 clipboard_stub_ = clipboard_stub; | 72 clipboard_stub_ = clipboard_stub; |
| 69 video_stub_ = video_stub; | 73 video_stub_ = video_stub; |
| 74 audio_stub_ = audio_stub; |
| 70 authenticator_ = authenticator.Pass(); | 75 authenticator_ = authenticator.Pass(); |
| 71 | 76 |
| 72 // Save jid of the host. The actual connection is created later after | 77 // Save jid of the host. The actual connection is created later after |
| 73 // |signal_strategy_| is connected. | 78 // |signal_strategy_| is connected. |
| 74 host_jid_ = host_jid; | 79 host_jid_ = host_jid; |
| 75 host_public_key_ = host_public_key; | 80 host_public_key_ = host_public_key; |
| 76 | 81 |
| 77 JavascriptSignalStrategy* strategy = new JavascriptSignalStrategy(local_jid); | 82 JavascriptSignalStrategy* strategy = new JavascriptSignalStrategy(local_jid); |
| 78 strategy->AttachXmppProxy(xmpp_proxy); | 83 strategy->AttachXmppProxy(xmpp_proxy); |
| 79 signal_strategy_.reset(strategy); | 84 signal_strategy_.reset(strategy); |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 155 case Session::CONNECTING: | 160 case Session::CONNECTING: |
| 156 case Session::CONNECTED: | 161 case Session::CONNECTED: |
| 157 // Don't care about these events. | 162 // Don't care about these events. |
| 158 break; | 163 break; |
| 159 | 164 |
| 160 case Session::AUTHENTICATED: | 165 case Session::AUTHENTICATED: |
| 161 video_reader_ = VideoReader::Create(session_->config()); | 166 video_reader_ = VideoReader::Create(session_->config()); |
| 162 video_reader_->Init(session_.get(), video_stub_, base::Bind( | 167 video_reader_->Init(session_.get(), video_stub_, base::Bind( |
| 163 &ConnectionToHost::OnChannelInitialized, base::Unretained(this))); | 168 &ConnectionToHost::OnChannelInitialized, base::Unretained(this))); |
| 164 | 169 |
| 170 audio_reader_ = AudioReader::Create(session_->config()); |
| 171 audio_reader_->Init(session_.get(), audio_stub_, base::Bind( |
| 172 &ConnectionToHost::OnChannelInitialized, base::Unretained(this))); |
| 173 |
| 165 control_dispatcher_.reset(new ClientControlDispatcher()); | 174 control_dispatcher_.reset(new ClientControlDispatcher()); |
| 166 control_dispatcher_->Init(session_.get(), base::Bind( | 175 control_dispatcher_->Init(session_.get(), base::Bind( |
| 167 &ConnectionToHost::OnChannelInitialized, base::Unretained(this))); | 176 &ConnectionToHost::OnChannelInitialized, base::Unretained(this))); |
| 168 control_dispatcher_->set_client_stub(client_stub_); | 177 control_dispatcher_->set_client_stub(client_stub_); |
| 169 control_dispatcher_->set_clipboard_stub(clipboard_stub_); | 178 control_dispatcher_->set_clipboard_stub(clipboard_stub_); |
| 170 | 179 |
| 171 event_dispatcher_.reset(new ClientEventDispatcher()); | 180 event_dispatcher_.reset(new ClientEventDispatcher()); |
| 172 event_dispatcher_->Init(session_.get(), base::Bind( | 181 event_dispatcher_->Init(session_.get(), base::Bind( |
| 173 &ConnectionToHost::OnChannelInitialized, base::Unretained(this))); | 182 &ConnectionToHost::OnChannelInitialized, base::Unretained(this))); |
| 174 break; | 183 break; |
| (...skipping 29 matching lines...) Expand all Loading... |
| 204 return; | 213 return; |
| 205 } | 214 } |
| 206 | 215 |
| 207 NotifyIfChannelsReady(); | 216 NotifyIfChannelsReady(); |
| 208 } | 217 } |
| 209 | 218 |
| 210 void ConnectionToHost::NotifyIfChannelsReady() { | 219 void ConnectionToHost::NotifyIfChannelsReady() { |
| 211 if (control_dispatcher_.get() && control_dispatcher_->is_connected() && | 220 if (control_dispatcher_.get() && control_dispatcher_->is_connected() && |
| 212 event_dispatcher_.get() && event_dispatcher_->is_connected() && | 221 event_dispatcher_.get() && event_dispatcher_->is_connected() && |
| 213 video_reader_.get() && video_reader_->is_connected() && | 222 video_reader_.get() && video_reader_->is_connected() && |
| 223 audio_reader_.get() && audio_reader_->is_connected() && |
| 214 state_ == CONNECTING) { | 224 state_ == CONNECTING) { |
| 215 // Start forwarding clipboard and input events. | 225 // Start forwarding clipboard and input events. |
| 216 clipboard_forwarder_.set_clipboard_stub(control_dispatcher_.get()); | 226 clipboard_forwarder_.set_clipboard_stub(control_dispatcher_.get()); |
| 217 event_forwarder_.set_input_stub(event_dispatcher_.get()); | 227 event_forwarder_.set_input_stub(event_dispatcher_.get()); |
| 218 SetState(CONNECTED, OK); | 228 SetState(CONNECTED, OK); |
| 219 } | 229 } |
| 220 } | 230 } |
| 221 | 231 |
| 222 void ConnectionToHost::CloseOnError(ErrorCode error) { | 232 void ConnectionToHost::CloseOnError(ErrorCode error) { |
| 223 CloseChannels(); | 233 CloseChannels(); |
| 224 SetState(FAILED, error); | 234 SetState(FAILED, error); |
| 225 } | 235 } |
| 226 | 236 |
| 227 void ConnectionToHost::CloseChannels() { | 237 void ConnectionToHost::CloseChannels() { |
| 228 control_dispatcher_.reset(); | 238 control_dispatcher_.reset(); |
| 229 event_dispatcher_.reset(); | 239 event_dispatcher_.reset(); |
| 230 clipboard_forwarder_.set_clipboard_stub(NULL); | 240 clipboard_forwarder_.set_clipboard_stub(NULL); |
| 231 event_forwarder_.set_input_stub(NULL); | 241 event_forwarder_.set_input_stub(NULL); |
| 232 video_reader_.reset(); | 242 video_reader_.reset(); |
| 243 audio_reader_.reset(); |
| 233 } | 244 } |
| 234 | 245 |
| 235 void ConnectionToHost::SetState(State state, ErrorCode error) { | 246 void ConnectionToHost::SetState(State state, ErrorCode error) { |
| 236 DCHECK(CalledOnValidThread()); | 247 DCHECK(CalledOnValidThread()); |
| 237 // |error| should be specified only when |state| is set to FAILED. | 248 // |error| should be specified only when |state| is set to FAILED. |
| 238 DCHECK(state == FAILED || error == OK); | 249 DCHECK(state == FAILED || error == OK); |
| 239 | 250 |
| 240 if (state != state_) { | 251 if (state != state_) { |
| 241 state_ = state; | 252 state_ = state; |
| 242 error_ = error; | 253 error_ = error; |
| 243 event_callback_->OnConnectionState(state_, error_); | 254 event_callback_->OnConnectionState(state_, error_); |
| 244 } | 255 } |
| 245 } | 256 } |
| 246 | 257 |
| 247 } // namespace protocol | 258 } // namespace protocol |
| 248 } // namespace remoting | 259 } // namespace remoting |
| OLD | NEW |