Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(14)

Side by Side Diff: remoting/protocol/connection_to_host.cc

Issue 7508044: Remove video_channel() from Session interface (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: - Created 9 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « remoting/protocol/connection_to_host.h ('k') | remoting/protocol/fake_session.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 20 matching lines...) Expand all
31 talk_base::PacketSocketFactory* socket_factory, 31 talk_base::PacketSocketFactory* socket_factory,
32 HostResolverFactory* host_resolver_factory, 32 HostResolverFactory* host_resolver_factory,
33 PortAllocatorSessionFactory* session_factory, 33 PortAllocatorSessionFactory* session_factory,
34 bool allow_nat_traversal) 34 bool allow_nat_traversal)
35 : message_loop_(message_loop), 35 : message_loop_(message_loop),
36 network_manager_(network_manager), 36 network_manager_(network_manager),
37 socket_factory_(socket_factory), 37 socket_factory_(socket_factory),
38 host_resolver_factory_(host_resolver_factory), 38 host_resolver_factory_(host_resolver_factory),
39 port_allocator_session_factory_(session_factory), 39 port_allocator_session_factory_(session_factory),
40 allow_nat_traversal_(allow_nat_traversal), 40 allow_nat_traversal_(allow_nat_traversal),
41 event_callback_(NULL),
42 client_stub_(NULL),
43 video_stub_(NULL),
41 state_(STATE_EMPTY), 44 state_(STATE_EMPTY),
42 event_callback_(NULL), 45 control_connected_(false),
43 dispatcher_(new ClientMessageDispatcher()), 46 input_connected_(false),
44 client_stub_(NULL), 47 video_connected_(false) {
45 video_stub_(NULL) {
46 } 48 }
47 49
48 ConnectionToHost::~ConnectionToHost() { 50 ConnectionToHost::~ConnectionToHost() {
49 } 51 }
50 52
51 InputStub* ConnectionToHost::input_stub() { 53 InputStub* ConnectionToHost::input_stub() {
52 return input_sender_.get(); 54 return input_sender_.get();
53 } 55 }
54 56
55 HostStub* ConnectionToHost::host_stub() { 57 HostStub* ConnectionToHost::host_stub() {
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
169 } 171 }
170 172
171 void ConnectionToHost::OnSessionStateChange( 173 void ConnectionToHost::OnSessionStateChange(
172 Session::State state) { 174 Session::State state) {
173 DCHECK_EQ(message_loop_, MessageLoop::current()); 175 DCHECK_EQ(message_loop_, MessageLoop::current());
174 DCHECK(event_callback_); 176 DCHECK(event_callback_);
175 177
176 switch (state) { 178 switch (state) {
177 case Session::FAILED: 179 case Session::FAILED:
178 state_ = STATE_FAILED; 180 state_ = STATE_FAILED;
179 CloseChannels(); 181 CloseOnError();
180 event_callback_->OnConnectionFailed(this);
181 break; 182 break;
182 183
183 case Session::CLOSED: 184 case Session::CLOSED:
184 state_ = STATE_CLOSED; 185 state_ = STATE_CLOSED;
185 CloseChannels(); 186 CloseChannels();
186 event_callback_->OnConnectionClosed(this); 187 event_callback_->OnConnectionClosed(this);
187 break; 188 break;
188 189
189 case Session::CONNECTED: 190 case Session::CONNECTED:
190 state_ = STATE_CONNECTED;
191 // Initialize reader and writer. 191 // Initialize reader and writer.
192 video_reader_.reset(VideoReader::Create(session_->config())); 192 video_reader_.reset(VideoReader::Create(session_->config()));
193 video_reader_->Init(session_.get(), video_stub_); 193 video_reader_->Init(
194 session_.get(), video_stub_,
195 base::Bind(&ConnectionToHost::OnVideoChannelInitialized,
196 base::Unretained(this)));
197 break;
198
199 case Session::CONNECTED_CHANNELS:
200 state_ = STATE_CONNECTED;
194 host_control_sender_.reset( 201 host_control_sender_.reset(
195 new HostControlSender(session_->control_channel())); 202 new HostControlSender(session_->control_channel()));
203 dispatcher_.reset(new ClientMessageDispatcher());
196 dispatcher_->Initialize(session_.get(), client_stub_); 204 dispatcher_->Initialize(session_.get(), client_stub_);
197 event_callback_->OnConnectionOpened(this); 205
206 control_connected_ = true;
207 input_connected_ = true;
208 NotifyIfChannelsReady();
198 break; 209 break;
199 210
200 default: 211 default:
201 // Ignore the other states by default. 212 // Ignore the other states by default.
202 break; 213 break;
203 } 214 }
204 } 215 }
205 216
217 void ConnectionToHost::OnVideoChannelInitialized(bool successful) {
218 if (!successful) {
219 LOG(ERROR) << "Failed to connect video channel";
220 CloseOnError();
221 return;
222 }
223
224 video_connected_ = true;
225 NotifyIfChannelsReady();
226 }
227
228 void ConnectionToHost::NotifyIfChannelsReady() {
229 if (control_connected_ && input_connected_ && video_connected_)
230 event_callback_->OnConnectionOpened(this);
231 }
232
233 void ConnectionToHost::CloseOnError() {
234 state_ = STATE_FAILED;
235 CloseChannels();
236 event_callback_->OnConnectionFailed(this);
237 }
238
206 void ConnectionToHost::CloseChannels() { 239 void ConnectionToHost::CloseChannels() {
207 if (input_sender_.get()) 240 if (input_sender_.get())
208 input_sender_->Close(); 241 input_sender_->Close();
209 242
210 if (host_control_sender_.get()) 243 if (host_control_sender_.get())
211 host_control_sender_->Close(); 244 host_control_sender_->Close();
245
246 video_reader_.reset();
212 } 247 }
213 248
214 void ConnectionToHost::OnClientAuthenticated() { 249 void ConnectionToHost::OnClientAuthenticated() {
215 // TODO(hclam): Don't send anything except authentication request if it is 250 // TODO(hclam): Don't send anything except authentication request if it is
216 // not authenticated. 251 // not authenticated.
217 state_ = STATE_AUTHENTICATED; 252 state_ = STATE_AUTHENTICATED;
218 253
219 // Create and enable the input stub now that we're authenticated. 254 // Create and enable the input stub now that we're authenticated.
220 input_sender_.reset(new InputSender(session_->event_channel())); 255 input_sender_.reset(new InputSender(session_->event_channel()));
221 } 256 }
222 257
223 ConnectionToHost::State ConnectionToHost::state() const { 258 ConnectionToHost::State ConnectionToHost::state() const {
224 return state_; 259 return state_;
225 } 260 }
226 261
227 } // namespace protocol 262 } // namespace protocol
228 } // namespace remoting 263 } // namespace remoting
OLDNEW
« no previous file with comments | « remoting/protocol/connection_to_host.h ('k') | remoting/protocol/fake_session.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698