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 <utility> | 7 #include <utility> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/callback.h" | 10 #include "base/callback.h" |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
113 // Configure video pipeline. | 113 // Configure video pipeline. |
114 video_renderer_->OnSessionConfig(session_->config()); | 114 video_renderer_->OnSessionConfig(session_->config()); |
115 monitored_video_stub_.reset(new MonitoredVideoStub( | 115 monitored_video_stub_.reset(new MonitoredVideoStub( |
116 video_renderer_->GetVideoStub(), | 116 video_renderer_->GetVideoStub(), |
117 base::TimeDelta::FromSeconds( | 117 base::TimeDelta::FromSeconds( |
118 MonitoredVideoStub::kConnectivityCheckDelaySeconds), | 118 MonitoredVideoStub::kConnectivityCheckDelaySeconds), |
119 base::Bind(&IceConnectionToHost::OnVideoChannelStatus, | 119 base::Bind(&IceConnectionToHost::OnVideoChannelStatus, |
120 base::Unretained(this)))); | 120 base::Unretained(this)))); |
121 video_dispatcher_.reset( | 121 video_dispatcher_.reset( |
122 new ClientVideoDispatcher(monitored_video_stub_.get())); | 122 new ClientVideoDispatcher(monitored_video_stub_.get())); |
123 video_dispatcher_->Init(transport_->GetStreamChannelFactory(), this); | 123 video_dispatcher_->Init(transport_->GetChannelFactory(), this); |
124 | 124 |
125 // Configure audio pipeline if necessary. | 125 // Configure audio pipeline if necessary. |
126 if (session_->config().is_audio_enabled()) { | 126 if (session_->config().is_audio_enabled()) { |
127 audio_reader_.reset(new AudioReader(audio_stub_)); | 127 audio_reader_.reset(new AudioReader(audio_stub_)); |
128 audio_reader_->Init(transport_->GetMultiplexedChannelFactory(), this); | 128 audio_reader_->Init(transport_->GetMultiplexedChannelFactory(), this); |
129 } | 129 } |
130 break; | 130 break; |
131 | 131 |
132 case Session::CLOSED: | 132 case Session::CLOSED: |
133 CloseChannels(); | 133 CloseChannels(); |
134 SetState(CLOSED, OK); | 134 SetState(CLOSED, OK); |
135 break; | 135 break; |
136 | 136 |
137 case Session::FAILED: | 137 case Session::FAILED: |
138 // If we were connected then treat signaling timeout error as if | 138 // If we were connected then treat signaling timeout error as if |
139 // the connection was closed by the peer. | 139 // the connection was closed by the peer. |
140 // | 140 // |
141 // TODO(sergeyu): This logic belongs to the webapp, but we | 141 // TODO(sergeyu): This logic belongs to the webapp, but we |
142 // currently don't expose this error code to the webapp, and it | 142 // currently don't expose this error code to the webapp, and it |
143 // would be hard to add it because client plugin and webapp | 143 // would be hard to add it because client plugin and webapp |
144 // versions may not be in sync. It should be easy to do after we | 144 // versions may not be in sync. It should be easy to do after we |
145 // are finished moving the client plugin to NaCl. | 145 // are finished moving the client plugin to NaCl. |
| 146 CloseChannels(); |
146 if (state_ == CONNECTED && session_->error() == SIGNALING_TIMEOUT) { | 147 if (state_ == CONNECTED && session_->error() == SIGNALING_TIMEOUT) { |
147 CloseChannels(); | |
148 SetState(CLOSED, OK); | 148 SetState(CLOSED, OK); |
149 } else { | 149 } else { |
150 CloseOnError(session_->error()); | 150 SetState(FAILED, session_->error()); |
151 } | 151 } |
152 break; | 152 break; |
153 } | 153 } |
154 } | 154 } |
155 | 155 |
156 void IceConnectionToHost::OnIceTransportRouteChange( | 156 void IceConnectionToHost::OnIceTransportRouteChange( |
157 const std::string& channel_name, | 157 const std::string& channel_name, |
158 const TransportRoute& route) { | 158 const TransportRoute& route) { |
159 event_callback_->OnRouteChanged(channel_name, route); | 159 event_callback_->OnRouteChanged(channel_name, route); |
160 } | 160 } |
161 | 161 |
162 void IceConnectionToHost::OnIceTransportError(ErrorCode error) { | 162 void IceConnectionToHost::OnIceTransportError(ErrorCode error) { |
163 session_->Close(error); | 163 session_->Close(error); |
164 } | 164 } |
165 | 165 |
166 void IceConnectionToHost::OnChannelInitialized( | 166 void IceConnectionToHost::OnChannelInitialized( |
167 ChannelDispatcherBase* channel_dispatcher) { | 167 ChannelDispatcherBase* channel_dispatcher) { |
168 NotifyIfChannelsReady(); | 168 NotifyIfChannelsReady(); |
169 } | 169 } |
170 | 170 |
171 void IceConnectionToHost::OnChannelError( | |
172 ChannelDispatcherBase* channel_dispatcher, | |
173 ErrorCode error) { | |
174 LOG(ERROR) << "Failed to connect channel " | |
175 << channel_dispatcher->channel_name(); | |
176 CloseOnError(CHANNEL_CONNECTION_ERROR); | |
177 } | |
178 | |
179 void IceConnectionToHost::OnVideoChannelStatus(bool active) { | 171 void IceConnectionToHost::OnVideoChannelStatus(bool active) { |
180 event_callback_->OnConnectionReady(active); | 172 event_callback_->OnConnectionReady(active); |
181 } | 173 } |
182 | 174 |
183 ConnectionToHost::State IceConnectionToHost::state() const { | 175 ConnectionToHost::State IceConnectionToHost::state() const { |
184 return state_; | 176 return state_; |
185 } | 177 } |
186 | 178 |
187 void IceConnectionToHost::NotifyIfChannelsReady() { | 179 void IceConnectionToHost::NotifyIfChannelsReady() { |
188 if (!control_dispatcher_.get() || !control_dispatcher_->is_connected()) | 180 if (!control_dispatcher_.get() || !control_dispatcher_->is_connected()) |
189 return; | 181 return; |
190 if (!event_dispatcher_.get() || !event_dispatcher_->is_connected()) | 182 if (!event_dispatcher_.get() || !event_dispatcher_->is_connected()) |
191 return; | 183 return; |
192 if (!video_dispatcher_.get() || !video_dispatcher_->is_connected()) | 184 if (!video_dispatcher_.get() || !video_dispatcher_->is_connected()) |
193 return; | 185 return; |
194 if ((!audio_reader_.get() || !audio_reader_->is_connected()) && | 186 if ((!audio_reader_.get() || !audio_reader_->is_connected()) && |
195 session_->config().is_audio_enabled()) { | 187 session_->config().is_audio_enabled()) { |
196 return; | 188 return; |
197 } | 189 } |
198 if (state_ != AUTHENTICATED) | 190 if (state_ != AUTHENTICATED) |
199 return; | 191 return; |
200 | 192 |
201 // Start forwarding clipboard and input events. | 193 // Start forwarding clipboard and input events. |
202 clipboard_forwarder_.set_clipboard_stub(control_dispatcher_.get()); | 194 clipboard_forwarder_.set_clipboard_stub(control_dispatcher_.get()); |
203 event_forwarder_.set_input_stub(event_dispatcher_.get()); | 195 event_forwarder_.set_input_stub(event_dispatcher_.get()); |
204 SetState(CONNECTED, OK); | 196 SetState(CONNECTED, OK); |
205 } | 197 } |
206 | 198 |
207 void IceConnectionToHost::CloseOnError(ErrorCode error) { | |
208 CloseChannels(); | |
209 SetState(FAILED, error); | |
210 } | |
211 | |
212 void IceConnectionToHost::CloseChannels() { | 199 void IceConnectionToHost::CloseChannels() { |
213 control_dispatcher_.reset(); | 200 control_dispatcher_.reset(); |
214 event_dispatcher_.reset(); | 201 event_dispatcher_.reset(); |
215 clipboard_forwarder_.set_clipboard_stub(nullptr); | 202 clipboard_forwarder_.set_clipboard_stub(nullptr); |
216 event_forwarder_.set_input_stub(nullptr); | 203 event_forwarder_.set_input_stub(nullptr); |
217 video_dispatcher_.reset(); | 204 video_dispatcher_.reset(); |
218 audio_reader_.reset(); | 205 audio_reader_.reset(); |
219 } | 206 } |
220 | 207 |
221 void IceConnectionToHost::SetState(State state, ErrorCode error) { | 208 void IceConnectionToHost::SetState(State state, ErrorCode error) { |
222 DCHECK(CalledOnValidThread()); | 209 DCHECK(CalledOnValidThread()); |
223 // |error| should be specified only when |state| is set to FAILED. | 210 // |error| should be specified only when |state| is set to FAILED. |
224 DCHECK(state == FAILED || error == OK); | 211 DCHECK(state == FAILED || error == OK); |
225 | 212 |
226 if (state != state_) { | 213 if (state != state_) { |
227 state_ = state; | 214 state_ = state; |
228 error_ = error; | 215 error_ = error; |
229 event_callback_->OnConnectionState(state_, error_); | 216 event_callback_->OnConnectionState(state_, error_); |
230 } | 217 } |
231 } | 218 } |
232 | 219 |
233 } // namespace protocol | 220 } // namespace protocol |
234 } // namespace remoting | 221 } // namespace remoting |
OLD | NEW |