Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(939)

Side by Side Diff: net/spdy/spdy_stream.h

Issue 17382012: [SPDY] Refactor SpdyStream's handling of response headers (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Forgot to rename a function Created 7 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 <deque> 8 #include <deque>
9 #include <string> 9 #include <string>
10 #include <vector> 10 #include <vector>
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
66 public: 66 public:
67 // Delegate handles protocol specific behavior of spdy stream. 67 // Delegate handles protocol specific behavior of spdy stream.
68 class NET_EXPORT_PRIVATE Delegate { 68 class NET_EXPORT_PRIVATE Delegate {
69 public: 69 public:
70 Delegate() {} 70 Delegate() {}
71 71
72 // Called when the request headers have been sent. Never called 72 // Called when the request headers have been sent. Never called
73 // for push streams. 73 // for push streams.
74 virtual void OnRequestHeadersSent() = 0; 74 virtual void OnRequestHeadersSent() = 0;
75 75
76 // Called when the SYN_STREAM, SYN_REPLY, or HEADERS frames are received. 76 // Called when the response headers are updated from the
77 // Normal streams will receive a SYN_REPLY and optional HEADERS frames. 77 // server. |headers| contains the set of all headers received up
78 // Pushed streams will receive a SYN_STREAM and optional HEADERS frames. 78 // to this point; delegates can assume that any headers previously
79 // Because a stream may have a SYN_* frame and multiple HEADERS frames, 79 // received remain unchanged.
80 // this callback may be called multiple times. 80 //
81 // |status| indicates network error. Returns network error code. 81 // This is called at least once before any data is
82 virtual int OnResponseHeadersReceived(const SpdyHeaderBlock& response, 82 // received. After that:
83 base::Time response_time, 83 //
84 int status) = 0; 84 // - for bidirectional streams, this can be called again any
85 // number of times interleaved with received data;
86 // - for request/response streams, this will never be called
87 // again;
88 // - and for pushed streams, this can be called again, but only
89 // until data is received.
90 //
91 // The semantics of the return value are a bit confusing:
92 //
93 // - This function must return either OK or
94 // ERR_INCOMPLETE_SPDY_HEADERS.
Ryan Hamilton 2013/06/19 18:58:36 nit: if there are only 2 return values, should it
akalin 2013/06/21 21:13:25 Done! Also use the enum in various other places.
95 //
96 // - If OK is returned, the delegate may still have closed the
97 // stream; OK means that the headers were processed
98 // successfully, but the headers may indicate an error condition
99 // that results in the closing of the stream.
Ryan Hamilton 2013/06/19 18:58:36 nit: can you rephrase this to something like: - If
akalin 2013/06/21 21:13:25 Done.
100 //
101 // - If ERR_INCOMPLETE_SPDY_HEADERS is returned, the delegate must
102 // not have closed the stream. For non-push streams, this is
103 // interpreted as an error condition and the stream will be
104 // closed. However, for push streams, this return value is not
105 // interpreted as an error condition, since additional headers
106 // may still be received.
107 virtual int OnResponseHeadersUpdated(
108 const SpdyHeaderBlock& response_headers) = 0;
85 109
86 // Called when data is received. |buffer| may be NULL, which 110 // Called when data is received. |buffer| may be NULL, which
87 // signals EOF. Must return OK if the data was received 111 // signals EOF. Must return OK if the data was received
88 // successfully, or a network error code otherwise. 112 // successfully, or a network error code otherwise.
113 //
114 // May cause the stream to be closed regardless of the return
115 // value.
89 virtual int OnDataReceived(scoped_ptr<SpdyBuffer> buffer) = 0; 116 virtual int OnDataReceived(scoped_ptr<SpdyBuffer> buffer) = 0;
90 117
91 // Called when data is sent. 118 // Called when data is sent.
92 virtual void OnDataSent() = 0; 119 virtual void OnDataSent() = 0;
93 120
94 // Called when SpdyStream is closed. No other delegate functions 121 // Called when SpdyStream is closed. No other delegate functions
95 // will be called after this is called, and the delegate must not 122 // will be called after this is called, and the delegate must not
96 // access the stream after this is called. 123 // access the stream after this is called.
97 virtual void OnClose(int status) = 0; 124 virtual void OnClose(int status) = 0;
98 125
99 protected: 126 protected:
100 virtual ~Delegate() {} 127 virtual ~Delegate() {}
101 128
102 private: 129 private:
103 DISALLOW_COPY_AND_ASSIGN(Delegate); 130 DISALLOW_COPY_AND_ASSIGN(Delegate);
104 }; 131 };
105 132
106 // SpdyStream constructor 133 // SpdyStream constructor
107 SpdyStream(SpdyStreamType type, 134 SpdyStream(SpdyStreamType type,
108 SpdySession* session, 135 SpdySession* session,
109 const std::string& path, 136 const std::string& path,
110 RequestPriority priority, 137 RequestPriority priority,
111 int32 initial_send_window_size, 138 int32 initial_send_window_size,
112 int32 initial_recv_window_size, 139 int32 initial_recv_window_size,
113 const BoundNetLog& net_log); 140 const BoundNetLog& net_log);
114 141
115 ~SpdyStream(); 142 ~SpdyStream();
116 143
117 // Set new |delegate|. |delegate| must not be NULL. If it already 144 // Set new |delegate|. |delegate| must not be NULL. If it already
118 // received SYN_REPLY or data, OnResponseHeadersReceived() or 145 // received SYN_REPLY or data, OnResponseHeadersUpdated() or
119 // OnDataReceived() will be called. 146 // OnDataReceived() will be called.
120 void SetDelegate(Delegate* delegate); 147 void SetDelegate(Delegate* delegate);
121 Delegate* GetDelegate() { return delegate_; } 148 Delegate* GetDelegate();
122 149
123 // Detach the delegate from the stream, which must not yet be 150 // Detach the delegate from the stream, which must not yet be
124 // closed, and cancel it. 151 // closed, and cancel it.
125 void DetachDelegate(); 152 void DetachDelegate();
126 153
154 // Whether or not the initial response headers have been received
155 // from the server.
156 bool ReceivedInitialResponseHeaders() const;
Ryan Hamilton 2013/06/19 18:58:36 nit: HasReceivedInitialResponseHeaders
akalin 2013/06/21 21:13:25 Done.
157
158 // The time at which the first bytes of the response were received
159 // from the server. Non-null only when ReceivedResponseHeaders()
160 // returns true.
161 base::Time response_time() const { return response_time_; }
162
127 SpdyStreamType type() const { return type_; } 163 SpdyStreamType type() const { return type_; }
128 164
129 SpdyStreamId stream_id() const { return stream_id_; } 165 SpdyStreamId stream_id() const { return stream_id_; }
130 void set_stream_id(SpdyStreamId stream_id) { stream_id_ = stream_id; } 166 void set_stream_id(SpdyStreamId stream_id) { stream_id_ = stream_id; }
131 167
132 bool response_received() const { return response_received_; }
133 void set_response_received() { response_received_ = true; }
134
135 const std::string& path() const { return path_; } 168 const std::string& path() const { return path_; }
136 169
137 RequestPriority priority() const { return priority_; } 170 RequestPriority priority() const { return priority_; }
138 171
139 int32 send_window_size() const { return send_window_size_; } 172 int32 send_window_size() const { return send_window_size_; }
140 173
141 int32 recv_window_size() const { return recv_window_size_; } 174 int32 recv_window_size() const { return recv_window_size_; }
142 175
143 bool send_stalled_by_flow_control() const { 176 bool send_stalled_by_flow_control() const {
144 return send_stalled_by_flow_control_; 177 return send_stalled_by_flow_control_;
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
221 254
222 // Returns true if the underlying transport socket ever had any reads or 255 // Returns true if the underlying transport socket ever had any reads or
223 // writes. 256 // writes.
224 bool WasEverUsed() const; 257 bool WasEverUsed() const;
225 258
226 const BoundNetLog& net_log() const { return net_log_; } 259 const BoundNetLog& net_log() const { return net_log_; }
227 260
228 base::Time GetRequestTime() const; 261 base::Time GetRequestTime() const;
229 void SetRequestTime(base::Time t); 262 void SetRequestTime(base::Time t);
230 263
231 // Called by the SpdySession when a response (e.g. a SYN_STREAM or 264 // Called at most once by the SpdySession when the initial response
232 // SYN_REPLY) has been received for this stream. This is the entry 265 // headers have been received for this stream, i.e., a SYN_REPLY (or
233 // point for a push stream. Returns a status code. 266 // SYN_STREAM for push streams) frame has been received. This is the
234 int OnResponseHeadersReceived(const SpdyHeaderBlock& response); 267 // entry point for a push stream. Returns a status code; if it is an
268 // error, the stream may have already been closed.
269 //
270 // TODO(akalin): Guarantee that the stream is already closed if an
271 // error is returned.
272 int OnInitialResponseHeadersReceived(const SpdyHeaderBlock& response_headers,
273 base::Time response_time,
274 base::TimeTicks recv_first_byte_time);
235 275
236 // Called by the SpdySession when late-bound headers are received for a 276 // Called by the SpdySession (only after
237 // stream. Returns a status code. 277 // OnInitialResponseHeadersReceived() has been called) when
238 int OnHeaders(const SpdyHeaderBlock& headers); 278 // late-bound headers are received for a stream. Returns a status
279 // code; if it is an error, ths stream may have already been closed.
280 //
281 // TODO(akalin): Guarantee that the stream is already closed if an
282 // error is returned.
283 int OnAdditionalResponseHeadersReceived(
284 const SpdyHeaderBlock& additional_response_headers);
239 285
240 // Called by the SpdySession when response data has been received 286 // Called by the SpdySession when response data has been received
241 // for this stream. This callback may be called multiple times as 287 // for this stream. This callback may be called multiple times as
242 // data arrives from the network, and will never be called prior to 288 // data arrives from the network, and will never be called prior to
243 // OnResponseHeadersReceived. 289 // OnResponseHeadersReceived.
244 // 290 //
245 // |buffer| contains the data received, or NULL if the stream is 291 // |buffer| contains the data received, or NULL if the stream is
246 // being closed. The stream must copy any data from this 292 // being closed. The stream must copy any data from this
247 // buffer before returning from this callback. 293 // buffer before returning from this callback.
248 // 294 //
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
282 328
283 // Only one send can be in flight at a time, except for push 329 // Only one send can be in flight at a time, except for push
284 // streams, which must not send anything. 330 // streams, which must not send anything.
285 331
286 // Sends the request headers. The delegate is called back via 332 // Sends the request headers. The delegate is called back via
287 // OnRequestHeadersSent() when the request headers have completed 333 // OnRequestHeadersSent() when the request headers have completed
288 // sending. |send_status| must be MORE_DATA_TO_SEND for 334 // sending. |send_status| must be MORE_DATA_TO_SEND for
289 // bidirectional streams; for request/response streams, it must be 335 // bidirectional streams; for request/response streams, it must be
290 // MORE_DATA_TO_SEND if the request has data to upload, or 336 // MORE_DATA_TO_SEND if the request has data to upload, or
291 // NO_MORE_DATA_TO_SEND if not. 337 // NO_MORE_DATA_TO_SEND if not.
292 int SendRequestHeaders(scoped_ptr<SpdyHeaderBlock> headers, 338 int SendRequestHeaders(scoped_ptr<SpdyHeaderBlock> request_headers,
293 SpdySendStatus send_status); 339 SpdySendStatus send_status);
294 340
295 // Sends a DATA frame. The delegate will be notified via 341 // Sends a DATA frame. The delegate will be notified via
296 // OnDataSent() when the send is complete. |send_status| must be 342 // OnDataSent() when the send is complete. |send_status| must be
297 // MORE_DATA_TO_SEND for bidirectional streams; for request/response 343 // MORE_DATA_TO_SEND for bidirectional streams; for request/response
298 // streams, it must be MORE_DATA_TO_SEND if there is more data to 344 // streams, it must be MORE_DATA_TO_SEND if there is more data to
299 // upload, or NO_MORE_DATA_TO_SEND if not. 345 // upload, or NO_MORE_DATA_TO_SEND if not.
300 void SendData(IOBuffer* data, int length, SpdySendStatus send_status); 346 void SendData(IOBuffer* data, int length, SpdySendStatus send_status);
301 347
302 // Fills SSL info in |ssl_info| and returns true when SSL is in use. 348 // Fills SSL info in |ssl_info| and returns true when SSL is in use.
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
362 int DoSendRequestHeaders(); 408 int DoSendRequestHeaders();
363 int DoSendRequestHeadersComplete(); 409 int DoSendRequestHeadersComplete();
364 int DoReadHeaders(); 410 int DoReadHeaders();
365 int DoReadHeadersComplete(int result); 411 int DoReadHeadersComplete(int result);
366 int DoOpen(); 412 int DoOpen();
367 413
368 // Update the histograms. Can safely be called repeatedly, but should only 414 // Update the histograms. Can safely be called repeatedly, but should only
369 // be called after the stream has completed. 415 // be called after the stream has completed.
370 void UpdateHistograms(); 416 void UpdateHistograms();
371 417
372 // When a server pushed stream is first created, this function is posted on 418 // When a server-pushed stream is first created, this function is
373 // the MessageLoop to replay all the data that the server has already sent. 419 // posted on the current MessageLoop to replay the data that the
420 // server has already sent.
374 void PushedStreamReplayData(); 421 void PushedStreamReplayData();
375 422
376 // Produces the SYN_STREAM frame for the stream. The stream must 423 // Produces the SYN_STREAM frame for the stream. The stream must
377 // already be activated. 424 // already be activated.
378 scoped_ptr<SpdyFrame> ProduceSynStreamFrame(); 425 scoped_ptr<SpdyFrame> ProduceSynStreamFrame();
379 426
380 // Produce the initial HEADER frame for the stream with the given 427 // Produce the initial HEADER frame for the stream with the given
381 // block. The stream must already be activated. 428 // block. The stream must already be activated.
382 scoped_ptr<SpdyFrame> ProduceHeaderFrame( 429 scoped_ptr<SpdyFrame> ProduceHeaderFrame(
383 scoped_ptr<SpdyHeaderBlock> header_block); 430 scoped_ptr<SpdyHeaderBlock> header_block);
384 431
385 // Queues the send for next frame of the remaining data in 432 // Queues the send for next frame of the remaining data in
386 // |pending_send_data_|. Must be called only when 433 // |pending_send_data_|. Must be called only when
387 // |pending_send_data_| is set. 434 // |pending_send_data_| is set.
388 void QueueNextDataFrame(); 435 void QueueNextDataFrame();
389 436
437 // Merge the given headers into |response_headers_| and calls
438 // OnResponseHeadersUpdated() on the delegate (if attached).
439 // Returns a status code; if it is an error, the stream may have
440 // already been closed.
441 //
442 // TODO(akalin): Guarantee that the stream is already closed if an
443 // error is returned.
444 int MergeWithResponseHeaders(const SpdyHeaderBlock& new_response_headers);
445
390 const SpdyStreamType type_; 446 const SpdyStreamType type_;
391 447
392 base::WeakPtrFactory<SpdyStream> weak_ptr_factory_; 448 base::WeakPtrFactory<SpdyStream> weak_ptr_factory_;
393 449
394 // Sentinel variable used to make sure we don't get destroyed by a 450 // Sentinel variable used to make sure we don't get destroyed by a
395 // function called from DoLoop(). 451 // function called from DoLoop().
396 bool in_do_loop_; 452 bool in_do_loop_;
397 453
398 // There is a small period of time between when a server pushed stream is 454 // There is a small period of time between when a server pushed stream is
399 // first created, and the pushed data is replayed. Any data received during 455 // first created, and the pushed data is replayed. Any data received during
400 // this time should continue to be buffered. 456 // this time should continue to be buffered.
401 bool continue_buffering_data_; 457 bool continue_buffering_data_;
402 458
403 SpdyStreamId stream_id_; 459 SpdyStreamId stream_id_;
404 const std::string path_; 460 const std::string path_;
405 const RequestPriority priority_; 461 const RequestPriority priority_;
406 size_t slot_; 462 size_t slot_;
407 463
408 // Flow control variables. 464 // Flow control variables.
409 bool send_stalled_by_flow_control_; 465 bool send_stalled_by_flow_control_;
410 int32 send_window_size_; 466 int32 send_window_size_;
411 int32 recv_window_size_; 467 int32 recv_window_size_;
412 int32 unacked_recv_window_bytes_; 468 int32 unacked_recv_window_bytes_;
413 469
414 ScopedBandwidthMetrics metrics_; 470 ScopedBandwidthMetrics metrics_;
415 bool response_received_;
416 471
417 scoped_refptr<SpdySession> session_; 472 scoped_refptr<SpdySession> session_;
418 473
419 // The transaction should own the delegate. 474 // The transaction should own the delegate.
420 SpdyStream::Delegate* delegate_; 475 SpdyStream::Delegate* delegate_;
421 476
422 // Whether or not we have more data to send on this stream. 477 // Whether or not we have more data to send on this stream.
423 SpdySendStatus send_status_; 478 SpdySendStatus send_status_;
424 479
425 // The headers for the request to send. 480 // The headers for the request to send.
426 // 481 //
427 // TODO(akalin): Hang onto this only until we send it. This 482 // TODO(akalin): Hang onto this only until we send it. This
428 // necessitates stashing the URL separately. 483 // necessitates stashing the URL separately.
429 scoped_ptr<SpdyHeaderBlock> request_; 484 scoped_ptr<SpdyHeaderBlock> request_headers_;
430 485
431 // The data waiting to be sent. 486 // The data waiting to be sent.
432 scoped_refptr<DrainableIOBuffer> pending_send_data_; 487 scoped_refptr<DrainableIOBuffer> pending_send_data_;
433 488
434 // The time at which the request was made that resulted in this response. 489 // The time at which the request was made that resulted in this response.
435 // For cached responses, this time could be "far" in the past. 490 // For cached responses, this time could be "far" in the past.
436 base::Time request_time_; 491 base::Time request_time_;
437 492
438 scoped_ptr<SpdyHeaderBlock> response_; 493 scoped_ptr<SpdyHeaderBlock> response_headers_;
439 base::Time response_time_; 494 base::Time response_time_;
440 495
441 State io_state_; 496 State io_state_;
442 497
443 // Since we buffer the response, we also buffer the response status. 498 // Since we buffer the response, we also buffer the response status.
444 // Not valid until the stream is closed. 499 // Not valid until the stream is closed.
445 int response_status_; 500 int response_status_;
446 501
447 BoundNetLog net_log_; 502 BoundNetLog net_log_;
448 503
(...skipping 17 matching lines...) Expand all
466 // When OnFrameWriteComplete() is called, these variables are set. 521 // When OnFrameWriteComplete() is called, these variables are set.
467 SpdyFrameType just_completed_frame_type_; 522 SpdyFrameType just_completed_frame_type_;
468 size_t just_completed_frame_size_; 523 size_t just_completed_frame_size_;
469 524
470 DISALLOW_COPY_AND_ASSIGN(SpdyStream); 525 DISALLOW_COPY_AND_ASSIGN(SpdyStream);
471 }; 526 };
472 527
473 } // namespace net 528 } // namespace net
474 529
475 #endif // NET_SPDY_SPDY_STREAM_H_ 530 #endif // NET_SPDY_SPDY_STREAM_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698