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

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

Issue 15936003: [SPDY] Refactor SpdyStream::Delegate (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Address comments 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
« no previous file with comments | « net/spdy/spdy_session_spdy3_unittest.cc ('k') | net/spdy/spdy_stream.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
64 // until such a time as a client object requests a stream for the path. 64 // until such a time as a client object requests a stream for the path.
65 class NET_EXPORT_PRIVATE SpdyStream { 65 class NET_EXPORT_PRIVATE SpdyStream {
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 OnSendRequestHeadersComplete() = 0; 74 virtual void OnRequestHeadersSent() = 0;
75
76 // Called when the stream is ready to send body data. The
77 // delegate must call SendStreamData() on the stream, either
78 // immediately or asynchronously (e.g., if the data to be send has
79 // to be read asynchronously).
80 //
81 // Called only for request/response streams when
82 // SendRequestHeaders() is called with MORE_DATA_TO_SEND.
83 //
84 // TODO(akalin): Unify this with OnSendRequestHeadersComplete().
85 virtual void OnSendBody() = 0;
86
87 // Called when body data has been sent.
88 //
89 // TODO(akalin): Unify this with OnDataSent().
90 virtual void OnSendBodyComplete() = 0;
91 75
92 // Called when the SYN_STREAM, SYN_REPLY, or HEADERS frames are received. 76 // Called when the SYN_STREAM, SYN_REPLY, or HEADERS frames are received.
93 // Normal streams will receive a SYN_REPLY and optional HEADERS frames. 77 // Normal streams will receive a SYN_REPLY and optional HEADERS frames.
94 // Pushed streams will receive a SYN_STREAM and optional HEADERS frames. 78 // Pushed streams will receive a SYN_STREAM and optional HEADERS frames.
95 // Because a stream may have a SYN_* frame and multiple HEADERS frames, 79 // Because a stream may have a SYN_* frame and multiple HEADERS frames,
96 // this callback may be called multiple times. 80 // this callback may be called multiple times.
97 // |status| indicates network error. Returns network error code. 81 // |status| indicates network error. Returns network error code.
98 virtual int OnResponseReceived(const SpdyHeaderBlock& response, 82 virtual int OnResponseHeadersReceived(const SpdyHeaderBlock& response,
99 base::Time response_time, 83 base::Time response_time,
100 int status) = 0; 84 int status) = 0;
101 85
102 // Called when data is received. |buffer| may be NULL, which 86 // Called when data is received. |buffer| may be NULL, which
103 // signals EOF. Must return OK if the data was received 87 // signals EOF. Must return OK if the data was received
104 // successfully, or a network error code otherwise. 88 // successfully, or a network error code otherwise.
105 virtual int OnDataReceived(scoped_ptr<SpdyBuffer> buffer) = 0; 89 virtual int OnDataReceived(scoped_ptr<SpdyBuffer> buffer) = 0;
106 90
107 // Called when data is sent. 91 // Called when data is sent.
108 virtual void OnDataSent() = 0; 92 virtual void OnDataSent() = 0;
109 93
110 // Called when SpdyStream is closed. No other delegate functions 94 // Called when SpdyStream is closed. No other delegate functions
(...skipping 12 matching lines...) Expand all
123 SpdyStream(SpdyStreamType type, 107 SpdyStream(SpdyStreamType type,
124 SpdySession* session, 108 SpdySession* session,
125 const std::string& path, 109 const std::string& path,
126 RequestPriority priority, 110 RequestPriority priority,
127 int32 initial_send_window_size, 111 int32 initial_send_window_size,
128 int32 initial_recv_window_size, 112 int32 initial_recv_window_size,
129 const BoundNetLog& net_log); 113 const BoundNetLog& net_log);
130 114
131 ~SpdyStream(); 115 ~SpdyStream();
132 116
133 // Set new |delegate|. |delegate| must not be NULL. 117 // Set new |delegate|. |delegate| must not be NULL. If it already
134 // If it already received SYN_REPLY or data, OnResponseReceived() or 118 // received SYN_REPLY or data, OnResponseHeadersReceived() or
135 // OnDataReceived() will be called. 119 // OnDataReceived() will be called.
136 void SetDelegate(Delegate* delegate); 120 void SetDelegate(Delegate* delegate);
137 Delegate* GetDelegate() { return delegate_; } 121 Delegate* GetDelegate() { return delegate_; }
138 122
139 // Detach the delegate from the stream, which must not yet be 123 // Detach the delegate from the stream, which must not yet be
140 // closed, and cancel it. 124 // closed, and cancel it.
141 void DetachDelegate(); 125 void DetachDelegate();
142 126
143 SpdyStreamType type() const { return type_; } 127 SpdyStreamType type() const { return type_; }
144 128
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
240 bool WasEverUsed() const; 224 bool WasEverUsed() const;
241 225
242 const BoundNetLog& net_log() const { return net_log_; } 226 const BoundNetLog& net_log() const { return net_log_; }
243 227
244 base::Time GetRequestTime() const; 228 base::Time GetRequestTime() const;
245 void SetRequestTime(base::Time t); 229 void SetRequestTime(base::Time t);
246 230
247 // Called by the SpdySession when a response (e.g. a SYN_STREAM or 231 // Called by the SpdySession when a response (e.g. a SYN_STREAM or
248 // SYN_REPLY) has been received for this stream. This is the entry 232 // SYN_REPLY) has been received for this stream. This is the entry
249 // point for a push stream. Returns a status code. 233 // point for a push stream. Returns a status code.
250 int OnResponseReceived(const SpdyHeaderBlock& response); 234 int OnResponseHeadersReceived(const SpdyHeaderBlock& response);
251 235
252 // Called by the SpdySession when late-bound headers are received for a 236 // Called by the SpdySession when late-bound headers are received for a
253 // stream. Returns a status code. 237 // stream. Returns a status code.
254 int OnHeaders(const SpdyHeaderBlock& headers); 238 int OnHeaders(const SpdyHeaderBlock& headers);
255 239
256 // Called by the SpdySession when response data has been received for this 240 // Called by the SpdySession when response data has been received
257 // stream. This callback may be called multiple times as data arrives 241 // for this stream. This callback may be called multiple times as
258 // from the network, and will never be called prior to OnResponseReceived. 242 // data arrives from the network, and will never be called prior to
243 // OnResponseHeadersReceived.
259 // 244 //
260 // |buffer| contains the data received, or NULL if the stream is 245 // |buffer| contains the data received, or NULL if the stream is
261 // being closed. The stream must copy any data from this 246 // being closed. The stream must copy any data from this
262 // buffer before returning from this callback. 247 // buffer before returning from this callback.
263 // 248 //
264 // |length| is the number of bytes received (at most 2^24 - 1) or 0 if 249 // |length| is the number of bytes received (at most 2^24 - 1) or 0 if
265 // the stream is being closed. 250 // the stream is being closed.
266 void OnDataReceived(scoped_ptr<SpdyBuffer> buffer); 251 void OnDataReceived(scoped_ptr<SpdyBuffer> buffer);
267 252
268 // Called by the SpdySession when a frame has been successfully and 253 // Called by the SpdySession when a frame has been successfully and
(...skipping 27 matching lines...) Expand all
296 // TODO(satorux): This is only for testing. We should be able to remove 281 // TODO(satorux): This is only for testing. We should be able to remove
297 // this once crbug.com/113107 is addressed. 282 // this once crbug.com/113107 is addressed.
298 bool body_sent() const { return io_state_ > STATE_SEND_BODY_COMPLETE; } 283 bool body_sent() const { return io_state_ > STATE_SEND_BODY_COMPLETE; }
299 284
300 // Interface for the delegate to use. 285 // Interface for the delegate to use.
301 286
302 // Only one send can be in flight at a time, except for push 287 // Only one send can be in flight at a time, except for push
303 // streams, which must not send anything. 288 // streams, which must not send anything.
304 289
305 // Sends the request headers. The delegate is called back via 290 // Sends the request headers. The delegate is called back via
306 // OnSendRequestHeadersComplete() when the request headers have 291 // OnRequestHeadersSent() when the request headers have completed
307 // completed sending. |send_status| must be MORE_DATA_TO_SEND for 292 // sending. |send_status| must be MORE_DATA_TO_SEND for
308 // bidirectional streams; for request/response streams, it must be 293 // bidirectional streams; for request/response streams, it must be
309 // MORE_DATA_TO_SEND if the request has data to upload, or 294 // MORE_DATA_TO_SEND if the request has data to upload, or
310 // NO_MORE_DATA_TO_SEND if not. 295 // NO_MORE_DATA_TO_SEND if not.
311 int SendRequestHeaders(scoped_ptr<SpdyHeaderBlock> headers, 296 int SendRequestHeaders(scoped_ptr<SpdyHeaderBlock> headers,
312 SpdySendStatus send_status); 297 SpdySendStatus send_status);
313 298
314 // Sends a DATA frame. The delegate will be notified via 299 // Sends a DATA frame. The delegate will be notified via
315 // OnSendBodyComplete() (if the response hasn't been received yet) 300 // OnDataSent() when the send is complete. |send_status| must be
316 // or OnDataSent() (if the response has been received) when the send 301 // MORE_DATA_TO_SEND for bidirectional streams; for request/response
317 // is complete. |send_status| must be MORE_DATA_TO_SEND for 302 // streams, it must be MORE_DATA_TO_SEND if there is more data to
318 // bidirectional streams; for request/response streams, it must be 303 // upload, or NO_MORE_DATA_TO_SEND if not.
319 // MORE_DATA_TO_SEND if there is more data to upload, or 304 void SendData(IOBuffer* data, int length, SpdySendStatus send_status);
320 // NO_MORE_DATA_TO_SEND if not.
321 void SendStreamData(IOBuffer* data, int length, SpdySendStatus send_status);
322 305
323 // Fills SSL info in |ssl_info| and returns true when SSL is in use. 306 // Fills SSL info in |ssl_info| and returns true when SSL is in use.
324 bool GetSSLInfo(SSLInfo* ssl_info, 307 bool GetSSLInfo(SSLInfo* ssl_info,
325 bool* was_npn_negotiated, 308 bool* was_npn_negotiated,
326 NextProto* protocol_negotiated); 309 NextProto* protocol_negotiated);
327 310
328 // Fills SSL Certificate Request info |cert_request_info| and returns 311 // Fills SSL Certificate Request info |cert_request_info| and returns
329 // true when SSL is in use. 312 // true when SSL is in use.
330 bool GetSSLCertRequestInfo(SSLCertRequestInfo* cert_request_info); 313 bool GetSSLCertRequestInfo(SSLCertRequestInfo* cert_request_info);
331 314
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after
499 // When OnFrameWriteComplete() is called, these variables are set. 482 // When OnFrameWriteComplete() is called, these variables are set.
500 SpdyFrameType just_completed_frame_type_; 483 SpdyFrameType just_completed_frame_type_;
501 size_t just_completed_frame_size_; 484 size_t just_completed_frame_size_;
502 485
503 DISALLOW_COPY_AND_ASSIGN(SpdyStream); 486 DISALLOW_COPY_AND_ASSIGN(SpdyStream);
504 }; 487 };
505 488
506 } // namespace net 489 } // namespace net
507 490
508 #endif // NET_SPDY_SPDY_STREAM_H_ 491 #endif // NET_SPDY_SPDY_STREAM_H_
OLDNEW
« no previous file with comments | « net/spdy/spdy_session_spdy3_unittest.cc ('k') | net/spdy/spdy_stream.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698