Chromium Code Reviews| 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..233c7701d45452ecfeca3eebaa473549d0cc5cc9 |
| --- /dev/null |
| +++ b/net/http/bidirectional_stream.h |
| @@ -0,0 +1,188 @@ |
| +// 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 <stdint.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/bidirectional_stream_request_info.h" |
| +#include "net/http/http_stream_factory.h" |
| +#include "net/ssl/ssl_config.h" |
| +#include "url/gurl.h" |
| + |
| +namespace net { |
| + |
| +class BoundNetLog; |
| +class HttpAuthController; |
| +class HttpNetworkSession; |
| +class HttpStream; |
| +class HttpStreamRequest; |
| +class IOBuffer; |
| +class ProxyInfo; |
| +class SpdyHeaderBlock; |
| + |
| +// A class to do HTTP/2 bidirectional streaming. Note that at most one each of |
| +// ReadData or SendData should be in flight until the operation completes |
|
mef
2015/12/15 22:59:40
nit: end with .
xunjieli
2015/12/16 00:26:09
Done.
|
| +// 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. |
| + class NET_EXPORT Delegate { |
| + public: |
| + Delegate() {} |
| + |
| + // Called when headers have been sent. This is called at most once for |
| + // the lifetime of a stream. |
| + // The delegate may call BidirectionalStreamJob::SendData to start |
| + // sending data. |
|
mef
2015/12/15 22:59:39
or call BidirectionalStream::Cancel to cancel the
xunjieli
2015/12/16 00:26:09
It's illegal to call Cancel during OnHeadersSent o
|
| + virtual void OnHeadersSent() = 0; |
| + |
| + // Called when headers are received. This is called at most once for the |
| + // lifetime of a stream. |
| + // The delegate may call BidirectionalStream::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. |
|
mef
2015/12/15 22:59:40
read -> pending read
is available -> is read.
xunjieli
2015/12/16 00:26:09
Done.
|
| + // The delegate may call BidirectionalStream::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. |
|
mef
2015/12/15 22:59:40
Update comment similarly to OnDataRead().
xunjieli
2015/12/16 00:26:09
Done.
|
| + virtual void OnDataSent() = 0; |
| + |
| + // Called when trailers are received. This is called as soon as trailers |
| + // are received, which can happen before a read completes. |
|
mef
2015/12/15 22:59:40
Maybe clarify that no action is required from the
xunjieli
2015/12/16 00:26:08
Done.
|
| + virtual void OnTrailersReceived(const SpdyHeaderBlock& trailers) = 0; |
| + |
| + // Called when the stream is closed or an error occurred. |
| + // No other delegate functions will be called after this. |
| + virtual void OnFailed(int error) = 0; |
| + |
| + protected: |
| + virtual ~Delegate() {} |
|
mef
2015/12/15 22:59:40
Should {} go into .cc file?
xunjieli
2015/12/16 00:26:09
Done. Good catch. Thanks!
|
| + |
| + private: |
| + DISALLOW_COPY_AND_ASSIGN(Delegate); |
| + }; |
| + |
| + BidirectionalStream(const BidirectionalStreamRequestInfo& request_info, |
|
mef
2015/12/15 22:59:40
need comment, especially considering that this is
xunjieli
2015/12/16 00:26:09
Done.
|
| + RequestPriority priority, |
| + HttpNetworkSession* session, |
| + Delegate* delegate); |
| + |
| + // Constructor that accepts a Timer, which can be used in tests to control |
| + // the buffering of received data. |
| + BidirectionalStream(const BidirectionalStreamRequestInfo& request_info, |
|
mef
2015/12/15 22:59:39
FWIW HttpStream-related classes pass request_info
xunjieli
2015/12/16 00:26:08
Done.
|
| + RequestPriority priority, |
| + HttpNetworkSession* session, |
| + Delegate* delegate, |
| + scoped_ptr<base::Timer> timer); |
| + |
| + // Cancels |stream_request_| or |stream_job_| if applicable. |
| + // |this| should not be destroyed during Delegate::OnHeadersSent or |
|
mef
2015/12/15 22:59:40
That's an interesting comment. Why not? Do we need
xunjieli
2015/12/16 00:26:08
It's illegal to call Cancel during OnHeadersSent o
mef
2015/12/16 20:24:40
Acknowledged. This should not be a problem for Cro
|
| + // Delegate::OnDataSent. |
| + ~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, or an |
| + // error code if any error occurred. |
| + // This should not be called before Delegate::OnHeadersSent is invoked, and |
|
mef
2015/12/15 22:59:40
OnHeadersSent -> OnHeadersReceived?
xunjieli
2015/12/16 00:26:09
Done.
|
| + // should not be called again unless it IO completes synchronously or until |
|
mef
2015/12/15 22:59:39
IO completes -> returns
xunjieli
2015/12/16 00:26:09
Done.
|
| + // Delegate::OnDataRead is invoked. |
| + int ReadData(IOBuffer* buf, int buf_len); |
| + |
| + // Sends data. This should not be called before Delegate::OnHeadersSent is |
| + // invoked, and should not be called again until Delegate::OnDataSent is |
| + // invoked. |
| + void SendData(IOBuffer* data, int length, bool end_stream); |
| + |
| + // If there is |stream_request_|, cancel it. If |stream_job_| is established, |
| + // cancel it. No delegate method will be called after Cancel(). |
| + // Any pending operations may or may not succeed. |
| + void Cancel(); |
| + |
| + // Getters that should only be called after Delegate::OnHeadersSent: |
| + |
| + // Returns the protocol used by this stream. If stream has not been |
| + // stablished, return kProtoUnknown. |
|
mef
2015/12/15 22:59:40
established (here and below).
xunjieli
2015/12/16 00:26:08
Done.
|
| + NextProto GetProtocol() const; |
| + |
| + // 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. |
| + // If stream has not been stablished, return 0. |
| + int64_t GetTotalReceivedBytes() const; |
| + |
| + // 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. |
| + int64_t GetTotalSentBytes() const; |
| + |
| + // TODO(xunjieli): Implement a method to do flow control and a method to ping |
| + // remote end point. |
| + |
| + private: |
| + // BidirectionalStreamJob::Delegate implementation: |
| + void OnHeadersSent() override; |
| + void OnHeadersReceived(const SpdyHeaderBlock& response_headers) override; |
| + void OnDataRead(int bytes_read) override; |
| + void OnDataSent() override; |
| + void OnTrailersReceived(const SpdyHeaderBlock& trailers) override; |
| + void OnFailed(int error) 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; |
| + void OnQuicBroken() override; |
| + |
| + const BidirectionalStreamRequestInfo request_info_; |
|
mef
2015/12/15 22:59:40
can this be a scoped_ptr<BidirectionalStreamReques
xunjieli
2015/12/16 00:26:09
Done. I think it should take a raw pointer. Whoeve
mef
2015/12/16 20:24:40
Excellent, sgtm!
|
| + const RequestPriority priority_; |
| + const BoundNetLog net_log_; |
| + |
| + Delegate* const delegate_; |
| + |
| + scoped_ptr<base::Timer> timer_; |
| + scoped_ptr<HttpStreamRequest> stream_request_; |
| + scoped_ptr<BidirectionalStreamJob> stream_job_; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(BidirectionalStream); |
| +}; |
| + |
| +} // namespace net |
| + |
| +#endif // NET_HTTP_BIDIRECTIONAL_STREAM_H_ |