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 <memory> | 10 #include <memory> |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 43 class NET_EXPORT Delegate { | 43 class NET_EXPORT Delegate { |
| 44 public: | 44 public: |
| 45 Delegate(); | 45 Delegate(); |
| 46 | 46 |
| 47 // Called when the stream is ready for writing and reading. This is called | 47 // Called when the stream is ready for writing and reading. This is called |
| 48 // at most once for the lifetime of a stream. | 48 // at most once for the lifetime of a stream. |
| 49 // The delegate may call BidirectionalStream::ReadData to start reading, | 49 // The delegate may call BidirectionalStream::ReadData to start reading, |
| 50 // or call BidirectionalStream::SendData to send data. | 50 // or call BidirectionalStream::SendData to send data. |
| 51 // The delegate should not call BidirectionalStream::Cancel | 51 // The delegate should not call BidirectionalStream::Cancel |
| 52 // during this callback. | 52 // during this callback. |
| 53 virtual void OnStreamReady() = 0; | 53 // |request_headers_sent| if true, request headers have been sent. If false, |
| 54 // SendRequestHeaders() needs to be explicitly called. | |
| 55 virtual void OnStreamReady(bool request_headers_sent) = 0; | |
| 54 | 56 |
| 55 // Called when headers are received. This is called at most once for the | 57 // Called when headers are received. This is called at most once for the |
| 56 // lifetime of a stream. | 58 // lifetime of a stream. |
| 57 // The delegate may call BidirectionalStream::ReadData to start reading, | 59 // The delegate may call BidirectionalStream::ReadData to start reading, |
| 58 // call BidirectionalStream::SendData to send data, | 60 // call BidirectionalStream::SendData to send data, |
| 59 // or call BidirectionalStream::Cancel to cancel the stream. | 61 // or call BidirectionalStream::Cancel to cancel the stream. |
| 60 virtual void OnHeadersReceived(const SpdyHeaderBlock& response_headers) = 0; | 62 virtual void OnHeadersReceived(const SpdyHeaderBlock& response_headers) = 0; |
| 61 | 63 |
| 62 // Called when a pending read is completed asynchronously. | 64 // Called when a pending read is completed asynchronously. |
| 63 // |bytes_read| specifies how much data is read. | 65 // |bytes_read| specifies how much data is read. |
| (...skipping 23 matching lines...) Expand all Loading... | |
| 87 virtual ~Delegate(); | 89 virtual ~Delegate(); |
| 88 | 90 |
| 89 private: | 91 private: |
| 90 DISALLOW_COPY_AND_ASSIGN(Delegate); | 92 DISALLOW_COPY_AND_ASSIGN(Delegate); |
| 91 }; | 93 }; |
| 92 | 94 |
| 93 // Constructs a BidirectionalStream. |request_info| contains information about | 95 // Constructs a BidirectionalStream. |request_info| contains information about |
| 94 // the request, and must be non-NULL. |session| is the http network session | 96 // the request, and must be non-NULL. |session| is the http network session |
| 95 // with which this request will be made. |delegate| must be non-NULL. | 97 // with which this request will be made. |delegate| must be non-NULL. |
| 96 // |session| and |delegate| must outlive |this|. | 98 // |session| and |delegate| must outlive |this|. |
| 99 // |send_request_headers_automatically| if true, request headers will be sent | |
| 100 // automatically when stream is negotiated. If false, request headers will be | |
| 101 // sent only if until SendRequestHeaders() is invoked or until next | |
|
mef
2016/06/01 21:33:21
if until => when
until => with
xunjieli
2016/06/01 22:27:16
Done.
| |
| 102 // SendData/SendvData. | |
| 97 BidirectionalStream( | 103 BidirectionalStream( |
| 98 std::unique_ptr<BidirectionalStreamRequestInfo> request_info, | 104 std::unique_ptr<BidirectionalStreamRequestInfo> request_info, |
| 99 HttpNetworkSession* session, | 105 HttpNetworkSession* session, |
| 100 bool disable_auto_flush, | 106 bool send_request_headers_automatically, |
| 101 Delegate* delegate); | 107 Delegate* delegate); |
| 102 | 108 |
| 103 // Constructor that accepts a Timer, which can be used in tests to control | 109 // Constructor that accepts a Timer, which can be used in tests to control |
| 104 // the buffering of received data. | 110 // the buffering of received data. |
| 105 BidirectionalStream( | 111 BidirectionalStream( |
| 106 std::unique_ptr<BidirectionalStreamRequestInfo> request_info, | 112 std::unique_ptr<BidirectionalStreamRequestInfo> request_info, |
| 107 HttpNetworkSession* session, | 113 HttpNetworkSession* session, |
| 108 bool disable_auto_flush, | 114 bool send_request_headers_automatically, |
| 109 Delegate* delegate, | 115 Delegate* delegate, |
| 110 std::unique_ptr<base::Timer> timer); | 116 std::unique_ptr<base::Timer> timer); |
| 111 | 117 |
| 112 // Cancels |stream_request_| or |stream_impl_| if applicable. | 118 // Cancels |stream_request_| or |stream_impl_| if applicable. |
| 113 // |this| should not be destroyed during Delegate::OnHeadersSent or | 119 // |this| should not be destroyed during Delegate::OnHeadersSent or |
| 114 // Delegate::OnDataSent. | 120 // Delegate::OnDataSent. |
| 115 ~BidirectionalStream() override; | 121 ~BidirectionalStream() override; |
| 116 | 122 |
| 123 // Sends request headers to server. | |
| 124 // This method cannot be called when |send_request_headers_automatically_| is | |
| 125 // true nor when OnStreamReady() is invoked with request_headers_sent = true, | |
| 126 // since headers have been sent by the stream when stream is negotiated | |
| 127 // successfully. When |send_request_headers_automatically_| is | |
| 128 // false and OnStreamReady() is invoked with request_headers_sent = false, | |
| 129 // headers will be combined with next SendData/SendvData unless this | |
| 130 // method is called first, in which case headers will be sent separately | |
| 131 // without delay. | |
| 132 void SendRequestHeaders(); | |
| 133 | |
| 117 // Reads at most |buf_len| bytes into |buf|. Returns the number of bytes read, | 134 // Reads at most |buf_len| bytes into |buf|. Returns the number of bytes read, |
| 118 // or ERR_IO_PENDING if the read is to be completed asynchronously, or an | 135 // or ERR_IO_PENDING if the read is to be completed asynchronously, or an |
| 119 // error code if any error occurred. If returns 0, there is no more data to | 136 // error code if any error occurred. If returns 0, there is no more data to |
| 120 // read. This should not be called before Delegate::OnHeadersReceived is | 137 // read. This should not be called before Delegate::OnHeadersReceived is |
| 121 // invoked, and should not be called again unless it returns with number | 138 // invoked, and should not be called again unless it returns with number |
| 122 // greater than 0 or until Delegate::OnDataRead is invoked. | 139 // greater than 0 or until Delegate::OnDataRead is invoked. |
| 123 int ReadData(IOBuffer* buf, int buf_len); | 140 int ReadData(IOBuffer* buf, int buf_len); |
| 124 | 141 |
| 125 // Sends data. This should not be called before Delegate::OnHeadersSent is | 142 // Sends data. This should not be called before Delegate::OnHeadersSent is |
| 126 // invoked, and should not be called again until Delegate::OnDataSent is | 143 // invoked, and should not be called again until Delegate::OnDataSent is |
| (...skipping 27 matching lines...) Expand all Loading... | |
| 154 // this stream, including the size of frame headers, before SSL encryption and | 171 // this stream, including the size of frame headers, before SSL encryption and |
| 155 // not including proxy overhead. Note that some SPDY frames such as pings are | 172 // not including proxy overhead. Note that some SPDY frames such as pings are |
| 156 // not associated with any stream, and are not included in this value. | 173 // not associated with any stream, and are not included in this value. |
| 157 int64_t GetTotalSentBytes() const; | 174 int64_t GetTotalSentBytes() const; |
| 158 | 175 |
| 159 // TODO(xunjieli): Implement a method to do flow control and a method to ping | 176 // TODO(xunjieli): Implement a method to do flow control and a method to ping |
| 160 // remote end point. | 177 // remote end point. |
| 161 | 178 |
| 162 private: | 179 private: |
| 163 // BidirectionalStreamImpl::Delegate implementation: | 180 // BidirectionalStreamImpl::Delegate implementation: |
| 164 void OnStreamReady() override; | 181 void OnStreamReady(bool request_headers_sent) override; |
| 165 void OnHeadersReceived(const SpdyHeaderBlock& response_headers) override; | 182 void OnHeadersReceived(const SpdyHeaderBlock& response_headers) override; |
| 166 void OnDataRead(int bytes_read) override; | 183 void OnDataRead(int bytes_read) override; |
| 167 void OnDataSent() override; | 184 void OnDataSent() override; |
| 168 void OnTrailersReceived(const SpdyHeaderBlock& trailers) override; | 185 void OnTrailersReceived(const SpdyHeaderBlock& trailers) override; |
| 169 void OnFailed(int error) override; | 186 void OnFailed(int error) override; |
| 170 | 187 |
| 171 // HttpStreamRequest::Delegate implementation: | 188 // HttpStreamRequest::Delegate implementation: |
| 172 void OnStreamReady(const SSLConfig& used_ssl_config, | 189 void OnStreamReady(const SSLConfig& used_ssl_config, |
| 173 const ProxyInfo& used_proxy_info, | 190 const ProxyInfo& used_proxy_info, |
| 174 HttpStream* stream) override; | 191 HttpStream* stream) override; |
| (...skipping 22 matching lines...) Expand all Loading... | |
| 197 const ProxyInfo& used_proxy_info, | 214 const ProxyInfo& used_proxy_info, |
| 198 HttpStream* stream) override; | 215 HttpStream* stream) override; |
| 199 void OnQuicBroken() override; | 216 void OnQuicBroken() override; |
| 200 | 217 |
| 201 // BidirectionalStreamRequestInfo used when requesting the stream. | 218 // BidirectionalStreamRequestInfo used when requesting the stream. |
| 202 std::unique_ptr<BidirectionalStreamRequestInfo> request_info_; | 219 std::unique_ptr<BidirectionalStreamRequestInfo> request_info_; |
| 203 const BoundNetLog net_log_; | 220 const BoundNetLog net_log_; |
| 204 | 221 |
| 205 HttpNetworkSession* session_; | 222 HttpNetworkSession* session_; |
| 206 | 223 |
| 207 bool disable_auto_flush_; | 224 bool send_request_headers_automatically_; |
| 225 // Whether request headers have been sent, as indicated in OnStreamReady() | |
| 226 // callback. | |
| 227 bool request_headers_sent_; | |
| 228 | |
| 208 Delegate* const delegate_; | 229 Delegate* const delegate_; |
| 209 | 230 |
| 210 // Timer used to buffer data received in short time-spans and send a single | 231 // Timer used to buffer data received in short time-spans and send a single |
| 211 // read completion notification. | 232 // read completion notification. |
| 212 std::unique_ptr<base::Timer> timer_; | 233 std::unique_ptr<base::Timer> timer_; |
| 213 // HttpStreamRequest used to request a BidirectionalStreamImpl. This is NULL | 234 // HttpStreamRequest used to request a BidirectionalStreamImpl. This is NULL |
| 214 // if the request has been canceled or completed. | 235 // if the request has been canceled or completed. |
| 215 std::unique_ptr<HttpStreamRequest> stream_request_; | 236 std::unique_ptr<HttpStreamRequest> stream_request_; |
| 216 // The underlying BidirectioanlStreamImpl used for this stream. It is | 237 // The underlying BidirectioanlStreamImpl used for this stream. It is |
| 217 // non-NULL, if the |stream_request_| successfully finishes. | 238 // non-NULL, if the |stream_request_| successfully finishes. |
| 218 std::unique_ptr<BidirectionalStreamImpl> stream_impl_; | 239 std::unique_ptr<BidirectionalStreamImpl> stream_impl_; |
| 219 | 240 |
| 220 // Buffer used for reading. | 241 // Buffer used for reading. |
| 221 scoped_refptr<IOBuffer> read_buffer_; | 242 scoped_refptr<IOBuffer> read_buffer_; |
| 222 // List of buffers used for writing. | 243 // List of buffers used for writing. |
| 223 std::vector<scoped_refptr<IOBuffer>> write_buffer_list_; | 244 std::vector<scoped_refptr<IOBuffer>> write_buffer_list_; |
| 224 // List of buffer length. | 245 // List of buffer length. |
| 225 std::vector<int> write_buffer_len_list_; | 246 std::vector<int> write_buffer_len_list_; |
| 226 | 247 |
| 227 DISALLOW_COPY_AND_ASSIGN(BidirectionalStream); | 248 DISALLOW_COPY_AND_ASSIGN(BidirectionalStream); |
| 228 }; | 249 }; |
| 229 | 250 |
| 230 } // namespace net | 251 } // namespace net |
| 231 | 252 |
| 232 #endif // NET_HTTP_BIDIRECTIONAL_STREAM_H_ | 253 #endif // NET_HTTP_BIDIRECTIONAL_STREAM_H_ |
| OLD | NEW |