QuicConnection methods call CloseConnection rather than
TearDownLocalConnectionState

Some of the QuicConnection methods call TearDownLocalConnectionState
rather than CloseConnection. This changes then all to call CloseConnection,
specifying ConnectionCloseBehavior::SILENT_CLOSE.

Some tests modified to expect calls to CloseConnection (preventing test failure due to unexpected calls).  Before this CL the connection closing happened via internal calls directly to TearDownLocalConnectionState; now these calls go through CloseConnection and trigger the expect.

This is done in preparation for landing another CL adding IETF QUIC Connection Close functionality.

QuicConnection::OnUnrecoverableError (which is an override of QuicPacketCreator::OnUnrecoverableError) called TearDownLocalConnectionState. It had to be modified to call CloseConnection.  OnUnrecoverableError has a ConnectionCloseSource parameter, which CloseConnection does not take.  Thus the parameter was removed from OnUnrecoverableError.  This is OK since all of the calls to OnUnrecoverableError specified FROM_SELF as the source. CloseConnection uses FROM_SELF as the source (unless the error code is a stateless reject or public reset).

gfe-relnote: No flag protection as it is only moving existing functionality around.
PiperOrigin-RevId: 250341745
Change-Id: Iafe499eda682f3db678d0eddbf7e2e3e4367cebd
diff --git a/quic/core/quic_connection.cc b/quic/core/quic_connection.cc
index db717b0..6afc62d 100644
--- a/quic/core/quic_connection.cc
+++ b/quic/core/quic_connection.cc
@@ -632,8 +632,8 @@
   if (perspective_ == Perspective::IS_CLIENT) {
     const std::string error_details = "Protocol version mismatch.";
     QUIC_BUG << ENDPOINT << error_details;
-    TearDownLocalConnectionState(QUIC_INTERNAL_ERROR, error_details,
-                                 ConnectionCloseSource::FROM_SELF);
+    CloseConnection(QUIC_INTERNAL_ERROR, error_details,
+                    ConnectionCloseBehavior::SILENT_CLOSE);
     return false;
   }
   if (no_version_negotiation_) {
@@ -706,8 +706,8 @@
         "Server received version negotiation packet.";
     QUIC_BUG << error_details;
     QUIC_CODE_COUNT(quic_tear_down_local_connection_on_version_negotiation);
-    TearDownLocalConnectionState(QUIC_INTERNAL_ERROR, error_details,
-                                 ConnectionCloseSource::FROM_SELF);
+    CloseConnection(QUIC_INTERNAL_ERROR, error_details,
+                    ConnectionCloseBehavior::SILENT_CLOSE);
     return;
   }
   if (debug_visitor_ != nullptr) {
@@ -724,9 +724,8 @@
         "Server already supports client's version and should have accepted the "
         "connection.";
     QUIC_DLOG(WARNING) << error_details;
-    TearDownLocalConnectionState(QUIC_INVALID_VERSION_NEGOTIATION_PACKET,
-                                 error_details,
-                                 ConnectionCloseSource::FROM_SELF);
+    CloseConnection(QUIC_INVALID_VERSION_NEGOTIATION_PACKET, error_details,
+                    ConnectionCloseBehavior::SILENT_CLOSE);
     return;
   }
 
@@ -766,8 +765,8 @@
         ParsedQuicVersionToString(original_version) + " and " +
         ParsedQuicVersionToString(version()) + " is currently unsupported.";
     QUIC_DLOG(WARNING) << error_details;
-    TearDownLocalConnectionState(QUIC_INVALID_VERSION, error_details,
-                                 ConnectionCloseSource::FROM_SELF);
+    CloseConnection(QUIC_INVALID_VERSION, error_details,
+                    ConnectionCloseBehavior::SILENT_CLOSE);
     return;
   }
 
@@ -2735,8 +2734,8 @@
         QUIC_CODE_COUNT(
             quic_tear_down_local_connection_on_write_error_non_ietf);
       }
-      TearDownLocalConnectionState(QUIC_PACKET_WRITE_ERROR, error_details,
-                                   ConnectionCloseSource::FROM_SELF);
+      CloseConnection(QUIC_PACKET_WRITE_ERROR, error_details,
+                      ConnectionCloseBehavior::SILENT_CLOSE);
   }
 }
 
@@ -2747,7 +2746,7 @@
 void QuicConnection::OnSerializedPacket(SerializedPacket* serialized_packet) {
   if (serialized_packet->encrypted_buffer == nullptr) {
     // We failed to serialize the packet, so close the connection.
-    // TearDownLocalConnectionState does not send close packet, so no infinite
+    // Specify that the close is silent, that no packet be sent, so no infinite
     // loop here.
     // TODO(ianswett): This is actually an internal error, not an
     // encryption failure.
@@ -2758,10 +2757,9 @@
       QUIC_CODE_COUNT(
           quic_tear_down_local_connection_on_serialized_packet_non_ietf);
     }
-    TearDownLocalConnectionState(
-        QUIC_ENCRYPTION_FAILURE,
-        "Serialized packet does not have an encrypted buffer.",
-        ConnectionCloseSource::FROM_SELF);
+    CloseConnection(QUIC_ENCRYPTION_FAILURE,
+                    "Serialized packet does not have an encrypted buffer.",
+                    ConnectionCloseBehavior::SILENT_CLOSE);
     return;
   }
 
@@ -2777,8 +2775,7 @@
 }
 
 void QuicConnection::OnUnrecoverableError(QuicErrorCode error,
-                                          const std::string& error_details,
-                                          ConnectionCloseSource source) {
+                                          const std::string& error_details) {
   // The packet creator or generator encountered an unrecoverable error: tear
   // down local connection state immediately.
   if (transport_version() > QUIC_VERSION_43) {
@@ -2788,7 +2785,7 @@
     QUIC_CODE_COUNT(
         quic_tear_down_local_connection_on_unrecoverable_error_non_ietf);
   }
-  TearDownLocalConnectionState(error, error_details, source);
+  CloseConnection(error, error_details, ConnectionCloseBehavior::SILENT_CLOSE);
 }
 
 void QuicConnection::OnCongestionChange() {
@@ -3120,6 +3117,7 @@
     // Regard stateless rejected connection as closed by server.
     source = ConnectionCloseSource::FROM_PEER;
   }
+
   TearDownLocalConnectionState(error, error_details, source);
 }