More minor improvements to BaseChannel/transport code.

Mostly from late comments on this CL:
https://codereview.webrtc.org/2614263002/

Changes SetTransport to DCHECK instead of returning false.
Renames it to SetTransports.
Fixes some possible transport resource leaks.

BUG=None

Review-Url: https://codereview.webrtc.org/2637503003
Cr-Commit-Position: refs/heads/master@{#16130}
diff --git a/webrtc/api/rtcstatscollector_unittest.cc b/webrtc/api/rtcstatscollector_unittest.cc
index 5860a3e..f8efb24 100644
--- a/webrtc/api/rtcstatscollector_unittest.cc
+++ b/webrtc/api/rtcstatscollector_unittest.cc
@@ -315,11 +315,11 @@
   RTCStatsCollectorTestHelper()
       : worker_thread_(rtc::Thread::Current()),
         network_thread_(rtc::Thread::Current()),
+        signaling_thread_(rtc::Thread::Current()),
         media_engine_(new cricket::FakeMediaEngine()),
-        channel_manager_(
-            new cricket::ChannelManager(media_engine_,
-                                        worker_thread_,
-                                        network_thread_)),
+        channel_manager_(new cricket::ChannelManager(media_engine_,
+                                                     worker_thread_,
+                                                     network_thread_)),
         media_controller_(
             MediaControllerInterface::Create(cricket::MediaConfig(),
                                              worker_thread_,
@@ -349,6 +349,7 @@
   rtc::ScopedFakeClock& fake_clock() { return fake_clock_; }
   rtc::Thread* worker_thread() { return worker_thread_; }
   rtc::Thread* network_thread() { return network_thread_; }
+  rtc::Thread* signaling_thread() { return signaling_thread_; }
   cricket::FakeMediaEngine* media_engine() { return media_engine_; }
   MockWebRtcSession& session() { return session_; }
   MockPeerConnection& pc() { return pc_; }
@@ -442,6 +443,7 @@
   RtcEventLogNullImpl event_log_;
   rtc::Thread* const worker_thread_;
   rtc::Thread* const network_thread_;
+  rtc::Thread* const signaling_thread_;
   cricket::FakeMediaEngine* media_engine_;
   std::unique_ptr<cricket::ChannelManager> channel_manager_;
   std::unique_ptr<MediaControllerInterface> media_controller_;
@@ -697,15 +699,15 @@
 TEST_F(RTCStatsCollectorTest, CollectRTCCodecStats) {
   MockVoiceMediaChannel* voice_media_channel = new MockVoiceMediaChannel();
   cricket::VoiceChannel voice_channel(
-      test_->worker_thread(), test_->network_thread(), nullptr,
-      test_->media_engine(), voice_media_channel, "VoiceContentName",
-      kDefaultRtcpMuxRequired, kDefaultSrtpRequired);
+      test_->worker_thread(), test_->network_thread(),
+      test_->signaling_thread(), test_->media_engine(), voice_media_channel,
+      "VoiceContentName", kDefaultRtcpMuxRequired, kDefaultSrtpRequired);
 
   MockVideoMediaChannel* video_media_channel = new MockVideoMediaChannel();
   cricket::VideoChannel video_channel(
-      test_->worker_thread(), test_->network_thread(), nullptr,
-      video_media_channel, "VideoContentName", kDefaultRtcpMuxRequired,
-      kDefaultSrtpRequired);
+      test_->worker_thread(), test_->network_thread(),
+      test_->signaling_thread(), video_media_channel, "VideoContentName",
+      kDefaultRtcpMuxRequired, kDefaultSrtpRequired);
 
   // Audio
   cricket::VoiceMediaInfo voice_media_info;
@@ -1550,9 +1552,9 @@
 TEST_F(RTCStatsCollectorTest, CollectRTCInboundRTPStreamStats_Audio) {
   MockVoiceMediaChannel* voice_media_channel = new MockVoiceMediaChannel();
   cricket::VoiceChannel voice_channel(
-      test_->worker_thread(), test_->network_thread(), nullptr,
-      test_->media_engine(), voice_media_channel, "VoiceContentName",
-      kDefaultRtcpMuxRequired, kDefaultSrtpRequired);
+      test_->worker_thread(), test_->network_thread(),
+      test_->signaling_thread(), test_->media_engine(), voice_media_channel,
+      "VoiceContentName", kDefaultRtcpMuxRequired, kDefaultSrtpRequired);
 
   test_->SetupRemoteTrackAndReceiver(
       cricket::MEDIA_TYPE_AUDIO, "RemoteAudioTrackID", 1);
@@ -1629,9 +1631,9 @@
 TEST_F(RTCStatsCollectorTest, CollectRTCInboundRTPStreamStats_Video) {
   MockVideoMediaChannel* video_media_channel = new MockVideoMediaChannel();
   cricket::VideoChannel video_channel(
-      test_->worker_thread(), test_->network_thread(), nullptr,
-      video_media_channel, "VideoContentName", kDefaultRtcpMuxRequired,
-      kDefaultSrtpRequired);
+      test_->worker_thread(), test_->network_thread(),
+      test_->signaling_thread(), video_media_channel, "VideoContentName",
+      kDefaultRtcpMuxRequired, kDefaultSrtpRequired);
 
   test_->SetupRemoteTrackAndReceiver(
       cricket::MEDIA_TYPE_VIDEO, "RemoteVideoTrackID", 1);
@@ -1714,9 +1716,9 @@
 TEST_F(RTCStatsCollectorTest, CollectRTCOutboundRTPStreamStats_Audio) {
   MockVoiceMediaChannel* voice_media_channel = new MockVoiceMediaChannel();
   cricket::VoiceChannel voice_channel(
-      test_->worker_thread(), test_->network_thread(), nullptr,
-      test_->media_engine(), voice_media_channel, "VoiceContentName",
-      kDefaultRtcpMuxRequired, kDefaultSrtpRequired);
+      test_->worker_thread(), test_->network_thread(),
+      test_->signaling_thread(), test_->media_engine(), voice_media_channel,
+      "VoiceContentName", kDefaultRtcpMuxRequired, kDefaultSrtpRequired);
 
   test_->SetupLocalTrackAndSender(
       cricket::MEDIA_TYPE_AUDIO, "LocalAudioTrackID", 1);
@@ -1787,9 +1789,9 @@
 TEST_F(RTCStatsCollectorTest, CollectRTCOutboundRTPStreamStats_Video) {
   MockVideoMediaChannel* video_media_channel = new MockVideoMediaChannel();
   cricket::VideoChannel video_channel(
-      test_->worker_thread(), test_->network_thread(), nullptr,
-      video_media_channel, "VideoContentName", kDefaultRtcpMuxRequired,
-      kDefaultSrtpRequired);
+      test_->worker_thread(), test_->network_thread(),
+      test_->signaling_thread(), video_media_channel, "VideoContentName",
+      kDefaultRtcpMuxRequired, kDefaultSrtpRequired);
 
   test_->SetupLocalTrackAndSender(
       cricket::MEDIA_TYPE_VIDEO, "LocalVideoTrackID", 1);
@@ -1870,14 +1872,14 @@
 TEST_F(RTCStatsCollectorTest, CollectRTCOutboundRTPStreamStats_Default) {
   MockVoiceMediaChannel* voice_media_channel = new MockVoiceMediaChannel();
   cricket::VoiceChannel voice_channel(
-      test_->worker_thread(), test_->network_thread(), nullptr,
-      test_->media_engine(), voice_media_channel, "VoiceContentName",
-      kDefaultRtcpMuxRequired, kDefaultSrtpRequired);
+      test_->worker_thread(), test_->network_thread(),
+      test_->signaling_thread(), test_->media_engine(), voice_media_channel,
+      "VoiceContentName", kDefaultRtcpMuxRequired, kDefaultSrtpRequired);
   MockVideoMediaChannel* video_media_channel = new MockVideoMediaChannel();
   cricket::VideoChannel video_channel(
-      test_->worker_thread(), test_->network_thread(), nullptr,
-      video_media_channel, "VideoContentName", kDefaultRtcpMuxRequired,
-      kDefaultSrtpRequired);
+      test_->worker_thread(), test_->network_thread(),
+      test_->signaling_thread(), video_media_channel, "VideoContentName",
+      kDefaultRtcpMuxRequired, kDefaultSrtpRequired);
 
   cricket::VoiceMediaInfo voice_media_info;
   voice_media_info.senders.push_back(cricket::VoiceSenderInfo());
diff --git a/webrtc/api/webrtcsession.cc b/webrtc/api/webrtcsession.cc
index a0c72c8..8487d2c 100644
--- a/webrtc/api/webrtcsession.cc
+++ b/webrtc/api/webrtcsession.cc
@@ -1092,18 +1092,16 @@
           transport_name, cricket::ICE_CANDIDATE_COMPONENT_RTCP);
     }
 
-    if (!ch->SetTransport(rtp_transport, rtcp_transport)) {
-      LOG(LS_WARNING) << "Failed to enable BUNDLE for " << ch->content_name();
-      return false;
-    }
+    ch->SetTransports(rtp_transport, rtcp_transport);
     LOG(LS_INFO) << "Enabled BUNDLE for " << ch->content_name() << " on "
                  << transport_name << ".";
-    DestroyTransport(old_transport_name, cricket::ICE_CANDIDATE_COMPONENT_RTP);
+    transport_controller_->DestroyTransportChannel(
+        old_transport_name, cricket::ICE_CANDIDATE_COMPONENT_RTP);
     // If the channel needs rtcp, it means that the channel used to have a
     // rtcp transport which needs to be deleted now.
     if (need_rtcp) {
-      DestroyTransport(old_transport_name,
-                       cricket::ICE_CANDIDATE_COMPONENT_RTCP);
+      transport_controller_->DestroyTransportChannel(
+          old_transport_name, cricket::ICE_CANDIDATE_COMPONENT_RTCP);
     }
     return true;
   };
@@ -1805,6 +1803,12 @@
       transport_controller_->signaling_thread(), content->name,
       bundle_transport, require_rtcp_mux, SrtpRequired(), audio_options_));
   if (!voice_channel_) {
+    transport_controller_->DestroyTransportChannel(
+        transport_name, cricket::ICE_CANDIDATE_COMPONENT_RTP);
+    if (rtcp_transport) {
+      transport_controller_->DestroyTransportChannel(
+          transport_name, cricket::ICE_CANDIDATE_COMPONENT_RTP);
+    }
     return false;
   }
 
@@ -1842,6 +1846,12 @@
       bundle_transport, require_rtcp_mux, SrtpRequired(), video_options_));
 
   if (!video_channel_) {
+    transport_controller_->DestroyTransportChannel(
+        transport_name, cricket::ICE_CANDIDATE_COMPONENT_RTP);
+    if (rtcp_transport) {
+      transport_controller_->DestroyTransportChannel(
+          transport_name, cricket::ICE_CANDIDATE_COMPONENT_RTP);
+    }
     return false;
   }
 
@@ -1901,6 +1911,12 @@
         bundle_transport, require_rtcp_mux, SrtpRequired()));
 
     if (!rtp_data_channel_) {
+      transport_controller_->DestroyTransportChannel(
+          transport_name, cricket::ICE_CANDIDATE_COMPONENT_RTP);
+      if (rtcp_transport) {
+        transport_controller_->DestroyTransportChannel(
+            transport_name, cricket::ICE_CANDIDATE_COMPONENT_RTP);
+      }
       return false;
     }
 
@@ -2365,14 +2381,6 @@
   return channel->transport_name();
 }
 
-void WebRtcSession::DestroyTransport(const std::string& transport_name,
-                                     int component) {
-  network_thread_->Invoke<void>(
-      RTC_FROM_HERE,
-      rtc::Bind(&cricket::TransportController::DestroyTransportChannel_n,
-                transport_controller_.get(), transport_name, component));
-}
-
 void WebRtcSession::DestroyRtcpTransport_n(const std::string& transport_name) {
   RTC_DCHECK(network_thread()->IsCurrent());
   transport_controller_->DestroyTransportChannel_n(
@@ -2386,9 +2394,11 @@
   transport_name = video_channel_->rtp_transport()->transport_name();
   bool need_to_delete_rtcp = (video_channel_->rtcp_transport() != nullptr);
   channel_manager_->DestroyVideoChannel(video_channel_.release());
-  DestroyTransport(transport_name, cricket::ICE_CANDIDATE_COMPONENT_RTP);
+  transport_controller_->DestroyTransportChannel(
+      transport_name, cricket::ICE_CANDIDATE_COMPONENT_RTP);
   if (need_to_delete_rtcp) {
-    DestroyTransport(transport_name, cricket::ICE_CANDIDATE_COMPONENT_RTCP);
+    transport_controller_->DestroyTransportChannel(
+        transport_name, cricket::ICE_CANDIDATE_COMPONENT_RTCP);
   }
 }
 
@@ -2399,9 +2409,11 @@
   transport_name = voice_channel_->rtp_transport()->transport_name();
   bool need_to_delete_rtcp = (voice_channel_->rtcp_transport() != nullptr);
   channel_manager_->DestroyVoiceChannel(voice_channel_.release());
-  DestroyTransport(transport_name, cricket::ICE_CANDIDATE_COMPONENT_RTP);
+  transport_controller_->DestroyTransportChannel(
+      transport_name, cricket::ICE_CANDIDATE_COMPONENT_RTP);
   if (need_to_delete_rtcp) {
-    DestroyTransport(transport_name, cricket::ICE_CANDIDATE_COMPONENT_RTCP);
+    transport_controller_->DestroyTransportChannel(
+        transport_name, cricket::ICE_CANDIDATE_COMPONENT_RTCP);
   }
 }
 
@@ -2412,9 +2424,11 @@
   transport_name = rtp_data_channel_->rtp_transport()->transport_name();
   bool need_to_delete_rtcp = (rtp_data_channel_->rtcp_transport() != nullptr);
   channel_manager_->DestroyRtpDataChannel(rtp_data_channel_.release());
-  DestroyTransport(transport_name, cricket::ICE_CANDIDATE_COMPONENT_RTP);
+  transport_controller_->DestroyTransportChannel(
+      transport_name, cricket::ICE_CANDIDATE_COMPONENT_RTP);
   if (need_to_delete_rtcp) {
-    DestroyTransport(transport_name, cricket::ICE_CANDIDATE_COMPONENT_RTCP);
+    transport_controller_->DestroyTransportChannel(
+        transport_name, cricket::ICE_CANDIDATE_COMPONENT_RTCP);
   }
 }
 }  // namespace webrtc
diff --git a/webrtc/api/webrtcsession.h b/webrtc/api/webrtcsession.h
index f75328f..0030342 100644
--- a/webrtc/api/webrtcsession.h
+++ b/webrtc/api/webrtcsession.h
@@ -553,7 +553,6 @@
 
   const std::string GetTransportName(const std::string& content_name);
 
-  void DestroyTransport(const std::string& transport_name, int component);
   void DestroyRtcpTransport_n(const std::string& transport_name);
   void DestroyVideoChannel();
   void DestroyVoiceChannel();