Add GetSize() and GetMaxSize() to the SessionCache interface.

This will be used in Chromium to implement the new memory pressure handler.

This is a no-op change to production code if the new methods are not called.

PiperOrigin-RevId: 878840543
diff --git a/quiche/quic/core/crypto/quic_client_session_cache.cc b/quiche/quic/core/crypto/quic_client_session_cache.cc
index a09d47c..a36fc07 100644
--- a/quiche/quic/core/crypto/quic_client_session_cache.cc
+++ b/quiche/quic/core/crypto/quic_client_session_cache.cc
@@ -140,6 +140,10 @@
   cache_.UpdateMaxSize(max_entries);
 }
 
+size_t QuicClientSessionCache::GetSize() const { return cache_.Size(); }
+
+size_t QuicClientSessionCache::GetMaxSize() const { return cache_.MaxSize(); }
+
 void QuicClientSessionCache::CreateAndInsertEntry(
     const QuicServerId& server_id, bssl::UniquePtr<SSL_SESSION> session,
     const TransportParameters& params,
diff --git a/quiche/quic/core/crypto/quic_client_session_cache.h b/quiche/quic/core/crypto/quic_client_session_cache.h
index 91f41b0..0782552 100644
--- a/quiche/quic/core/crypto/quic_client_session_cache.h
+++ b/quiche/quic/core/crypto/quic_client_session_cache.h
@@ -45,9 +45,11 @@
 
   void Clear() override;
 
-  void UpdateMaxSize(size_t max_entries) override;
+  size_t GetSize() const override;
 
-  size_t size() const { return cache_.Size(); }
+  size_t GetMaxSize() const override;
+
+  void UpdateMaxSize(size_t max_entries) override;
 
  private:
   friend class test::QuicClientSessionCachePeer;
diff --git a/quiche/quic/core/crypto/quic_client_session_cache_test.cc b/quiche/quic/core/crypto/quic_client_session_cache_test.cc
index 8438515..14d3e8b 100644
--- a/quiche/quic/core/crypto/quic_client_session_cache_test.cc
+++ b/quiche/quic/core/crypto/quic_client_session_cache_test.cc
@@ -199,26 +199,26 @@
 
   EXPECT_EQ(nullptr, cache.Lookup(id1, clock_.WallNow(), ssl_ctx_.get()));
   EXPECT_EQ(nullptr, cache.Lookup(id2, clock_.WallNow(), ssl_ctx_.get()));
-  EXPECT_EQ(0u, cache.size());
+  EXPECT_EQ(0u, cache.GetSize());
 
   cache.Insert(id1, std::move(session), *params, nullptr);
-  EXPECT_EQ(1u, cache.size());
+  EXPECT_EQ(1u, cache.GetSize());
   EXPECT_EQ(
       *params,
       *(cache.Lookup(id1, clock_.WallNow(), ssl_ctx_.get())->transport_params));
   EXPECT_EQ(nullptr, cache.Lookup(id2, clock_.WallNow(), ssl_ctx_.get()));
   // No session is available for id1, even though the entry exists.
-  EXPECT_EQ(1u, cache.size());
+  EXPECT_EQ(1u, cache.GetSize());
   EXPECT_EQ(nullptr, cache.Lookup(id1, clock_.WallNow(), ssl_ctx_.get()));
   // Lookup() will trigger a deletion of invalid entry.
-  EXPECT_EQ(0u, cache.size());
+  EXPECT_EQ(0u, cache.GetSize());
 
   auto session3 = MakeTestSession();
   SSL_SESSION* unowned3 = session3.get();
   QuicServerId id3("c.com", 443);
   cache.Insert(id3, std::move(session3), *params, nullptr);
   cache.Insert(id2, std::move(session2), *params2, nullptr);
-  EXPECT_EQ(2u, cache.size());
+  EXPECT_EQ(2u, cache.GetSize());
   EXPECT_EQ(
       unowned2,
       cache.Lookup(id2, clock_.WallNow(), ssl_ctx_.get())->tls_session.get());
@@ -230,7 +230,7 @@
   EXPECT_EQ(nullptr, cache.Lookup(id1, clock_.WallNow(), ssl_ctx_.get()));
   EXPECT_EQ(nullptr, cache.Lookup(id2, clock_.WallNow(), ssl_ctx_.get()));
   EXPECT_EQ(nullptr, cache.Lookup(id3, clock_.WallNow(), ssl_ctx_.get()));
-  EXPECT_EQ(0u, cache.size());
+  EXPECT_EQ(0u, cache.GetSize());
 }
 
 TEST_F(QuicClientSessionCacheTest, MultipleSessions) {
@@ -345,7 +345,7 @@
   cache.Insert(id2, std::move(session2), *params, nullptr);
   cache.Insert(id3, std::move(session3), *params, nullptr);
 
-  EXPECT_EQ(2u, cache.size());
+  EXPECT_EQ(2u, cache.GetSize());
   EXPECT_EQ(
       unowned2,
       cache.Lookup(id2, clock_.WallNow(), ssl_ctx_.get())->tls_session.get());
@@ -396,18 +396,18 @@
   cache.Insert(id1, std::move(session), *params, nullptr);
   cache.Insert(id2, std::move(session2), *params, nullptr);
 
-  EXPECT_EQ(2u, cache.size());
+  EXPECT_EQ(2u, cache.GetSize());
   // Expire the session.
   clock_.AdvanceTime(kTimeout * 2);
   // The entry has not been removed yet.
-  EXPECT_EQ(2u, cache.size());
+  EXPECT_EQ(2u, cache.GetSize());
 
   EXPECT_EQ(nullptr, cache.Lookup(id1, clock_.WallNow(), ssl_ctx_.get()));
-  EXPECT_EQ(1u, cache.size());
+  EXPECT_EQ(1u, cache.GetSize());
   EXPECT_EQ(
       unowned2,
       cache.Lookup(id2, clock_.WallNow(), ssl_ctx_.get())->tls_session.get());
-  EXPECT_EQ(1u, cache.size());
+  EXPECT_EQ(1u, cache.GetSize());
 }
 
 TEST_F(QuicClientSessionCacheTest, RemoveExpiredEntriesAndClear) {
@@ -423,21 +423,21 @@
   cache.Insert(id1, std::move(session), *params, nullptr);
   cache.Insert(id2, std::move(session2), *params, nullptr);
 
-  EXPECT_EQ(2u, cache.size());
+  EXPECT_EQ(2u, cache.GetSize());
   // Expire the session.
   clock_.AdvanceTime(kTimeout * 2);
   // The entry has not been removed yet.
-  EXPECT_EQ(2u, cache.size());
+  EXPECT_EQ(2u, cache.GetSize());
 
   // Flush expired sessions.
   cache.RemoveExpiredEntries(clock_.WallNow());
 
   // session is expired and should be flushed.
   EXPECT_EQ(nullptr, cache.Lookup(id1, clock_.WallNow(), ssl_ctx_.get()));
-  EXPECT_EQ(1u, cache.size());
+  EXPECT_EQ(1u, cache.GetSize());
 
   cache.Clear();
-  EXPECT_EQ(0u, cache.size());
+  EXPECT_EQ(0u, cache.GetSize());
 }
 
 }  // namespace
diff --git a/quiche/quic/core/crypto/quic_crypto_client_config.h b/quiche/quic/core/crypto/quic_crypto_client_config.h
index a8374f8..c39bc6a 100644
--- a/quiche/quic/core/crypto/quic_crypto_client_config.h
+++ b/quiche/quic/core/crypto/quic_crypto_client_config.h
@@ -99,6 +99,12 @@
   // Clear the session cache.
   virtual void Clear() = 0;
 
+  // Returns the current size of the cache.
+  virtual size_t GetSize() const = 0;
+
+  // Returns the maximum size of the cache.
+  virtual size_t GetMaxSize() const = 0;
+
   // Update the maximum size of the cache. If the new capacity is smaller than
   // current size, evicts the oldest entries.
   virtual void UpdateMaxSize(size_t max_entries) = 0;
diff --git a/quiche/quic/test_tools/simple_session_cache.cc b/quiche/quic/test_tools/simple_session_cache.cc
index 39cbed0..53521f8 100644
--- a/quiche/quic/test_tools/simple_session_cache.cc
+++ b/quiche/quic/test_tools/simple_session_cache.cc
@@ -81,5 +81,11 @@
   // SimpleSessionCache does not support updating the maximum size of the cache.
 }
 
+size_t SimpleSessionCache::GetSize() const { return cache_entries_.size(); }
+
+size_t SimpleSessionCache::GetMaxSize() const {
+  return std::numeric_limits<size_t>::max();
+}
+
 }  // namespace test
 }  // namespace quic
diff --git a/quiche/quic/test_tools/simple_session_cache.h b/quiche/quic/test_tools/simple_session_cache.h
index b8c71a0..6d47926 100644
--- a/quiche/quic/test_tools/simple_session_cache.h
+++ b/quiche/quic/test_tools/simple_session_cache.h
@@ -38,6 +38,8 @@
                           absl::string_view token) override;
   void RemoveExpiredEntries(QuicWallTime now) override;
   void Clear() override;
+  size_t GetSize() const override;
+  size_t GetMaxSize() const override;
   void UpdateMaxSize(size_t max_entries) override;
 
  private: