Refactor SETTINGS creation and submission in OgHttp2Session.

This CL increases sharing between SubmitSettings() and MaybeSetupPreface(), the
two places in OgHttp2Session that handle the creation of SpdySettingsIR for
sending to the peer. This refactoring will come in handy when adding another
step, i.e., SETTINGS ack callbacks, to the SETTINGS sending process.

PiperOrigin-RevId: 413286843
diff --git a/http2/adapter/oghttp2_session.cc b/http2/adapter/oghttp2_session.cc
index 0792a5c..16d302a 100644
--- a/http2/adapter/oghttp2_session.cc
+++ b/http2/adapter/oghttp2_session.cc
@@ -765,11 +765,7 @@
 }
 
 void OgHttp2Session::SubmitSettings(absl::Span<const Http2Setting> settings) {
-  auto settings_ir = absl::make_unique<SpdySettingsIR>();
-  for (const Http2Setting& setting : settings) {
-    settings_ir->AddSetting(setting.id, setting.value);
-  }
-  EnqueueFrame(std::move(settings_ir));
+  EnqueueFrame(PrepareSettingsFrame(settings));
 }
 
 void OgHttp2Session::OnError(SpdyFramerError error,
@@ -1119,21 +1115,30 @@
     if (frames_.empty() ||
         frames_.front()->frame_type() != spdy::SpdyFrameType::SETTINGS ||
         reinterpret_cast<SpdySettingsIR&>(*frames_.front()).is_ack()) {
-      auto settings = absl::make_unique<SpdySettingsIR>();
-      FillInitialSettingsFrame(*settings);
-      frames_.push_front(std::move(settings));
+      frames_.push_front(PrepareSettingsFrame(GetInitialSettings()));
     }
     queued_preface_ = true;
   }
 }
 
-void OgHttp2Session::FillInitialSettingsFrame(SpdySettingsIR& settings) {
+std::vector<Http2Setting> OgHttp2Session::GetInitialSettings() const {
+  std::vector<Http2Setting> settings;
   if (!IsServerSession()) {
     // Disable server push. Note that server push from clients is already
     // disabled, so the server does not need to send this disabling setting.
     // TODO(diannahu): Consider applying server push disabling on SETTINGS ack.
-    settings.AddSetting(spdy::SETTINGS_ENABLE_PUSH, false);
+    settings.push_back({Http2KnownSettingsId::ENABLE_PUSH, 0});
   }
+  return settings;
+}
+
+std::unique_ptr<SpdySettingsIR> OgHttp2Session::PrepareSettingsFrame(
+    absl::Span<const Http2Setting> settings) {
+  auto settings_ir = absl::make_unique<SpdySettingsIR>();
+  for (const Http2Setting& setting : settings) {
+    settings_ir->AddSetting(setting.id, setting.value);
+  }
+  return settings_ir;
 }
 
 void OgHttp2Session::SendWindowUpdate(Http2StreamId stream_id,
diff --git a/http2/adapter/oghttp2_session.h b/http2/adapter/oghttp2_session.h
index 00d5f3e..3126e00 100644
--- a/http2/adapter/oghttp2_session.h
+++ b/http2/adapter/oghttp2_session.h
@@ -3,6 +3,8 @@
 
 #include <cstdint>
 #include <list>
+#include <memory>
+#include <vector>
 
 #include "absl/strings/string_view.h"
 #include "http2/adapter/data_source.h"
@@ -252,8 +254,14 @@
   // Queues the connection preface, if not already done.
   void MaybeSetupPreface();
 
-  // Fills the initial SETTINGS frame sent as part of the connection preface.
-  void FillInitialSettingsFrame(spdy::SpdySettingsIR& settings);
+  // Gets the settings to be sent in the initial SETTINGS frame sent as part of
+  // the connection preface.
+  std::vector<Http2Setting> GetInitialSettings() const;
+
+  // Prepares and returns a SETTINGS frame with the given `settings`.
+  // TODO(diannahu): Add the SETTINGS ack callback here.
+  std::unique_ptr<spdy::SpdySettingsIR> PrepareSettingsFrame(
+      absl::Span<const Http2Setting> settings);
 
   void SendWindowUpdate(Http2StreamId stream_id, size_t update_delta);