Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(855)

Unified Diff: net/http/bidirectional_stream_job.h

Issue 1326503003: Added a net::BidirectionalStream to expose a bidirectional streaming interface (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address Matt's comments Created 5 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: net/http/bidirectional_stream_job.h
diff --git a/net/http/bidirectional_stream_job.h b/net/http/bidirectional_stream_job.h
new file mode 100644
index 0000000000000000000000000000000000000000..2e9afa7c3de3ad1461e694b09484325caf493b90
--- /dev/null
+++ b/net/http/bidirectional_stream_job.h
@@ -0,0 +1,114 @@
+// Copyright 2015 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef NET_HTTP_BIDIRECTIONAL_STREAM_JOB_H_
+#define NET_HTTP_BIDIRECTIONAL_STREAM_JOB_H_
+
+#include "base/basictypes.h"
mmenke 2015/12/11 22:19:58 nit: Not needed.
xunjieli 2015/12/11 23:48:40 Done.
+#include "base/macros.h"
+#include "net/base/net_export.h"
+#include "net/base/request_priority.h"
+#include "net/socket/next_proto.h"
+
+namespace net {
+
+class BoundNetLog;
+class IOBuffer;
+class SpdyHeaderBlock;
+struct HttpRequestInfo;
+
+// Exposes an interface to do HTTP/2 bidirectional streaming.
+// Note that only one ReadData or SendData should be in flight until the
+// operation completes synchronously or asynchronously.
+// BidirectionalStreamJob once created by HttpStreamFactoryImpl should be owned
+// by BidirectionalStream.
+class NET_EXPORT_PRIVATE BidirectionalStreamJob {
+ public:
+ // Delegate to handle BidirectionalStreamJob events.
+ class Delegate {
+ public:
+ Delegate();
+
+ // Called when the request headers have been sent.
+ // The delegate may call BidirectionalStreamJob::SendData to start
+ // sending data.
+ virtual void OnHeadersSent() = 0;
+
+ // Called when response headers are received.
+ // This is called at most once for the lifetime of a stream.
+ // The delegate may call BidirectionalStreamJob::ReadData to start
+ // reading or call BidirectionalStream::Cancel to cancel the stream.
+ virtual void OnHeadersReceived(const SpdyHeaderBlock& response_headers) = 0;
+
+ // Called when read is completed asynchronously. |bytes_read| specifies how
+ // much data is available.
+ // The delegate may call BidirectionalStreamJob::ReadData to continue
+ // reading or call BidirectionalStream::Cancel to cancel the stream.
+ virtual void OnDataRead(int bytes_read) = 0;
+
+ // Called when the entire buffer passed through SendData is sent.
+ virtual void OnDataSent() = 0;
+
+ // Called when trailers are received.
+ virtual void OnTrailersReceived(const SpdyHeaderBlock& trailers) = 0;
+
+ // Called when an error occurred.
+ // No other delegate functions will be called after this.
+ virtual void OnFailed(int status) = 0;
+
+ protected:
+ virtual ~Delegate();
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(Delegate);
+ };
+
+ BidirectionalStreamJob();
+ virtual ~BidirectionalStreamJob();
+
+ // Starts the BidirectionalStreamJob and sends request headers.
+ virtual void Start(const HttpRequestInfo& request_info,
+ RequestPriority priority,
+ const BoundNetLog& net_log,
+ Delegate* delegate) = 0;
+
+ // Reads at most |buf_len| bytes into |buf|. Returns the number of bytes read,
+ // ERR_IO_PENDING if the read is to be completed asynchronously, or an error
+ // code if any error occurred.
+ // This should not be called before Delegate::OnHeadersSent is invoked, and
+ // should not be called again unless it IO completes synchronously or until
+ // Delegate::OnDataRead is invoked.
+ virtual int ReadData(IOBuffer* buf, int buf_len) = 0;
+
+ // Sends data. This should not be called be called before
+ // Delegate::OnHeadersSent is invoked, and should not be called again until
+ // Delegate::OnDataSent is invoked.
+ virtual void SendData(IOBuffer* data, int length, bool end_stream) = 0;
+
+ // Cancels the stream. No Delegate method will be called. Any pending
+ // operations may or may not succeed.
+ virtual void Cancel() = 0;
+
+ // Returns the protocol used by this stream. Always between
+ // kProtoSPDYMinimumVersion and kProtoSPDYMaximumVersion.
+ virtual NextProto GetProtocol() const = 0;
+
+ // Total number of bytes received over the network of SPDY data, headers, and
+ // push_promise frames associated with this stream, including the size of
+ // frame headers, after SSL decryption and not including proxy overhead.
+ virtual int64_t GetTotalReceivedBytes() const = 0;
+
+ // Total number of bytes sent over the network of SPDY frames associated with
+ // this stream, including the size of frame headers, before SSL encryption and
+ // not including proxy overhead. Note that some SPDY frames such as pings are
+ // not associated with any stream, and are not included in this value.
+ virtual int64_t GetTotalSentBytes() const = 0;
mmenke 2015/12/11 22:19:58 include <stdint.h>
xunjieli 2015/12/11 23:48:40 Done.
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(BidirectionalStreamJob);
+};
+
+} // namespace net
+
+#endif // NET_HTTP_BIDIRECTIONAL_STREAM_JOB_H_

Powered by Google App Engine
This is Rietveld 408576698