Updates spdy::Http2DecoderAdapter to hold HpackDecoderAdapter directly, rather than as a pointer.

This may very slightly improve memory usage and performance.

Protected by not protected: minor refactoring, no functional change.

PiperOrigin-RevId: 596076512
diff --git a/quiche/http2/adapter/oghttp2_session.cc b/quiche/http2/adapter/oghttp2_session.cc
index d91d9dc..18a87d1 100644
--- a/quiche/http2/adapter/oghttp2_session.cc
+++ b/quiche/http2/adapter/oghttp2_session.cc
@@ -353,10 +353,10 @@
   decoder_.set_visitor(&receive_logger_);
   if (options_.max_header_list_bytes) {
     // Limit buffering of encoded HPACK data to 2x the decoded limit.
-    decoder_.GetHpackDecoder()->set_max_decode_buffer_size_bytes(
+    decoder_.GetHpackDecoder().set_max_decode_buffer_size_bytes(
         2 * *options_.max_header_list_bytes);
     // Limit the total bytes accepted for HPACK decoding to 4x the limit.
-    decoder_.GetHpackDecoder()->set_max_header_block_bytes(
+    decoder_.GetHpackDecoder().set_max_header_block_bytes(
         4 * *options_.max_header_list_bytes);
   }
   if (IsServerSession()) {
@@ -442,13 +442,11 @@
 }
 
 int OgHttp2Session::GetHpackDecoderDynamicTableSize() const {
-  const spdy::HpackDecoderAdapter* decoder = decoder_.GetHpackDecoder();
-  return decoder == nullptr ? 0 : decoder->GetDynamicTableSize();
+  return decoder_.GetHpackDecoder().GetDynamicTableSize();
 }
 
 int OgHttp2Session::GetHpackDecoderSizeLimit() const {
-  const spdy::HpackDecoderAdapter* decoder = decoder_.GetHpackDecoder();
-  return decoder == nullptr ? 0 : decoder->GetCurrentHeaderTableSizeSetting();
+  return decoder_.GetHpackDecoder().GetCurrentHeaderTableSizeSetting();
 }
 
 int64_t OgHttp2Session::ProcessBytes(absl::string_view bytes) {
@@ -1698,7 +1696,7 @@
               max_inbound_concurrent_streams_ = value;
               break;
             case HEADER_TABLE_SIZE:
-              decoder_.GetHpackDecoder()->ApplyHeaderTableSizeSetting(value);
+              decoder_.GetHpackDecoder().ApplyHeaderTableSizeSetting(value);
               break;
             case INITIAL_WINDOW_SIZE:
               UpdateStreamReceiveWindowSizes(value);
diff --git a/quiche/quic/core/http/quic_spdy_session.cc b/quiche/quic/core/http/quic_spdy_session.cc
index 9a937c7..d88951a 100644
--- a/quiche/quic/core/http/quic_spdy_session.cc
+++ b/quiche/quic/core/http/quic_spdy_session.cc
@@ -532,7 +532,7 @@
   spdy_framer_visitor_->set_max_header_list_size(max_inbound_header_list_size_);
 
   // Limit HPACK buffering to 2x header list size limit.
-  h2_deframer_.GetHpackDecoder()->set_max_decode_buffer_size_bytes(
+  h2_deframer_.GetHpackDecoder().set_max_decode_buffer_size_bytes(
       2 * max_inbound_header_list_size_);
 }
 
diff --git a/quiche/spdy/core/http2_frame_decoder_adapter.cc b/quiche/spdy/core/http2_frame_decoder_adapter.cc
index fcbc79f..58cf162 100644
--- a/quiche/spdy/core/http2_frame_decoder_adapter.cc
+++ b/quiche/spdy/core/http2_frame_decoder_adapter.cc
@@ -472,10 +472,10 @@
 void Http2DecoderAdapter::OnHpackFragment(const char* data, size_t len) {
   QUICHE_DVLOG(1) << "OnHpackFragment: len=" << len;
   on_hpack_fragment_called_ = true;
-  auto* decoder = GetHpackDecoder();
-  if (!decoder->HandleControlFrameHeadersData(data, len)) {
-    SetSpdyErrorAndNotify(HpackDecodingErrorToSpdyFramerError(decoder->error()),
-                          decoder->detailed_error());
+  auto& decoder = GetHpackDecoder();
+  if (!decoder.HandleControlFrameHeadersData(data, len)) {
+    SetSpdyErrorAndNotify(HpackDecodingErrorToSpdyFramerError(decoder.error()),
+                          decoder.detailed_error());
     return;
   }
 }
@@ -1029,13 +1029,6 @@
   }
 }
 
-HpackDecoderAdapter* Http2DecoderAdapter::GetHpackDecoder() {
-  if (hpack_decoder_ == nullptr) {
-    hpack_decoder_ = std::make_unique<HpackDecoderAdapter>();
-  }
-  return hpack_decoder_.get();
-}
-
 void Http2DecoderAdapter::CommonStartHpackBlock() {
   QUICHE_DVLOG(1) << "CommonStartHpackBlock";
   QUICHE_DCHECK(!has_hpack_first_frame_header_);
@@ -1053,7 +1046,7 @@
     SetSpdyErrorAndNotify(SpdyFramerError::SPDY_INTERNAL_FRAMER_ERROR, "");
     return;
   }
-  GetHpackDecoder()->HandleControlFrameHeadersStart(handler);
+  GetHpackDecoder().HandleControlFrameHeadersStart(handler);
 }
 
 // SpdyFramer calls HandleControlFrameHeadersData even if there are zero
@@ -1078,12 +1071,12 @@
                      frame_type() == Http2FrameType::CONTINUATION)
         << frame_header();
     has_expected_frame_type_ = false;
-    auto* decoder = GetHpackDecoder();
-    if (decoder->HandleControlFrameHeadersComplete()) {
+    auto& decoder = GetHpackDecoder();
+    if (decoder.HandleControlFrameHeadersComplete()) {
       visitor()->OnHeaderFrameEnd(stream_id());
     } else {
       SetSpdyErrorAndNotify(
-          HpackDecodingErrorToSpdyFramerError(decoder->error()), "");
+          HpackDecodingErrorToSpdyFramerError(decoder.error()), "");
       return;
     }
     const Http2FrameHeader& first = frame_type() == Http2FrameType::CONTINUATION
diff --git a/quiche/spdy/core/http2_frame_decoder_adapter.h b/quiche/spdy/core/http2_frame_decoder_adapter.h
index 87ab4c5..fab2669 100644
--- a/quiche/spdy/core/http2_frame_decoder_adapter.h
+++ b/quiche/spdy/core/http2_frame_decoder_adapter.h
@@ -154,9 +154,9 @@
   // has responded with an HTTP/1.1 (or earlier) response.
   bool probable_http_response() const;
 
-  spdy::HpackDecoderAdapter* GetHpackDecoder();
-  const spdy::HpackDecoderAdapter* GetHpackDecoder() const {
-    return hpack_decoder_.get();
+  spdy::HpackDecoderAdapter& GetHpackDecoder() { return hpack_decoder_; }
+  const spdy::HpackDecoderAdapter& GetHpackDecoder() const {
+    return hpack_decoder_;
   }
 
   bool HasError() const;
@@ -290,9 +290,8 @@
   // If non-null, unknown frames and settings are passed to the extension.
   spdy::ExtensionVisitorInterface* extension_ = nullptr;
 
-  // The HPACK decoder to be used for this adapter. User is responsible for
-  // clearing if the adapter is to be used for another connection.
-  std::unique_ptr<spdy::HpackDecoderAdapter> hpack_decoder_;
+  // The HPACK decoder to be used for this adapter.
+  spdy::HpackDecoderAdapter hpack_decoder_;
 
   // The HTTP/2 frame decoder.
   Http2FrameDecoder frame_decoder_;