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" |
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
177 case Session::ACCEPTING: | 177 case Session::ACCEPTING: |
178 case Session::CONNECTED: | 178 case Session::CONNECTED: |
179 case Session::AUTHENTICATING: | 179 case Session::AUTHENTICATING: |
180 // Don't care about these events. | 180 // Don't care about these events. |
181 break; | 181 break; |
182 | 182 |
183 case Session::AUTHENTICATED: | 183 case Session::AUTHENTICATED: |
184 SetState(AUTHENTICATED, OK); | 184 SetState(AUTHENTICATED, OK); |
185 | 185 |
186 control_dispatcher_.reset(new ClientControlDispatcher()); | 186 control_dispatcher_.reset(new ClientControlDispatcher()); |
187 control_dispatcher_->Init( | 187 control_dispatcher_->Init(session_.get(), |
188 session_.get(), session_->config().control_config(), | 188 session_->config().control_config(), this); |
189 base::Bind(&ConnectionToHost::OnChannelInitialized, | |
190 base::Unretained(this))); | |
191 control_dispatcher_->set_client_stub(client_stub_); | 189 control_dispatcher_->set_client_stub(client_stub_); |
192 control_dispatcher_->set_clipboard_stub(clipboard_stub_); | 190 control_dispatcher_->set_clipboard_stub(clipboard_stub_); |
193 | 191 |
194 event_dispatcher_.reset(new ClientEventDispatcher()); | 192 event_dispatcher_.reset(new ClientEventDispatcher()); |
195 event_dispatcher_->Init( | 193 event_dispatcher_->Init(session_.get(), session_->config().event_config(), |
196 session_.get(), session_->config().event_config(), | 194 this); |
197 base::Bind(&ConnectionToHost::OnChannelInitialized, | |
198 base::Unretained(this))); | |
199 | 195 |
200 video_dispatcher_.reset( | 196 video_dispatcher_.reset( |
201 new ClientVideoDispatcher(monitored_video_stub_.get())); | 197 new ClientVideoDispatcher(monitored_video_stub_.get())); |
202 video_dispatcher_->Init(session_.get(), session_->config().video_config(), | 198 video_dispatcher_->Init(session_.get(), session_->config().video_config(), |
203 base::Bind(&ConnectionToHost::OnChannelInitialized, | 199 this); |
204 base::Unretained(this))); | |
205 | 200 |
206 audio_reader_ = AudioReader::Create(session_->config()); | 201 if (session_->config().is_audio_enabled()) { |
207 if (audio_reader_.get()) { | 202 audio_reader_.reset(new AudioReader(audio_stub_)); |
208 audio_reader_->Init(session_.get(), session_->config().audio_config(), | 203 audio_reader_->Init(session_.get(), session_->config().audio_config(), |
209 base::Bind(&ConnectionToHost::OnChannelInitialized, | 204 this); |
210 base::Unretained(this))); | |
211 audio_reader_->set_audio_stub(audio_stub_); | |
212 } | 205 } |
213 break; | 206 break; |
214 | 207 |
215 case Session::CLOSED: | 208 case Session::CLOSED: |
216 CloseChannels(); | 209 CloseChannels(); |
217 SetState(CLOSED, OK); | 210 SetState(CLOSED, OK); |
218 break; | 211 break; |
219 | 212 |
220 case Session::FAILED: | 213 case Session::FAILED: |
221 // If we were connected then treat signaling timeout error as if | 214 // If we were connected then treat signaling timeout error as if |
(...skipping 12 matching lines...) Expand all Loading... |
234 } | 227 } |
235 break; | 228 break; |
236 } | 229 } |
237 } | 230 } |
238 | 231 |
239 void ConnectionToHost::OnSessionRouteChange(const std::string& channel_name, | 232 void ConnectionToHost::OnSessionRouteChange(const std::string& channel_name, |
240 const TransportRoute& route) { | 233 const TransportRoute& route) { |
241 event_callback_->OnRouteChanged(channel_name, route); | 234 event_callback_->OnRouteChanged(channel_name, route); |
242 } | 235 } |
243 | 236 |
| 237 void ConnectionToHost::OnChannelInitialized( |
| 238 ChannelDispatcherBase* channel_dispatcher) { |
| 239 NotifyIfChannelsReady(); |
| 240 } |
| 241 |
| 242 void ConnectionToHost::OnChannelError( |
| 243 ChannelDispatcherBase* channel_dispatcher, |
| 244 ErrorCode error) { |
| 245 LOG(ERROR) << "Failed to connect channel " << channel_dispatcher; |
| 246 CloseOnError(CHANNEL_CONNECTION_ERROR); |
| 247 return; |
| 248 } |
| 249 |
244 void ConnectionToHost::OnVideoChannelStatus(bool active) { | 250 void ConnectionToHost::OnVideoChannelStatus(bool active) { |
245 event_callback_->OnConnectionReady(active); | 251 event_callback_->OnConnectionReady(active); |
246 } | 252 } |
247 | 253 |
248 ConnectionToHost::State ConnectionToHost::state() const { | 254 ConnectionToHost::State ConnectionToHost::state() const { |
249 return state_; | 255 return state_; |
250 } | 256 } |
251 | 257 |
252 void ConnectionToHost::OnChannelInitialized(bool successful) { | |
253 if (!successful) { | |
254 LOG(ERROR) << "Failed to connect video channel"; | |
255 CloseOnError(CHANNEL_CONNECTION_ERROR); | |
256 return; | |
257 } | |
258 | |
259 NotifyIfChannelsReady(); | |
260 } | |
261 | |
262 void ConnectionToHost::NotifyIfChannelsReady() { | 258 void ConnectionToHost::NotifyIfChannelsReady() { |
263 if (!control_dispatcher_.get() || !control_dispatcher_->is_connected()) | 259 if (!control_dispatcher_.get() || !control_dispatcher_->is_connected()) |
264 return; | 260 return; |
265 if (!event_dispatcher_.get() || !event_dispatcher_->is_connected()) | 261 if (!event_dispatcher_.get() || !event_dispatcher_->is_connected()) |
266 return; | 262 return; |
267 if (!video_dispatcher_.get() || !video_dispatcher_->is_connected()) | 263 if (!video_dispatcher_.get() || !video_dispatcher_->is_connected()) |
268 return; | 264 return; |
269 if ((!audio_reader_.get() || !audio_reader_->is_connected()) && | 265 if ((!audio_reader_.get() || !audio_reader_->is_connected()) && |
270 session_->config().is_audio_enabled()) { | 266 session_->config().is_audio_enabled()) { |
271 return; | 267 return; |
(...skipping 28 matching lines...) Expand all Loading... |
300 | 296 |
301 if (state != state_) { | 297 if (state != state_) { |
302 state_ = state; | 298 state_ = state; |
303 error_ = error; | 299 error_ = error; |
304 event_callback_->OnConnectionState(state_, error_); | 300 event_callback_->OnConnectionState(state_, error_); |
305 } | 301 } |
306 } | 302 } |
307 | 303 |
308 } // namespace protocol | 304 } // namespace protocol |
309 } // namespace remoting | 305 } // namespace remoting |
OLD | NEW |