Refactor TlsHandshaker interactions with the session's config

Before this CL, both TlsClientHandshaker and TlsServerHandshaker used to access session->config() directly to read and write transport parameters. This CL refactors this to go through the handshaker delegate, which is implemented by the session. This goes towards our goal of removing the session from the handshakers, but also is needed to allow the session to make some modifications to the transport parameters - that will happen in a subsequent CL aimed at supporting the draft-28 transport parameters.

Refactor, no behavior change, not flag protected

PiperOrigin-RevId: 313495203
Change-Id: I2d8acf8887c40de6be284395a57948dbc1cadc66
diff --git a/quic/core/handshaker_delegate_interface.h b/quic/core/handshaker_delegate_interface.h
index c157e08..bfc8761 100644
--- a/quic/core/handshaker_delegate_interface.h
+++ b/quic/core/handshaker_delegate_interface.h
@@ -5,6 +5,7 @@
 #ifndef QUICHE_QUIC_CORE_HANDSHAKER_DELEGATE_INTERFACE_H_
 #define QUICHE_QUIC_CORE_HANDSHAKER_DELEGATE_INTERFACE_H_
 
+#include "net/third_party/quiche/src/quic/core/crypto/transport_parameters.h"
 #include "net/third_party/quiche/src/quic/core/quic_types.h"
 
 namespace quic {
@@ -58,6 +59,18 @@
   // Called when 0-RTT data is rejected by the server. This is only called in
   // TLS handshakes and only called on clients.
   virtual void OnZeroRttRejected() = 0;
+
+  // Fills in |params| with values from the delegate's QuicConfig.
+  // Returns whether the operation succeeded.
+  virtual bool FillTransportParameters(TransportParameters* params) = 0;
+
+  // Read |params| and apply the values to the delegate's QuicConfig.
+  // On failure, returns a QuicErrorCode and saves a detailed error in
+  // |error_details|.
+  virtual QuicErrorCode ProcessTransportParameters(
+      const TransportParameters& params,
+      bool is_resumption,
+      std::string* error_details) = 0;
 };
 
 }  // namespace quic
diff --git a/quic/core/quic_session.cc b/quic/core/quic_session.cc
index f019522..56914eb 100644
--- a/quic/core/quic_session.cc
+++ b/quic/core/quic_session.cc
@@ -1613,6 +1613,24 @@
   // TODO(b/153726130): Handle early data rejection.
 }
 
+bool QuicSession::FillTransportParameters(TransportParameters* params) {
+  return config_.FillTransportParameters(params);
+}
+
+QuicErrorCode QuicSession::ProcessTransportParameters(
+    const TransportParameters& params,
+    bool is_resumption,
+    std::string* error_details) {
+  HelloType hello_type;
+  if (perspective_ == Perspective::IS_CLIENT) {
+    hello_type = SERVER;
+  } else {
+    hello_type = CLIENT;
+  }
+  return config_.ProcessTransportParameters(params, hello_type, is_resumption,
+                                            error_details);
+}
+
 void QuicSession::OnCryptoHandshakeMessageSent(
     const CryptoHandshakeMessage& /*message*/) {}
 
diff --git a/quic/core/quic_session.h b/quic/core/quic_session.h
index ae41efc..b4c3e98 100644
--- a/quic/core/quic_session.h
+++ b/quic/core/quic_session.h
@@ -260,6 +260,10 @@
   void NeuterUnencryptedData() override;
   void NeuterHandshakeData() override;
   void OnZeroRttRejected() override;
+  bool FillTransportParameters(TransportParameters* params) override;
+  QuicErrorCode ProcessTransportParameters(const TransportParameters& params,
+                                           bool is_resumption,
+                                           std::string* error_details) override;
 
   // Implement StreamDelegateInterface.
   void OnStreamError(QuicErrorCode error_code,
diff --git a/quic/core/tls_client_handshaker.cc b/quic/core/tls_client_handshaker.cc
index 4c4dbab..af37236 100644
--- a/quic/core/tls_client_handshaker.cc
+++ b/quic/core/tls_client_handshaker.cc
@@ -137,8 +137,8 @@
 bool TlsClientHandshaker::PrepareZeroRttConfig(
     QuicResumptionState* cached_state) {
   std::string error_details;
-  if (session()->config()->ProcessTransportParameters(
-          *(cached_state->transport_params), SERVER,
+  if (handshaker_delegate()->ProcessTransportParameters(
+          *(cached_state->transport_params),
           /*is_resumption = */ true, &error_details) != QUIC_NO_ERROR) {
     QUIC_BUG << "Unable to parse cached transport parameters.";
     CloseConnection(QUIC_HANDSHAKE_FAILED,
@@ -204,7 +204,7 @@
   params.version =
       CreateQuicVersionLabel(session()->supported_versions().front());
 
-  if (!session()->config()->FillTransportParameters(&params)) {
+  if (!handshaker_delegate()->FillTransportParameters(&params)) {
     return false;
   }
   if (GetQuicRestartFlag(quic_google_transport_param_send_new)) {
@@ -271,8 +271,8 @@
           received_transport_params_->supported_versions,
           session()->connection()->server_supported_versions(),
           error_details) != QUIC_NO_ERROR ||
-      session()->config()->ProcessTransportParameters(
-          *received_transport_params_, SERVER, /* is_resumption = */ false,
+      handshaker_delegate()->ProcessTransportParameters(
+          *received_transport_params_, /* is_resumption = */ false,
           error_details) != QUIC_NO_ERROR) {
     DCHECK(!error_details->empty());
     return false;
diff --git a/quic/core/tls_server_handshaker.cc b/quic/core/tls_server_handshaker.cc
index 012cb11..18b8cce 100644
--- a/quic/core/tls_server_handshaker.cc
+++ b/quic/core/tls_server_handshaker.cc
@@ -297,8 +297,8 @@
   if (CryptoUtils::ValidateClientHelloVersion(
           client_params.version, session()->connection()->version(),
           session()->supported_versions(), error_details) != QUIC_NO_ERROR ||
-      session()->config()->ProcessTransportParameters(
-          client_params, CLIENT, /* is_resumption = */ false, error_details) !=
+      handshaker_delegate()->ProcessTransportParameters(
+          client_params, /* is_resumption = */ false, error_details) !=
           QUIC_NO_ERROR) {
     return false;
   }
@@ -315,7 +315,7 @@
   server_params.version =
       CreateQuicVersionLabel(session()->connection()->version());
 
-  if (!session()->config()->FillTransportParameters(&server_params)) {
+  if (!handshaker_delegate()->FillTransportParameters(&server_params)) {
     return false;
   }