Adds comments, updates data provider utilities.

PiperOrigin-RevId: 375475271
diff --git a/http2/adapter/data_source.h b/http2/adapter/data_source.h
index 768a412..5658bfd 100644
--- a/http2/adapter/data_source.h
+++ b/http2/adapter/data_source.h
@@ -18,12 +18,13 @@
   static constexpr ssize_t kError = -1;
 
   // Returns the number of bytes to send in the next DATA frame, and whether
-  // this frame indicates the end of the data. Returns kBlocked if blocked,
-  // kError on error.
+  // this frame indicates the end of the data. Returns {kBlocked, false} if
+  // blocked, {kError, false} on error.
   virtual std::pair<ssize_t, bool> SelectPayloadLength(size_t max_length) = 0;
 
   // This method is called with a frame header and a payload length to send. The
   // source should send or buffer the entire frame.
+  // TODO(birenroy): Consider adding a return value to indicate write blockage.
   virtual void Send(absl::string_view frame_header, size_t payload_length) = 0;
 
   // If true, the end of this data source indicates the end of the stream.
diff --git a/http2/adapter/nghttp2_callbacks.cc b/http2/adapter/nghttp2_callbacks.cc
index c3e1dc8..5b8a3c5 100644
--- a/http2/adapter/nghttp2_callbacks.cc
+++ b/http2/adapter/nghttp2_callbacks.cc
@@ -6,6 +6,7 @@
 #include "absl/strings/string_view.h"
 #include "http2/adapter/http2_protocol.h"
 #include "http2/adapter/http2_visitor_interface.h"
+#include "http2/adapter/nghttp2_data_provider.h"
 #include "http2/adapter/nghttp2_util.h"
 #include "third_party/nghttp2/nghttp2.h"
 #include "third_party/nghttp2/src/lib/includes/nghttp2/nghttp2.h"
@@ -218,6 +219,8 @@
                                                             &OnDataChunk);
   nghttp2_session_callbacks_set_on_stream_close_callback(callbacks,
                                                          &OnStreamClosed);
+  nghttp2_session_callbacks_set_send_data_callback(
+      callbacks, &DataFrameSourceSendCallback);
   return MakeCallbacksPtr(callbacks);
 }
 
diff --git a/http2/adapter/nghttp2_data_provider.cc b/http2/adapter/nghttp2_data_provider.cc
index 0a7850e..7a70965 100644
--- a/http2/adapter/nghttp2_data_provider.cc
+++ b/http2/adapter/nghttp2_data_provider.cc
@@ -5,8 +5,11 @@
 
 namespace http2 {
 namespace adapter {
+namespace callbacks {
 
+namespace {
 const size_t kFrameHeaderSize = 9;
+}
 
 ssize_t DataFrameSourceReadCallback(nghttp2_session* /* session */,
                                     int32_t /* stream_id */,
@@ -43,10 +46,16 @@
   return 0;
 }
 
-nghttp2_data_provider MakeDataProvider(DataFrameSource* source) {
-  nghttp2_data_provider provider;
-  provider.source.ptr = source;
-  provider.read_callback = &DataFrameSourceReadCallback;
+}  // namespace callbacks
+
+std::unique_ptr<nghttp2_data_provider> MakeDataProvider(
+    DataFrameSource* source) {
+  if (source == nullptr) {
+    return nullptr;
+  }
+  auto provider = absl::make_unique<nghttp2_data_provider>();
+  provider->source.ptr = source;
+  provider->read_callback = &callbacks::DataFrameSourceReadCallback;
   return provider;
 }
 
diff --git a/http2/adapter/nghttp2_data_provider.h b/http2/adapter/nghttp2_data_provider.h
index d4315f1..241bab9 100644
--- a/http2/adapter/nghttp2_data_provider.h
+++ b/http2/adapter/nghttp2_data_provider.h
@@ -6,6 +6,7 @@
 
 namespace http2 {
 namespace adapter {
+namespace callbacks {
 
 // Assumes |source| is a DataFrameSource.
 ssize_t DataFrameSourceReadCallback(nghttp2_session* /*session */,
@@ -23,8 +24,12 @@
                                 nghttp2_data_source* source,
                                 void* /* user_data */);
 
-// Does not take ownership of |source|.
-nghttp2_data_provider MakeDataProvider(DataFrameSource* source);
+}  // namespace callbacks
+
+// Transforms a DataFrameSource into a nghttp2_data_provider. Does not take
+// ownership of |source|. Returns nullptr if |source| is nullptr.
+std::unique_ptr<nghttp2_data_provider> MakeDataProvider(
+    DataFrameSource* source);
 
 }  // namespace adapter
 }  // namespace http2
diff --git a/http2/adapter/oghttp2_session.h b/http2/adapter/oghttp2_session.h
index 39f4cdc..bb58085 100644
--- a/http2/adapter/oghttp2_session.h
+++ b/http2/adapter/oghttp2_session.h
@@ -121,15 +121,34 @@
     Http2StreamId stream_id_ = 0;
   };
 
+  // Receives events when inbound frames are parsed.
   Http2VisitorInterface& visitor_;
+
+  // Encodes outbound frames.
   spdy::SpdyFramer framer_{spdy::SpdyFramer::ENABLE_COMPRESSION};
+
+  // Decodes inbound frames.
   http2::Http2DecoderAdapter decoder_;
+
+  // Maintains the state of all streams known to this session.
   absl::flat_hash_map<Http2StreamId, StreamState> stream_map_;
+
+  // Maintains the queue of outbound frames, and any serialized bytes that have
+  // not yet been consumed.
   std::list<std::unique_ptr<spdy::SpdyFrameIR>> frames_;
-  PassthroughHeadersHandler headers_handler_;
   std::string serialized_prefix_;
+
+  // Delivers header name-value pairs to the visitor.
+  PassthroughHeadersHandler headers_handler_;
+
+  // Tracks the remaining client connection preface, in the case of a server
+  // session.
   absl::string_view remaining_preface_;
+
+  Http2StreamId next_stream_id_ = 1;
   int peer_window_ = 65535;
+  int stream_receive_window_limit_ = 65535;
+  int max_frame_payload_ = 16384;
   Options options_;
   bool received_goaway_ = false;
 };