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/location.h" | 9 #include "base/location.h" |
10 #include "base/message_loop_proxy.h" | 10 #include "base/message_loop_proxy.h" |
11 #include "remoting/base/constants.h" | 11 #include "remoting/base/constants.h" |
12 #include "remoting/jingle_glue/javascript_signal_strategy.h" | 12 #include "remoting/jingle_glue/javascript_signal_strategy.h" |
13 #include "remoting/jingle_glue/xmpp_signal_strategy.h" | 13 #include "remoting/jingle_glue/xmpp_signal_strategy.h" |
14 #include "remoting/protocol/auth_token_utils.h" | 14 #include "remoting/protocol/auth_token_utils.h" |
15 #include "remoting/protocol/client_message_dispatcher.h" | 15 #include "remoting/protocol/client_control_dispatcher.h" |
| 16 #include "remoting/protocol/client_event_dispatcher.h" |
16 #include "remoting/protocol/client_stub.h" | 17 #include "remoting/protocol/client_stub.h" |
17 #include "remoting/protocol/host_control_sender.h" | |
18 #include "remoting/protocol/input_sender.h" | |
19 #include "remoting/protocol/jingle_session_manager.h" | 18 #include "remoting/protocol/jingle_session_manager.h" |
20 #include "remoting/protocol/pepper_session_manager.h" | 19 #include "remoting/protocol/pepper_session_manager.h" |
21 #include "remoting/protocol/video_reader.h" | 20 #include "remoting/protocol/video_reader.h" |
22 #include "remoting/protocol/video_stub.h" | 21 #include "remoting/protocol/video_stub.h" |
23 #include "remoting/protocol/util.h" | 22 #include "remoting/protocol/util.h" |
24 | 23 |
25 namespace remoting { | 24 namespace remoting { |
26 namespace protocol { | 25 namespace protocol { |
27 | 26 |
28 ConnectionToHost::ConnectionToHost( | 27 ConnectionToHost::ConnectionToHost( |
(...skipping 10 matching lines...) Expand all Loading... |
39 error_(OK), | 38 error_(OK), |
40 control_connected_(false), | 39 control_connected_(false), |
41 input_connected_(false), | 40 input_connected_(false), |
42 video_connected_(false) { | 41 video_connected_(false) { |
43 } | 42 } |
44 | 43 |
45 ConnectionToHost::~ConnectionToHost() { | 44 ConnectionToHost::~ConnectionToHost() { |
46 } | 45 } |
47 | 46 |
48 InputStub* ConnectionToHost::input_stub() { | 47 InputStub* ConnectionToHost::input_stub() { |
49 return input_sender_.get(); | 48 return input_dispatcher_.get(); |
50 } | 49 } |
51 | 50 |
52 HostStub* ConnectionToHost::host_stub() { | 51 HostStub* ConnectionToHost::host_stub() { |
53 return host_control_sender_.get(); | 52 return control_dispatcher_.get(); |
54 } | 53 } |
55 | 54 |
56 void ConnectionToHost::Connect(scoped_refptr<XmppProxy> xmpp_proxy, | 55 void ConnectionToHost::Connect(scoped_refptr<XmppProxy> xmpp_proxy, |
57 const std::string& your_jid, | 56 const std::string& your_jid, |
58 const std::string& host_jid, | 57 const std::string& host_jid, |
59 const std::string& host_public_key, | 58 const std::string& host_public_key, |
60 const std::string& access_code, | 59 const std::string& access_code, |
61 HostEventCallback* event_callback, | 60 HostEventCallback* event_callback, |
62 ClientStub* client_stub, | 61 ClientStub* client_stub, |
63 VideoStub* video_stub) { | 62 VideoStub* video_stub) { |
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
193 case Session::CONNECTED: | 192 case Session::CONNECTED: |
194 video_reader_.reset( | 193 video_reader_.reset( |
195 VideoReader::Create(message_loop_, session_->config())); | 194 VideoReader::Create(message_loop_, session_->config())); |
196 video_reader_->Init( | 195 video_reader_->Init( |
197 session_.get(), video_stub_, | 196 session_.get(), video_stub_, |
198 base::Bind(&ConnectionToHost::OnVideoChannelInitialized, | 197 base::Bind(&ConnectionToHost::OnVideoChannelInitialized, |
199 base::Unretained(this))); | 198 base::Unretained(this))); |
200 break; | 199 break; |
201 | 200 |
202 case Session::CONNECTED_CHANNELS: | 201 case Session::CONNECTED_CHANNELS: |
203 host_control_sender_.reset( | 202 control_dispatcher_.reset(new ClientControlDispatcher()); |
204 new HostControlSender(message_loop_, session_->control_channel())); | 203 control_dispatcher_->Init(session_.get()); |
205 input_sender_.reset( | 204 control_dispatcher_->set_client_stub(client_stub_); |
206 new InputSender(message_loop_, session_->event_channel())); | 205 input_dispatcher_.reset(new ClientEventDispatcher()); |
207 dispatcher_.reset(new ClientMessageDispatcher()); | 206 input_dispatcher_->Init(session_.get()); |
208 dispatcher_->Initialize(session_.get(), client_stub_); | |
209 | 207 |
210 control_connected_ = true; | 208 control_connected_ = true; |
211 input_connected_ = true; | 209 input_connected_ = true; |
212 NotifyIfChannelsReady(); | 210 NotifyIfChannelsReady(); |
213 break; | 211 break; |
214 | 212 |
215 default: | 213 default: |
216 // Ignore the other states by default. | 214 // Ignore the other states by default. |
217 break; | 215 break; |
218 } | 216 } |
(...skipping 17 matching lines...) Expand all Loading... |
236 SetState(AUTHENTICATED, OK); | 234 SetState(AUTHENTICATED, OK); |
237 } | 235 } |
238 } | 236 } |
239 | 237 |
240 void ConnectionToHost::CloseOnError(Error error) { | 238 void ConnectionToHost::CloseOnError(Error error) { |
241 CloseChannels(); | 239 CloseChannels(); |
242 SetState(FAILED, error); | 240 SetState(FAILED, error); |
243 } | 241 } |
244 | 242 |
245 void ConnectionToHost::CloseChannels() { | 243 void ConnectionToHost::CloseChannels() { |
246 if (input_sender_.get()) | 244 control_dispatcher_.reset(); |
247 input_sender_->Close(); | 245 input_dispatcher_.reset(); |
248 | |
249 if (host_control_sender_.get()) | |
250 host_control_sender_->Close(); | |
251 | |
252 video_reader_.reset(); | 246 video_reader_.reset(); |
253 } | 247 } |
254 | 248 |
255 void ConnectionToHost::SetState(State state, Error error) { | 249 void ConnectionToHost::SetState(State state, Error error) { |
256 DCHECK(message_loop_->BelongsToCurrentThread()); | 250 DCHECK(message_loop_->BelongsToCurrentThread()); |
257 // |error| should be specified only when |state| is set to FAILED. | 251 // |error| should be specified only when |state| is set to FAILED. |
258 DCHECK(state == FAILED || error == OK); | 252 DCHECK(state == FAILED || error == OK); |
259 | 253 |
260 if (state != state_) { | 254 if (state != state_) { |
261 state_ = state; | 255 state_ = state; |
262 error_ = error; | 256 error_ = error; |
263 event_callback_->OnConnectionState(state_, error_); | 257 event_callback_->OnConnectionState(state_, error_); |
264 } | 258 } |
265 } | 259 } |
266 | 260 |
267 } // namespace protocol | 261 } // namespace protocol |
268 } // namespace remoting | 262 } // namespace remoting |
OLD | NEW |