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

Side by Side Diff: talk/app/webrtc/webrtcsessiondescriptionfactory.cc

Issue 1231823002: Make sure we process all pending offer/answer requests before terminating. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Quit() instead of ProcessMessage Created 5 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
« no previous file with comments | « talk/app/webrtc/webrtcsessiondescriptionfactory.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * libjingle 2 * libjingle
3 * Copyright 2013 Google Inc. 3 * Copyright 2013 Google Inc.
4 * 4 *
5 * Redistribution and use in source and binary forms, with or without 5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met: 6 * modification, are permitted provided that the following conditions are met:
7 * 7 *
8 * 1. Redistributions of source code must retain the above copyright notice, 8 * 1. Redistributions of source code must retain the above copyright notice,
9 * this list of conditions and the following disclaimer. 9 * this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright notice, 10 * 2. Redistributions in binary form must reproduce the above copyright notice,
(...skipping 22 matching lines...) Expand all
33 #include "talk/app/webrtc/mediaconstraintsinterface.h" 33 #include "talk/app/webrtc/mediaconstraintsinterface.h"
34 #include "talk/app/webrtc/mediastreamsignaling.h" 34 #include "talk/app/webrtc/mediastreamsignaling.h"
35 #include "talk/app/webrtc/webrtcsession.h" 35 #include "talk/app/webrtc/webrtcsession.h"
36 36
37 using cricket::MediaSessionOptions; 37 using cricket::MediaSessionOptions;
38 38
39 namespace webrtc { 39 namespace webrtc {
40 namespace { 40 namespace {
41 static const char kFailedDueToIdentityFailed[] = 41 static const char kFailedDueToIdentityFailed[] =
42 " failed because DTLS identity request failed"; 42 " failed because DTLS identity request failed";
43 static const char kFailedDueToSessionShutdown[] =
44 " failed because the session was shut down";
43 45
44 static const uint64 kInitSessionVersion = 2; 46 static const uint64 kInitSessionVersion = 2;
45 47
46 static bool CompareStream(const MediaSessionOptions::Stream& stream1, 48 static bool CompareStream(const MediaSessionOptions::Stream& stream1,
47 const MediaSessionOptions::Stream& stream2) { 49 const MediaSessionOptions::Stream& stream2) {
48 return stream1.id < stream2.id; 50 return stream1.id < stream2.id;
49 } 51 }
50 52
51 static bool SameId(const MediaSessionOptions::Stream& stream1, 53 static bool SameId(const MediaSessionOptions::Stream& stream1,
52 const MediaSessionOptions::Stream& stream2) { 54 const MediaSessionOptions::Stream& stream2) {
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
176 } 178 }
177 } else { 179 } else {
178 identity_request_state_ = IDENTITY_WAITING; 180 identity_request_state_ = IDENTITY_WAITING;
179 // Do not generate the identity in the constructor since the caller has 181 // Do not generate the identity in the constructor since the caller has
180 // not got a chance to connect to SignalIdentityReady. 182 // not got a chance to connect to SignalIdentityReady.
181 signaling_thread_->Post(this, MSG_GENERATE_IDENTITY, NULL); 183 signaling_thread_->Post(this, MSG_GENERATE_IDENTITY, NULL);
182 } 184 }
183 } 185 }
184 186
185 WebRtcSessionDescriptionFactory::~WebRtcSessionDescriptionFactory() { 187 WebRtcSessionDescriptionFactory::~WebRtcSessionDescriptionFactory() {
188 ASSERT(signaling_thread_->IsCurrent());
189
190 // Fail any requests that were asked for before identity generation completed.
191 FailPendingRequests(kFailedDueToSessionShutdown);
192
193 // Process all pending notifications in the message queue. If we don't do
194 // this, requests will linger and not know they succeeded or failed.
195 rtc::MessageList list;
196 signaling_thread_->Clear(this, rtc::MQID_ANY, &list);
197 for (auto& msg : list)
198 OnMessage(&msg);
199
186 transport_desc_factory_.set_identity(NULL); 200 transport_desc_factory_.set_identity(NULL);
187 } 201 }
188 202
189 void WebRtcSessionDescriptionFactory::CreateOffer( 203 void WebRtcSessionDescriptionFactory::CreateOffer(
190 CreateSessionDescriptionObserver* observer, 204 CreateSessionDescriptionObserver* observer,
191 const PeerConnectionInterface::RTCOfferAnswerOptions& options) { 205 const PeerConnectionInterface::RTCOfferAnswerOptions& options) {
192 cricket::MediaSessionOptions session_options; 206 cricket::MediaSessionOptions session_options;
193 207
194 std::string error = "CreateOffer"; 208 std::string error = "CreateOffer";
195 if (identity_request_state_ == IDENTITY_FAILED) { 209 if (identity_request_state_ == IDENTITY_FAILED) {
(...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after
393 if (session_->local_description() && 407 if (session_->local_description() &&
394 !request.options.transport_options.ice_restart) { 408 !request.options.transport_options.ice_restart) {
395 // Include all local ice candidates in the SessionDescription unless 409 // Include all local ice candidates in the SessionDescription unless
396 // the remote peer has requested an ice restart. 410 // the remote peer has requested an ice restart.
397 CopyCandidatesFromSessionDescription(session_->local_description(), answer); 411 CopyCandidatesFromSessionDescription(session_->local_description(), answer);
398 } 412 }
399 session_->ResetIceRestartLatch(); 413 session_->ResetIceRestartLatch();
400 PostCreateSessionDescriptionSucceeded(request.observer, answer); 414 PostCreateSessionDescriptionSucceeded(request.observer, answer);
401 } 415 }
402 416
417 void WebRtcSessionDescriptionFactory::FailPendingRequests(
418 const std::string& reason) {
419 ASSERT(signaling_thread_->IsCurrent());
420 while (!create_session_description_requests_.empty()) {
421 const CreateSessionDescriptionRequest& request =
422 create_session_description_requests_.front();
423 PostCreateSessionDescriptionFailed(request.observer,
424 ((request.type == CreateSessionDescriptionRequest::kOffer) ?
425 "CreateOffer" : "CreateAnswer") + reason);
426 create_session_description_requests_.pop();
427 }
428 }
429
403 void WebRtcSessionDescriptionFactory::PostCreateSessionDescriptionFailed( 430 void WebRtcSessionDescriptionFactory::PostCreateSessionDescriptionFailed(
404 CreateSessionDescriptionObserver* observer, const std::string& error) { 431 CreateSessionDescriptionObserver* observer, const std::string& error) {
405 CreateSessionDescriptionMsg* msg = new CreateSessionDescriptionMsg(observer); 432 CreateSessionDescriptionMsg* msg = new CreateSessionDescriptionMsg(observer);
406 msg->error = error; 433 msg->error = error;
407 signaling_thread_->Post(this, MSG_CREATE_SESSIONDESCRIPTION_FAILED, msg); 434 signaling_thread_->Post(this, MSG_CREATE_SESSIONDESCRIPTION_FAILED, msg);
408 LOG(LS_ERROR) << "Create SDP failed: " << error; 435 LOG(LS_ERROR) << "Create SDP failed: " << error;
409 } 436 }
410 437
411 void WebRtcSessionDescriptionFactory::PostCreateSessionDescriptionSucceeded( 438 void WebRtcSessionDescriptionFactory::PostCreateSessionDescriptionSucceeded(
412 CreateSessionDescriptionObserver* observer, 439 CreateSessionDescriptionObserver* observer,
413 SessionDescriptionInterface* description) { 440 SessionDescriptionInterface* description) {
414 CreateSessionDescriptionMsg* msg = new CreateSessionDescriptionMsg(observer); 441 CreateSessionDescriptionMsg* msg = new CreateSessionDescriptionMsg(observer);
415 msg->description.reset(description); 442 msg->description.reset(description);
416 signaling_thread_->Post(this, MSG_CREATE_SESSIONDESCRIPTION_SUCCESS, msg); 443 signaling_thread_->Post(this, MSG_CREATE_SESSIONDESCRIPTION_SUCCESS, msg);
417 } 444 }
418 445
419 void WebRtcSessionDescriptionFactory::OnIdentityRequestFailed(int error) { 446 void WebRtcSessionDescriptionFactory::OnIdentityRequestFailed(int error) {
420 ASSERT(signaling_thread_->IsCurrent()); 447 ASSERT(signaling_thread_->IsCurrent());
421 448
422 LOG(LS_ERROR) << "Async identity request failed: error = " << error; 449 LOG(LS_ERROR) << "Async identity request failed: error = " << error;
423 identity_request_state_ = IDENTITY_FAILED; 450 identity_request_state_ = IDENTITY_FAILED;
424 451
425 std::string msg = kFailedDueToIdentityFailed; 452 FailPendingRequests(kFailedDueToIdentityFailed);
426 while (!create_session_description_requests_.empty()) {
427 const CreateSessionDescriptionRequest& request =
428 create_session_description_requests_.front();
429 PostCreateSessionDescriptionFailed(
430 request.observer,
431 ((request.type == CreateSessionDescriptionRequest::kOffer) ?
432 "CreateOffer" : "CreateAnswer") + msg);
433 create_session_description_requests_.pop();
434 }
435 } 453 }
436 454
437 void WebRtcSessionDescriptionFactory::SetIdentity( 455 void WebRtcSessionDescriptionFactory::SetIdentity(
438 rtc::SSLIdentity* identity) { 456 rtc::SSLIdentity* identity) {
439 LOG(LS_VERBOSE) << "Setting new identity"; 457 LOG(LS_VERBOSE) << "Setting new identity";
440 458
441 identity_request_state_ = IDENTITY_SUCCEEDED; 459 identity_request_state_ = IDENTITY_SUCCEEDED;
442 SignalIdentityReady(identity); 460 SignalIdentityReady(identity);
443 461
444 transport_desc_factory_.set_identity(identity); 462 transport_desc_factory_.set_identity(identity);
445 transport_desc_factory_.set_secure(cricket::SEC_ENABLED); 463 transport_desc_factory_.set_secure(cricket::SEC_ENABLED);
446 464
447 while (!create_session_description_requests_.empty()) { 465 while (!create_session_description_requests_.empty()) {
448 if (create_session_description_requests_.front().type == 466 if (create_session_description_requests_.front().type ==
449 CreateSessionDescriptionRequest::kOffer) { 467 CreateSessionDescriptionRequest::kOffer) {
450 InternalCreateOffer(create_session_description_requests_.front()); 468 InternalCreateOffer(create_session_description_requests_.front());
451 } else { 469 } else {
452 InternalCreateAnswer(create_session_description_requests_.front()); 470 InternalCreateAnswer(create_session_description_requests_.front());
453 } 471 }
454 create_session_description_requests_.pop(); 472 create_session_description_requests_.pop();
455 } 473 }
456 } 474 }
457 } // namespace webrtc 475 } // namespace webrtc
OLDNEW
« no previous file with comments | « talk/app/webrtc/webrtcsessiondescriptionfactory.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698