Move QuicCryptoClientStreamBase::EarlyDataReason to QuicCryptoStream

PiperOrigin-RevId: 332301712
Change-Id: I391a8dfcd7f927d71de91355ba26a0d62bcf9e7c
diff --git a/quic/core/http/quic_spdy_session_test.cc b/quic/core/http/quic_spdy_session_test.cc
index a3c4a52..c8fdf4c 100644
--- a/quic/core/http/quic_spdy_session_test.cc
+++ b/quic/core/http/quic_spdy_session_test.cc
@@ -131,6 +131,9 @@
   }
 
   // QuicCryptoStream implementation
+  ssl_early_data_reason_t EarlyDataReason() const override {
+    return ssl_early_data_unknown;
+  }
   bool encryption_established() const override {
     return encryption_established_;
   }
diff --git a/quic/core/http/quic_spdy_stream_test.cc b/quic/core/http/quic_spdy_stream_test.cc
index 85e6467..1c55c96 100644
--- a/quic/core/http/quic_spdy_stream_test.cc
+++ b/quic/core/http/quic_spdy_stream_test.cc
@@ -119,6 +119,9 @@
   }
 
   // QuicCryptoStream implementation
+  ssl_early_data_reason_t EarlyDataReason() const override {
+    return ssl_early_data_unknown;
+  }
   bool encryption_established() const override {
     return encryption_established_;
   }
diff --git a/quic/core/quic_crypto_client_stream.h b/quic/core/quic_crypto_client_stream.h
index 4100a50..1d9b04b 100644
--- a/quic/core/quic_crypto_client_stream.h
+++ b/quic/core/quic_crypto_client_stream.h
@@ -9,7 +9,6 @@
 #include <memory>
 #include <string>
 
-#include "third_party/boringssl/src/include/openssl/ssl.h"
 #include "net/third_party/quiche/src/quic/core/crypto/proof_verifier.h"
 #include "net/third_party/quiche/src/quic/core/crypto/quic_crypto_client_config.h"
 #include "net/third_party/quiche/src/quic/core/quic_config.h"
@@ -54,10 +53,6 @@
   // Returns true if early data (0-RTT) was accepted in the connection.
   virtual bool EarlyDataAccepted() const = 0;
 
-  // Returns the ssl_early_data_reason_t describing why 0-RTT was accepted or
-  // rejected.
-  virtual ssl_early_data_reason_t EarlyDataReason() const = 0;
-
   // Returns true if the client received an inchoate REJ during the handshake,
   // extending the handshake by one round trip. This only applies for QUIC
   // crypto handshakes. The equivalent feature in IETF QUIC is a Retry packet,
diff --git a/quic/core/quic_crypto_server_stream.cc b/quic/core/quic_crypto_server_stream.cc
index 665cae1..5fc6839 100644
--- a/quic/core/quic_crypto_server_stream.cc
+++ b/quic/core/quic_crypto_server_stream.cc
@@ -360,6 +360,16 @@
   return true;
 }
 
+ssl_early_data_reason_t QuicCryptoServerStream::EarlyDataReason() const {
+  if (IsZeroRtt()) {
+    return ssl_early_data_accepted;
+  }
+  if (zero_rtt_attempted_) {
+    return ssl_early_data_session_not_resumed;
+  }
+  return ssl_early_data_no_session_offered;
+}
+
 bool QuicCryptoServerStream::encryption_established() const {
   return encryption_established_;
 }
diff --git a/quic/core/quic_crypto_server_stream.h b/quic/core/quic_crypto_server_stream.h
index 5a4b9b1..29d680e 100644
--- a/quic/core/quic_crypto_server_stream.h
+++ b/quic/core/quic_crypto_server_stream.h
@@ -51,6 +51,7 @@
   const ProofSource::Details* ProofSourceDetails() const override;
 
   // From QuicCryptoStream
+  ssl_early_data_reason_t EarlyDataReason() const override;
   bool encryption_established() const override;
   bool one_rtt_keys_available() const override;
   const QuicCryptoNegotiatedParameters& crypto_negotiated_params()
diff --git a/quic/core/quic_crypto_stream.h b/quic/core/quic_crypto_stream.h
index 54d1b25..d73d970 100644
--- a/quic/core/quic_crypto_stream.h
+++ b/quic/core/quic_crypto_stream.h
@@ -9,6 +9,7 @@
 #include <cstddef>
 #include <string>
 
+#include "third_party/boringssl/src/include/openssl/ssl.h"
 #include "net/third_party/quiche/src/quic/core/crypto/crypto_framer.h"
 #include "net/third_party/quiche/src/quic/core/crypto/crypto_utils.h"
 #include "net/third_party/quiche/src/quic/core/quic_config.h"
@@ -72,6 +73,13 @@
   virtual void WriteCryptoData(EncryptionLevel level,
                                quiche::QuicheStringPiece data);
 
+  // Returns the ssl_early_data_reason_t describing why 0-RTT was accepted or
+  // rejected. Note that the value returned by this function may vary during the
+  // handshake. Once |one_rtt_keys_available| returns true, the value returned
+  // by this function will not change for the rest of the lifetime of the
+  // QuicCryptoStream.
+  virtual ssl_early_data_reason_t EarlyDataReason() const = 0;
+
   // Returns true once an encrypter has been set for the connection.
   virtual bool encryption_established() const = 0;
 
diff --git a/quic/core/quic_crypto_stream_test.cc b/quic/core/quic_crypto_stream_test.cc
index f763d2d..b0f4de3 100644
--- a/quic/core/quic_crypto_stream_test.cc
+++ b/quic/core/quic_crypto_stream_test.cc
@@ -46,6 +46,9 @@
 
   std::vector<CryptoHandshakeMessage>* messages() { return &messages_; }
 
+  ssl_early_data_reason_t EarlyDataReason() const override {
+    return ssl_early_data_unknown;
+  }
   bool encryption_established() const override { return false; }
   bool one_rtt_keys_available() const override { return false; }
 
diff --git a/quic/core/quic_session_test.cc b/quic/core/quic_session_test.cc
index fad4082..5da254d 100644
--- a/quic/core/quic_session_test.cc
+++ b/quic/core/quic_session_test.cc
@@ -115,6 +115,9 @@
   }
 
   // QuicCryptoStream implementation
+  ssl_early_data_reason_t EarlyDataReason() const override {
+    return ssl_early_data_unknown;
+  }
   bool encryption_established() const override {
     return encryption_established_;
   }
diff --git a/quic/core/tls_client_handshaker.cc b/quic/core/tls_client_handshaker.cc
index d11437d..9c316a7 100644
--- a/quic/core/tls_client_handshaker.cc
+++ b/quic/core/tls_client_handshaker.cc
@@ -296,7 +296,7 @@
 }
 
 ssl_early_data_reason_t TlsClientHandshaker::EarlyDataReason() const {
-  return SSL_get_early_data_reason(ssl());
+  return TlsHandshaker::EarlyDataReason();
 }
 
 bool TlsClientHandshaker::ReceivedInchoateReject() const {
diff --git a/quic/core/tls_handshaker.cc b/quic/core/tls_handshaker.cc
index 1b20063..04fab15 100644
--- a/quic/core/tls_handshaker.cc
+++ b/quic/core/tls_handshaker.cc
@@ -57,6 +57,10 @@
       ssl(), TlsConnection::BoringEncryptionLevel(level));
 }
 
+ssl_early_data_reason_t TlsHandshaker::EarlyDataReason() const {
+  return SSL_get_early_data_reason(ssl());
+}
+
 const EVP_MD* TlsHandshaker::Prf(const SSL_CIPHER* cipher) {
   return EVP_get_digestbynid(SSL_CIPHER_get_prf_nid(cipher));
 }
diff --git a/quic/core/tls_handshaker.h b/quic/core/tls_handshaker.h
index 282c89d..2b3c9fc 100644
--- a/quic/core/tls_handshaker.h
+++ b/quic/core/tls_handshaker.h
@@ -48,6 +48,7 @@
   // TlsHandshaker which use them to implement methods of QuicCryptoStream.
   CryptoMessageParser* crypto_message_parser() { return this; }
   size_t BufferSizeLimitForLevel(EncryptionLevel level) const;
+  ssl_early_data_reason_t EarlyDataReason() const;
 
  protected:
   virtual void AdvanceHandshake() = 0;
diff --git a/quic/core/tls_server_handshaker.cc b/quic/core/tls_server_handshaker.cc
index 46e4b81..85f65e2 100644
--- a/quic/core/tls_server_handshaker.cc
+++ b/quic/core/tls_server_handshaker.cc
@@ -175,6 +175,10 @@
   state_ = STATE_CONNECTION_CLOSED;
 }
 
+ssl_early_data_reason_t TlsServerHandshaker::EarlyDataReason() const {
+  return TlsHandshaker::EarlyDataReason();
+}
+
 bool TlsServerHandshaker::encryption_established() const {
   return encryption_established_;
 }
diff --git a/quic/core/tls_server_handshaker.h b/quic/core/tls_server_handshaker.h
index b0212db..063e5ca 100644
--- a/quic/core/tls_server_handshaker.h
+++ b/quic/core/tls_server_handshaker.h
@@ -56,6 +56,7 @@
   const ProofSource::Details* ProofSourceDetails() const override;
 
   // From QuicCryptoServerStreamBase and TlsHandshaker
+  ssl_early_data_reason_t EarlyDataReason() const override;
   bool encryption_established() const override;
   bool one_rtt_keys_available() const override;
   const QuicCryptoNegotiatedParameters& crypto_negotiated_params()
diff --git a/quic/test_tools/quic_test_utils.cc b/quic/test_tools/quic_test_utils.cc
index e6bd7e4..6e83351 100644
--- a/quic/test_tools/quic_test_utils.cc
+++ b/quic/test_tools/quic_test_utils.cc
@@ -643,6 +643,10 @@
 
 MockQuicCryptoStream::~MockQuicCryptoStream() {}
 
+ssl_early_data_reason_t MockQuicCryptoStream::EarlyDataReason() const {
+  return ssl_early_data_unknown;
+}
+
 bool MockQuicCryptoStream::encryption_established() const {
   return false;
 }
diff --git a/quic/test_tools/quic_test_utils.h b/quic/test_tools/quic_test_utils.h
index 86f2003..a47bdd1 100644
--- a/quic/test_tools/quic_test_utils.h
+++ b/quic/test_tools/quic_test_utils.h
@@ -851,6 +851,7 @@
 
   ~MockQuicCryptoStream() override;
 
+  ssl_early_data_reason_t EarlyDataReason() const override;
   bool encryption_established() const override;
   bool one_rtt_keys_available() const override;
   const QuicCryptoNegotiatedParameters& crypto_negotiated_params()