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/message_loop.h" | 9 #include "base/message_loop.h" |
10 #include "remoting/base/constants.h" | 10 #include "remoting/base/constants.h" |
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
165 } | 165 } |
166 | 166 |
167 void ConnectionToHost::OnSessionStateChange( | 167 void ConnectionToHost::OnSessionStateChange( |
168 Session::State state) { | 168 Session::State state) { |
169 DCHECK_EQ(message_loop_, MessageLoop::current()); | 169 DCHECK_EQ(message_loop_, MessageLoop::current()); |
170 DCHECK(event_callback_); | 170 DCHECK(event_callback_); |
171 | 171 |
172 switch (state) { | 172 switch (state) { |
173 case Session::FAILED: | 173 case Session::FAILED: |
174 state_ = STATE_FAILED; | 174 state_ = STATE_FAILED; |
175 CloseChannels(); | 175 CloseOnError(); |
176 event_callback_->OnConnectionFailed(this); | |
177 break; | 176 break; |
178 | 177 |
179 case Session::CLOSED: | 178 case Session::CLOSED: |
180 state_ = STATE_CLOSED; | 179 state_ = STATE_CLOSED; |
181 CloseChannels(); | 180 CloseChannels(); |
182 event_callback_->OnConnectionClosed(this); | 181 event_callback_->OnConnectionClosed(this); |
183 break; | 182 break; |
184 | 183 |
185 case Session::CONNECTED: | 184 case Session::CONNECTED: |
186 state_ = STATE_CONNECTED; | 185 state_ = STATE_CONNECTED; |
187 // Initialize reader and writer. | 186 // Initialize reader and writer. |
188 video_reader_.reset(VideoReader::Create(session_->config())); | 187 video_reader_.reset(VideoReader::Create(session_->config())); |
189 video_reader_->Init(session_.get(), video_stub_); | 188 video_reader_->Init( |
| 189 session_.get(), video_stub_, |
| 190 base::Bind(&ConnectionToHost::OnVideoChannelInitialized, |
| 191 base::Unretained(this))); |
190 host_control_sender_.reset( | 192 host_control_sender_.reset( |
191 new HostControlSender(session_->control_channel())); | 193 new HostControlSender(session_->control_channel())); |
192 dispatcher_->Initialize(session_.get(), client_stub_); | 194 dispatcher_->Initialize(session_.get(), client_stub_); |
193 event_callback_->OnConnectionOpened(this); | 195 event_callback_->OnConnectionOpened(this); |
194 break; | 196 break; |
195 | 197 |
196 default: | 198 default: |
197 // Ignore the other states by default. | 199 // Ignore the other states by default. |
198 break; | 200 break; |
199 } | 201 } |
200 } | 202 } |
201 | 203 |
| 204 void ConnectionToHost::OnVideoChannelInitialized(bool successful) { |
| 205 if (!successful) { |
| 206 CloseOnError(); |
| 207 return; |
| 208 } |
| 209 } |
| 210 |
| 211 void ConnectionToHost::CloseOnError() { |
| 212 state_ = STATE_FAILED; |
| 213 CloseChannels(); |
| 214 event_callback_->OnConnectionFailed(this); |
| 215 } |
| 216 |
202 void ConnectionToHost::CloseChannels() { | 217 void ConnectionToHost::CloseChannels() { |
203 if (input_sender_.get()) | 218 if (input_sender_.get()) |
204 input_sender_->Close(); | 219 input_sender_->Close(); |
205 | 220 |
206 if (host_control_sender_.get()) | 221 if (host_control_sender_.get()) |
207 host_control_sender_->Close(); | 222 host_control_sender_->Close(); |
| 223 |
| 224 video_reader_.reset(); |
208 } | 225 } |
209 | 226 |
210 void ConnectionToHost::OnClientAuthenticated() { | 227 void ConnectionToHost::OnClientAuthenticated() { |
211 // TODO(hclam): Don't send anything except authentication request if it is | 228 // TODO(hclam): Don't send anything except authentication request if it is |
212 // not authenticated. | 229 // not authenticated. |
213 state_ = STATE_AUTHENTICATED; | 230 state_ = STATE_AUTHENTICATED; |
214 | 231 |
215 // Create and enable the input stub now that we're authenticated. | 232 // Create and enable the input stub now that we're authenticated. |
216 input_sender_.reset(new InputSender(session_->event_channel())); | 233 input_sender_.reset(new InputSender(session_->event_channel())); |
217 } | 234 } |
218 | 235 |
219 ConnectionToHost::State ConnectionToHost::state() const { | 236 ConnectionToHost::State ConnectionToHost::state() const { |
220 return state_; | 237 return state_; |
221 } | 238 } |
222 | 239 |
223 } // namespace protocol | 240 } // namespace protocol |
224 } // namespace remoting | 241 } // namespace remoting |
OLD | NEW |