Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef NET_HTTP_BIDIRECTIONAL_STREAM_H_ | 5 #ifndef NET_HTTP_BIDIRECTIONAL_STREAM_H_ |
| 6 #define NET_HTTP_BIDIRECTIONAL_STREAM_H_ | 6 #define NET_HTTP_BIDIRECTIONAL_STREAM_H_ |
| 7 | 7 |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include "base/compiler_specific.h" | 10 #include "base/compiler_specific.h" |
| 11 #include "base/macros.h" | 11 #include "base/macros.h" |
| 12 #include "base/memory/scoped_ptr.h" | 12 #include "base/memory/scoped_ptr.h" |
| 13 #include "net/http/bidirectional_stream_job.h" | 13 #include "net/http/bidirectional_stream_impl.h" |
| 14 #include "net/http/http_stream_factory.h" | 14 #include "net/http/http_stream_factory.h" |
| 15 #include "net/log/net_log.h" | 15 #include "net/log/net_log.h" |
| 16 | 16 |
| 17 class GURL; | 17 class GURL; |
| 18 | 18 |
| 19 namespace net { | 19 namespace net { |
| 20 | 20 |
| 21 class HttpAuthController; | 21 class HttpAuthController; |
| 22 class HttpNetworkSession; | 22 class HttpNetworkSession; |
| 23 class HttpStream; | 23 class HttpStream; |
| 24 class HttpStreamRequest; | 24 class HttpStreamRequest; |
| 25 class IOBuffer; | 25 class IOBuffer; |
| 26 class ProxyInfo; | 26 class ProxyInfo; |
| 27 class SpdyHeaderBlock; | 27 class SpdyHeaderBlock; |
| 28 struct BidirectionalStreamRequestInfo; | 28 struct BidirectionalStreamRequestInfo; |
| 29 struct SSLConfig; | 29 struct SSLConfig; |
| 30 | 30 |
| 31 // A class to do HTTP/2 bidirectional streaming. Note that at most one each of | 31 // A class to do HTTP/2 bidirectional streaming. Note that at most one each of |
| 32 // ReadData or SendData should be in flight until the operation completes. | 32 // ReadData or SendData should be in flight until the operation completes. |
| 33 // The BidirectionalStream must be torn down before the HttpNetworkSession. | 33 // The BidirectionalStream must be torn down before the HttpNetworkSession. |
| 34 class NET_EXPORT BidirectionalStream | 34 class NET_EXPORT BidirectionalStream |
| 35 : public NON_EXPORTED_BASE(BidirectionalStreamJob::Delegate), | 35 : public NON_EXPORTED_BASE(BidirectionalStreamImpl::Delegate), |
| 36 public NON_EXPORTED_BASE(HttpStreamRequest::Delegate) { | 36 public NON_EXPORTED_BASE(HttpStreamRequest::Delegate) { |
| 37 public: | 37 public: |
| 38 // Delegate interface to get notified of success of failure. Callbacks will be | 38 // Delegate interface to get notified of success of failure. Callbacks will be |
| 39 // invoked asynchronously. | 39 // invoked asynchronously. |
| 40 class NET_EXPORT Delegate { | 40 class NET_EXPORT Delegate { |
| 41 public: | 41 public: |
| 42 Delegate(); | 42 Delegate(); |
| 43 | 43 |
| 44 // Called when headers have been sent. This is called at most once for | 44 // Called when headers have been sent. This is called at most once for |
| 45 // the lifetime of a stream. | 45 // the lifetime of a stream. |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 95 HttpNetworkSession* session, | 95 HttpNetworkSession* session, |
| 96 Delegate* delegate); | 96 Delegate* delegate); |
| 97 | 97 |
| 98 // Constructor that accepts a Timer, which can be used in tests to control | 98 // Constructor that accepts a Timer, which can be used in tests to control |
| 99 // the buffering of received data. | 99 // the buffering of received data. |
| 100 BidirectionalStream(scoped_ptr<BidirectionalStreamRequestInfo> request_info, | 100 BidirectionalStream(scoped_ptr<BidirectionalStreamRequestInfo> request_info, |
| 101 HttpNetworkSession* session, | 101 HttpNetworkSession* session, |
| 102 Delegate* delegate, | 102 Delegate* delegate, |
| 103 scoped_ptr<base::Timer> timer); | 103 scoped_ptr<base::Timer> timer); |
| 104 | 104 |
| 105 // Cancels |stream_request_| or |stream_job_| if applicable. | 105 // Cancels |stream_request_| or |stream_impl_| if applicable. |
| 106 // |this| should not be destroyed during Delegate::OnHeadersSent or | 106 // |this| should not be destroyed during Delegate::OnHeadersSent or |
| 107 // Delegate::OnDataSent. | 107 // Delegate::OnDataSent. |
| 108 ~BidirectionalStream() override; | 108 ~BidirectionalStream() override; |
| 109 | 109 |
| 110 // Reads at most |buf_len| bytes into |buf|. Returns the number of bytes read, | 110 // Reads at most |buf_len| bytes into |buf|. Returns the number of bytes read, |
| 111 // or ERR_IO_PENDING if the read is to be completed asynchronously, or an | 111 // or ERR_IO_PENDING if the read is to be completed asynchronously, or an |
| 112 // error code if any error occurred. If returns 0, there is no more data to | 112 // error code if any error occurred. If returns 0, there is no more data to |
| 113 // read. This should not be called before Delegate::OnHeadersReceived is | 113 // read. This should not be called before Delegate::OnHeadersReceived is |
| 114 // invoked, and should not be called again unless it returns with number | 114 // invoked, and should not be called again unless it returns with number |
| 115 // greater than 0 or until Delegate::OnDataRead is invoked. | 115 // greater than 0 or until Delegate::OnDataRead is invoked. |
| 116 int ReadData(IOBuffer* buf, int buf_len); | 116 int ReadData(IOBuffer* buf, int buf_len); |
| 117 | 117 |
| 118 // Sends data. This should not be called before Delegate::OnHeadersSent is | 118 // Sends data. This should not be called before Delegate::OnHeadersSent is |
| 119 // invoked, and should not be called again until Delegate::OnDataSent is | 119 // invoked, and should not be called again until Delegate::OnDataSent is |
| 120 // invoked. If |end_stream| is true, the DATA frame will have an END_STREAM | 120 // invoked. If |end_stream| is true, the DATA frame will have an END_STREAM |
| 121 // flag. | 121 // flag. |
| 122 void SendData(IOBuffer* data, int length, bool end_stream); | 122 void SendData(IOBuffer* data, int length, bool end_stream); |
| 123 | 123 |
| 124 // If |stream_request_| is non-NULL, cancel it. If |stream_job_| is | 124 // If |stream_request_| is non-NULL, cancel it. If |stream_impl_| is |
| 125 // established, cancel it. No delegate method will be called after Cancel(). | 125 // established, cancel it. No delegate method will be called after Cancel(). |
| 126 // Any pending operations may or may not succeed. | 126 // Any pending operations may or may not succeed. |
| 127 void Cancel(); | 127 void Cancel(); |
| 128 | 128 |
| 129 // Returns the protocol used by this stream. If stream has not been | 129 // Returns the protocol used by this stream. If stream has not been |
| 130 // established, return kProtoUnknown. | 130 // established, return kProtoUnknown. |
| 131 NextProto GetProtocol() const; | 131 NextProto GetProtocol() const; |
| 132 | 132 |
| 133 // Total number of bytes received over the network of SPDY data, headers, and | 133 // Total number of bytes received over the network of SPDY data, headers, and |
| 134 // push_promise frames associated with this stream, including the size of | 134 // push_promise frames associated with this stream, including the size of |
| 135 // frame headers, after SSL decryption and not including proxy overhead. | 135 // frame headers, after SSL decryption and not including proxy overhead. |
| 136 // If stream has not been established, return 0. | 136 // If stream has not been established, return 0. |
| 137 int64_t GetTotalReceivedBytes() const; | 137 int64_t GetTotalReceivedBytes() const; |
| 138 | 138 |
| 139 // Total number of bytes sent over the network of SPDY frames associated with | 139 // Total number of bytes sent over the network of SPDY frames associated with |
| 140 // this stream, including the size of frame headers, before SSL encryption and | 140 // this stream, including the size of frame headers, before SSL encryption and |
| 141 // not including proxy overhead. Note that some SPDY frames such as pings are | 141 // not including proxy overhead. Note that some SPDY frames such as pings are |
| 142 // not associated with any stream, and are not included in this value. | 142 // not associated with any stream, and are not included in this value. |
| 143 int64_t GetTotalSentBytes() const; | 143 int64_t GetTotalSentBytes() const; |
| 144 | 144 |
| 145 // TODO(xunjieli): Implement a method to do flow control and a method to ping | 145 // TODO(xunjieli): Implement a method to do flow control and a method to ping |
| 146 // remote end point. | 146 // remote end point. |
| 147 | 147 |
| 148 private: | 148 private: |
| 149 // BidirectionalStreamJob::Delegate implementation: | 149 // BidirectionalStreamImpl::Delegate implementation: |
| 150 void OnHeadersSent() override; | 150 void OnHeadersSent() override; |
| 151 void OnHeadersReceived(const SpdyHeaderBlock& response_headers) override; | 151 void OnHeadersReceived(const SpdyHeaderBlock& response_headers) override; |
| 152 void OnDataRead(int bytes_read) override; | 152 void OnDataRead(int bytes_read) override; |
| 153 void OnDataSent() override; | 153 void OnDataSent() override; |
| 154 void OnTrailersReceived(const SpdyHeaderBlock& trailers) override; | 154 void OnTrailersReceived(const SpdyHeaderBlock& trailers) override; |
| 155 void OnFailed(int error) override; | 155 void OnFailed(int error) override; |
| 156 | 156 |
| 157 // HttpStreamRequest::Delegate implementation: | 157 // HttpStreamRequest::Delegate implementation: |
| 158 void OnStreamReady(const SSLConfig& used_ssl_config, | 158 void OnStreamReady(const SSLConfig& used_ssl_config, |
| 159 const ProxyInfo& used_proxy_info, | 159 const ProxyInfo& used_proxy_info, |
| 160 HttpStream* stream) override; | 160 HttpStream* stream) override; |
| 161 void OnBidirectionalStreamJobReady(const SSLConfig& used_ssl_config, | 161 void OnBidirectionalStreamImplReady(const SSLConfig& used_ssl_config, |
| 162 const ProxyInfo& used_proxy_info, | 162 const ProxyInfo& used_proxy_info, |
| 163 BidirectionalStreamJob* stream) override; | 163 BidirectionalStreamImpl* stream) override; |
|
mef
2016/03/21 22:00:43
should this param be called |stream_impl|?
xunjieli
2016/03/22 15:24:24
Done.
| |
| 164 void OnWebSocketHandshakeStreamReady( | 164 void OnWebSocketHandshakeStreamReady( |
| 165 const SSLConfig& used_ssl_config, | 165 const SSLConfig& used_ssl_config, |
| 166 const ProxyInfo& used_proxy_info, | 166 const ProxyInfo& used_proxy_info, |
| 167 WebSocketHandshakeStreamBase* stream) override; | 167 WebSocketHandshakeStreamBase* stream) override; |
| 168 void OnStreamFailed(int status, | 168 void OnStreamFailed(int status, |
| 169 const SSLConfig& used_ssl_config, | 169 const SSLConfig& used_ssl_config, |
| 170 SSLFailureState ssl_failure_state) override; | 170 SSLFailureState ssl_failure_state) override; |
| 171 void OnCertificateError(int status, | 171 void OnCertificateError(int status, |
| 172 const SSLConfig& used_ssl_config, | 172 const SSLConfig& used_ssl_config, |
| 173 const SSLInfo& ssl_info) override; | 173 const SSLInfo& ssl_info) override; |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 185 | 185 |
| 186 // BidirectionalStreamRequestInfo used when requesting the stream. | 186 // BidirectionalStreamRequestInfo used when requesting the stream. |
| 187 scoped_ptr<BidirectionalStreamRequestInfo> request_info_; | 187 scoped_ptr<BidirectionalStreamRequestInfo> request_info_; |
| 188 const BoundNetLog net_log_; | 188 const BoundNetLog net_log_; |
| 189 | 189 |
| 190 Delegate* const delegate_; | 190 Delegate* const delegate_; |
| 191 | 191 |
| 192 // Timer used to buffer data received in short time-spans and send a single | 192 // Timer used to buffer data received in short time-spans and send a single |
| 193 // read completion notification. | 193 // read completion notification. |
| 194 scoped_ptr<base::Timer> timer_; | 194 scoped_ptr<base::Timer> timer_; |
| 195 // HttpStreamRequest used to request a BidirectionalStreamJob. This is NULL if | 195 // HttpStreamRequest used to request a BidirectionalStreamImpl. This is NULL |
| 196 // the request has been canceled or completed. | 196 // if the request has been canceled or completed. |
| 197 scoped_ptr<HttpStreamRequest> stream_request_; | 197 scoped_ptr<HttpStreamRequest> stream_request_; |
| 198 // The underlying BidirectioanlStreamJob used for this stream. It is non-NULL, | 198 // The underlying BidirectioanlStreamJob used for this stream. It is non-NULL, |
|
mef
2016/03/21 22:00:43
BidirectionalStreamImpl
xunjieli
2016/03/22 15:24:24
Done.
| |
| 199 // if the |stream_request_| successfully finishes. | 199 // if the |stream_request_| successfully finishes. |
| 200 scoped_ptr<BidirectionalStreamJob> stream_job_; | 200 scoped_ptr<BidirectionalStreamImpl> stream_impl_; |
| 201 | 201 |
| 202 DISALLOW_COPY_AND_ASSIGN(BidirectionalStream); | 202 DISALLOW_COPY_AND_ASSIGN(BidirectionalStream); |
| 203 }; | 203 }; |
| 204 | 204 |
| 205 } // namespace net | 205 } // namespace net |
| 206 | 206 |
| 207 #endif // NET_HTTP_BIDIRECTIONAL_STREAM_H_ | 207 #endif // NET_HTTP_BIDIRECTIONAL_STREAM_H_ |
| OLD | NEW |