Within WindowManager, changes the representation of flow control windows from size_t to int64_t.

This is preparation for handling negative window values within WindowManager. Refactoring, no functional change.

PiperOrigin-RevId: 429021557
diff --git a/http2/adapter/window_manager.cc b/http2/adapter/window_manager.cc
index de45dc3..9ab661d 100644
--- a/http2/adapter/window_manager.cc
+++ b/http2/adapter/window_manager.cc
@@ -8,12 +8,14 @@
 namespace http2 {
 namespace adapter {
 
-WindowManager::WindowManager(size_t window_size_limit,
+WindowManager::WindowManager(int64_t window_size_limit,
                              WindowUpdateListener listener)
-    : limit_(window_size_limit), window_(window_size_limit), buffered_(0),
+    : limit_(window_size_limit),
+      window_(window_size_limit),
+      buffered_(0),
       listener_(std::move(listener)) {}
 
-void WindowManager::OnWindowSizeLimitChange(const size_t new_limit) {
+void WindowManager::OnWindowSizeLimitChange(const int64_t new_limit) {
   QUICHE_VLOG(2) << "WindowManager@" << this
                  << " OnWindowSizeLimitChange from old limit of " << limit_
                  << " to new limit of " << new_limit;
@@ -26,7 +28,7 @@
   limit_ = new_limit;
 }
 
-void WindowManager::SetWindowSizeLimit(size_t new_limit) {
+void WindowManager::SetWindowSizeLimit(int64_t new_limit) {
   QUICHE_VLOG(2) << "WindowManager@" << this
                  << " SetWindowSizeLimit from old limit of " << limit_
                  << " to new limit of " << new_limit;
@@ -34,7 +36,7 @@
   MaybeNotifyListener();
 }
 
-bool WindowManager::MarkDataBuffered(size_t bytes) {
+bool WindowManager::MarkDataBuffered(int64_t bytes) {
   QUICHE_VLOG(2) << "WindowManager@" << this << " window: " << window_
                  << " bytes: " << bytes;
   if (window_ < bytes) {
@@ -52,7 +54,7 @@
   return window_ > 0;
 }
 
-void WindowManager::MarkDataFlushed(size_t bytes) {
+void WindowManager::MarkDataFlushed(int64_t bytes) {
   QUICHE_VLOG(2) << "WindowManager@" << this << " buffered: " << buffered_
                  << " bytes: " << bytes;
   if (buffered_ < bytes) {
@@ -73,9 +75,9 @@
   }
   // For the sake of efficiency, we want to send window updates if less than
   // half of the max quota is available to the peer at any point in time.
-  const size_t kDesiredMinWindow = limit_ / 2;
-  const size_t kDesiredMinDelta = limit_ / 3;
-  const size_t delta = limit_ - (buffered_ + window_);
+  const int64_t kDesiredMinWindow = limit_ / 2;
+  const int64_t kDesiredMinDelta = limit_ / 3;
+  const int64_t delta = limit_ - (buffered_ + window_);
   bool send_update = false;
   if (delta >= kDesiredMinDelta) {
     // This particular window update was sent because the available delta
diff --git a/http2/adapter/window_manager.h b/http2/adapter/window_manager.h
index 5a7701e..a4fe468 100644
--- a/http2/adapter/window_manager.h
+++ b/http2/adapter/window_manager.h
@@ -19,34 +19,33 @@
 class QUICHE_EXPORT_PRIVATE WindowManager {
  public:
   // A WindowUpdateListener is invoked when it is time to send a window update.
-  typedef std::function<void(size_t)> WindowUpdateListener;
+  typedef std::function<void(int64_t)> WindowUpdateListener;
 
-  WindowManager(size_t window_size_limit,
-                WindowUpdateListener listener);
+  WindowManager(int64_t window_size_limit, WindowUpdateListener listener);
 
-  size_t CurrentWindowSize() const { return window_; }
-  size_t WindowSizeLimit() const { return limit_; }
+  int64_t CurrentWindowSize() const { return window_; }
+  int64_t WindowSizeLimit() const { return limit_; }
 
   // Called when the window size limit is changed (typically via settings) but
   // no window update should be sent.
-  void OnWindowSizeLimitChange(size_t new_limit);
+  void OnWindowSizeLimitChange(int64_t new_limit);
 
   // Sets the window size limit to |new_limit| and notifies the listener to
   // update as necessary.
-  void SetWindowSizeLimit(size_t new_limit);
+  void SetWindowSizeLimit(int64_t new_limit);
 
   // Increments the running total of data bytes buffered. Returns true iff there
   // is more window remaining.
-  bool MarkDataBuffered(size_t bytes);
+  bool MarkDataBuffered(int64_t bytes);
 
   // Increments the running total of data bytes that have been flushed or
   // dropped. Invokes the listener if the current window is smaller than some
   // threshold and there is quota available to send.
-  void MarkDataFlushed(size_t bytes);
+  void MarkDataFlushed(int64_t bytes);
 
   // Convenience method, used when incoming data is immediately dropped or
   // ignored.
-  void MarkWindowConsumed(size_t bytes) {
+  void MarkWindowConsumed(int64_t bytes) {
     MarkDataBuffered(bytes);
     MarkDataFlushed(bytes);
   }
@@ -58,16 +57,16 @@
 
   // The upper bound on the flow control window. The GFE attempts to maintain a
   // window of this size at the peer as data is proxied through.
-  size_t limit_;
+  int64_t limit_;
 
   // The current flow control window that has not been advertised to the peer
   // and not yet consumed. The peer can send this many bytes before becoming
   // blocked.
-  size_t window_;
+  int64_t window_;
 
   // The amount of data already buffered, which should count against the flow
   // control window upper bound.
-  size_t buffered_;
+  int64_t buffered_;
 
   WindowUpdateListener listener_;
 };
diff --git a/http2/adapter/window_manager_test.cc b/http2/adapter/window_manager_test.cc
index e706156..e81dc94 100644
--- a/http2/adapter/window_manager_test.cc
+++ b/http2/adapter/window_manager_test.cc
@@ -16,9 +16,7 @@
  public:
   explicit WindowManagerPeer(const WindowManager& wm) : wm_(wm) {}
 
-  size_t buffered() {
-    return wm_.buffered_;
-  }
+  int64_t buffered() { return wm_.buffered_; }
 
  private:
   const WindowManager& wm_;
@@ -32,12 +30,10 @@
       : wm_(kDefaultLimit, absl::bind_front(&WindowManagerTest::OnCall, this)),
         peer_(wm_) {}
 
-  void OnCall(size_t s) {
-    call_sequence_.push_back(s);
-  }
+  void OnCall(int64_t s) { call_sequence_.push_back(s); }
 
-  const size_t kDefaultLimit = 32 * 1024 * 3;
-  std::list<size_t> call_sequence_;
+  const int64_t kDefaultLimit = 32 * 1024 * 3;
+  std::list<int64_t> call_sequence_;
   WindowManager wm_;
   WindowManagerPeer peer_;
   ::http2::test::Http2Random random_;
@@ -56,9 +52,9 @@
 // This test verifies that WindowManager does not notify its listener when data
 // is only buffered, and never flushed.
 TEST_F(WindowManagerTest, DataOnlyBuffered) {
-  size_t total = 0;
+  int64_t total = 0;
   while (total < kDefaultLimit) {
-    size_t s = std::min<size_t>(kDefaultLimit - total, random_.Uniform(1024));
+    int64_t s = std::min<int64_t>(kDefaultLimit - total, random_.Uniform(1024));
     total += s;
     wm_.MarkDataBuffered(s);
   }
@@ -68,15 +64,15 @@
 // This test verifies that WindowManager does notify its listener when data is
 // buffered and subsequently flushed.
 TEST_F(WindowManagerTest, DataBufferedAndFlushed) {
-  size_t total_buffered = 0;
-  size_t total_flushed = 0;
+  int64_t total_buffered = 0;
+  int64_t total_flushed = 0;
   while (call_sequence_.empty()) {
-    size_t buffered =
-        std::min<size_t>(kDefaultLimit - total_buffered, random_.Uniform(1024));
+    int64_t buffered = std::min<int64_t>(kDefaultLimit - total_buffered,
+                                         random_.Uniform(1024));
     wm_.MarkDataBuffered(buffered);
     total_buffered += buffered;
     EXPECT_TRUE(call_sequence_.empty());
-    size_t flushed = random_.Uniform(total_buffered - total_flushed);
+    int64_t flushed = random_.Uniform(total_buffered - total_flushed);
     wm_.MarkDataFlushed(flushed);
     total_flushed += flushed;
   }
@@ -110,10 +106,10 @@
 // This test verifies that WindowManager notifies its listener when window is
 // consumed (data is ignored or immediately dropped).
 TEST_F(WindowManagerTest, WindowConsumed) {
-  size_t consumed = kDefaultLimit / 3 - 1;
+  int64_t consumed = kDefaultLimit / 3 - 1;
   wm_.MarkWindowConsumed(consumed);
   EXPECT_TRUE(call_sequence_.empty());
-  const size_t extra = 1;
+  const int64_t extra = 1;
   wm_.MarkWindowConsumed(extra);
   EXPECT_THAT(call_sequence_, testing::ElementsAre(consumed + extra));
 }