Move OnCoalescedPacketSent right after a coalesced packet gets serialized (and before it is sent to the writer).

PiperOrigin-RevId: 398059396
diff --git a/quic/core/quic_connection.cc b/quic/core/quic_connection.cc
index 64636bf..431382f 100644
--- a/quic/core/quic_connection.cc
+++ b/quic/core/quic_connection.cc
@@ -6041,6 +6041,9 @@
   if (length == 0) {
     return false;
   }
+  if (debug_visitor_ != nullptr) {
+    debug_visitor_->OnCoalescedPacketSent(coalesced_packet_, length);
+  }
   QUIC_DVLOG(1) << ENDPOINT << "Sending coalesced packet "
                 << coalesced_packet_.ToString(length);
 
@@ -6050,9 +6053,6 @@
     buffered_packets_.emplace_back(
         buffer, static_cast<QuicPacketLength>(length),
         coalesced_packet_.self_address(), coalesced_packet_.peer_address());
-    if (debug_visitor_ != nullptr) {
-      debug_visitor_->OnCoalescedPacketSent(coalesced_packet_, length);
-    }
     return true;
   }
 
@@ -6073,9 +6073,6 @@
           coalesced_packet_.self_address(), coalesced_packet_.peer_address());
     }
   }
-  if (debug_visitor_ != nullptr) {
-    debug_visitor_->OnCoalescedPacketSent(coalesced_packet_, length);
-  }
   // Account for added padding.
   if (length > coalesced_packet_.length()) {
     size_t padding_size = length - coalesced_packet_.length();
diff --git a/quic/core/quic_connection.h b/quic/core/quic_connection.h
index eaec4cd..5d8ff27 100644
--- a/quic/core/quic_connection.h
+++ b/quic/core/quic_connection.h
@@ -263,10 +263,9 @@
                             const QuicFrames& /*nonretransmittable_frames*/,
                             QuicTime /*sent_time*/) {}
 
-  // Called when a coalesced packet has been sent.
+  // Called when a coalesced packet is successfully serialized.
   virtual void OnCoalescedPacketSent(
-      const QuicCoalescedPacket& /*coalesced_packet*/,
-      size_t /*length*/) {}
+      const QuicCoalescedPacket& /*coalesced_packet*/, size_t /*length*/) {}
 
   // Called when a PING frame has been sent.
   virtual void OnPingSent() {}