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

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: Rebased Created 5 years, 1 month 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..79fccf3e3163ae6e059ffb400981bb0058bc08f8
--- /dev/null
+++ b/net/http/bidirectional_stream_job.h
@@ -0,0 +1,85 @@
+// 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/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.
mef 2015/11/10 23:00:27 Maybe add a comment about lifetime scenarios that
xunjieli 2015/11/13 23:41:45 I am not very sure what the lifetime scenarios you
xunjieli 2015/11/25 16:58:58 Done.
+class NET_EXPORT_PRIVATE BidirectionalStreamJob {
+ public:
+ // Delegate to handle BidirectionalStreamJob events.
+ class Delegate {
+ public:
+ Delegate();
+
+ // Called when an error occurs. E.g. when a connection to the server cannot
+ // be established.
+ virtual void OnFailed(Error error) = 0;
+
+ // Called when the request headers have been sent.
+ virtual void OnRequestHeadersSent() = 0;
+
+ // Called when response headers are received.
+ virtual void OnHeaders(const SpdyHeaderBlock& response_headers) = 0;
+
+ // Called when read is completed asynchronously. |bytes_read| specifies how
+ // much data is available.
+ virtual void OnReadCompleted(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 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);
+ };
+
+ 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,
+ // 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;
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(BidirectionalStreamJob);
+};
+
+} // namespace net
+
+#endif // NET_HTTP_BIDIRECTIONAL_STREAM_JOB_H_

Powered by Google App Engine
This is Rietveld 408576698