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

Unified Diff: net/http/bidirectional_stream.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: Make the wrapper class own the stream Created 5 years, 2 months 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
« no previous file with comments | « no previous file | net/http/bidirectional_stream.cc » ('j') | net/http/bidirectional_stream_helper.h » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: net/http/bidirectional_stream.h
diff --git a/net/http/bidirectional_stream.h b/net/http/bidirectional_stream.h
new file mode 100644
index 0000000000000000000000000000000000000000..470e6710017629929702dbfdc82dc8bcb5d4ba33
--- /dev/null
+++ b/net/http/bidirectional_stream.h
@@ -0,0 +1,89 @@
+// 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_H_
+#define NET_HTTP_BIDIRECTIONAL_STREAM_H_
+
+#include "base/macros.h"
+#include "net/base/net_export.h"
+#include "net/base/request_priority.h"
+#include "net/http/http_request_info.h"
+#include "net/spdy/spdy_session.h"
+#include "net/spdy/spdy_stream.h"
+
+namespace net {
+
+struct HttpRequestInfo;
+class IOBuffer;
+class BoundNetLog;
+
+// An interface that exposes bidirectional streaming. Note that only one
+// ReadData or SendData should be in flight until the operation completes
+// synchronously or asynchronously.
+class NET_EXPORT BidirectionalStream {
mmenke 2015/11/03 20:32:13 NET_EXPORT_PRIVATE (You'll need to make the helper
xunjieli 2015/11/05 23:17:13 Done.
+ public:
+ // Delegate to handle BidirectionalStream events.
+ class Delegate {
+ public:
+ Delegate();
+
+ // Called when an error occurs. E.g. when a connection to the server cannot
+ // be established.
+ virtual void OnFailed(int error) = 0;
mef 2015/11/04 20:13:53 UrlRequest has a status() method. Does this callba
mmenke 2015/11/04 20:42:41 This and knowledge of whether you're waiting on it
+
+ // Called when the request headers have been sent.
+ virtual void OnRequestHeadersSent() = 0;
mef 2015/11/04 20:13:53 We need to add something like HttpResponseInfo, wi
xunjieli 2015/11/05 23:17:13 Acknowledged. Added as a TODO.
+
+ // Called when response headers are received.
+ virtual void OnHeaders(const SpdyHeaderBlock& response_headers) = 0;
mef 2015/11/02 18:00:42 Is this called only once or could it happen multip
mef 2015/11/04 20:13:53 Is there some way to get Http status code at this
xunjieli 2015/11/05 23:17:13 Yes, we can get it from the header ":status"
xunjieli 2015/11/05 23:17:13 It's called once. I've added comment.
+
+ // Called when read is completed asynchronously. |bytes_read| specifies how
+ // much data is available.
+ virtual void OnReadCompleted(int bytes_read) = 0;
mef 2015/11/04 20:13:52 Is there some way to get running received bytes co
xunjieli 2015/11/05 23:17:13 This byte count here is pre-decompression. We can
+
+ // Called when the entire buffer passed through SendData is sent.
+ virtual void OnDataSent() = 0;
+
+ // Called when trailers are received.
+ virtual void OnTrailers(const SpdyHeaderBlock& trailers) = 0;
+
+ // Called when the stream is closed. No other delegate functions will be
+ // called after this. |status| is an error code or OK.
+ virtual void OnClose(int status) = 0;
+
+ protected:
+ virtual ~Delegate();
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(Delegate);
+ };
+
+ BidirectionalStream();
+ virtual ~BidirectionalStream();
+
+ // Starts the BidirectionalStream 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,
+ // or ERR_IO_PENDING if the read is to be completed asynchronously.
+ virtual int ReadData(IOBuffer* buf, int buf_len) = 0;
+
+ // Sends data. This should not be called again until OnDataSent is invoked.
+ virtual void SendData(IOBuffer* data, int length, bool end_stream) = 0;
+
+ // Cancels the stream. No Delegate method will be called.
+ virtual void Cancel() = 0;
+
+ // TODO(xunjieli): implement a method to do flow control.
mef 2015/11/02 18:00:42 We also need a method for ping, but fine to have i
xunjieli 2015/11/05 23:17:13 Acknowledged.
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(BidirectionalStream);
+};
+
+} // namespace net
+
+#endif // NET_HTTP_BIDIRECTIONAL_STREAM_H_
« no previous file with comments | « no previous file | net/http/bidirectional_stream.cc » ('j') | net/http/bidirectional_stream_helper.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698