OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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_SPDY_SPDY_STREAM_H_ | 5 #ifndef NET_SPDY_SPDY_STREAM_H_ |
6 #define NET_SPDY_SPDY_STREAM_H_ | 6 #define NET_SPDY_SPDY_STREAM_H_ |
7 | 7 |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
10 #include <deque> | 10 #include <deque> |
11 #include <string> | 11 #include <string> |
12 #include <vector> | 12 #include <vector> |
13 | 13 |
14 #include "base/basictypes.h" | |
15 #include "base/memory/ref_counted.h" | 14 #include "base/memory/ref_counted.h" |
16 #include "base/memory/scoped_ptr.h" | 15 #include "base/memory/scoped_ptr.h" |
17 #include "base/memory/weak_ptr.h" | 16 #include "base/memory/weak_ptr.h" |
18 #include "net/base/io_buffer.h" | 17 #include "net/base/io_buffer.h" |
19 #include "net/base/net_export.h" | 18 #include "net/base/net_export.h" |
20 #include "net/base/request_priority.h" | 19 #include "net/base/request_priority.h" |
21 #include "net/log/net_log.h" | 20 #include "net/log/net_log.h" |
22 #include "net/socket/ssl_client_socket.h" | 21 #include "net/socket/ssl_client_socket.h" |
23 #include "net/spdy/spdy_buffer.h" | 22 #include "net/spdy/spdy_buffer.h" |
24 #include "net/spdy/spdy_framer.h" | 23 #include "net/spdy/spdy_framer.h" |
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
162 | 161 |
163 private: | 162 private: |
164 DISALLOW_COPY_AND_ASSIGN(Delegate); | 163 DISALLOW_COPY_AND_ASSIGN(Delegate); |
165 }; | 164 }; |
166 | 165 |
167 // SpdyStream constructor | 166 // SpdyStream constructor |
168 SpdyStream(SpdyStreamType type, | 167 SpdyStream(SpdyStreamType type, |
169 const base::WeakPtr<SpdySession>& session, | 168 const base::WeakPtr<SpdySession>& session, |
170 const GURL& url, | 169 const GURL& url, |
171 RequestPriority priority, | 170 RequestPriority priority, |
172 int32 initial_send_window_size, | 171 int32_t initial_send_window_size, |
173 int32 max_recv_window_size, | 172 int32_t max_recv_window_size, |
174 const BoundNetLog& net_log); | 173 const BoundNetLog& net_log); |
175 | 174 |
176 ~SpdyStream(); | 175 ~SpdyStream(); |
177 | 176 |
178 // Set the delegate, which must not be NULL. Must not be called more | 177 // Set the delegate, which must not be NULL. Must not be called more |
179 // than once. For push streams, calling this may cause buffered data | 178 // than once. For push streams, calling this may cause buffered data |
180 // to be sent to the delegate (from a posted task). | 179 // to be sent to the delegate (from a posted task). |
181 void SetDelegate(Delegate* delegate); | 180 void SetDelegate(Delegate* delegate); |
182 | 181 |
183 // Detach the delegate from the stream, which must not yet be | 182 // Detach the delegate from the stream, which must not yet be |
184 // closed, and cancel it. | 183 // closed, and cancel it. |
185 void DetachDelegate(); | 184 void DetachDelegate(); |
186 | 185 |
187 // The time at which the first bytes of the response were received | 186 // The time at which the first bytes of the response were received |
188 // from the server, or null if the response hasn't been received | 187 // from the server, or null if the response hasn't been received |
189 // yet. | 188 // yet. |
190 base::Time response_time() const { return response_time_; } | 189 base::Time response_time() const { return response_time_; } |
191 | 190 |
192 SpdyStreamType type() const { return type_; } | 191 SpdyStreamType type() const { return type_; } |
193 | 192 |
194 SpdyStreamId stream_id() const { return stream_id_; } | 193 SpdyStreamId stream_id() const { return stream_id_; } |
195 void set_stream_id(SpdyStreamId stream_id) { stream_id_ = stream_id; } | 194 void set_stream_id(SpdyStreamId stream_id) { stream_id_ = stream_id; } |
196 | 195 |
197 const GURL& url() const { return url_; } | 196 const GURL& url() const { return url_; } |
198 | 197 |
199 RequestPriority priority() const { return priority_; } | 198 RequestPriority priority() const { return priority_; } |
200 | 199 |
201 int32 send_window_size() const { return send_window_size_; } | 200 int32_t send_window_size() const { return send_window_size_; } |
202 | 201 |
203 int32 recv_window_size() const { return recv_window_size_; } | 202 int32_t recv_window_size() const { return recv_window_size_; } |
204 | 203 |
205 bool send_stalled_by_flow_control() const { | 204 bool send_stalled_by_flow_control() const { |
206 return send_stalled_by_flow_control_; | 205 return send_stalled_by_flow_control_; |
207 } | 206 } |
208 | 207 |
209 void set_send_stalled_by_flow_control(bool stalled) { | 208 void set_send_stalled_by_flow_control(bool stalled) { |
210 send_stalled_by_flow_control_ = stalled; | 209 send_stalled_by_flow_control_ = stalled; |
211 } | 210 } |
212 | 211 |
213 // Called by the session to adjust this stream's send window size by | 212 // Called by the session to adjust this stream's send window size by |
214 // |delta_window_size|, which is the difference between the | 213 // |delta_window_size|, which is the difference between the |
215 // SETTINGS_INITIAL_WINDOW_SIZE in the most recent SETTINGS frame | 214 // SETTINGS_INITIAL_WINDOW_SIZE in the most recent SETTINGS frame |
216 // and the previous initial send window size, possibly unstalling | 215 // and the previous initial send window size, possibly unstalling |
217 // this stream. Although |delta_window_size| may cause this stream's | 216 // this stream. Although |delta_window_size| may cause this stream's |
218 // send window size to go negative, it must not cause it to wrap | 217 // send window size to go negative, it must not cause it to wrap |
219 // around in either direction. Does nothing if the stream is already | 218 // around in either direction. Does nothing if the stream is already |
220 // closed. | 219 // closed. |
221 // | 220 // |
222 // If stream flow control is turned off, this must not be called. | 221 // If stream flow control is turned off, this must not be called. |
223 void AdjustSendWindowSize(int32 delta_window_size); | 222 void AdjustSendWindowSize(int32_t delta_window_size); |
224 | 223 |
225 // Called when bytes are consumed from a SpdyBuffer for a DATA frame | 224 // Called when bytes are consumed from a SpdyBuffer for a DATA frame |
226 // that is to be written or is being written. Increases the send | 225 // that is to be written or is being written. Increases the send |
227 // window size accordingly if some or all of the SpdyBuffer is being | 226 // window size accordingly if some or all of the SpdyBuffer is being |
228 // discarded. | 227 // discarded. |
229 // | 228 // |
230 // If stream flow control is turned off, this must not be called. | 229 // If stream flow control is turned off, this must not be called. |
231 void OnWriteBufferConsumed(size_t frame_payload_size, | 230 void OnWriteBufferConsumed(size_t frame_payload_size, |
232 size_t consume_size, | 231 size_t consume_size, |
233 SpdyBuffer::ConsumeSource consume_source); | 232 SpdyBuffer::ConsumeSource consume_source); |
234 | 233 |
235 // Called by the session to increase this stream's send window size | 234 // Called by the session to increase this stream's send window size |
236 // by |delta_window_size| (which must be at least 1) from a received | 235 // by |delta_window_size| (which must be at least 1) from a received |
237 // WINDOW_UPDATE frame or from a dropped DATA frame that was | 236 // WINDOW_UPDATE frame or from a dropped DATA frame that was |
238 // intended to be sent, possibly unstalling this stream. If | 237 // intended to be sent, possibly unstalling this stream. If |
239 // |delta_window_size| would cause this stream's send window size to | 238 // |delta_window_size| would cause this stream's send window size to |
240 // overflow, calls into the session to reset this stream. Does | 239 // overflow, calls into the session to reset this stream. Does |
241 // nothing if the stream is already closed. | 240 // nothing if the stream is already closed. |
242 // | 241 // |
243 // If stream flow control is turned off, this must not be called. | 242 // If stream flow control is turned off, this must not be called. |
244 void IncreaseSendWindowSize(int32 delta_window_size); | 243 void IncreaseSendWindowSize(int32_t delta_window_size); |
245 | 244 |
246 // If stream flow control is turned on, called by the session to | 245 // If stream flow control is turned on, called by the session to |
247 // decrease this stream's send window size by |delta_window_size|, | 246 // decrease this stream's send window size by |delta_window_size|, |
248 // which must be at least 0 and at most kMaxSpdyFrameChunkSize. | 247 // which must be at least 0 and at most kMaxSpdyFrameChunkSize. |
249 // |delta_window_size| must not cause this stream's send window size | 248 // |delta_window_size| must not cause this stream's send window size |
250 // to go negative. Does nothing if the stream is already closed. | 249 // to go negative. Does nothing if the stream is already closed. |
251 // | 250 // |
252 // If stream flow control is turned off, this must not be called. | 251 // If stream flow control is turned off, this must not be called. |
253 void DecreaseSendWindowSize(int32 delta_window_size); | 252 void DecreaseSendWindowSize(int32_t delta_window_size); |
254 | 253 |
255 // Called when bytes are consumed by the delegate from a SpdyBuffer | 254 // Called when bytes are consumed by the delegate from a SpdyBuffer |
256 // containing received data. Increases the receive window size | 255 // containing received data. Increases the receive window size |
257 // accordingly. | 256 // accordingly. |
258 // | 257 // |
259 // If stream flow control is turned off, this must not be called. | 258 // If stream flow control is turned off, this must not be called. |
260 void OnReadBufferConsumed(size_t consume_size, | 259 void OnReadBufferConsumed(size_t consume_size, |
261 SpdyBuffer::ConsumeSource consume_source); | 260 SpdyBuffer::ConsumeSource consume_source); |
262 | 261 |
263 // Called by OnReadBufferConsume to increase this stream's receive | 262 // Called by OnReadBufferConsume to increase this stream's receive |
264 // window size by |delta_window_size|, which must be at least 1 and | 263 // window size by |delta_window_size|, which must be at least 1 and |
265 // must not cause this stream's receive window size to overflow, | 264 // must not cause this stream's receive window size to overflow, |
266 // possibly also sending a WINDOW_UPDATE frame. Does nothing if the | 265 // possibly also sending a WINDOW_UPDATE frame. Does nothing if the |
267 // stream is not active. | 266 // stream is not active. |
268 // | 267 // |
269 // If stream flow control is turned off, this must not be called. | 268 // If stream flow control is turned off, this must not be called. |
270 void IncreaseRecvWindowSize(int32 delta_window_size); | 269 void IncreaseRecvWindowSize(int32_t delta_window_size); |
271 | 270 |
272 // Called by OnDataReceived or OnPaddingConsumed (which are in turn called by | 271 // Called by OnDataReceived or OnPaddingConsumed (which are in turn called by |
273 // the session) to decrease this stream's receive window size by | 272 // the session) to decrease this stream's receive window size by |
274 // |delta_window_size|, which must be at least 1. May close the stream on | 273 // |delta_window_size|, which must be at least 1. May close the stream on |
275 // flow control error. | 274 // flow control error. |
276 // | 275 // |
277 // If stream flow control is turned off or the stream is not active, | 276 // If stream flow control is turned off or the stream is not active, |
278 // this must not be called. | 277 // this must not be called. |
279 void DecreaseRecvWindowSize(int32 delta_window_size); | 278 void DecreaseRecvWindowSize(int32_t delta_window_size); |
280 | 279 |
281 int GetPeerAddress(IPEndPoint* address) const; | 280 int GetPeerAddress(IPEndPoint* address) const; |
282 int GetLocalAddress(IPEndPoint* address) const; | 281 int GetLocalAddress(IPEndPoint* address) const; |
283 | 282 |
284 // Returns true if the underlying transport socket ever had any reads or | 283 // Returns true if the underlying transport socket ever had any reads or |
285 // writes. | 284 // writes. |
286 bool WasEverUsed() const; | 285 bool WasEverUsed() const; |
287 | 286 |
288 const BoundNetLog& net_log() const { return net_log_; } | 287 const BoundNetLog& net_log() const { return net_log_; } |
289 | 288 |
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
418 | 417 |
419 // Returns the protocol used by this stream. Always between | 418 // Returns the protocol used by this stream. Always between |
420 // kProtoSPDYMinimumVersion and kProtoSPDYMaximumVersion. | 419 // kProtoSPDYMinimumVersion and kProtoSPDYMaximumVersion. |
421 NextProto GetProtocol() const; | 420 NextProto GetProtocol() const; |
422 | 421 |
423 int response_status() const { return response_status_; } | 422 int response_status() const { return response_status_; } |
424 | 423 |
425 void AddRawReceivedBytes(size_t received_bytes); | 424 void AddRawReceivedBytes(size_t received_bytes); |
426 void AddRawSentBytes(size_t sent_bytes); | 425 void AddRawSentBytes(size_t sent_bytes); |
427 | 426 |
428 int64 raw_received_bytes() const { return raw_received_bytes_; } | 427 int64_t raw_received_bytes() const { return raw_received_bytes_; } |
429 int64_t raw_sent_bytes() const { return raw_sent_bytes_; } | 428 int64_t raw_sent_bytes() const { return raw_sent_bytes_; } |
430 | 429 |
431 bool GetLoadTimingInfo(LoadTimingInfo* load_timing_info) const; | 430 bool GetLoadTimingInfo(LoadTimingInfo* load_timing_info) const; |
432 | 431 |
433 // Get the URL from the appropriate stream headers, or the empty | 432 // Get the URL from the appropriate stream headers, or the empty |
434 // GURL() if it is unknown. | 433 // GURL() if it is unknown. |
435 // | 434 // |
436 // TODO(akalin): Figure out if we really need this function, | 435 // TODO(akalin): Figure out if we really need this function, |
437 // i.e. can we just use the URL this stream was created with and/or | 436 // i.e. can we just use the URL this stream was created with and/or |
438 // one we receive headers validate that the URL from them is the | 437 // one we receive headers validate that the URL from them is the |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
502 | 501 |
503 const SpdyStreamType type_; | 502 const SpdyStreamType type_; |
504 | 503 |
505 SpdyStreamId stream_id_; | 504 SpdyStreamId stream_id_; |
506 const GURL url_; | 505 const GURL url_; |
507 const RequestPriority priority_; | 506 const RequestPriority priority_; |
508 | 507 |
509 bool send_stalled_by_flow_control_; | 508 bool send_stalled_by_flow_control_; |
510 | 509 |
511 // Current send window size. | 510 // Current send window size. |
512 int32 send_window_size_; | 511 int32_t send_window_size_; |
513 | 512 |
514 // Maximum receive window size. Each time a WINDOW_UPDATE is sent, it | 513 // Maximum receive window size. Each time a WINDOW_UPDATE is sent, it |
515 // restores the receive window size to this value. | 514 // restores the receive window size to this value. |
516 int32 max_recv_window_size_; | 515 int32_t max_recv_window_size_; |
517 | 516 |
518 // Sum of |session_unacked_recv_window_bytes_| and current receive window | 517 // Sum of |session_unacked_recv_window_bytes_| and current receive window |
519 // size. | 518 // size. |
520 // TODO(bnc): Rename or change semantics so that |window_size_| is actual | 519 // TODO(bnc): Rename or change semantics so that |window_size_| is actual |
521 // window size. | 520 // window size. |
522 int32 recv_window_size_; | 521 int32_t recv_window_size_; |
523 | 522 |
524 // When bytes are consumed, SpdyIOBuffer destructor calls back to SpdySession, | 523 // When bytes are consumed, SpdyIOBuffer destructor calls back to SpdySession, |
525 // and this member keeps count of them until the corresponding WINDOW_UPDATEs | 524 // and this member keeps count of them until the corresponding WINDOW_UPDATEs |
526 // are sent. | 525 // are sent. |
527 int32 unacked_recv_window_bytes_; | 526 int32_t unacked_recv_window_bytes_; |
528 | 527 |
529 const base::WeakPtr<SpdySession> session_; | 528 const base::WeakPtr<SpdySession> session_; |
530 | 529 |
531 // The transaction should own the delegate. | 530 // The transaction should own the delegate. |
532 SpdyStream::Delegate* delegate_; | 531 SpdyStream::Delegate* delegate_; |
533 | 532 |
534 // The headers for the request to send. | 533 // The headers for the request to send. |
535 // | 534 // |
536 // TODO(akalin): Hang onto this only until we send it. This | 535 // TODO(akalin): Hang onto this only until we send it. This |
537 // necessitates stashing the URL separately. | 536 // necessitates stashing the URL separately. |
(...skipping 25 matching lines...) Expand all Loading... |
563 int response_status_; | 562 int response_status_; |
564 | 563 |
565 BoundNetLog net_log_; | 564 BoundNetLog net_log_; |
566 | 565 |
567 base::TimeTicks send_time_; | 566 base::TimeTicks send_time_; |
568 base::TimeTicks recv_first_byte_time_; | 567 base::TimeTicks recv_first_byte_time_; |
569 base::TimeTicks recv_last_byte_time_; | 568 base::TimeTicks recv_last_byte_time_; |
570 | 569 |
571 // Number of bytes that have been received on this stream, including frame | 570 // Number of bytes that have been received on this stream, including frame |
572 // overhead and headers. | 571 // overhead and headers. |
573 int64 raw_received_bytes_; | 572 int64_t raw_received_bytes_; |
574 // Number of bytes that have been sent on this stream, including frame | 573 // Number of bytes that have been sent on this stream, including frame |
575 // overhead and headers. | 574 // overhead and headers. |
576 int64_t raw_sent_bytes_; | 575 int64_t raw_sent_bytes_; |
577 | 576 |
578 // Number of data bytes that have been sent/received on this stream, not | 577 // Number of data bytes that have been sent/received on this stream, not |
579 // including frame overhead. Note that this does not count headers. | 578 // including frame overhead. Note that this does not count headers. |
580 int send_bytes_; | 579 int send_bytes_; |
581 int recv_bytes_; | 580 int recv_bytes_; |
582 | 581 |
583 // Guards calls of delegate write handlers ensuring |this| is not destroyed. | 582 // Guards calls of delegate write handlers ensuring |this| is not destroyed. |
584 // TODO(jgraettinger): Consider removing after crbug.com/35511 is tracked | 583 // TODO(jgraettinger): Consider removing after crbug.com/35511 is tracked |
585 // down. | 584 // down. |
586 bool write_handler_guard_; | 585 bool write_handler_guard_; |
587 | 586 |
588 base::WeakPtrFactory<SpdyStream> weak_ptr_factory_; | 587 base::WeakPtrFactory<SpdyStream> weak_ptr_factory_; |
589 | 588 |
590 DISALLOW_COPY_AND_ASSIGN(SpdyStream); | 589 DISALLOW_COPY_AND_ASSIGN(SpdyStream); |
591 }; | 590 }; |
592 | 591 |
593 } // namespace net | 592 } // namespace net |
594 | 593 |
595 #endif // NET_SPDY_SPDY_STREAM_H_ | 594 #endif // NET_SPDY_SPDY_STREAM_H_ |
OLD | NEW |