Blocked decoding part 1: QpackHeaderTable::Observer.

gfe-relnote: n/a, QUIC v99-only change.
PiperOrigin-RevId: 257104083
Change-Id: I6209b6f2be59b32fba1790765a00abee7b75bfe2
diff --git a/quic/core/qpack/qpack_header_table.cc b/quic/core/qpack/qpack_header_table.cc
index 0194330..9522666 100644
--- a/quic/core/qpack/qpack_header_table.cc
+++ b/quic/core/qpack/qpack_header_table.cc
@@ -140,6 +140,14 @@
     CHECK(result.second);
   }
 
+  // Notify and deregister observers whose threshold is met, if any.
+  while (!observers_.empty() &&
+         observers_.top().required_insert_count <= inserted_entry_count()) {
+    Observer* observer = observers_.top().observer;
+    observers_.pop();
+    observer->OnInsertCountReachedThreshold();
+  }
+
   return new_entry;
 }
 
@@ -169,6 +177,17 @@
   max_entries_ = maximum_dynamic_table_capacity / 32;
 }
 
+void QpackHeaderTable::RegisterObserver(Observer* observer,
+                                        uint64_t required_insert_count) {
+  DCHECK_GT(required_insert_count, 0u);
+  observers_.push({observer, required_insert_count});
+}
+
+bool QpackHeaderTable::ObserverWithThreshold::operator>(
+    const ObserverWithThreshold& other) const {
+  return required_insert_count > other.required_insert_count;
+}
+
 void QpackHeaderTable::EvictDownToCurrentCapacity() {
   while (dynamic_table_size_ > dynamic_table_capacity_) {
     DCHECK(!dynamic_entries_.empty());