Move have_pending_rtp_data_channel_ to sdp_offer_answer

Also use accessors for the last few member variable references
in PeerConnection.

This completes removing the variable accesses from SdpOfferAnswerHandler
to PeerConnection.

Bug: webrtc:11995
Change-Id: I70c78b43035c15f20559f7a6a5b50c3a613fe907
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/186200
Reviewed-by: Björn Terelius <terelius@webrtc.org>
Commit-Queue: Harald Alvestrand <hta@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#32272}
diff --git a/pc/peer_connection.cc b/pc/peer_connection.cc
index 4196359..cdd529d 100644
--- a/pc/peer_connection.cc
+++ b/pc/peer_connection.cc
@@ -3925,7 +3925,7 @@
           this, &PeerConnection::OnSentPacket_w);
       data_channel_controller_.rtp_data_channel()->SetRtpTransport(
           rtp_transport);
-      have_pending_rtp_data_channel_ = true;
+      sdp_handler_.SetHavePendingRtpDataChannel();
       return true;
   }
   return false;
diff --git a/pc/peer_connection.h b/pc/peer_connection.h
index e5a7ae8..780ba94 100644
--- a/pc/peer_connection.h
+++ b/pc/peer_connection.h
@@ -683,7 +683,8 @@
   // to the user. If this is false, Plan B semantics are assumed.
   // TODO(bugs.webrtc.org/8530): Flip the default to be Unified Plan once
   // sufficient time has passed.
-  bool IsUnifiedPlan() const RTC_RUN_ON(signaling_thread()) {
+  bool IsUnifiedPlan() const {
+    RTC_DCHECK_RUN_ON(signaling_thread());
     return configuration_.sdp_semantics == SdpSemantics::kUnifiedPlan;
   }
 
@@ -1048,9 +1049,6 @@
       RTC_GUARDED_BY(signaling_thread());  // A pointer is passed to senders_
   rtc::scoped_refptr<RTCStatsCollector> stats_collector_
       RTC_GUARDED_BY(signaling_thread());
-  // Used when rolling back RTP data channels.
-  bool have_pending_rtp_data_channel_ RTC_GUARDED_BY(signaling_thread()) =
-      false;
   TransceiverList transceivers_;
 
   // MIDs will be generated using this generator which will keep track of
diff --git a/pc/sdp_offer_answer.cc b/pc/sdp_offer_answer.cc
index b150ce9..273ba11 100644
--- a/pc/sdp_offer_answer.cc
+++ b/pc/sdp_offer_answer.cc
@@ -2271,11 +2271,10 @@
                              ? PeerConnectionInterface::kHaveLocalPrAnswer
                              : PeerConnectionInterface::kHaveRemotePrAnswer);
   } else {
-    RTC_DCHECK_RUN_ON(pc_->signaling_thread());
     RTC_DCHECK(type == SdpType::kAnswer);
     ChangeSignalingState(PeerConnectionInterface::kStable);
     pc_->transceivers_.DiscardStableStates();
-    pc_->have_pending_rtp_data_channel_ = false;
+    have_pending_rtp_data_channel_ = false;
   }
 
   // Update internal objects according to the session description's media
@@ -2378,14 +2377,11 @@
     transceiver->internal()->set_mline_index(state.mline_index());
   }
   pc_->transport_controller_->RollbackTransports();
-  {
-    RTC_DCHECK_RUN_ON(pc_->signaling_thread());
-    if (pc_->have_pending_rtp_data_channel_) {
-      pc_->DestroyDataChannelTransport();
-      pc_->have_pending_rtp_data_channel_ = false;
-    }
-    pc_->transceivers_.DiscardStableStates();
+  if (have_pending_rtp_data_channel_) {
+    pc_->DestroyDataChannelTransport();
+    have_pending_rtp_data_channel_ = false;
   }
+  pc_->transceivers_.DiscardStableStates();
   pending_local_description_.reset();
   pending_remote_description_.reset();
   ChangeSignalingState(PeerConnectionInterface::kStable);
@@ -2416,7 +2412,6 @@
 }
 
 bool SdpOfferAnswerHandler::IsUnifiedPlan() const {
-  RTC_DCHECK_RUN_ON(pc_->signaling_thread());
   return pc_->IsUnifiedPlan();
 }
 
@@ -3030,8 +3025,8 @@
     RTC_LOG(LS_INFO) << "Rejected data channel, mid=" << content.mid();
     pc_->DestroyDataChannelTransport();
   } else {
-    if (!pc_->data_channel_controller_.rtp_data_channel() &&
-        !pc_->data_channel_controller_.data_channel_transport()) {
+    if (!pc_->data_channel_controller()->rtp_data_channel() &&
+        !pc_->data_channel_controller()->data_channel_transport()) {
       RTC_LOG(LS_INFO) << "Creating data channel, mid=" << content.mid();
       if (!pc_->CreateDataChannel(content.name)) {
         LOG_AND_RETURN_ERROR(RTCErrorType::INTERNAL_ERROR,
@@ -3041,7 +3036,7 @@
     if (source == cricket::CS_REMOTE) {
       const MediaContentDescription* data_desc = content.media_description();
       if (data_desc && cricket::IsRtpProtocol(data_desc->protocol())) {
-        pc_->data_channel_controller_.UpdateRemoteRtpDataChannels(
+        pc_->data_channel_controller()->UpdateRemoteRtpDataChannels(
             GetActiveStreams(data_desc));
       }
     }
diff --git a/pc/sdp_offer_answer.h b/pc/sdp_offer_answer.h
index b84c8bd..92ecbdf 100644
--- a/pc/sdp_offer_answer.h
+++ b/pc/sdp_offer_answer.h
@@ -130,6 +130,10 @@
   bool HasNewIceCredentials();
   bool IceRestartPending(const std::string& content_name) const;
   void UpdateNegotiationNeeded();
+  void SetHavePendingRtpDataChannel() {
+    RTC_DCHECK_RUN_ON(signaling_thread());
+    have_pending_rtp_data_channel_ = true;
+  }
 
   // Returns the media section in the given session description that is
   // associated with the RtpTransceiver. Returns null if none found or this
@@ -362,6 +366,10 @@
   rtc::scoped_refptr<MediaStreamInterface> missing_msid_default_stream_
       RTC_GUARDED_BY(signaling_thread());
 
+  // Used when rolling back RTP data channels.
+  bool have_pending_rtp_data_channel_ RTC_GUARDED_BY(signaling_thread()) =
+      false;
+
   rtc::WeakPtrFactory<SdpOfferAnswerHandler> weak_ptr_factory_
       RTC_GUARDED_BY(signaling_thread());
 };