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

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

Issue 7289006: Basic HTTP pipelining support (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Simplify transaction unit tests Created 9 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 | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #ifndef NET_HTTP_HTTP_PIPELINED_CONNECTION_IMPL_H_
6 #define NET_HTTP_HTTP_PIPELINED_CONNECTION_IMPL_H_
7 #pragma once
8
9 #include <map>
10 #include <queue>
11 #include <string>
12
13 #include "base/basictypes.h"
14 #include "base/task.h"
15 #include "net/base/completion_callback.h"
16 #include "net/base/net_log.h"
17 #include "net/base/ssl_config_service.h"
18 #include "net/base/upload_data_stream.h"
19 #include "net/http/http_pipelined_connection.h"
20 #include "net/http/http_request_info.h"
21 #include "net/proxy/proxy_info.h"
22
23 namespace net {
24
25 class ClientSocketHandle;
26 class GrowableIOBuffer;
27 class HttpRequestHeaders;
28 class HttpResponseInfo;
29 class HttpStreamParser;
30 class IOBuffer;
31 class SSLCertRequestInfo;
32 class SSLInfo;
33
34 // This class manages all of the state for a single pipelined connection. It
35 // tracks the order that HTTP requests are sent and enforces that the
36 // subsequent reads occur in the appropriate order.
37 //
38 // If an error occurs related to pipelining, ERR_PIPELINE_EVICTION will be
39 // returned to the client. This indicates the client should retry the request
40 // without pipelining.
41 class NET_EXPORT_PRIVATE HttpPipelinedConnectionImpl
42 : public HttpPipelinedConnection {
43 public:
44 HttpPipelinedConnectionImpl(ClientSocketHandle* connection,
45 Delegate* delegate,
46 const SSLConfig& used_ssl_config,
47 const ProxyInfo& used_proxy_info,
48 const BoundNetLog& net_log,
49 bool was_npn_negotiated);
50 ~HttpPipelinedConnectionImpl();
51
52 // HttpPipelinedConnection interface.
53
54 // Used by HttpStreamFactoryImpl and friends.
55 virtual HttpStream* CreateNewStream() OVERRIDE;
56
57 // Used by HttpPipelinedHost.
58 virtual int depth() const OVERRIDE { return stream_state_map_.size(); }
willchan no longer on Chromium 2011/09/26 23:49:20 I suspect this won't pass the clang bot. You might
James Simonsen 2011/09/29 02:39:31 Seems fine. It did find something else, which I've
59 virtual bool usable() const OVERRIDE { return usable_; }
60 virtual bool active() const OVERRIDE { return active_; }
61
62 // Used by HttpStreamFactoryImpl.
63 virtual const SSLConfig& used_ssl_config() const OVERRIDE {
64 return used_ssl_config_;
65 }
66 virtual const ProxyInfo& used_proxy_info() const OVERRIDE {
67 return used_proxy_info_;
68 }
69 virtual const NetLog::Source& source() const OVERRIDE {
70 return net_log_.source();
71 }
72 virtual bool was_npn_negotiated() const OVERRIDE {
73 return was_npn_negotiated_;
74 }
75
76 // Used by HttpPipelinedStream.
77 virtual void OnStreamDeleted(int pipeline_id) OVERRIDE;
78
79 // Effective implementation of HttpStream. Note that we don't directly
80 // implement that interface. Instead, these functions will be called by the
81 // pass-through methods in HttpPipelinedStream.
82 void InitializeParser(int pipeline_id,
83 const HttpRequestInfo* request,
84 const BoundNetLog& net_log);
85
86 int SendRequest(int pipeline_id,
87 const std::string& request_line,
88 const HttpRequestHeaders& headers,
89 UploadDataStream* request_body,
90 HttpResponseInfo* response,
91 CompletionCallback* callback);
92
93 int ReadResponseHeaders(int pipeline_id,
94 CompletionCallback* callback);
95
96 int ReadResponseBody(int pipeline_id,
97 IOBuffer* buf, int buf_len,
98 CompletionCallback* callback);
99
100 void Close(int pipeline_id,
101 bool not_reusable);
102
103 uint64 GetUploadProgress(int pipeline_id) const;
104
105 HttpResponseInfo* GetResponseInfo(int pipeline_id);
106
107 bool IsResponseBodyComplete(int pipeline_id) const;
108
109 bool CanFindEndOfResponse(int pipeline_id) const;
110
111 bool IsMoreDataBuffered(int pipeline_id) const;
112
113 bool IsConnectionReused(int pipeline_id) const;
114
115 void SetConnectionReused(int pipeline_id);
116
117 void GetSSLInfo(int pipeline_id,
118 SSLInfo* ssl_info);
119
120 void GetSSLCertRequestInfo(int pipeline_id,
121 SSLCertRequestInfo* cert_request_info);
122
123 private:
124 enum StreamState {
125 STREAM_CREATED,
126 STREAM_BOUND,
127 STREAM_SENDING,
128 STREAM_SENT,
129 STREAM_READ_PENDING,
130 STREAM_ACTIVE,
131 STREAM_CLOSED,
132 STREAM_UNUSED,
133 };
134 enum SendRequestState {
135 SEND_STATE_NEXT_REQUEST,
136 SEND_STATE_COMPLETE,
137 SEND_STATE_NONE,
138 SEND_STATE_UNUSABLE,
139 };
140 enum ReadHeadersState {
141 READ_STATE_NEXT_HEADERS,
142 READ_STATE_COMPLETE,
143 READ_STATE_WAITING_FOR_CLOSE,
144 READ_STATE_STREAM_CLOSED,
145 READ_STATE_NONE,
146 READ_STATE_UNUSABLE,
147 };
148
149 struct DeferredSendRequest {
150 int pipeline_id;
151 std::string request_line;
152 HttpRequestHeaders headers;
153 UploadDataStream* request_body;
154 HttpResponseInfo* response;
155 CompletionCallback* callback;
156 };
157
158 // Called after the first request is processed, allowing the rest of this
159 // pipeline to fill up with any pending requests.
160 void FillPipeline();
161
162 // Responsible for sending one request at a time and waiting until each
163 // comepletes.
164 int DoSendRequestLoop(int result);
165
166 // Called when an asynchronous Send() completes.
167 void OnSendIOCallback(int result);
168
169 // Sends the next deferred request. This may be called immediately after
170 // SendRequest(), or it may be in a new task after a prior send completes in
171 // DoSendComplete().
172 int DoSendNextRequest(int result);
173
174 // Notifies the user that the send has completed. This may be called directly
175 // after SendRequest() for a synchronous request, or it may be called in
176 // response to OnSendIOCallback for an asynchronous request.
177 int DoSendComplete(int result);
178
179 // Evicts all unsent deferred requests. This is called if there is a Send()
180 // error or one of our streams informs us the connection is no longer
181 // reusable.
182 int DoEvictPendingSendRequests(int result);
183
184 // Ensures that only the active request's HttpPipelinedSocket can read from
185 // the underlying socket until it completes. A HttpPipelinedSocket informs us
186 // that it's done by calling Close().
187 int DoReadHeadersLoop(int result);
188
189 // Called when the pending asynchronous ReadResponseHeaders() completes.
190 void OnReadIOCallback(int result);
191
192 // Determines if the next response in the pipeline is ready to be read.
193 // If it's ready, then we call ReadResponseHeaders() on the underlying parser.
194 // HttpPipelinedSocket indicates its readiness by calling
195 // ReadResponseHeaders(). This function may be called immediately after
196 // ReadResponseHeaders(), or it may be called in a new task after a previous
197 // HttpPipelinedSocket finishes its work.
198 int DoReadNextHeaders(int result);
199
200 // Notifies the user that reading the headers has completed. This may happen
201 // directly after DoReadNextHeaders() if the response is already available.
202 // Otherwise, it is called in response to OnReadIOCallback().
203 int DoReadHeadersComplete(int result);
204
205 // This is a holding state. It does not do anything, except exit the
206 // DoReadHeadersLoop(). It is called after DoReadHeadersComplete().
207 int DoReadWaitingForClose(int result);
208
209 // Cleans up the state associated with the active request. Invokes
210 // DoReadNextHeaders() in a new task to start the next response. This is
211 // called after the active request's HttpPipelinedSocket calls Close().
212 int DoReadStreamClosed();
213
214 // Removes all pending ReadResponseHeaders() requests from the queue. This may
215 // happen if there is an error with the pipeline or one of our
216 // HttpPipelinedSockets indicates the connection was suddenly closed.
217 int DoEvictPendingReadHeaders(int result);
218
219 // Invokes the user's callback in response to ReadResponseHeaders() completing
220 // on an underlying parser. This might be invoked in response to our own
221 // read_io_callback_ being invoked, or it may be due to ReadResponseHeaders()
222 // completing synchronously after we've already returned ERR_IO_PENDING to the
223 // user.
224 void FireReadUserCallback(int result);
225
226 Delegate* delegate_;
227 scoped_ptr<ClientSocketHandle> connection_;
228 SSLConfig used_ssl_config_;
229 ProxyInfo used_proxy_info_;
230 BoundNetLog net_log_;
231 bool was_npn_negotiated_;
232 scoped_refptr<GrowableIOBuffer> read_buf_;
233 int next_pipeline_id_;
234 bool active_;
235 bool usable_;
236 bool completed_one_request_;
237 ScopedRunnableMethodFactory<HttpPipelinedConnectionImpl> method_factory_;
238
239 typedef std::map<int, StreamState> StreamStateMap;
240 StreamStateMap stream_state_map_;
241 typedef std::map<int, HttpStreamParser*> ParserMap;
242 ParserMap parser_map_;
243
244 std::queue<int> request_order_;
245
246 std::queue<DeferredSendRequest> deferred_request_queue_;
247 SendRequestState send_next_state_;
248 CompletionCallbackImpl<HttpPipelinedConnectionImpl> send_io_callback_;
249 CompletionCallback* send_user_callback_;
250
251 ReadHeadersState read_next_state_;
252 CompletionCallbackImpl<HttpPipelinedConnectionImpl> read_io_callback_;
253 CompletionCallback* read_user_callback_;
254 typedef std::map<int, CompletionCallback*> CallbackMap;
255 CallbackMap callback_map_;
256
257 DISALLOW_COPY_AND_ASSIGN(HttpPipelinedConnectionImpl);
258 };
259
260 } // namespace net
261
262 #endif // NET_HTTP_HTTP_PIPELINED_CONNECTION_IMPL_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698