Add the check for enough loss events into the Bbr2NetworkModel::IsInflightTooHigh() method to simplify the code.

PiperOrigin-RevId: 336470593
Change-Id: I370b79fd09736d508df1996a47dde4b21d453143
diff --git a/quic/core/congestion_control/bbr2_misc.cc b/quic/core/congestion_control/bbr2_misc.cc
index 6053185..9f6744e 100644
--- a/quic/core/congestion_control/bbr2_misc.cc
+++ b/quic/core/congestion_control/bbr2_misc.cc
@@ -243,21 +243,29 @@
 }
 
 bool Bbr2NetworkModel::IsInflightTooHigh(
-    const Bbr2CongestionEvent& congestion_event) const {
+    const Bbr2CongestionEvent& congestion_event,
+    int64_t max_loss_events) const {
   const SendTimeState& send_state = congestion_event.last_packet_send_state;
   if (!send_state.is_valid) {
     // Not enough information.
     return false;
   }
 
+  if (loss_events_in_round() < max_loss_events) {
+    return false;
+  }
+
   const QuicByteCount inflight_at_send = BytesInFlight(send_state);
   // TODO(wub): Consider total_bytes_lost() - send_state.total_bytes_lost, which
   // is the total bytes lost when the largest numbered packet was inflight.
   // bytes_lost_in_round_, OTOH, is the total bytes lost in the "current" round.
   const QuicByteCount bytes_lost_in_round = bytes_lost_in_round_;
 
-  QUIC_DVLOG(3) << "IsInflightTooHigh: bytes_lost_in_round:"
-                << bytes_lost_in_round << ", lost_in_round_threshold:"
+  QUIC_DVLOG(3) << "IsInflightTooHigh: loss_events_in_round:"
+                << loss_events_in_round()
+
+                << " bytes_lost_in_round:" << bytes_lost_in_round
+                << ", lost_in_round_threshold:"
                 << inflight_at_send * Params().loss_threshold;
 
   if (inflight_at_send > 0 && bytes_lost_in_round > 0) {
diff --git a/quic/core/congestion_control/bbr2_misc.h b/quic/core/congestion_control/bbr2_misc.h
index f68092b..a6f710a 100644
--- a/quic/core/congestion_control/bbr2_misc.h
+++ b/quic/core/congestion_control/bbr2_misc.h
@@ -394,9 +394,10 @@
   bool IsCongestionWindowLimited(
       const Bbr2CongestionEvent& congestion_event) const;
 
-  // TODO(wub): Replace this by a new version which takes two thresholds, one
-  // is the number of loss events, the other is the percentage of bytes lost.
-  bool IsInflightTooHigh(const Bbr2CongestionEvent& congestion_event) const;
+  // Return true if the number of loss events exceeds max_loss_events and
+  // fraction of bytes lost exceed the loss threshold.
+  bool IsInflightTooHigh(const Bbr2CongestionEvent& congestion_event,
+                         int64_t max_loss_events) const;
 
   QuicPacketNumber last_sent_packet() const {
     return round_trip_counter_.last_sent_packet();
diff --git a/quic/core/congestion_control/bbr2_probe_bw.cc b/quic/core/congestion_control/bbr2_probe_bw.cc
index 1729118..fa72d9f 100644
--- a/quic/core/congestion_control/bbr2_probe_bw.cc
+++ b/quic/core/congestion_control/bbr2_probe_bw.cc
@@ -199,10 +199,8 @@
     return NOT_ADAPTED_INVALID_SAMPLE;
   }
 
-  const bool has_enough_loss_events =
-      model_->loss_events_in_round() >= Params().probe_bw_full_loss_count;
-
-  if (has_enough_loss_events && model_->IsInflightTooHigh(congestion_event)) {
+  if (model_->IsInflightTooHigh(congestion_event,
+                                Params().probe_bw_full_loss_count)) {
     if (cycle_.is_sample_from_probing) {
       cycle_.is_sample_from_probing = false;
 
diff --git a/quic/core/congestion_control/bbr2_startup.cc b/quic/core/congestion_control/bbr2_startup.cc
index 1141ca0..c134765 100644
--- a/quic/core/congestion_control/bbr2_startup.cc
+++ b/quic/core/congestion_control/bbr2_startup.cc
@@ -93,8 +93,6 @@
     return;
   }
 
-  const int64_t loss_events_in_round = model_->loss_events_in_round();
-
   // TODO(wub): In TCP, loss based exit only happens at end of a loss round, in
   // QUIC we use the end of the normal round here. It is possible to exit after
   // any congestion event, using information of the "rolling round".
@@ -102,19 +100,13 @@
     return;
   }
 
-  QUIC_DVLOG(3)
-      << sender_
-      << " CheckExcessiveLosses at end of round. loss_events_in_round:"
-      << loss_events_in_round
-      << ", threshold:" << Params().startup_full_loss_count << "  @ "
-      << congestion_event.event_time;
-
   // At the end of a round trip. Check if loss is too high in this round.
-  if (loss_events_in_round >= Params().startup_full_loss_count &&
-      model_->IsInflightTooHigh(congestion_event)) {
+  if (model_->IsInflightTooHigh(congestion_event,
+                                Params().startup_full_loss_count)) {
     const QuicByteCount bdp = model_->BDP(model_->MaxBandwidth());
     QUIC_DVLOG(3) << sender_
                   << " Exiting STARTUP due to loss. inflight_hi:" << bdp;
+    // TODO(ianswett): Add a shared method to set inflight_hi in the model.
     model_->set_inflight_hi(bdp);
 
     full_bandwidth_reached_ = true;