Deprecate gfe2_reloadable_flag_quic_use_write_or_buffer_data_at_level.

PiperOrigin-RevId: 386969653
diff --git a/quic/core/http/quic_spdy_session_test.cc b/quic/core/http/quic_spdy_session_test.cc
index c42b8ff..be475b8 100644
--- a/quic/core/http/quic_spdy_session_test.cc
+++ b/quic/core/http/quic_spdy_session_test.cc
@@ -308,12 +308,10 @@
     return QuicSpdySession::GetOrCreateStream(stream_id);
   }
 
-  QuicConsumedData WritevData(QuicStreamId id,
-                              size_t write_length,
-                              QuicStreamOffset offset,
-                              StreamSendingState state,
+  QuicConsumedData WritevData(QuicStreamId id, size_t write_length,
+                              QuicStreamOffset offset, StreamSendingState state,
                               TransmissionType type,
-                              absl::optional<EncryptionLevel> level) override {
+                              EncryptionLevel level) override {
     bool fin = state != NO_FIN;
     QuicConsumedData consumed(write_length, fin);
     if (!writev_consumes_all_data_) {
diff --git a/quic/core/quic_crypto_handshaker.cc b/quic/core/quic_crypto_handshaker.cc
index 25bf9dc..79142c4 100644
--- a/quic/core/quic_crypto_handshaker.cc
+++ b/quic/core/quic_crypto_handshaker.cc
@@ -27,10 +27,7 @@
   session()->OnCryptoHandshakeMessageSent(message);
   last_sent_handshake_message_tag_ = message.tag();
   const QuicData& data = message.GetSerialized();
-  stream_->WriteCryptoData(session_->use_write_or_buffer_data_at_level()
-                               ? level
-                               : session_->connection()->encryption_level(),
-                           data.AsStringPiece());
+  stream_->WriteCryptoData(level, data.AsStringPiece());
 }
 
 void QuicCryptoHandshaker::OnError(CryptoFramer* framer) {
diff --git a/quic/core/quic_crypto_server_stream.cc b/quic/core/quic_crypto_server_stream.cc
index 1dd6899..9bd9c7b 100644
--- a/quic/core/quic_crypto_server_stream.cc
+++ b/quic/core/quic_crypto_server_stream.cc
@@ -287,15 +287,8 @@
   QUIC_DVLOG(1) << "Server: Sending server config update: "
                 << message.DebugString();
 
-  if (!session()->use_write_or_buffer_data_at_level() &&
-      !QuicVersionUsesCryptoFrames(transport_version())) {
-    const QuicData& data = message.GetSerialized();
-    WriteOrBufferData(absl::string_view(data.data(), data.length()), false,
-                      nullptr);
-  } else {
-    // Send server config update in ENCRYPTION_FORWARD_SECURE.
-    SendHandshakeMessage(message, ENCRYPTION_FORWARD_SECURE);
-  }
+  // Send server config update in ENCRYPTION_FORWARD_SECURE.
+  SendHandshakeMessage(message, ENCRYPTION_FORWARD_SECURE);
 
   ++num_server_config_update_messages_sent_;
 }
diff --git a/quic/core/quic_crypto_stream.cc b/quic/core/quic_crypto_stream.cc
index f8f34df..a14cef0 100644
--- a/quic/core/quic_crypto_stream.cc
+++ b/quic/core/quic_crypto_stream.cc
@@ -144,15 +144,8 @@
 void QuicCryptoStream::WriteCryptoData(EncryptionLevel level,
                                        absl::string_view data) {
   if (!QuicVersionUsesCryptoFrames(session()->transport_version())) {
-    if (session()->use_write_or_buffer_data_at_level()) {
-      WriteOrBufferDataAtLevel(data, /*fin=*/false, level,
-                               /*ack_listener=*/nullptr);
-      return;
-    }
-    // The QUIC crypto handshake takes care of setting the appropriate
-    // encryption level before writing data. Since that is the only handshake
-    // supported in versions less than 47, |level| can be ignored here.
-    WriteOrBufferData(data, /* fin */ false, /* ack_listener */ nullptr);
+    WriteOrBufferDataAtLevel(data, /*fin=*/false, level,
+                             /*ack_listener=*/nullptr);
     return;
   }
   if (data.empty()) {
diff --git a/quic/core/quic_flags_list.h b/quic/core/quic_flags_list.h
index 18595fe..db96f8a 100644
--- a/quic/core/quic_flags_list.h
+++ b/quic/core/quic_flags_list.h
@@ -111,8 +111,6 @@
 QUIC_FLAG(FLAGS_quic_reloadable_flag_quic_default_to_bbr_v2, false)
 // If true, use ScopedEncryptionLevelContext when sending data.
 QUIC_FLAG(FLAGS_quic_reloadable_flag_quic_use_encryption_level_context, true)
-// If true, use WriteOrBufferDataAtLevel to send crypto data. Existing WriteOrBufferData is used to send application data.
-QUIC_FLAG(FLAGS_quic_reloadable_flag_quic_use_write_or_buffer_data_at_level, false)
 // If true, use new connection ID in connection migration.
 QUIC_FLAG(FLAGS_quic_reloadable_flag_quic_connection_migration_use_new_cid_v2, true)
 // If true, uses conservative cwnd gain and pacing gain when cwnd gets bootstrapped.
diff --git a/quic/core/quic_session.cc b/quic/core/quic_session.cc
index 081d322..ea6da6c 100644
--- a/quic/core/quic_session.cc
+++ b/quic/core/quic_session.cc
@@ -756,16 +756,13 @@
   connection_->ProcessUdpPacket(self_address, peer_address, packet);
 }
 
-QuicConsumedData QuicSession::WritevData(
-    QuicStreamId id,
-    size_t write_length,
-    QuicStreamOffset offset,
-    StreamSendingState state,
-    TransmissionType type,
-    absl::optional<EncryptionLevel> level) {
+QuicConsumedData QuicSession::WritevData(QuicStreamId id, size_t write_length,
+                                         QuicStreamOffset offset,
+                                         StreamSendingState state,
+                                         TransmissionType type,
+                                         EncryptionLevel level) {
   QUICHE_DCHECK(connection_->connected())
       << ENDPOINT << "Try to write stream data when connection is closed.";
-  QUICHE_DCHECK(!use_write_or_buffer_data_at_level_ || level.has_value());
   if (!IsEncryptionEstablished() &&
       !QuicUtils::IsCryptoStreamId(transport_version(), id)) {
     // Do not let streams write without encryption. The calling stream will end
@@ -799,13 +796,11 @@
   SetTransmissionType(type);
   const auto current_level = connection()->encryption_level();
   if (!use_encryption_level_context()) {
-    if (level.has_value()) {
-      connection()->SetDefaultEncryptionLevel(level.value());
-    }
+    connection()->SetDefaultEncryptionLevel(level);
   }
   QuicConnection::ScopedEncryptionLevelContext context(
       use_encryption_level_context() ? connection() : nullptr,
-      use_encryption_level_context() ? level.value() : NUM_ENCRYPTION_LEVELS);
+      use_encryption_level_context() ? level : NUM_ENCRYPTION_LEVELS);
 
   QuicConsumedData data =
       connection_->SendStreamData(id, write_length, offset, state);
@@ -817,9 +812,7 @@
   // Restore the encryption level.
   if (!use_encryption_level_context()) {
     // Restore the encryption level.
-    if (level.has_value()) {
-      connection()->SetDefaultEncryptionLevel(current_level);
-    }
+    connection()->SetDefaultEncryptionLevel(current_level);
   }
 
   return data;
diff --git a/quic/core/quic_session.h b/quic/core/quic_session.h
index d48f0d5..c7d96e9 100644
--- a/quic/core/quic_session.h
+++ b/quic/core/quic_session.h
@@ -338,12 +338,10 @@
   // indicating if the fin bit was consumed.  This does not indicate the data
   // has been sent on the wire: it may have been turned into a packet and queued
   // if the socket was unexpectedly blocked.
-  QuicConsumedData WritevData(QuicStreamId id,
-                              size_t write_length,
-                              QuicStreamOffset offset,
-                              StreamSendingState state,
+  QuicConsumedData WritevData(QuicStreamId id, size_t write_length,
+                              QuicStreamOffset offset, StreamSendingState state,
                               TransmissionType type,
-                              absl::optional<EncryptionLevel> level) override;
+                              EncryptionLevel level) override;
 
   size_t SendCryptoData(EncryptionLevel level,
                         size_t write_length,
@@ -621,13 +619,8 @@
     return liveness_testing_in_progress_;
   }
 
-  bool use_write_or_buffer_data_at_level() const {
-    return use_write_or_buffer_data_at_level_;
-  }
-
   bool use_encryption_level_context() const {
-    return connection_->use_encryption_level_context() &&
-           use_write_or_buffer_data_at_level_;
+    return connection_->use_encryption_level_context();
   }
 
   bool permutes_tls_extensions() const { return permutes_tls_extensions_; }
@@ -965,9 +958,6 @@
 
   // Whether BoringSSL randomizes the order of TLS extensions.
   bool permutes_tls_extensions_ = false;
-
-  const bool use_write_or_buffer_data_at_level_ =
-      GetQuicReloadableFlag(quic_use_write_or_buffer_data_at_level);
 };
 
 }  // namespace quic
diff --git a/quic/core/quic_session_test.cc b/quic/core/quic_session_test.cc
index e77355c..84b9e2e 100644
--- a/quic/core/quic_session_test.cc
+++ b/quic/core/quic_session_test.cc
@@ -313,12 +313,10 @@
     return GetNumActiveStreams() > 0;
   }
 
-  QuicConsumedData WritevData(QuicStreamId id,
-                              size_t write_length,
-                              QuicStreamOffset offset,
-                              StreamSendingState state,
+  QuicConsumedData WritevData(QuicStreamId id, size_t write_length,
+                              QuicStreamOffset offset, StreamSendingState state,
                               TransmissionType type,
-                              absl::optional<EncryptionLevel> level) override {
+                              EncryptionLevel level) override {
     bool fin = state != NO_FIN;
     QuicConsumedData consumed(write_length, fin);
     if (!writev_consumes_all_data_) {
diff --git a/quic/core/quic_stream.cc b/quic/core/quic_stream.cc
index 9744ed3..cde50ef 100644
--- a/quic/core/quic_stream.cc
+++ b/quic/core/quic_stream.cc
@@ -631,23 +631,18 @@
     absl::string_view data,
     bool fin,
     QuicReferenceCountedPointer<QuicAckListenerInterface> ack_listener) {
-  if (session()->use_write_or_buffer_data_at_level()) {
-    QUIC_BUG_IF(quic_bug_12570_4,
-                QuicUtils::IsCryptoStreamId(transport_version(), id_))
-        << ENDPOINT
-        << "WriteOrBufferData is used to send application data, use "
-           "WriteOrBufferDataAtLevel to send crypto data.";
-    return WriteOrBufferDataAtLevel(
-        data, fin, session()->GetEncryptionLevelToSendApplicationData(),
-        ack_listener);
-  }
-  return WriteOrBufferDataInner(data, fin, absl::nullopt, ack_listener);
+  QUIC_BUG_IF(quic_bug_12570_4,
+              QuicUtils::IsCryptoStreamId(transport_version(), id_))
+      << ENDPOINT
+      << "WriteOrBufferData is used to send application data, use "
+         "WriteOrBufferDataAtLevel to send crypto data.";
+  return WriteOrBufferDataAtLevel(
+      data, fin, session()->GetEncryptionLevelToSendApplicationData(),
+      ack_listener);
 }
 
-void QuicStream::WriteOrBufferDataInner(
-    absl::string_view data,
-    bool fin,
-    absl::optional<EncryptionLevel> level,
+void QuicStream::WriteOrBufferDataAtLevel(
+    absl::string_view data, bool fin, EncryptionLevel level,
     QuicReferenceCountedPointer<QuicAckListenerInterface> ack_listener) {
   if (data.empty() && !fin) {
     QUIC_BUG(quic_bug_10586_2) << "data.empty() && !fin";
@@ -692,16 +687,6 @@
   }
 }
 
-void QuicStream::WriteOrBufferDataAtLevel(
-    absl::string_view data,
-    bool fin,
-    EncryptionLevel level,
-    QuicReferenceCountedPointer<QuicAckListenerInterface> ack_listener) {
-  QUICHE_DCHECK(session()->use_write_or_buffer_data_at_level());
-  QUIC_RELOADABLE_FLAG_COUNT(quic_use_write_or_buffer_data_at_level);
-  return WriteOrBufferDataInner(data, fin, level, ack_listener);
-}
-
 void QuicStream::OnCanWrite() {
   if (HasDeadlinePassed()) {
     OnDeadlinePassed();
@@ -721,11 +706,7 @@
     return;
   }
   if (HasBufferedData() || (fin_buffered_ && !fin_sent_)) {
-    absl::optional<EncryptionLevel> send_level = absl::nullopt;
-    if (session()->use_write_or_buffer_data_at_level()) {
-      send_level = session()->GetEncryptionLevelToSendApplicationData();
-    }
-    WriteBufferedData(send_level);
+    WriteBufferedData(session()->GetEncryptionLevelToSendApplicationData());
   }
   if (!fin_buffered_ && !fin_sent_ && CanWriteNewData()) {
     // Notify upper layer to write new data when buffered data size is below
@@ -813,11 +794,7 @@
 
   if (!had_buffered_data && (HasBufferedData() || fin_buffered_)) {
     // Write data if there is no buffered data before.
-    absl::optional<EncryptionLevel> send_level = absl::nullopt;
-    if (session()->use_write_or_buffer_data_at_level()) {
-      send_level = session()->GetEncryptionLevelToSendApplicationData();
-    }
-    WriteBufferedData(send_level);
+    WriteBufferedData(session()->GetEncryptionLevelToSendApplicationData());
   }
 
   return consumed_data;
@@ -1159,10 +1136,6 @@
   if (retransmission.Empty() && !retransmit_fin) {
     return true;
   }
-  absl::optional<EncryptionLevel> send_level = absl::nullopt;
-  if (session()->use_write_or_buffer_data_at_level()) {
-    send_level = session()->GetEncryptionLevelToSendApplicationData();
-  }
   QuicConsumedData consumed(0, false);
   for (const auto& interval : retransmission) {
     QuicStreamOffset retransmission_offset = interval.min();
@@ -1172,7 +1145,8 @@
                            stream_bytes_written());
     consumed = stream_delegate_->WritevData(
         id_, retransmission_length, retransmission_offset,
-        can_bundle_fin ? FIN : NO_FIN, type, send_level);
+        can_bundle_fin ? FIN : NO_FIN, type,
+        session()->GetEncryptionLevelToSendApplicationData());
     QUIC_DVLOG(1) << ENDPOINT << "stream " << id_
                   << " is forced to retransmit stream data ["
                   << retransmission_offset << ", "
@@ -1193,8 +1167,9 @@
   if (retransmit_fin) {
     QUIC_DVLOG(1) << ENDPOINT << "stream " << id_
                   << " retransmits fin only frame.";
-    consumed = stream_delegate_->WritevData(id_, 0, stream_bytes_written(), FIN,
-                                            type, send_level);
+    consumed = stream_delegate_->WritevData(
+        id_, 0, stream_bytes_written(), FIN, type,
+        session()->GetEncryptionLevelToSendApplicationData());
     if (!consumed.fin_consumed) {
       return false;
     }
@@ -1220,7 +1195,7 @@
   return send_buffer_.WriteStreamData(offset, data_length, writer);
 }
 
-void QuicStream::WriteBufferedData(absl::optional<EncryptionLevel> level) {
+void QuicStream::WriteBufferedData(EncryptionLevel level) {
   QUICHE_DCHECK(!write_side_closed_ && (HasBufferedData() || fin_buffered_));
 
   if (session_->ShouldYield(id())) {
@@ -1344,15 +1319,12 @@
 void QuicStream::WritePendingRetransmission() {
   while (HasPendingRetransmission()) {
     QuicConsumedData consumed(0, false);
-    absl::optional<EncryptionLevel> send_level = absl::nullopt;
-    if (session()->use_write_or_buffer_data_at_level()) {
-      send_level = session()->GetEncryptionLevelToSendApplicationData();
-    }
     if (!send_buffer_.HasPendingRetransmission()) {
       QUIC_DVLOG(1) << ENDPOINT << "stream " << id_
                     << " retransmits fin only frame.";
       consumed = stream_delegate_->WritevData(
-          id_, 0, stream_bytes_written(), FIN, LOSS_RETRANSMISSION, send_level);
+          id_, 0, stream_bytes_written(), FIN, LOSS_RETRANSMISSION,
+          session()->GetEncryptionLevelToSendApplicationData());
       fin_lost_ = !consumed.fin_consumed;
       if (fin_lost_) {
         // Connection is write blocked.
@@ -1367,7 +1339,8 @@
           (pending.offset + pending.length == stream_bytes_written());
       consumed = stream_delegate_->WritevData(
           id_, pending.length, pending.offset, can_bundle_fin ? FIN : NO_FIN,
-          LOSS_RETRANSMISSION, send_level);
+          LOSS_RETRANSMISSION,
+          session()->GetEncryptionLevelToSendApplicationData());
       QUIC_DVLOG(1) << ENDPOINT << "stream " << id_
                     << " tries to retransmit stream data [" << pending.offset
                     << ", " << pending.offset + pending.length
diff --git a/quic/core/quic_stream.h b/quic/core/quic_stream.h
index 51080cd..6374d8a 100644
--- a/quic/core/quic_stream.h
+++ b/quic/core/quic_stream.h
@@ -506,10 +506,8 @@
   // controller, marks this stream as connection-level write blocked.
   void MaybeSendBlocked();
 
-  // Write buffered data in send buffer.
-  // TODO(fayang): Change absl::optional<EncryptionLevel> to EncryptionLevel
-  // when deprecating quic_use_write_or_buffer_data_at_level.
-  void WriteBufferedData(absl::optional<EncryptionLevel> level);
+  // Write buffered data (in send buffer) at |level|.
+  void WriteBufferedData(EncryptionLevel level);
 
   // Close the read side of the stream.  May cause the stream to be closed.
   void CloseReadSide();
@@ -517,14 +515,6 @@
   // Called when bytes are sent to the peer.
   void AddBytesSent(QuicByteCount bytes);
 
-  // TODO(fayang): Inline this function when deprecating
-  // quic_use_write_or_buffer_data_at_level.
-  void WriteOrBufferDataInner(
-      absl::string_view data,
-      bool fin,
-      absl::optional<EncryptionLevel> level,
-      QuicReferenceCountedPointer<QuicAckListenerInterface> ack_listener);
-
   // Returns true if deadline_ has passed.
   bool HasDeadlinePassed() const;
 
diff --git a/quic/core/stream_delegate_interface.h b/quic/core/stream_delegate_interface.h
index 38b8e53..02b195e 100644
--- a/quic/core/stream_delegate_interface.h
+++ b/quic/core/stream_delegate_interface.h
@@ -28,18 +28,13 @@
   virtual void OnStreamError(QuicErrorCode error_code,
                              QuicIetfTransportErrorCodes ietf_error,
                              std::string error_details) = 0;
-  // Called when the stream needs to write data. If |level| is present, the data
-  // will be written at the specified |level|. The data will be written
-  // at specified transmission |type|.
-  // TODO(fayang): Change absl::optional<EncryptionLevel> to EncryptionLevel
-  // when deprecating quic_use_write_or_buffer_data_at_level.
-  virtual QuicConsumedData WritevData(
-      QuicStreamId id,
-      size_t write_length,
-      QuicStreamOffset offset,
-      StreamSendingState state,
-      TransmissionType type,
-      absl::optional<EncryptionLevel> level) = 0;
+  // Called when the stream needs to write data at specified |level| and
+  // transmission |type|.
+  virtual QuicConsumedData WritevData(QuicStreamId id, size_t write_length,
+                                      QuicStreamOffset offset,
+                                      StreamSendingState state,
+                                      TransmissionType type,
+                                      EncryptionLevel level) = 0;
   // Called to write crypto data.
   virtual size_t SendCryptoData(EncryptionLevel level,
                                 size_t write_length,
diff --git a/quic/qbone/qbone_stream_test.cc b/quic/qbone/qbone_stream_test.cc
index bcbc5a5..fc2ce81 100644
--- a/quic/qbone/qbone_stream_test.cc
+++ b/quic/qbone/qbone_stream_test.cc
@@ -40,12 +40,10 @@
   ~MockQuicSession() override {}
 
   // Writes outgoing data from QuicStream to a string.
-  QuicConsumedData WritevData(QuicStreamId id,
-                              size_t write_length,
-                              QuicStreamOffset offset,
-                              StreamSendingState state,
+  QuicConsumedData WritevData(QuicStreamId id, size_t write_length,
+                              QuicStreamOffset offset, StreamSendingState state,
                               TransmissionType type,
-                              absl::optional<EncryptionLevel> level) override {
+                              EncryptionLevel level) override {
     if (!writable_) {
       return QuicConsumedData(0, false);
     }
diff --git a/quic/test_tools/quic_test_utils.h b/quic/test_tools/quic_test_utils.h
index 17aa920..06f3eec 100644
--- a/quic/test_tools/quic_test_utils.h
+++ b/quic/test_tools/quic_test_utils.h
@@ -902,14 +902,10 @@
               CreateIncomingStream,
               (PendingStream*),
               (override));
-  MOCK_METHOD(QuicConsumedData,
-              WritevData,
-              (QuicStreamId id,
-               size_t write_length,
-               QuicStreamOffset offset,
-               StreamSendingState state,
-               TransmissionType type,
-               absl::optional<EncryptionLevel> level),
+  MOCK_METHOD(QuicConsumedData, WritevData,
+              (QuicStreamId id, size_t write_length, QuicStreamOffset offset,
+               StreamSendingState state, TransmissionType type,
+               EncryptionLevel level),
               (override));
   MOCK_METHOD(bool,
               WriteControlFrame,
@@ -1040,14 +1036,10 @@
   MOCK_METHOD(bool, ShouldCreateIncomingStream, (QuicStreamId id), (override));
   MOCK_METHOD(bool, ShouldCreateOutgoingBidirectionalStream, (), (override));
   MOCK_METHOD(bool, ShouldCreateOutgoingUnidirectionalStream, (), (override));
-  MOCK_METHOD(QuicConsumedData,
-              WritevData,
-              (QuicStreamId id,
-               size_t write_length,
-               QuicStreamOffset offset,
-               StreamSendingState state,
-               TransmissionType type,
-               absl::optional<EncryptionLevel> level),
+  MOCK_METHOD(QuicConsumedData, WritevData,
+              (QuicStreamId id, size_t write_length, QuicStreamOffset offset,
+               StreamSendingState state, TransmissionType type,
+               EncryptionLevel level),
               (override));
   MOCK_METHOD(void,
               MaybeSendRstStreamFrame,
diff --git a/quic/tools/quic_simple_server_stream_test.cc b/quic/tools/quic_simple_server_stream_test.cc
index 4154a2d..5c9cd22 100644
--- a/quic/tools/quic_simple_server_stream_test.cc
+++ b/quic/tools/quic_simple_server_stream_test.cc
@@ -157,14 +157,10 @@
               CreateIncomingStream,
               (QuicStreamId id),
               (override));
-  MOCK_METHOD(QuicConsumedData,
-              WritevData,
-              (QuicStreamId id,
-               size_t write_length,
-               QuicStreamOffset offset,
-               StreamSendingState state,
-               TransmissionType type,
-               absl::optional<EncryptionLevel> level),
+  MOCK_METHOD(QuicConsumedData, WritevData,
+              (QuicStreamId id, size_t write_length, QuicStreamOffset offset,
+               StreamSendingState state, TransmissionType type,
+               EncryptionLevel level),
               (override));
   MOCK_METHOD(void,
               OnStreamHeaderList,