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

Side by Side Diff: net/http/http_stream.h

Issue 1320683003: Move logic to figure out if a socket can be reused into HttpStream. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix tests Created 5 years, 3 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
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 // HttpStream provides an abstraction for a basic http streams, SPDY, and QUIC. 5 // HttpStream provides an abstraction for a basic http streams, SPDY, and QUIC.
6 // The HttpStream subtype is expected to manage the underlying transport 6 // The HttpStream subtype is expected to manage the underlying transport
7 // appropriately. For example, a basic http stream will return the transport 7 // appropriately. For example, a basic http stream will return the transport
8 // socket to the pool for reuse. SPDY streams on the other hand leave the 8 // socket to the pool for reuse. SPDY streams on the other hand leave the
9 // transport socket management to the SpdySession. 9 // transport socket management to the SpdySession.
10 10
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
82 // the socket acquires a reference to the provided buffer until the callback 82 // the socket acquires a reference to the provided buffer until the callback
83 // is invoked or the socket is destroyed. 83 // is invoked or the socket is destroyed.
84 virtual int ReadResponseBody(IOBuffer* buf, int buf_len, 84 virtual int ReadResponseBody(IOBuffer* buf, int buf_len,
85 const CompletionCallback& callback) = 0; 85 const CompletionCallback& callback) = 0;
86 86
87 // Closes the stream. 87 // Closes the stream.
88 // |not_reusable| indicates if the stream can be used for further requests. 88 // |not_reusable| indicates if the stream can be used for further requests.
89 // In the case of HTTP, where we re-use the byte-stream (e.g. the connection) 89 // In the case of HTTP, where we re-use the byte-stream (e.g. the connection)
90 // this means we need to close the connection; in the case of SPDY, where the 90 // this means we need to close the connection; in the case of SPDY, where the
91 // underlying stream is never reused, it has no effect. 91 // underlying stream is never reused, it has no effect.
92 // TODO(mbelshe): We should figure out how to fold the not_reusable flag 92 // TODO(mmenke): We should fold the |not_reusable| flag into the stream
93 // into the stream implementation itself so that the caller 93 // implementation itself so that the caller does not need to
94 // does not need to pass it at all. We might also be able to 94 // pass it at all. Ideally we'd be able to remove
95 // eliminate the SetConnectionReused() below. 95 // CanReuseConnection() and IsResponseBodyComplete().
96 // TODO(mmenke): We should try and merge Drain() into this method as well.
96 virtual void Close(bool not_reusable) = 0; 97 virtual void Close(bool not_reusable) = 0;
97 98
98 // Indicates if the response body has been completely read. 99 // Indicates if the response body has been completely read.
99 virtual bool IsResponseBodyComplete() const = 0; 100 virtual bool IsResponseBodyComplete() const = 0;
100 101
101 // Indicates that the end of the response is detectable. This means that
102 // the response headers indicate either chunked encoding or content length.
103 // If neither is sent, the server must close the connection for us to detect
104 // the end of the response.
105 // TODO(rch): Rename this method, so that it is clear why it exists
106 // particularly as it applies to QUIC and SPDY for which the end of the
107 // response is always findable.
108 virtual bool CanFindEndOfResponse() const = 0;
109
110 // A stream exists on top of a connection. If the connection has been used 102 // A stream exists on top of a connection. If the connection has been used
111 // to successfully exchange data in the past, error handling for the 103 // to successfully exchange data in the past, error handling for the
112 // stream is done differently. This method returns true if the underlying 104 // stream is done differently. This method returns true if the underlying
113 // connection is reused or has been connected and idle for some time. 105 // connection is reused or has been connected and idle for some time.
114 virtual bool IsConnectionReused() const = 0; 106 virtual bool IsConnectionReused() const = 0;
107 // TODO(mmenke): We should fold this into RenewStreamForAuth(), and make that
108 // method drain the stream as well, if needed (And return asynchronously).
115 virtual void SetConnectionReused() = 0; 109 virtual void SetConnectionReused() = 0;
116 110
117 // Checks whether the current state of the underlying connection 111 // Checks whether the underlying connection can be reused. The stream's
118 // allows it to be reused. 112 // connection can be reused if the response headers allow for it, the socket
119 virtual bool IsConnectionReusable() const = 0; 113 // is still connected, and the stream exclusively owns the underlying
114 // connection. SPDY and QUIC streams don't own their own connections, so
115 // always return false.
116 virtual bool CanReuseConnection() const = 0;
120 117
121 // Get the total number of bytes received from network for this stream. 118 // Get the total number of bytes received from network for this stream.
122 virtual int64 GetTotalReceivedBytes() const = 0; 119 virtual int64 GetTotalReceivedBytes() const = 0;
123 120
124 // Populates the connection establishment part of |load_timing_info|, and 121 // Populates the connection establishment part of |load_timing_info|, and
125 // socket ID. |load_timing_info| must have all null times when called. 122 // socket ID. |load_timing_info| must have all null times when called.
126 // Returns false and does nothing if there is no underlying connection, either 123 // Returns false and does nothing if there is no underlying connection, either
127 // because one has yet to be assigned to the stream, or because the underlying 124 // because one has yet to be assigned to the stream, or because the underlying
128 // socket has been closed. 125 // socket has been closed.
129 // 126 //
130 // In practice, this means that this function will always succeed any time 127 // In practice, this means that this function will always succeed any time
131 // between when the full headers have been received and the stream has been 128 // between when the full headers have been received and the stream has been
132 // closed. 129 // closed.
133 virtual bool GetLoadTimingInfo(LoadTimingInfo* load_timing_info) const = 0; 130 virtual bool GetLoadTimingInfo(LoadTimingInfo* load_timing_info) const = 0;
134 131
135 // Get the SSLInfo associated with this stream's connection. This should 132 // Get the SSLInfo associated with this stream's connection. This should
136 // only be called for streams over SSL sockets, otherwise the behavior is 133 // only be called for streams over SSL sockets, otherwise the behavior is
137 // undefined. 134 // undefined.
138 virtual void GetSSLInfo(SSLInfo* ssl_info) = 0; 135 virtual void GetSSLInfo(SSLInfo* ssl_info) = 0;
139 136
140 // Get the SSLCertRequestInfo associated with this stream's connection. 137 // Get the SSLCertRequestInfo associated with this stream's connection.
141 // This should only be called for streams over SSL sockets, otherwise the 138 // This should only be called for streams over SSL sockets, otherwise the
142 // behavior is undefined. 139 // behavior is undefined.
143 virtual void GetSSLCertRequestInfo(SSLCertRequestInfo* cert_request_info) = 0; 140 virtual void GetSSLCertRequestInfo(SSLCertRequestInfo* cert_request_info) = 0;
144 141
145 // HACK(willchan): Really, we should move the HttpResponseDrainer logic into
146 // the HttpStream implementation. This is just a quick hack.
147 virtual bool IsSpdyHttpStream() const = 0;
148
149 // In the case of an HTTP error or redirect, flush the response body (usually 142 // In the case of an HTTP error or redirect, flush the response body (usually
150 // a simple error or "this page has moved") so that we can re-use the 143 // a simple error or "this page has moved") so that we can re-use the
151 // underlying connection. This stream is responsible for deleting itself when 144 // underlying connection. This stream is responsible for deleting itself when
152 // draining is complete. 145 // draining is complete.
153 virtual void Drain(HttpNetworkSession* session) = 0; 146 virtual void Drain(HttpNetworkSession* session) = 0;
154 147
155 // Called when the priority of the parent transaction changes. 148 // Called when the priority of the parent transaction changes.
156 virtual void SetPriority(RequestPriority priority) = 0; 149 virtual void SetPriority(RequestPriority priority) = 0;
157 150
158 // Queries the UploadDataStream for its progress (bytes sent). 151 // Queries the UploadDataStream for its progress (bytes sent).
159 virtual UploadProgress GetUploadProgress() const = 0; 152 virtual UploadProgress GetUploadProgress() const = 0;
160 153
161 // Returns a new (not initialized) stream using the same underlying 154 // Returns a new (not initialized) stream using the same underlying
162 // connection and invalidates the old stream - no further methods should be 155 // connection and invalidates the old stream - no further methods should be
163 // called on the old stream. The caller should ensure that the response body 156 // called on the old stream. The caller should ensure that the response body
164 // from the previous request is drained before calling this method. If the 157 // from the previous request is drained before calling this method. If the
165 // subclass does not support renewing the stream, NULL is returned. 158 // subclass does not support renewing the stream, NULL is returned.
166 virtual HttpStream* RenewStreamForAuth() = 0; 159 virtual HttpStream* RenewStreamForAuth() = 0;
167 160
168 private: 161 private:
169 DISALLOW_COPY_AND_ASSIGN(HttpStream); 162 DISALLOW_COPY_AND_ASSIGN(HttpStream);
170 }; 163 };
171 164
172 } // namespace net 165 } // namespace net
173 166
174 #endif // NET_HTTP_HTTP_STREAM_H_ 167 #endif // NET_HTTP_HTTP_STREAM_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698