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..8d407a598a7f606a9a42bd445e392b9c0db11299 |
--- /dev/null |
+++ b/net/http/bidirectional_stream.h |
@@ -0,0 +1,155 @@ |
+// 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 "base/memory/scoped_ptr.h" |
+#include "net/base/request_priority.h" |
+#include "net/http/bidirectional_stream_job.h" |
+#include "net/http/http_stream_factory.h" |
+#include "net/ssl/ssl_config.h" |
+ |
+namespace net { |
+ |
+class BoundNetLog; |
+class HttpAuthController; |
+class HttpNetworkSession; |
+class HttpStream; |
+class HttpStreamRequest; |
+class IOBuffer; |
+class ProxyInfo; |
+struct HttpRequestInfo; |
+ |
+// A class to do HTTP/2 bidirectional streaming. Note that only one |
+// ReadData or SendData should be in flight until the operation completes |
+// synchronously or asynchronously. The BidirectionalStream must be torn down |
+// before the HttpNetworkSession. |
+class NET_EXPORT BidirectionalStream : public BidirectionalStreamJob::Delegate, |
+ public HttpStreamRequest::Delegate { |
+ public: |
+ // Delegate interface to get notified of success of failure. Callbacks will be |
+ // invoked asynchronously. |
+ // TODO(xunjieli): Surface the protocol negotiated. |
+ class NET_EXPORT 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. |
mef
2015/11/10 23:00:27
Is |status| indeed a net Error Code?
xunjieli
2015/11/13 23:41:44
Done. Yes. I modified the comment to make this cle
|
+ virtual void OnClose(int status) = 0; |
+ |
+ protected: |
+ virtual ~Delegate() {} |
+ |
+ private: |
+ DISALLOW_COPY_AND_ASSIGN(Delegate); |
+ }; |
+ |
+ // Parts of |request_info| are ignored (e.g. |upload_data_stream| and most |
+ // load flags). |
mef
2015/11/10 23:00:27
That's a good point, should we specify which load_
xunjieli
2015/11/13 23:41:44
I'd like to say all for now. But I don't really kn
|
+ BidirectionalStream(const HttpRequestInfo& request_info, |
+ RequestPriority priority, |
+ HttpNetworkSession* session, |
+ Delegate* delegate); |
+ |
+ // Destroys the helper and cancels any pending request. |
+ ~BidirectionalStream() override; |
+ |
+ // 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. |
mef
2015/11/10 23:00:27
Can this have more than one call in flight? If not
xunjieli
2015/11/13 23:41:45
Done.
|
+ int ReadData(IOBuffer* buf, int buf_len); |
+ |
+ // Sends data. This should not be called again until OnDataSent is invoked. |
+ void SendData(IOBuffer* data, int length, bool end_stream); |
+ |
+ // If there is |stream_request_|, cancel it. If |stream_| is established, |
+ // cancel it. |
+ void Cancel(); |
mef
2015/11/10 23:00:27
What if BidirectionalStream is deleted without bei
xunjieli
2015/11/13 23:41:44
Hmm.. Then we probably should call cancel in that
|
+ |
+ // TODO(xunjieli): implement a method to do flow control, and a method to ping |
+ // remote end point. |
+ |
+ private: |
+ // BidirectionalStreamJob::Delegate implementation: |
+ |
+ void OnFailed(Error error) override; |
+ |
+ void OnRequestHeadersSent() override; |
+ |
+ void OnHeaders(const SpdyHeaderBlock& response_headers) override; |
+ |
+ void OnReadCompleted(int bytes_read) override; |
+ |
+ void OnDataSent() override; |
+ |
+ void OnTrailers(const SpdyHeaderBlock& trailers) override; |
+ |
+ void OnClose(int status) override; |
+ |
+ // HttpStreamRequest::Delegate implementation: |
+ |
+ void OnStreamReady(const SSLConfig& used_ssl_config, |
+ const ProxyInfo& used_proxy_info, |
+ HttpStream* stream) override; |
+ void OnBidirectionalStreamJobReady(const SSLConfig& used_ssl_config, |
+ const ProxyInfo& used_proxy_info, |
+ BidirectionalStreamJob* stream) override; |
+ void OnWebSocketHandshakeStreamReady( |
+ const SSLConfig& used_ssl_config, |
+ const ProxyInfo& used_proxy_info, |
+ WebSocketHandshakeStreamBase* stream) override; |
+ void OnStreamFailed(int status, |
+ const SSLConfig& used_ssl_config, |
+ SSLFailureState ssl_failure_state) override; |
+ void OnCertificateError(int status, |
+ const SSLConfig& used_ssl_config, |
+ const SSLInfo& ssl_info) override; |
+ void OnNeedsProxyAuth(const HttpResponseInfo& response_info, |
+ const SSLConfig& used_ssl_config, |
+ const ProxyInfo& used_proxy_info, |
+ HttpAuthController* auth_controller) override; |
+ void OnNeedsClientAuth(const SSLConfig& used_ssl_config, |
+ SSLCertRequestInfo* cert_info) override; |
+ void OnHttpsProxyTunnelResponse(const HttpResponseInfo& response_info, |
+ const SSLConfig& used_ssl_config, |
+ const ProxyInfo& used_proxy_info, |
+ HttpStream* stream) override; |
+ |
+ const HttpRequestInfo request_info_; |
+ RequestPriority priority_; |
+ BoundNetLog net_log_; |
+ |
+ Delegate* delegate_; |
+ |
+ scoped_ptr<HttpStreamRequest> stream_request_; |
+ scoped_ptr<BidirectionalStreamJob> stream_; |
mef
2015/11/10 23:00:27
should this be called |stream_job_| to avoid confu
xunjieli
2015/11/13 23:41:44
Done.
|
+ |
+ DISALLOW_COPY_AND_ASSIGN(BidirectionalStream); |
+}; |
+ |
+} // namespace net |
+ |
+#endif // NET_HTTP_BIDIRECTIONAL_STREAM_H_ |