| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/ice_connection_to_host.h" | 5 #include "remoting/protocol/ice_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/client_control_dispatcher.h" | 14 #include "remoting/protocol/client_control_dispatcher.h" |
| 15 #include "remoting/protocol/client_event_dispatcher.h" | 15 #include "remoting/protocol/client_event_dispatcher.h" |
| 16 #include "remoting/protocol/client_stub.h" | 16 #include "remoting/protocol/client_stub.h" |
| 17 #include "remoting/protocol/client_video_dispatcher.h" | 17 #include "remoting/protocol/client_video_dispatcher.h" |
| 18 #include "remoting/protocol/clipboard_stub.h" | 18 #include "remoting/protocol/clipboard_stub.h" |
| 19 #include "remoting/protocol/errors.h" | 19 #include "remoting/protocol/errors.h" |
| 20 #include "remoting/protocol/ice_transport.h" | 20 #include "remoting/protocol/ice_transport.h" |
| 21 #include "remoting/protocol/transport.h" | 21 #include "remoting/protocol/transport_context.h" |
| 22 #include "remoting/protocol/video_stub.h" | 22 #include "remoting/protocol/video_stub.h" |
| 23 | 23 |
| 24 namespace remoting { | 24 namespace remoting { |
| 25 namespace protocol { | 25 namespace protocol { |
| 26 | 26 |
| 27 IceConnectionToHost::IceConnectionToHost() {} | 27 IceConnectionToHost::IceConnectionToHost() {} |
| 28 IceConnectionToHost::~IceConnectionToHost() {} | 28 IceConnectionToHost::~IceConnectionToHost() {} |
| 29 | 29 |
| 30 void IceConnectionToHost::Connect(scoped_ptr<Session> session, | 30 void IceConnectionToHost::Connect( |
| 31 HostEventCallback* event_callback) { | 31 scoped_ptr<Session> session, |
| 32 scoped_refptr<TransportContext> transport_context, |
| 33 HostEventCallback* event_callback) { |
| 32 DCHECK(client_stub_); | 34 DCHECK(client_stub_); |
| 33 DCHECK(clipboard_stub_); | 35 DCHECK(clipboard_stub_); |
| 34 DCHECK(monitored_video_stub_); | 36 DCHECK(monitored_video_stub_); |
| 35 | 37 |
| 38 transport_.reset(new IceTransport(transport_context, this)); |
| 39 |
| 36 session_ = std::move(session); | 40 session_ = std::move(session); |
| 37 session_->SetEventHandler(this); | 41 session_->SetEventHandler(this); |
| 42 session_->SetTransport(transport_.get()); |
| 38 | 43 |
| 39 event_callback_ = event_callback; | 44 event_callback_ = event_callback; |
| 40 | 45 |
| 41 SetState(CONNECTING, OK); | 46 SetState(CONNECTING, OK); |
| 42 } | 47 } |
| 43 | 48 |
| 44 const SessionConfig& IceConnectionToHost::config() { | 49 const SessionConfig& IceConnectionToHost::config() { |
| 45 return session_->config(); | 50 return session_->config(); |
| 46 } | 51 } |
| 47 | 52 |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 82 void IceConnectionToHost::OnSessionStateChange(Session::State state) { | 87 void IceConnectionToHost::OnSessionStateChange(Session::State state) { |
| 83 DCHECK(CalledOnValidThread()); | 88 DCHECK(CalledOnValidThread()); |
| 84 DCHECK(event_callback_); | 89 DCHECK(event_callback_); |
| 85 | 90 |
| 86 switch (state) { | 91 switch (state) { |
| 87 case Session::INITIALIZING: | 92 case Session::INITIALIZING: |
| 88 case Session::CONNECTING: | 93 case Session::CONNECTING: |
| 89 case Session::ACCEPTING: | 94 case Session::ACCEPTING: |
| 90 case Session::ACCEPTED: | 95 case Session::ACCEPTED: |
| 91 case Session::AUTHENTICATING: | 96 case Session::AUTHENTICATING: |
| 92 case Session::CONNECTED: | |
| 93 // Don't care about these events. | 97 // Don't care about these events. |
| 94 break; | 98 break; |
| 95 | 99 |
| 96 case Session::AUTHENTICATED: | 100 case Session::AUTHENTICATED: |
| 97 SetState(AUTHENTICATED, OK); | 101 SetState(AUTHENTICATED, OK); |
| 98 | |
| 99 control_dispatcher_.reset(new ClientControlDispatcher()); | 102 control_dispatcher_.reset(new ClientControlDispatcher()); |
| 100 control_dispatcher_->Init( | 103 control_dispatcher_->Init(transport_->GetMultiplexedChannelFactory(), |
| 101 session_->GetTransport()->GetMultiplexedChannelFactory(), this); | 104 this); |
| 102 control_dispatcher_->set_client_stub(client_stub_); | 105 control_dispatcher_->set_client_stub(client_stub_); |
| 103 control_dispatcher_->set_clipboard_stub(clipboard_stub_); | 106 control_dispatcher_->set_clipboard_stub(clipboard_stub_); |
| 104 | 107 |
| 105 event_dispatcher_.reset(new ClientEventDispatcher()); | 108 event_dispatcher_.reset(new ClientEventDispatcher()); |
| 106 event_dispatcher_->Init( | 109 event_dispatcher_->Init(transport_->GetMultiplexedChannelFactory(), this); |
| 107 session_->GetTransport()->GetMultiplexedChannelFactory(), this); | |
| 108 | 110 |
| 109 video_dispatcher_.reset( | 111 video_dispatcher_.reset( |
| 110 new ClientVideoDispatcher(monitored_video_stub_.get())); | 112 new ClientVideoDispatcher(monitored_video_stub_.get())); |
| 111 video_dispatcher_->Init( | 113 video_dispatcher_->Init(transport_->GetStreamChannelFactory(), this); |
| 112 session_->GetTransport()->GetStreamChannelFactory(), this); | |
| 113 | 114 |
| 114 if (session_->config().is_audio_enabled()) { | 115 if (session_->config().is_audio_enabled()) { |
| 115 audio_reader_.reset(new AudioReader(audio_stub_)); | 116 audio_reader_.reset(new AudioReader(audio_stub_)); |
| 116 audio_reader_->Init( | 117 audio_reader_->Init(transport_->GetMultiplexedChannelFactory(), this); |
| 117 session_->GetTransport()->GetMultiplexedChannelFactory(), this); | |
| 118 } | 118 } |
| 119 break; | 119 break; |
| 120 | 120 |
| 121 case Session::CLOSED: | 121 case Session::CLOSED: |
| 122 CloseChannels(); | 122 CloseChannels(); |
| 123 SetState(CLOSED, OK); | 123 SetState(CLOSED, OK); |
| 124 break; | 124 break; |
| 125 | 125 |
| 126 case Session::FAILED: | 126 case Session::FAILED: |
| 127 // If we were connected then treat signaling timeout error as if | 127 // If we were connected then treat signaling timeout error as if |
| 128 // the connection was closed by the peer. | 128 // the connection was closed by the peer. |
| 129 // | 129 // |
| 130 // TODO(sergeyu): This logic belongs to the webapp, but we | 130 // TODO(sergeyu): This logic belongs to the webapp, but we |
| 131 // currently don't expose this error code to the webapp, and it | 131 // currently don't expose this error code to the webapp, and it |
| 132 // would be hard to add it because client plugin and webapp | 132 // would be hard to add it because client plugin and webapp |
| 133 // versions may not be in sync. It should be easy to do after we | 133 // versions may not be in sync. It should be easy to do after we |
| 134 // are finished moving the client plugin to NaCl. | 134 // are finished moving the client plugin to NaCl. |
| 135 if (state_ == CONNECTED && session_->error() == SIGNALING_TIMEOUT) { | 135 if (state_ == CONNECTED && session_->error() == SIGNALING_TIMEOUT) { |
| 136 CloseChannels(); | 136 CloseChannels(); |
| 137 SetState(CLOSED, OK); | 137 SetState(CLOSED, OK); |
| 138 } else { | 138 } else { |
| 139 CloseOnError(session_->error()); | 139 CloseOnError(session_->error()); |
| 140 } | 140 } |
| 141 break; | 141 break; |
| 142 } | 142 } |
| 143 } | 143 } |
| 144 | 144 |
| 145 void IceConnectionToHost::OnSessionRouteChange(const std::string& channel_name, | 145 void IceConnectionToHost::OnIceTransportRouteChange( |
| 146 const TransportRoute& route) { | 146 const std::string& channel_name, |
| 147 const TransportRoute& route) { |
| 147 event_callback_->OnRouteChanged(channel_name, route); | 148 event_callback_->OnRouteChanged(channel_name, route); |
| 148 } | 149 } |
| 149 | 150 |
| 151 void IceConnectionToHost::OnIceTransportError(ErrorCode error) { |
| 152 session_->Close(error); |
| 153 } |
| 154 |
| 150 void IceConnectionToHost::OnChannelInitialized( | 155 void IceConnectionToHost::OnChannelInitialized( |
| 151 ChannelDispatcherBase* channel_dispatcher) { | 156 ChannelDispatcherBase* channel_dispatcher) { |
| 152 NotifyIfChannelsReady(); | 157 NotifyIfChannelsReady(); |
| 153 } | 158 } |
| 154 | 159 |
| 155 void IceConnectionToHost::OnChannelError( | 160 void IceConnectionToHost::OnChannelError( |
| 156 ChannelDispatcherBase* channel_dispatcher, | 161 ChannelDispatcherBase* channel_dispatcher, |
| 157 ErrorCode error) { | 162 ErrorCode error) { |
| 158 LOG(ERROR) << "Failed to connect channel " << channel_dispatcher; | 163 LOG(ERROR) << "Failed to connect channel " |
| 164 << channel_dispatcher->channel_name(); |
| 159 CloseOnError(CHANNEL_CONNECTION_ERROR); | 165 CloseOnError(CHANNEL_CONNECTION_ERROR); |
| 160 return; | |
| 161 } | 166 } |
| 162 | 167 |
| 163 void IceConnectionToHost::OnVideoChannelStatus(bool active) { | 168 void IceConnectionToHost::OnVideoChannelStatus(bool active) { |
| 164 event_callback_->OnConnectionReady(active); | 169 event_callback_->OnConnectionReady(active); |
| 165 } | 170 } |
| 166 | 171 |
| 167 ConnectionToHost::State IceConnectionToHost::state() const { | 172 ConnectionToHost::State IceConnectionToHost::state() const { |
| 168 return state_; | 173 return state_; |
| 169 } | 174 } |
| 170 | 175 |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 209 | 214 |
| 210 if (state != state_) { | 215 if (state != state_) { |
| 211 state_ = state; | 216 state_ = state; |
| 212 error_ = error; | 217 error_ = error; |
| 213 event_callback_->OnConnectionState(state_, error_); | 218 event_callback_->OnConnectionState(state_, error_); |
| 214 } | 219 } |
| 215 } | 220 } |
| 216 | 221 |
| 217 } // namespace protocol | 222 } // namespace protocol |
| 218 } // namespace remoting | 223 } // namespace remoting |
| OLD | NEW |