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 <list> | 8 #include <deque> |
9 #include <string> | 9 #include <string> |
10 #include <vector> | 10 #include <vector> |
11 | 11 |
12 #include "base/basictypes.h" | 12 #include "base/basictypes.h" |
13 #include "base/memory/ref_counted.h" | 13 #include "base/memory/ref_counted.h" |
14 #include "base/memory/scoped_ptr.h" | 14 #include "base/memory/scoped_ptr.h" |
15 #include "base/memory/weak_ptr.h" | 15 #include "base/memory/weak_ptr.h" |
16 #include "googleurl/src/gurl.h" | 16 #include "googleurl/src/gurl.h" |
17 #include "net/base/bandwidth_metrics.h" | 17 #include "net/base/bandwidth_metrics.h" |
18 #include "net/base/io_buffer.h" | 18 #include "net/base/io_buffer.h" |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
95 private: | 95 private: |
96 DISALLOW_COPY_AND_ASSIGN(Delegate); | 96 DISALLOW_COPY_AND_ASSIGN(Delegate); |
97 }; | 97 }; |
98 | 98 |
99 // Indicates pending frame type. | 99 // Indicates pending frame type. |
100 enum FrameType { | 100 enum FrameType { |
101 TYPE_HEADERS, | 101 TYPE_HEADERS, |
102 TYPE_DATA | 102 TYPE_DATA |
103 }; | 103 }; |
104 | 104 |
105 // Structure to contains pending frame information. | |
106 typedef struct { | |
107 FrameType type; | |
108 union { | |
109 SpdyHeaderBlock* header_block; | |
110 SpdyFrame* data_frame; | |
111 }; | |
112 } PendingFrame; | |
113 | |
114 // SpdyStream constructor | 105 // SpdyStream constructor |
115 SpdyStream(SpdySession* session, | 106 SpdyStream(SpdySession* session, |
116 const std::string& path, | 107 const std::string& path, |
117 RequestPriority priority, | 108 RequestPriority priority, |
118 int32 initial_send_window_size, | 109 int32 initial_send_window_size, |
119 int32 initial_recv_window_size, | 110 int32 initial_recv_window_size, |
120 bool pushed, | 111 bool pushed, |
121 const BoundNetLog& net_log); | 112 const BoundNetLog& net_log); |
122 | 113 |
123 // Set new |delegate|. |delegate| must not be NULL. | 114 // Set new |delegate|. |delegate| must not be NULL. |
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
292 // Returns true if the URL for this stream is known. | 283 // Returns true if the URL for this stream is known. |
293 bool HasUrl() const; | 284 bool HasUrl() const; |
294 | 285 |
295 // Get the URL associated with this stream. Only valid when has_url() is | 286 // Get the URL associated with this stream. Only valid when has_url() is |
296 // true. | 287 // true. |
297 GURL GetUrl() const; | 288 GURL GetUrl() const; |
298 | 289 |
299 int GetProtocolVersion() const; | 290 int GetProtocolVersion() const; |
300 | 291 |
301 private: | 292 private: |
302 class SpdyStreamIOBufferProducer; | 293 class SynStreamFrameProducer; |
| 294 class HeaderFrameProducer; |
303 | 295 |
304 enum State { | 296 enum State { |
305 STATE_NONE, | 297 STATE_NONE, |
306 STATE_GET_DOMAIN_BOUND_CERT, | 298 STATE_GET_DOMAIN_BOUND_CERT, |
307 STATE_GET_DOMAIN_BOUND_CERT_COMPLETE, | 299 STATE_GET_DOMAIN_BOUND_CERT_COMPLETE, |
308 STATE_SEND_DOMAIN_BOUND_CERT, | 300 STATE_SEND_DOMAIN_BOUND_CERT, |
309 STATE_SEND_DOMAIN_BOUND_CERT_COMPLETE, | 301 STATE_SEND_DOMAIN_BOUND_CERT_COMPLETE, |
310 STATE_SEND_HEADERS, | 302 STATE_SEND_HEADERS, |
311 STATE_SEND_HEADERS_COMPLETE, | 303 STATE_SEND_HEADERS_COMPLETE, |
312 STATE_SEND_BODY, | 304 STATE_SEND_BODY, |
(...skipping 26 matching lines...) Expand all Loading... |
339 int DoOpen(int result); | 331 int DoOpen(int result); |
340 | 332 |
341 // Update the histograms. Can safely be called repeatedly, but should only | 333 // Update the histograms. Can safely be called repeatedly, but should only |
342 // be called after the stream has completed. | 334 // be called after the stream has completed. |
343 void UpdateHistograms(); | 335 void UpdateHistograms(); |
344 | 336 |
345 // When a server pushed stream is first created, this function is posted on | 337 // When a server pushed stream is first created, this function is posted on |
346 // the MessageLoop to replay all the data that the server has already sent. | 338 // the MessageLoop to replay all the data that the server has already sent. |
347 void PushedStreamReplayData(); | 339 void PushedStreamReplayData(); |
348 | 340 |
349 // Informs the SpdySession that this stream has a write available. | 341 // Produces the SYN_STREAM frame for the stream. The stream must |
350 void SetHasWriteAvailable(); | 342 // already be activated. |
| 343 scoped_ptr<SpdyFrame> ProduceSynStreamFrame(); |
351 | 344 |
352 // Returns a newly created SPDY frame owned by the called that contains | 345 // Produce the initial HEADER frame for the stream with the given |
353 // the next frame to be sent by this frame. May return NULL if this | 346 // block. The stream must already be activated. |
354 // stream has become stalled on flow control. | 347 scoped_ptr<SpdyFrame> ProduceHeaderFrame( |
355 scoped_ptr<SpdyFrame> ProduceNextFrame(); | 348 scoped_ptr<SpdyHeaderBlock> header_block); |
356 | 349 |
357 // If the stream is active and stream flow control is turned on, | 350 // If the stream is active and stream flow control is turned on, |
358 // called by OnDataReceived (which is in turn called by the session) | 351 // called by OnDataReceived (which is in turn called by the session) |
359 // to decrease this stream's receive window size by | 352 // to decrease this stream's receive window size by |
360 // |delta_window_size|, which must be at least 1 and must not cause | 353 // |delta_window_size|, which must be at least 1 and must not cause |
361 // this stream's receive window size to go negative. | 354 // this stream's receive window size to go negative. |
362 void DecreaseRecvWindowSize(int32 delta_window_size); | 355 void DecreaseRecvWindowSize(int32 delta_window_size); |
363 | 356 |
364 base::WeakPtrFactory<SpdyStream> weak_ptr_factory_; | 357 base::WeakPtrFactory<SpdyStream> weak_ptr_factory_; |
365 | 358 |
(...skipping 25 matching lines...) Expand all Loading... |
391 // The request to send. | 384 // The request to send. |
392 scoped_ptr<SpdyHeaderBlock> request_; | 385 scoped_ptr<SpdyHeaderBlock> request_; |
393 | 386 |
394 // The time at which the request was made that resulted in this response. | 387 // The time at which the request was made that resulted in this response. |
395 // For cached responses, this time could be "far" in the past. | 388 // For cached responses, this time could be "far" in the past. |
396 base::Time request_time_; | 389 base::Time request_time_; |
397 | 390 |
398 scoped_ptr<SpdyHeaderBlock> response_; | 391 scoped_ptr<SpdyHeaderBlock> response_; |
399 base::Time response_time_; | 392 base::Time response_time_; |
400 | 393 |
401 // An in order list of pending frame data that are going to be sent. HEADERS | 394 // An in order list of sending frame types. Used communicate to the |
402 // frames are queued as SpdyHeaderBlock structures because these must be | 395 // delegate which type of frame was sent in DoOpen(). |
403 // compressed just before sending. Data frames are queued as SpdyDataFrame. | 396 // |
404 std::list<PendingFrame> pending_frames_; | 397 // TODO(akalin): We can remove the need for this queue if we add an |
405 | 398 // OnFrameSent() callback to SpdyFrameProducer and have the session |
406 // An in order list of sending frame types. It will be used to know which type | 399 // call that instead of SpdyStream::OnWriteComplete(). |
407 // of frame is sent and which callback should be invoked in OnOpen(). | 400 std::deque<FrameType> waiting_completions_; |
408 std::list<FrameType> waiting_completions_; | |
409 | 401 |
410 State io_state_; | 402 State io_state_; |
411 | 403 |
412 // Since we buffer the response, we also buffer the response status. | 404 // Since we buffer the response, we also buffer the response status. |
413 // Not valid until the stream is closed. | 405 // Not valid until the stream is closed. |
414 int response_status_; | 406 int response_status_; |
415 | 407 |
416 bool cancelled_; | 408 bool cancelled_; |
417 bool has_upload_data_; | 409 bool has_upload_data_; |
418 | 410 |
(...skipping 11 matching lines...) Expand all Loading... |
430 std::string domain_bound_private_key_; | 422 std::string domain_bound_private_key_; |
431 std::string domain_bound_cert_; | 423 std::string domain_bound_cert_; |
432 ServerBoundCertService::RequestHandle domain_bound_cert_request_handle_; | 424 ServerBoundCertService::RequestHandle domain_bound_cert_request_handle_; |
433 | 425 |
434 DISALLOW_COPY_AND_ASSIGN(SpdyStream); | 426 DISALLOW_COPY_AND_ASSIGN(SpdyStream); |
435 }; | 427 }; |
436 | 428 |
437 } // namespace net | 429 } // namespace net |
438 | 430 |
439 #endif // NET_SPDY_SPDY_STREAM_H_ | 431 #endif // NET_SPDY_SPDY_STREAM_H_ |
OLD | NEW |