Add a new callback for probing retransmissions.

Whenever the connection needs to send probing retransmissions it calls the
session to decide what data to send.

gfe-relnote: n/a (probing retransmissions only used by Quartc)
PiperOrigin-RevId: 245817562
Change-Id: I2239c32ea4e2f6aa7dd6f733045ccc8fa0da4dc5
diff --git a/quic/core/quic_connection.cc b/quic/core/quic_connection.cc
index 6cb6c85..1fc69e1 100644
--- a/quic/core/quic_connection.cc
+++ b/quic/core/quic_connection.cc
@@ -2281,10 +2281,7 @@
 void QuicConnection::SendProbingRetransmissions() {
   while (sent_packet_manager_.GetSendAlgorithm()->ShouldSendProbingPacket() &&
          CanWrite(HAS_RETRANSMITTABLE_DATA)) {
-    const bool can_retransmit =
-        sent_packet_manager_.MaybeRetransmitOldestPacket(
-            PROBING_RETRANSMISSION);
-    if (!can_retransmit) {
+    if (!visitor_->SendProbingData()) {
       QUIC_DVLOG(1)
           << "Cannot send probing retransmissions: nothing to retransmit.";
       break;
diff --git a/quic/core/quic_connection.h b/quic/core/quic_connection.h
index b37b60c..3173ee3 100644
--- a/quic/core/quic_connection.h
+++ b/quic/core/quic_connection.h
@@ -143,6 +143,10 @@
   // Called when a blocked socket becomes writable.
   virtual void OnCanWrite() = 0;
 
+  // Called when the connection needs more data to probe for additional
+  // bandwidth.  Returns true if data was sent, false otherwise.
+  virtual bool SendProbingData() = 0;
+
   // Called when the connection experiences a change in congestion window.
   virtual void OnCongestionWindowChange(QuicTime now) = 0;
 
diff --git a/quic/core/quic_connection_test.cc b/quic/core/quic_connection_test.cc
index 5d35353..fe74768 100644
--- a/quic/core/quic_connection_test.cc
+++ b/quic/core/quic_connection_test.cc
@@ -8063,6 +8063,10 @@
     EXPECT_CALL(visitor_, WillingAndAbleToWrite())
         .WillRepeatedly(Return(false));
   }
+  EXPECT_CALL(visitor_, SendProbingData()).WillRepeatedly([this] {
+    return connection_.sent_packet_manager().MaybeRetransmitOldestPacket(
+        PROBING_RETRANSMISSION);
+  });
   // Fix congestion window to be 20,000 bytes.
   EXPECT_CALL(*send_algorithm_, CanSend(Ge(20000u)))
       .WillRepeatedly(Return(false));
@@ -8209,6 +8213,10 @@
       }));
   EXPECT_CALL(*send_algorithm_, ShouldSendProbingPacket())
       .WillRepeatedly(Return(true));
+  EXPECT_CALL(visitor_, SendProbingData()).WillRepeatedly([this] {
+    return connection_.sent_packet_manager().MaybeRetransmitOldestPacket(
+        PROBING_RETRANSMISSION);
+  });
 
   connection_.SendProbingRetransmissions();
 
@@ -8232,6 +8240,10 @@
   EXPECT_CALL(debug_visitor, OnPacketSent(_, _, _, _)).Times(0);
   EXPECT_CALL(*send_algorithm_, ShouldSendProbingPacket())
       .WillRepeatedly(Return(true));
+  EXPECT_CALL(visitor_, SendProbingData()).WillRepeatedly([this] {
+    return connection_.sent_packet_manager().MaybeRetransmitOldestPacket(
+        PROBING_RETRANSMISSION);
+  });
 
   connection_.SendProbingRetransmissions();
 }
diff --git a/quic/core/quic_session.cc b/quic/core/quic_session.cc
index 86ee78f..2b9ffa5 100644
--- a/quic/core/quic_session.cc
+++ b/quic/core/quic_session.cc
@@ -587,6 +587,14 @@
   }
 }
 
+bool QuicSession::SendProbingData() {
+  if (connection()->sent_packet_manager().MaybeRetransmitOldestPacket(
+          PROBING_RETRANSMISSION)) {
+    return true;
+  }
+  return false;
+}
+
 bool QuicSession::WillingAndAbleToWrite() const {
   // Schedule a write when:
   // 1) control frame manager has pending or new control frames, or
diff --git a/quic/core/quic_session.h b/quic/core/quic_session.h
index 54637d4..b24e5b6 100644
--- a/quic/core/quic_session.h
+++ b/quic/core/quic_session.h
@@ -115,6 +115,7 @@
       const QuicSocketAddress& self_address,
       const QuicSocketAddress& peer_address) override;
   void OnCanWrite() override;
+  bool SendProbingData() override;
   void OnCongestionWindowChange(QuicTime /*now*/) override {}
   void OnConnectionMigration(AddressChangeType type) override {}
   // Adds a connection level WINDOW_UPDATE frame.