Use QuicSession::transport_version() instead of QuicConnection::transport_version() to make code cleaner.

gfe-relnote: code cleanup, not protected.
PiperOrigin-RevId: 267628510
Change-Id: I2b28c42ec2345870905e7e5d7e88721be86ad6e4
diff --git a/quic/core/http/quic_headers_stream.cc b/quic/core/http/quic_headers_stream.cc
index 9c99ab7..394d42a 100644
--- a/quic/core/http/quic_headers_stream.cc
+++ b/quic/core/http/quic_headers_stream.cc
@@ -27,8 +27,7 @@
 QuicHeadersStream::CompressedHeaderInfo::~CompressedHeaderInfo() {}
 
 QuicHeadersStream::QuicHeadersStream(QuicSpdySession* session)
-    : QuicStream(QuicUtils::GetHeadersStreamId(
-                     session->connection()->transport_version()),
+    : QuicStream(QuicUtils::GetHeadersStreamId(session->transport_version()),
                  session,
                  /*is_static=*/true,
                  BIDIRECTIONAL),
diff --git a/quic/core/http/quic_headers_stream_test.cc b/quic/core/http/quic_headers_stream_test.cc
index 2035d47..cfc5381 100644
--- a/quic/core/http/quic_headers_stream_test.cc
+++ b/quic/core/http/quic_headers_stream_test.cc
@@ -202,7 +202,7 @@
     deframer_ = std::unique_ptr<http2::Http2DecoderAdapter>(
         new http2::Http2DecoderAdapter());
     deframer_->set_visitor(&visitor_);
-    EXPECT_EQ(transport_version(), session_.connection()->transport_version());
+    EXPECT_EQ(transport_version(), session_.transport_version());
     EXPECT_TRUE(headers_stream_ != nullptr);
     connection_->AdvanceTime(QuicTime::Delta::FromMilliseconds(1));
     client_id_1_ = GetNthClientInitiatedBidirectionalStreamId(
diff --git a/quic/core/http/quic_server_session_base.cc b/quic/core/http/quic_server_session_base.cc
index 29bce86..5805fc9 100644
--- a/quic/core/http/quic_server_session_base.cc
+++ b/quic/core/http/quic_server_session_base.cc
@@ -201,8 +201,7 @@
     return false;
   }
 
-  if (QuicUtils::IsServerInitiatedStreamId(connection()->transport_version(),
-                                           id)) {
+  if (QuicUtils::IsServerInitiatedStreamId(transport_version(), id)) {
     QUIC_DLOG(INFO) << "Invalid incoming even stream_id:" << id;
     connection()->CloseConnection(
         QUIC_INVALID_STREAM_ID, "Client created even numbered stream",
@@ -224,7 +223,7 @@
   }
 
   if (!GetQuicReloadableFlag(quic_use_common_stream_check) &&
-      !VersionHasIetfQuicFrames(connection()->transport_version())) {
+      !VersionHasIetfQuicFrames(transport_version())) {
     if (GetNumOpenOutgoingStreams() >=
         stream_id_manager().max_open_outgoing_streams()) {
       QUIC_VLOG(1) << "No more streams should be created. "
@@ -248,7 +247,7 @@
   }
 
   if (!GetQuicReloadableFlag(quic_use_common_stream_check) &&
-      !VersionHasIetfQuicFrames(connection()->transport_version())) {
+      !VersionHasIetfQuicFrames(transport_version())) {
     if (GetNumOpenOutgoingStreams() >=
         stream_id_manager().max_open_outgoing_streams()) {
       QUIC_VLOG(1) << "No more streams should be created. "
diff --git a/quic/core/http/quic_spdy_client_session.cc b/quic/core/http/quic_spdy_client_session.cc
index 50ed00d..ef9f2e2 100644
--- a/quic/core/http/quic_spdy_client_session.cc
+++ b/quic/core/http/quic_spdy_client_session.cc
@@ -53,7 +53,7 @@
     return false;
   }
   if (!GetQuicReloadableFlag(quic_use_common_stream_check) &&
-      !VersionHasIetfQuicFrames(connection()->transport_version())) {
+      !VersionHasIetfQuicFrames(transport_version())) {
     if (GetNumOpenOutgoingStreams() >=
         stream_id_manager().max_open_outgoing_streams()) {
       QUIC_DLOG(INFO) << "Failed to create a new outgoing stream. "
@@ -136,9 +136,8 @@
                     << "Already received goaway.";
     return false;
   }
-  if (QuicUtils::IsClientInitiatedStreamId(connection()->transport_version(),
-                                           id) ||
-      (VersionHasIetfQuicFrames(connection()->transport_version()) &&
+  if (QuicUtils::IsClientInitiatedStreamId(transport_version(), id) ||
+      (VersionHasIetfQuicFrames(transport_version()) &&
        QuicUtils::IsBidirectionalStreamId(id))) {
     QUIC_LOG(WARNING) << "Received invalid push stream id " << id;
     connection()->CloseConnection(
diff --git a/quic/core/http/quic_spdy_client_session_base.cc b/quic/core/http/quic_spdy_client_session_base.cc
index a2a9aae..37e5dd5 100644
--- a/quic/core/http/quic_spdy_client_session_base.cc
+++ b/quic/core/http/quic_spdy_client_session_base.cc
@@ -43,7 +43,7 @@
     CryptoHandshakeEvent event) {
   QuicSpdySession::OnCryptoHandshakeEvent(event);
   if (event == HANDSHAKE_CONFIRMED && max_allowed_push_id() > 0 &&
-      VersionHasIetfQuicFrames(connection()->transport_version())) {
+      VersionHasIetfQuicFrames(transport_version())) {
     SendMaxPushId(max_allowed_push_id());
   }
 }
@@ -75,9 +75,9 @@
     return;
   }
   if (promised_stream_id !=
-          QuicUtils::GetInvalidStreamId(connection()->transport_version()) &&
+          QuicUtils::GetInvalidStreamId(transport_version()) &&
       largest_promised_stream_id_ !=
-          QuicUtils::GetInvalidStreamId(connection()->transport_version()) &&
+          QuicUtils::GetInvalidStreamId(transport_version()) &&
       promised_stream_id <= largest_promised_stream_id_) {
     connection()->CloseConnection(
         QUIC_INVALID_STREAM_ID,
@@ -93,7 +93,7 @@
     return;
   }
 
-  if (VersionHasIetfQuicFrames(connection()->transport_version()) &&
+  if (VersionHasIetfQuicFrames(transport_version()) &&
       promised_stream_id > max_allowed_push_id()) {
     connection()->CloseConnection(
         QUIC_INVALID_STREAM_ID,
@@ -199,7 +199,7 @@
   // ToDo: Consider implementing logic to send a new MAX_PUSH_ID frame to allow
   // another stream to be promised.
   promised_by_id_.erase(promised->id());
-  if (!VersionUsesQpack(connection()->transport_version())) {
+  if (!VersionUsesQpack(transport_version())) {
     headers_stream()->MaybeReleaseSequencerBuffer();
   }
 }
@@ -219,7 +219,7 @@
 void QuicSpdyClientSessionBase::CloseStreamInner(QuicStreamId stream_id,
                                                  bool locally_reset) {
   QuicSpdySession::CloseStreamInner(stream_id, locally_reset);
-  if (!VersionUsesQpack(connection()->transport_version())) {
+  if (!VersionUsesQpack(transport_version())) {
     headers_stream()->MaybeReleaseSequencerBuffer();
   }
 }
diff --git a/quic/core/http/quic_spdy_server_stream_base_test.cc b/quic/core/http/quic_spdy_server_stream_base_test.cc
index 15638ca..1888e03 100644
--- a/quic/core/http/quic_spdy_server_stream_base_test.cc
+++ b/quic/core/http/quic_spdy_server_stream_base_test.cc
@@ -31,10 +31,10 @@
       : session_(new MockQuicConnection(&helper_,
                                         &alarm_factory_,
                                         Perspective::IS_SERVER)) {
-    stream_ = new TestQuicSpdyServerStream(
-        GetNthClientInitiatedBidirectionalStreamId(
-            session_.connection()->transport_version(), 0),
-        &session_, BIDIRECTIONAL);
+    stream_ =
+        new TestQuicSpdyServerStream(GetNthClientInitiatedBidirectionalStreamId(
+                                         session_.transport_version(), 0),
+                                     &session_, BIDIRECTIONAL);
     session_.ActivateStream(QuicWrapUnique(stream_));
     helper_.AdvanceTime(QuicTime::Delta::FromSeconds(1));
   }
@@ -59,7 +59,7 @@
 
   EXPECT_CALL(session_, SendRstStream(_, QUIC_STREAM_NO_ERROR, _)).Times(0);
 
-  if (!VersionHasIetfQuicFrames(session_.connection()->transport_version())) {
+  if (!VersionHasIetfQuicFrames(session_.transport_version())) {
     EXPECT_CALL(session_, SendRstStream(_, QUIC_RST_ACKNOWLEDGEMENT, _))
         .Times(1);
   } else {
@@ -76,7 +76,7 @@
   QuicRstStreamFrame rst_frame(kInvalidControlFrameId, stream_->id(),
                                QUIC_STREAM_CANCELLED, 1234);
   stream_->OnStreamReset(rst_frame);
-  if (VersionHasIetfQuicFrames(session_.connection()->transport_version())) {
+  if (VersionHasIetfQuicFrames(session_.transport_version())) {
     // Create and inject a STOP SENDING frame to complete the close
     // of the stream. This is only needed for version 99/IETF QUIC.
     QuicStopSendingFrame stop_sending(
diff --git a/quic/core/http/quic_spdy_session.cc b/quic/core/http/quic_spdy_session.cc
index 719b3dc..e626f2a 100644
--- a/quic/core/http/quic_spdy_session.cc
+++ b/quic/core/http/quic_spdy_session.cc
@@ -186,7 +186,7 @@
       return;
     }
 
-    if (VersionUsesQpack(session_->connection()->transport_version())) {
+    if (VersionUsesQpack(session_->transport_version())) {
       CloseConnection("HEADERS frame not allowed on headers stream.",
                       QUIC_INVALID_HEADERS_STREAM_DATA);
       return;
@@ -239,7 +239,7 @@
                   int weight,
                   bool exclusive) override {
     DCHECK(!VersionUsesQpack(session_->transport_version()));
-    if (session_->connection()->transport_version() <= QUIC_VERSION_39) {
+    if (session_->transport_version() <= QUIC_VERSION_39) {
       CloseConnection("SPDY PRIORITY frame received.",
                       QUIC_INVALID_HEADERS_STREAM_DATA);
       return;
@@ -368,17 +368,17 @@
 void QuicSpdySession::Initialize() {
   QuicSession::Initialize();
 
-  if (!VersionUsesQpack(connection()->transport_version())) {
+  if (!VersionUsesQpack(transport_version())) {
     if (perspective() == Perspective::IS_SERVER) {
       set_largest_peer_created_stream_id(
-          QuicUtils::GetHeadersStreamId(connection()->transport_version()));
+          QuicUtils::GetHeadersStreamId(transport_version()));
     } else {
       QuicStreamId headers_stream_id = GetNextOutgoingBidirectionalStreamId();
-      DCHECK_EQ(headers_stream_id, QuicUtils::GetHeadersStreamId(
-                                       connection()->transport_version()));
+      DCHECK_EQ(headers_stream_id,
+                QuicUtils::GetHeadersStreamId(transport_version()));
     }
     auto headers_stream = QuicMakeUnique<QuicHeadersStream>((this));
-    DCHECK_EQ(QuicUtils::GetHeadersStreamId(connection()->transport_version()),
+    DCHECK_EQ(QuicUtils::GetHeadersStreamId(transport_version()),
               headers_stream->id());
 
     headers_stream_ = headers_stream.get();
@@ -403,14 +403,14 @@
 }
 
 void QuicSpdySession::OnDecoderStreamError(QuicStringPiece /*error_message*/) {
-  DCHECK(VersionUsesQpack(connection()->transport_version()));
+  DCHECK(VersionUsesQpack(transport_version()));
 
   // TODO(112770235): Signal connection error on decoder stream errors.
   QUIC_NOTREACHED();
 }
 
 void QuicSpdySession::OnEncoderStreamError(QuicStringPiece /*error_message*/) {
-  DCHECK(VersionUsesQpack(connection()->transport_version()));
+  DCHECK(VersionUsesQpack(transport_version()));
 
   // TODO(112770235): Signal connection error on encoder stream errors.
   QUIC_NOTREACHED();
@@ -491,7 +491,7 @@
     bool fin,
     const spdy::SpdyStreamPrecedence& precedence,
     QuicReferenceCountedPointer<QuicAckListenerInterface> ack_listener) {
-  DCHECK(!VersionUsesQpack(connection()->transport_version()));
+  DCHECK(!VersionUsesQpack(transport_version()));
 
   return WriteHeadersOnHeadersStreamImpl(
       id, std::move(headers), fin,
@@ -504,8 +504,8 @@
                                       QuicStreamId parent_stream_id,
                                       int weight,
                                       bool exclusive) {
-  DCHECK(!VersionUsesQpack(connection()->transport_version()));
-  if (connection()->transport_version() <= QUIC_VERSION_39) {
+  DCHECK(!VersionUsesQpack(transport_version()));
+  if (transport_version() <= QUIC_VERSION_39) {
     return 0;
   }
   SpdyPriorityIR priority_frame(id, parent_stream_id, weight, exclusive);
@@ -516,7 +516,7 @@
 }
 
 void QuicSpdySession::WriteH3Priority(const PriorityFrame& priority) {
-  DCHECK(VersionHasStreamType(connection()->transport_version()));
+  DCHECK(VersionHasStreamType(transport_version()));
   DCHECK(perspective() == Perspective::IS_CLIENT)
       << "Server must not send priority";
 
@@ -533,14 +533,14 @@
     return;
   }
 
-  if (VersionHasIetfQuicFrames(connection()->transport_version()) &&
+  if (VersionHasIetfQuicFrames(transport_version()) &&
       promised_stream_id > max_allowed_push_id()) {
     QUIC_BUG
         << "Server shouldn't send push id higher than client's MAX_PUSH_ID.";
     return;
   }
 
-  if (!VersionHasStreamType(connection()->transport_version())) {
+  if (!VersionHasStreamType(transport_version())) {
     SpdyPushPromiseIR push_promise(original_stream_id, promised_stream_id,
                                    std::move(headers));
     // PUSH_PROMISE must not be the last frame sent out, at least followed by
@@ -564,7 +564,7 @@
 }
 
 void QuicSpdySession::SendMaxHeaderListSize(size_t value) {
-  if (VersionHasStreamType(connection()->transport_version())) {
+  if (VersionHasStreamType(transport_version())) {
     QuicConnection::ScopedPacketFlusher flusher(connection());
     send_control_stream_->MaybeSendSettingsFrame();
     // TODO(renjietang): Remove this once stream id manager can take dynamically
@@ -587,13 +587,13 @@
 }
 
 QpackEncoder* QuicSpdySession::qpack_encoder() {
-  DCHECK(VersionUsesQpack(connection()->transport_version()));
+  DCHECK(VersionUsesQpack(transport_version()));
 
   return qpack_encoder_.get();
 }
 
 QpackDecoder* QuicSpdySession::qpack_decoder() {
-  DCHECK(VersionUsesQpack(connection()->transport_version()));
+  DCHECK(VersionUsesQpack(transport_version()));
 
   return qpack_decoder_.get();
 }
@@ -645,7 +645,7 @@
   // QuicSpdySession supports PendingStreams, therefore this method should
   // eventually just return true.  However, pending streams can only be used if
   // unidirectional stream type is supported.
-  return VersionHasStreamType(connection()->transport_version());
+  return VersionHasStreamType(transport_version());
 }
 
 size_t QuicSpdySession::WriteHeadersOnHeadersStreamImpl(
@@ -656,7 +656,7 @@
     int weight,
     bool exclusive,
     QuicReferenceCountedPointer<QuicAckListenerInterface> ack_listener) {
-  DCHECK(!VersionUsesQpack(connection()->transport_version()));
+  DCHECK(!VersionUsesQpack(transport_version()));
 
   SpdyHeadersIR headers_frame(id, std::move(headers));
   headers_frame.set_fin(fin);
@@ -686,7 +686,7 @@
 }
 
 void QuicSpdySession::OnSetting(uint64_t id, uint64_t value) {
-  if (VersionHasStreamType(connection()->transport_version())) {
+  if (VersionHasStreamType(transport_version())) {
     // SETTINGS frame received on the control stream.
     switch (id) {
       case SETTINGS_QPACK_MAX_TABLE_CAPACITY:
@@ -798,9 +798,8 @@
       return;
     }
   }
-  DCHECK_EQ(QuicUtils::GetInvalidStreamId(connection()->transport_version()),
-            stream_id_);
-  DCHECK_EQ(QuicUtils::GetInvalidStreamId(connection()->transport_version()),
+  DCHECK_EQ(QuicUtils::GetInvalidStreamId(transport_version()), stream_id_);
+  DCHECK_EQ(QuicUtils::GetInvalidStreamId(transport_version()),
             promised_stream_id_);
   stream_id_ = stream_id;
   fin_ = fin;
@@ -808,9 +807,8 @@
 
 void QuicSpdySession::OnPushPromise(SpdyStreamId stream_id,
                                     SpdyStreamId promised_stream_id) {
-  DCHECK_EQ(QuicUtils::GetInvalidStreamId(connection()->transport_version()),
-            stream_id_);
-  DCHECK_EQ(QuicUtils::GetInvalidStreamId(connection()->transport_version()),
+  DCHECK_EQ(QuicUtils::GetInvalidStreamId(transport_version()), stream_id_);
+  DCHECK_EQ(QuicUtils::GetInvalidStreamId(transport_version()),
             promised_stream_id_);
   stream_id_ = stream_id;
   promised_stream_id_ = promised_stream_id;
@@ -832,21 +830,20 @@
   QUIC_DVLOG(1) << "Received header list for stream " << stream_id_ << ": "
                 << header_list.DebugString();
   // This code path is only executed for push promise in IETF QUIC.
-  if (VersionUsesQpack(connection()->transport_version())) {
+  if (VersionUsesQpack(transport_version())) {
     DCHECK(promised_stream_id_ !=
-           QuicUtils::GetInvalidStreamId(connection()->transport_version()));
+           QuicUtils::GetInvalidStreamId(transport_version()));
   }
   if (promised_stream_id_ ==
-      QuicUtils::GetInvalidStreamId(connection()->transport_version())) {
+      QuicUtils::GetInvalidStreamId(transport_version())) {
     OnStreamHeaderList(stream_id_, fin_, frame_len_, header_list);
   } else {
     OnPromiseHeaderList(stream_id_, promised_stream_id_, frame_len_,
                         header_list);
   }
   // Reset state for the next frame.
-  promised_stream_id_ =
-      QuicUtils::GetInvalidStreamId(connection()->transport_version());
-  stream_id_ = QuicUtils::GetInvalidStreamId(connection()->transport_version());
+  promised_stream_id_ = QuicUtils::GetInvalidStreamId(transport_version());
+  stream_id_ = QuicUtils::GetInvalidStreamId(transport_version());
   fin_ = false;
   frame_len_ = 0;
 }
@@ -894,7 +891,7 @@
 }
 
 bool QuicSpdySession::ProcessPendingStream(PendingStream* pending) {
-  DCHECK(VersionHasStreamType(connection()->transport_version()));
+  DCHECK(VersionHasStreamType(transport_version()));
   DCHECK(connection()->connected());
   struct iovec iov;
   if (!pending->sequencer()->GetReadableRegion(&iov)) {
@@ -968,7 +965,7 @@
 }
 
 void QuicSpdySession::MaybeInitializeHttp3UnidirectionalStreams() {
-  DCHECK(VersionHasStreamType(connection()->transport_version()));
+  DCHECK(VersionHasStreamType(transport_version()));
   if (!send_control_stream_ && CanOpenNextOutgoingUnidirectionalStream()) {
     auto send_control = QuicMakeUnique<QuicSendControlStream>(
         GetNextOutgoingUnidirectionalStreamId(), this,
@@ -999,15 +996,14 @@
 }
 
 void QuicSpdySession::OnCanCreateNewOutgoingStream(bool unidirectional) {
-  if (unidirectional &&
-      VersionHasStreamType(connection()->transport_version())) {
+  if (unidirectional && VersionHasStreamType(transport_version())) {
     MaybeInitializeHttp3UnidirectionalStreams();
   }
 }
 
 void QuicSpdySession::set_max_allowed_push_id(
     QuicStreamId max_allowed_push_id) {
-  if (VersionHasIetfQuicFrames(connection()->transport_version()) &&
+  if (VersionHasIetfQuicFrames(transport_version()) &&
       perspective() == Perspective::IS_SERVER &&
       max_allowed_push_id > max_allowed_push_id_) {
     OnCanCreateNewOutgoingStream(true);
@@ -1015,14 +1011,14 @@
 
   max_allowed_push_id_ = max_allowed_push_id;
 
-  if (VersionHasIetfQuicFrames(connection()->transport_version()) &&
+  if (VersionHasIetfQuicFrames(transport_version()) &&
       perspective() == Perspective::IS_CLIENT && IsHandshakeConfirmed()) {
     SendMaxPushId(max_allowed_push_id);
   }
 }
 
 void QuicSpdySession::SendMaxPushId(QuicStreamId max_allowed_push_id) {
-  DCHECK(VersionHasStreamType(connection()->transport_version()));
+  DCHECK(VersionHasStreamType(transport_version()));
   send_control_stream_->SendMaxPushIdFrame(max_allowed_push_id);
 }
 
diff --git a/quic/core/http/quic_spdy_stream.cc b/quic/core/http/quic_spdy_stream.cc
index 28bcdcf..d77cfef 100644
--- a/quic/core/http/quic_spdy_stream.cc
+++ b/quic/core/http/quic_spdy_stream.cc
@@ -199,8 +199,7 @@
       is_decoder_processing_input_(false),
       ack_listener_(nullptr) {
   DCHECK_EQ(session()->connection(), spdy_session->connection());
-  DCHECK_EQ(transport_version(),
-            spdy_session->connection()->transport_version());
+  DCHECK_EQ(transport_version(), spdy_session->transport_version());
   DCHECK(!QuicUtils::IsCryptoStreamId(transport_version(), id));
   DCHECK_EQ(0u, sequencer()->NumBytesConsumed());
   // If headers are sent on the headers stream, then do not receive any
@@ -234,8 +233,7 @@
       is_decoder_processing_input_(false),
       ack_listener_(nullptr) {
   DCHECK_EQ(session()->connection(), spdy_session->connection());
-  DCHECK_EQ(transport_version(),
-            spdy_session->connection()->transport_version());
+  DCHECK_EQ(transport_version(), spdy_session->transport_version());
   DCHECK(!QuicUtils::IsCryptoStreamId(transport_version(), id()));
   // If headers are sent on the headers stream, then do not receive any
   // callbacks from the sequencer until headers are complete.
@@ -983,8 +981,7 @@
 
 void QuicSpdyStream::ProcessDecodedHeaders(const QuicHeaderList& headers) {
   if (spdy_session_->promised_stream_id() ==
-      QuicUtils::GetInvalidStreamId(
-          session()->connection()->transport_version())) {
+      QuicUtils::GetInvalidStreamId(session()->transport_version())) {
     const QuicByteCount frame_length = headers_decompressed_
                                            ? trailers_payload_length_
                                            : headers_payload_length_;
diff --git a/quic/core/http/quic_spdy_stream_test.cc b/quic/core/http/quic_spdy_stream_test.cc
index e09cbf4..572ba5c 100644
--- a/quic/core/http/quic_spdy_stream_test.cc
+++ b/quic/core/http/quic_spdy_stream_test.cc
@@ -1527,11 +1527,11 @@
       SupportedVersions(GetParam()));
   std::unique_ptr<TestMockUpdateStreamSession> session(
       new StrictMock<TestMockUpdateStreamSession>(connection));
-  auto stream = new StrictMock<TestStream>(
-      GetNthClientInitiatedBidirectionalStreamId(
-          session->connection()->transport_version(), 0),
-      session.get(),
-      /*should_process_data=*/true);
+  auto stream =
+      new StrictMock<TestStream>(GetNthClientInitiatedBidirectionalStreamId(
+                                     session->transport_version(), 0),
+                                 session.get(),
+                                 /*should_process_data=*/true);
   session->ActivateStream(QuicWrapUnique(stream));
 
   // QuicSpdyStream::SetPriority() should eventually call UpdateStreamPriority()