OLD | NEW |
---|---|
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/jingle_connection_to_host.h" | 5 #include "remoting/protocol/jingle_connection_to_host.h" |
6 | 6 |
7 #include "base/callback.h" | 7 #include "base/callback.h" |
8 #include "base/message_loop.h" | 8 #include "base/message_loop.h" |
9 #include "remoting/base/constants.h" | 9 #include "remoting/base/constants.h" |
10 #include "remoting/jingle_glue/jingle_thread.h" | 10 #include "remoting/jingle_glue/jingle_thread.h" |
11 #include "remoting/proto/auth.pb.h" | 11 #include "remoting/proto/auth.pb.h" |
12 #include "remoting/protocol/client_message_dispatcher.h" | |
12 #include "remoting/protocol/client_stub.h" | 13 #include "remoting/protocol/client_stub.h" |
13 #include "remoting/protocol/input_sender.h" | 14 #include "remoting/protocol/input_sender.h" |
14 #include "remoting/protocol/jingle_session_manager.h" | 15 #include "remoting/protocol/jingle_session_manager.h" |
15 #include "remoting/protocol/video_reader.h" | 16 #include "remoting/protocol/video_reader.h" |
16 #include "remoting/protocol/video_stub.h" | 17 #include "remoting/protocol/video_stub.h" |
17 #include "remoting/protocol/util.h" | 18 #include "remoting/protocol/util.h" |
18 | 19 |
19 namespace remoting { | 20 namespace remoting { |
20 namespace protocol { | 21 namespace protocol { |
21 | 22 |
22 JingleConnectionToHost::JingleConnectionToHost(JingleThread* thread) | 23 JingleConnectionToHost::JingleConnectionToHost(JingleThread* thread) |
23 : thread_(thread), | 24 : thread_(thread), |
24 event_callback_(NULL) { | 25 event_callback_(NULL), |
26 dispatcher_(new ClientMessageDispatcher()) { | |
25 } | 27 } |
26 | 28 |
27 JingleConnectionToHost::~JingleConnectionToHost() { | 29 JingleConnectionToHost::~JingleConnectionToHost() { |
28 } | 30 } |
29 | 31 |
30 void JingleConnectionToHost::Connect(const std::string& username, | 32 void JingleConnectionToHost::Connect(const std::string& username, |
31 const std::string& auth_token, | 33 const std::string& auth_token, |
32 const std::string& host_jid, | 34 const std::string& host_jid, |
33 HostEventCallback* event_callback, | 35 HostEventCallback* event_callback, |
34 ClientStub* client_stub, | 36 ClientStub* client_stub, |
35 VideoStub* video_stub) { | 37 VideoStub* video_stub) { |
36 event_callback_ = event_callback; | 38 event_callback_ = event_callback; |
39 client_stub_ = client_stub; | |
37 video_stub_ = video_stub; | 40 video_stub_ = video_stub; |
38 | 41 |
39 // Initialize |jingle_client_|. | 42 // Initialize |jingle_client_|. |
40 jingle_client_ = new JingleClient(thread_); | 43 jingle_client_ = new JingleClient(thread_); |
41 jingle_client_->Init(username, auth_token, | 44 jingle_client_->Init(username, auth_token, |
42 kChromotingTokenServiceName, this); | 45 kChromotingTokenServiceName, this); |
43 | 46 |
44 // Save jid of the host. The actual connection is created later after | 47 // Save jid of the host. The actual connection is created later after |
45 // |jingle_client_| is connected. | 48 // |jingle_client_| is connected. |
46 host_jid_ = host_jid; | 49 host_jid_ = host_jid; |
(...skipping 21 matching lines...) Expand all Loading... | |
68 void JingleConnectionToHost::OnControlMessage(ControlMessage* msg) { | 71 void JingleConnectionToHost::OnControlMessage(ControlMessage* msg) { |
69 // TODO(sergeyu): Remove this method and pass ClientStub to the control | 72 // TODO(sergeyu): Remove this method and pass ClientStub to the control |
70 // stream dispatcher. | 73 // stream dispatcher. |
71 delete msg; | 74 delete msg; |
72 } | 75 } |
73 | 76 |
74 void JingleConnectionToHost::InitSession() { | 77 void JingleConnectionToHost::InitSession() { |
75 DCHECK_EQ(message_loop(), MessageLoop::current()); | 78 DCHECK_EQ(message_loop(), MessageLoop::current()); |
76 | 79 |
77 // Initialize chromotocol |session_manager_|. | 80 // Initialize chromotocol |session_manager_|. |
78 protocol::JingleSessionManager* session_manager = | 81 JingleSessionManager* session_manager = |
79 new protocol::JingleSessionManager(thread_); | 82 new JingleSessionManager(thread_); |
80 // TODO(ajwong): Make this a command switch when we're more stable. | 83 // TODO(ajwong): Make this a command switch when we're more stable. |
81 session_manager->set_allow_local_ips(true); | 84 session_manager->set_allow_local_ips(true); |
82 session_manager->Init( | 85 session_manager->Init( |
83 jingle_client_->GetFullJid(), | 86 jingle_client_->GetFullJid(), |
84 jingle_client_->session_manager(), | 87 jingle_client_->session_manager(), |
85 NewCallback(this, &JingleConnectionToHost::OnNewSession)); | 88 NewCallback(this, &JingleConnectionToHost::OnNewSession)); |
86 session_manager_ = session_manager; | 89 session_manager_ = session_manager; |
87 | 90 |
88 CandidateSessionConfig* candidate_config = | 91 CandidateSessionConfig* candidate_config = |
89 CandidateSessionConfig::CreateDefault(); | 92 CandidateSessionConfig::CreateDefault(); |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
137 | 140 |
138 if (state == JingleClient::CONNECTED) { | 141 if (state == JingleClient::CONNECTED) { |
139 VLOG(1) << "Connected as: " << client->GetFullJid(); | 142 VLOG(1) << "Connected as: " << client->GetFullJid(); |
140 InitSession(); | 143 InitSession(); |
141 } else if (state == JingleClient::CLOSED) { | 144 } else if (state == JingleClient::CLOSED) { |
142 VLOG(1) << "Connection closed."; | 145 VLOG(1) << "Connection closed."; |
143 event_callback_->OnConnectionClosed(this); | 146 event_callback_->OnConnectionClosed(this); |
144 } | 147 } |
145 } | 148 } |
146 | 149 |
147 void JingleConnectionToHost::OnNewSession(protocol::Session* session, | 150 void JingleConnectionToHost::OnNewSession(Session* session, |
148 protocol::SessionManager::IncomingSessionResponse* response) { | 151 SessionManager::IncomingSessionResponse* response) { |
149 DCHECK_EQ(message_loop(), MessageLoop::current()); | 152 DCHECK_EQ(message_loop(), MessageLoop::current()); |
150 // Client always rejects incoming sessions. | 153 // Client always rejects incoming sessions. |
151 *response = protocol::SessionManager::DECLINE; | 154 *response = SessionManager::DECLINE; |
152 } | 155 } |
153 | 156 |
154 void JingleConnectionToHost::OnSessionStateChange( | 157 void JingleConnectionToHost::OnSessionStateChange( |
155 protocol::Session::State state) { | 158 Session::State state) { |
156 DCHECK_EQ(message_loop(), MessageLoop::current()); | 159 DCHECK_EQ(message_loop(), MessageLoop::current()); |
157 DCHECK(event_callback_); | 160 DCHECK(event_callback_); |
158 | 161 |
159 switch (state) { | 162 switch (state) { |
160 case protocol::Session::FAILED: | 163 case Session::FAILED: |
161 event_callback_->OnConnectionFailed(this); | 164 event_callback_->OnConnectionFailed(this); |
162 break; | 165 break; |
163 | 166 |
164 case protocol::Session::CLOSED: | 167 case Session::CLOSED: |
165 event_callback_->OnConnectionClosed(this); | 168 event_callback_->OnConnectionClosed(this); |
166 break; | 169 break; |
167 | 170 |
168 case protocol::Session::CONNECTED: | 171 case Session::CONNECTED: |
169 // Initialize reader and writer. | 172 // Initialize reader and writer. |
170 control_reader_.Init<ControlMessage>( | 173 control_reader_.Init<ControlMessage>( |
171 session_->control_channel(), | 174 session_->control_channel(), |
172 NewCallback(this, &JingleConnectionToHost::OnControlMessage)); | 175 NewCallback(this, &JingleConnectionToHost::OnControlMessage)); |
173 video_reader_.reset(VideoReader::Create(session_->config())); | 176 video_reader_.reset(VideoReader::Create(session_->config())); |
174 video_reader_->Init(session_, video_stub_); | 177 video_reader_->Init(session_, video_stub_); |
175 input_stub_.reset(new InputSender(session_->event_channel())); | 178 input_stub_.reset(new InputSender(session_->event_channel())); |
179 dispatcher_->Initialize(session_.get(), client_stub_); | |
awong
2010/12/23 01:15:10
If Initialize() reutrns a bool, shouldn't we check
Alpha Left Google
2010/12/23 02:17:58
Done.
| |
176 event_callback_->OnConnectionOpened(this); | 180 event_callback_->OnConnectionOpened(this); |
177 break; | 181 break; |
178 | 182 |
179 default: | 183 default: |
180 // Ignore the other states by default. | 184 // Ignore the other states by default. |
181 break; | 185 break; |
182 } | 186 } |
183 } | 187 } |
184 | 188 |
185 MessageLoop* JingleConnectionToHost::message_loop() { | 189 MessageLoop* JingleConnectionToHost::message_loop() { |
186 return thread_->message_loop(); | 190 return thread_->message_loop(); |
187 } | 191 } |
188 | 192 |
189 } // namespace protocol | 193 } // namespace protocol |
190 } // namespace remoting | 194 } // namespace remoting |
OLD | NEW |