Making WebRtcSession fire a destroyed signal.
This ensures the DtmfSender won't try to access it after it's destroyed. BUG=webrtc:5403 Review URL: https://codereview.webrtc.org/1590333004 Cr-Commit-Position: refs/heads/master@{#11327}
This commit is contained in:
parent
da99da81c9
commit
057ecf01e4
@ -99,6 +99,8 @@ DtmfSender::DtmfSender(AudioTrackInterface* track,
|
||||
inter_tone_gap_(kDtmfDefaultGapMs) {
|
||||
ASSERT(track_ != NULL);
|
||||
ASSERT(signaling_thread_ != NULL);
|
||||
// TODO(deadbeef): Once we can use shared_ptr and weak_ptr,
|
||||
// do that instead of relying on a "destroyed" signal.
|
||||
if (provider_) {
|
||||
ASSERT(provider_->GetOnDestroyedSignal() != NULL);
|
||||
provider_->GetOnDestroyedSignal()->connect(
|
||||
@ -107,10 +109,6 @@ DtmfSender::DtmfSender(AudioTrackInterface* track,
|
||||
}
|
||||
|
||||
DtmfSender::~DtmfSender() {
|
||||
if (provider_) {
|
||||
ASSERT(provider_->GetOnDestroyedSignal() != NULL);
|
||||
provider_->GetOnDestroyedSignal()->disconnect(this);
|
||||
}
|
||||
StopSending();
|
||||
}
|
||||
|
||||
|
||||
@ -590,6 +590,7 @@ WebRtcSession::~WebRtcSession() {
|
||||
SignalDataChannelDestroyed();
|
||||
channel_manager_->DestroyDataChannel(data_channel_.release());
|
||||
}
|
||||
SignalDestroyed();
|
||||
|
||||
LOG(LS_INFO) << "Session: " << id() << " is destroyed.";
|
||||
}
|
||||
@ -1428,7 +1429,7 @@ bool WebRtcSession::InsertDtmf(const std::string& track_id,
|
||||
}
|
||||
|
||||
sigslot::signal0<>* WebRtcSession::GetOnDestroyedSignal() {
|
||||
return &SignalVoiceChannelDestroyed;
|
||||
return &SignalDestroyed;
|
||||
}
|
||||
|
||||
bool WebRtcSession::SendData(const cricket::SendDataParams& params,
|
||||
|
||||
@ -327,6 +327,8 @@ class WebRtcSession : public AudioProviderInterface,
|
||||
sigslot::signal0<> SignalVideoChannelDestroyed;
|
||||
sigslot::signal0<> SignalDataChannelCreated;
|
||||
sigslot::signal0<> SignalDataChannelDestroyed;
|
||||
// Called when the whole session is destroyed.
|
||||
sigslot::signal0<> SignalDestroyed;
|
||||
|
||||
// Called when a valid data channel OPEN message is received.
|
||||
// std::string represents the data channel label.
|
||||
|
||||
@ -410,6 +410,8 @@ class WebRtcSessionTest
|
||||
allocator_.get(), &observer_));
|
||||
session_->SignalDataChannelOpenMessage.connect(
|
||||
this, &WebRtcSessionTest::OnDataChannelOpenMessage);
|
||||
session_->GetOnDestroyedSignal()->connect(
|
||||
this, &WebRtcSessionTest::OnSessionDestroyed);
|
||||
|
||||
EXPECT_EQ(PeerConnectionInterface::kIceConnectionNew,
|
||||
observer_.ice_connection_state_);
|
||||
@ -428,6 +430,8 @@ class WebRtcSessionTest
|
||||
last_data_channel_config_ = config;
|
||||
}
|
||||
|
||||
void OnSessionDestroyed() { session_destroyed_ = true; }
|
||||
|
||||
void Init() {
|
||||
PeerConnectionInterface::RTCConfiguration configuration;
|
||||
Init(nullptr, configuration);
|
||||
@ -1473,6 +1477,7 @@ class WebRtcSessionTest
|
||||
// Last values received from data channel creation signal.
|
||||
std::string last_data_channel_label_;
|
||||
InternalDataChannelInit last_data_channel_config_;
|
||||
bool session_destroyed_;
|
||||
};
|
||||
|
||||
TEST_P(WebRtcSessionTest, TestInitializeWithDtls) {
|
||||
@ -4313,6 +4318,14 @@ TEST_F(WebRtcSessionTest, TestPacketOptionsAndOnPacketSent) {
|
||||
TestPacketOptions();
|
||||
}
|
||||
|
||||
// Make sure the signal from "GetOnDestroyedSignal()" fires when the session
|
||||
// is destroyed.
|
||||
TEST_F(WebRtcSessionTest, TestOnDestroyedSignal) {
|
||||
Init();
|
||||
session_.reset();
|
||||
EXPECT_TRUE(session_destroyed_);
|
||||
}
|
||||
|
||||
// TODO(bemasc): Add a TestIceStatesBundle with BUNDLE enabled. That test
|
||||
// currently fails because upon disconnection and reconnection OnIceComplete is
|
||||
// called more than once without returning to IceGatheringGathering.
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user