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

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

Issue 7289032: Remove SocketWrapper to expose the threading issues it masks. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase once more. Created 9 years, 5 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/jingle_session.h ('k') | remoting/protocol/socket_wrapper.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/jingle_session.h" 5 #include "remoting/protocol/jingle_session.h"
6 6
7 #include "base/message_loop.h" 7 #include "base/message_loop.h"
8 #include "base/rand_util.h" 8 #include "base/rand_util.h"
9 #include "crypto/hmac.h" 9 #include "crypto/hmac.h"
10 #include "crypto/rsa_private_key.h" 10 #include "crypto/rsa_private_key.h"
11 #include "jingle/glue/channel_socket_adapter.h" 11 #include "jingle/glue/channel_socket_adapter.h"
12 #include "jingle/glue/pseudotcp_adapter.h" 12 #include "jingle/glue/pseudotcp_adapter.h"
13 #include "net/base/cert_status_flags.h" 13 #include "net/base/cert_status_flags.h"
14 #include "net/base/cert_verifier.h" 14 #include "net/base/cert_verifier.h"
15 #include "net/base/host_port_pair.h" 15 #include "net/base/host_port_pair.h"
16 #include "net/base/net_errors.h" 16 #include "net/base/net_errors.h"
17 #include "net/base/ssl_config_service.h" 17 #include "net/base/ssl_config_service.h"
18 #include "net/base/x509_certificate.h" 18 #include "net/base/x509_certificate.h"
19 #include "net/socket/client_socket_factory.h" 19 #include "net/socket/client_socket_factory.h"
20 #include "net/socket/ssl_client_socket.h" 20 #include "net/socket/ssl_client_socket.h"
21 #include "net/socket/ssl_server_socket.h" 21 #include "net/socket/ssl_server_socket.h"
22 #include "remoting/base/constants.h" 22 #include "remoting/base/constants.h"
23 #include "remoting/protocol/jingle_session_manager.h" 23 #include "remoting/protocol/jingle_session_manager.h"
24 #include "remoting/protocol/socket_wrapper.h"
25 #include "third_party/libjingle/source/talk/base/thread.h" 24 #include "third_party/libjingle/source/talk/base/thread.h"
26 #include "third_party/libjingle/source/talk/p2p/base/session.h" 25 #include "third_party/libjingle/source/talk/p2p/base/session.h"
27 #include "third_party/libjingle/source/talk/p2p/base/p2ptransportchannel.h" 26 #include "third_party/libjingle/source/talk/p2p/base/p2ptransportchannel.h"
28 27
29 using cricket::BaseSession; 28 using cricket::BaseSession;
30 29
31 namespace remoting { 30 namespace remoting {
32 31
33 namespace protocol { 32 namespace protocol {
34 33
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after
181 DCHECK(CalledOnValidThread()); 180 DCHECK(CalledOnValidThread());
182 return EncryptMasterKey(peer_public_key_, master_key_); 181 return EncryptMasterKey(peer_public_key_, master_key_);
183 } 182 }
184 183
185 void JingleSession::CloseInternal(int result, bool failed) { 184 void JingleSession::CloseInternal(int result, bool failed) {
186 DCHECK(CalledOnValidThread()); 185 DCHECK(CalledOnValidThread());
187 186
188 if (!closed_ && !closing_) { 187 if (!closed_ && !closing_) {
189 closing_ = true; 188 closing_ = true;
190 189
191 if (control_channel_.get()) 190 // Inform the StateChangeCallback, so calling code knows not to touch any
192 control_channel_->Close(result); 191 // channels.
192 if (failed)
193 SetState(FAILED);
194 else
195 SetState(CLOSED);
196
197 // Now tear down the remoting channel resources.
198 control_channel_.reset();
193 control_socket_.reset(); 199 control_socket_.reset();
194 control_ssl_socket_.reset(); 200 control_ssl_socket_.reset();
195 if (control_socket_wrapper_.get()) 201 event_channel_.reset();
196 control_socket_wrapper_->Disconnect();
197
198 if (event_channel_.get())
199 event_channel_->Close(result);
200 event_socket_.reset(); 202 event_socket_.reset();
201 event_ssl_socket_.reset(); 203 event_ssl_socket_.reset();
202 if (event_socket_wrapper_.get()) 204 video_channel_.reset();
203 event_socket_wrapper_->Disconnect();
204
205 if (video_channel_.get())
206 video_channel_->Close(result);
207 video_socket_.reset(); 205 video_socket_.reset();
208 video_ssl_socket_.reset(); 206 video_ssl_socket_.reset();
209 if (video_socket_wrapper_.get()) 207 video_rtp_channel_.reset();
210 video_socket_wrapper_->Disconnect(); 208 video_rtcp_channel_.reset();
211 209
212 if (video_rtp_channel_.get()) 210 // Tear down the cricket session, including the cricket transport channels.
213 video_rtp_channel_->Close(result);
214 if (video_rtcp_channel_.get())
215 video_rtcp_channel_->Close(result);
216
217 if (cricket_session_) { 211 if (cricket_session_) {
218 cricket_session_->Terminate(); 212 cricket_session_->Terminate();
219 cricket_session_->SignalState.disconnect(this); 213 cricket_session_->SignalState.disconnect(this);
220 } 214 }
221 215
222 if (failed)
223 SetState(FAILED);
224 else
225 SetState(CLOSED);
226
227 closed_ = true; 216 closed_ = true;
228 } 217 }
229 cert_verifier_.reset(); 218 cert_verifier_.reset();
230 } 219 }
231 220
232 bool JingleSession::HasSession(cricket::Session* cricket_session) { 221 bool JingleSession::HasSession(cricket::Session* cricket_session) {
233 DCHECK(CalledOnValidThread()); 222 DCHECK(CalledOnValidThread());
234 return cricket_session_ == cricket_session; 223 return cricket_session_ == cricket_session;
235 } 224 }
236 225
(...skipping 11 matching lines...) Expand all
248 } 237 }
249 238
250 void JingleSession::SetStateChangeCallback(StateChangeCallback* callback) { 239 void JingleSession::SetStateChangeCallback(StateChangeCallback* callback) {
251 DCHECK(CalledOnValidThread()); 240 DCHECK(CalledOnValidThread());
252 DCHECK(callback); 241 DCHECK(callback);
253 state_change_callback_.reset(callback); 242 state_change_callback_.reset(callback);
254 } 243 }
255 244
256 net::Socket* JingleSession::control_channel() { 245 net::Socket* JingleSession::control_channel() {
257 DCHECK(CalledOnValidThread()); 246 DCHECK(CalledOnValidThread());
258 return control_socket_wrapper_.get(); 247 return control_ssl_socket_.get();
259 } 248 }
260 249
261 net::Socket* JingleSession::event_channel() { 250 net::Socket* JingleSession::event_channel() {
262 DCHECK(CalledOnValidThread()); 251 DCHECK(CalledOnValidThread());
263 return event_socket_wrapper_.get(); 252 return event_ssl_socket_.get();
264 } 253 }
265 254
266 // TODO(sergeyu): Remove this method after we switch to RTP. 255 // TODO(sergeyu): Remove this method after we switch to RTP.
267 net::Socket* JingleSession::video_channel() { 256 net::Socket* JingleSession::video_channel() {
268 DCHECK(CalledOnValidThread()); 257 DCHECK(CalledOnValidThread());
269 return video_socket_wrapper_.get(); 258 return video_ssl_socket_.get();
270 } 259 }
271 260
272 net::Socket* JingleSession::video_rtp_channel() { 261 net::Socket* JingleSession::video_rtp_channel() {
273 DCHECK(CalledOnValidThread()); 262 DCHECK(CalledOnValidThread());
274 return video_rtp_channel_.get(); 263 return video_rtp_channel_.get();
275 } 264 }
276 265
277 net::Socket* JingleSession::video_rtcp_channel() { 266 net::Socket* JingleSession::video_rtcp_channel() {
278 DCHECK(CalledOnValidThread()); 267 DCHECK(CalledOnValidThread());
279 return video_rtcp_channel_.get(); 268 return video_rtcp_channel_.get();
(...skipping 366 matching lines...) Expand 10 before | Expand all | Expand 10 after
646 void JingleSession::OnSSLConnect(int result) { 635 void JingleSession::OnSSLConnect(int result) {
647 DCHECK(CalledOnValidThread()); 636 DCHECK(CalledOnValidThread());
648 637
649 DCHECK(!closed_); 638 DCHECK(!closed_);
650 if (result != net::OK) { 639 if (result != net::OK) {
651 LOG(ERROR) << "Error during SSL connection: " << result; 640 LOG(ERROR) << "Error during SSL connection: " << result;
652 CloseInternal(result, true); 641 CloseInternal(result, true);
653 return; 642 return;
654 } 643 }
655 644
656 if (control_ssl_socket_.get() && control_ssl_socket_->IsConnected()) { 645 if (event_ssl_socket_.get() && event_ssl_socket_->IsConnected() &&
657 control_socket_wrapper_.reset( 646 control_ssl_socket_.get() && control_ssl_socket_->IsConnected() &&
658 new SocketWrapper(control_ssl_socket_.release())); 647 video_ssl_socket_.get() && video_ssl_socket_->IsConnected()) {
659 }
660 if (event_ssl_socket_.get() && event_ssl_socket_->IsConnected()) {
661 event_socket_wrapper_.reset(
662 new SocketWrapper(event_ssl_socket_.release()));
663 }
664 if (video_ssl_socket_.get() && video_ssl_socket_->IsConnected()) {
665 video_socket_wrapper_.reset(
666 new SocketWrapper(video_ssl_socket_.release()));
667 }
668
669 if (event_socket_wrapper_.get() &&
670 control_socket_wrapper_.get() &&
671 video_socket_wrapper_.get()) {
672 SetState(CONNECTED); 648 SetState(CONNECTED);
673 } 649 }
674 } 650 }
675 651
676 void JingleSession::SetState(State new_state) { 652 void JingleSession::SetState(State new_state) {
677 DCHECK(CalledOnValidThread()); 653 DCHECK(CalledOnValidThread());
678 654
679 if (new_state != state_) { 655 if (new_state != state_) {
680 DCHECK_NE(state_, CLOSED); 656 DCHECK_NE(state_, CLOSED);
681 DCHECK_NE(state_, FAILED); 657 DCHECK_NE(state_, FAILED);
682 658
683 state_ = new_state; 659 state_ = new_state;
684 if (!closed_ && state_change_callback_.get()) 660 if (!closed_ && state_change_callback_.get())
685 state_change_callback_->Run(new_state); 661 state_change_callback_->Run(new_state);
686 } 662 }
687 } 663 }
688 664
689 } // namespace protocol 665 } // namespace protocol
690 666
691 } // namespace remoting 667 } // namespace remoting
OLDNEW
« no previous file with comments | « remoting/protocol/jingle_session.h ('k') | remoting/protocol/socket_wrapper.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698