OLD | NEW |
---|---|
(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 // This class manages all of the state for a single pipelined connection. It | |
mmenke
2011/08/03 21:09:39
nit: All this should go just before the class, ra
James Simonsen
2011/08/05 01:39:00
Done.
| |
6 // tracks the order that HTTP requests are sent and enforces that the | |
7 // subsequent reads occur in the appropriate order. | |
8 // | |
9 // If an error occurs related to pipelining, ERR_PIPELINE_EVICTION will be | |
10 // returned to the client. This indicates the client should retry the request | |
11 // without pipelining. | |
12 | |
13 #ifndef NET_HTTP_HTTP_PIPELINED_CONNECTION_H_ | |
14 #define NET_HTTP_HTTP_PIPELINED_CONNECTION_H_ | |
15 #pragma once | |
16 | |
17 #include <map> | |
18 #include <queue> | |
19 #include <string> | |
20 | |
21 #include "base/basictypes.h" | |
22 #include "base/task.h" | |
23 #include "net/base/completion_callback.h" | |
24 #include "net/base/net_log.h" | |
25 #include "net/base/ssl_config_service.h" | |
26 #include "net/base/upload_data_stream.h" | |
27 #include "net/http/http_request_info.h" | |
28 #include "net/proxy/proxy_info.h" | |
29 | |
30 namespace net { | |
31 | |
32 class ClientSocketHandle; | |
33 class GrowableIOBuffer; | |
34 class HttpPipelinedHost; | |
35 class HttpPipelinedStream; | |
36 class HttpRequestHeaders; | |
37 class HttpResponseInfo; | |
38 class HttpStreamParser; | |
39 class IOBuffer; | |
40 class SSLCertRequestInfo; | |
41 class SSLInfo; | |
42 | |
43 class HttpPipelinedConnection { | |
44 public: | |
45 HttpPipelinedConnection(ClientSocketHandle* connection, | |
46 HttpPipelinedHost* host, | |
47 const SSLConfig& used_ssl_config, | |
48 const ProxyInfo& used_proxy_info, | |
49 const BoundNetLog& net_log, | |
50 bool was_npn_negotiated); | |
51 ~HttpPipelinedConnection(); | |
52 | |
53 // The number of HTTP requests pending on this pipeline. | |
54 int depth() const { return stream_state_map_.size(); } | |
55 | |
56 // True if this pipeline can accept new HTTP requests. False if a fatal error | |
57 // has occurred. | |
58 bool usable() const { return usable_; } | |
59 | |
60 // True if this pipeline has bound one request is ready for additional | |
mmenke
2011/08/03 21:09:39
nit: "has bound one request and...".
James Simonsen
2011/08/05 01:39:00
Done.
| |
61 // requests. | |
62 bool active() const { return active_; } | |
63 | |
64 const SSLConfig& used_ssl_config() const { return used_ssl_config_; } | |
65 const ProxyInfo& used_proxy_info() const { return used_proxy_info_; } | |
66 const NetLog::Source& source() const { return net_log_.source(); } | |
67 bool was_npn_negotiated() const { return was_npn_negotiated_; } | |
68 | |
69 // HttpPipelinedStream uses these functions. | |
70 | |
71 // Associates a HttpPipelinedStream with this connection. Returns a unique | |
72 // identifier. | |
73 int AddStream(); | |
74 | |
75 // Disassociates a previously associated HttpPipelinedStream. | |
76 void RemoveStream(int pipeline_id); | |
77 | |
78 // Constructs a HttpStreamParser for the associated HttpPipelinedStream. | |
79 void InitializeParser(int pipeline_id, | |
80 const HttpRequestInfo* request, | |
81 const BoundNetLog& net_log); | |
82 | |
83 // Indirect implementation of HttpStream used by our HttpPipelinedStreams. | |
84 int SendRequest(int pipeline_id, | |
85 const std::string& request_line, | |
86 const HttpRequestHeaders& headers, | |
87 UploadDataStream* request_body, | |
88 HttpResponseInfo* response, | |
89 CompletionCallback* callback); | |
90 | |
91 int ReadResponseHeaders(int pipeline_id, | |
92 CompletionCallback* callback); | |
93 | |
94 int ReadResponseBody(int pipeline_id, | |
95 IOBuffer* buf, int buf_len, | |
96 CompletionCallback* callback); | |
97 | |
98 void Close(int pipeline_id, | |
99 bool not_reusable); | |
100 | |
101 uint64 GetUploadProgress(int pipeline_id) const; | |
102 | |
103 HttpResponseInfo* GetResponseInfo(int pipeline_id); | |
104 | |
105 bool IsResponseBodyComplete(int pipeline_id) const; | |
106 | |
107 bool CanFindEndOfResponse(int pipeline_id) const; | |
108 | |
109 bool IsMoreDataBuffered(int pipeline_id) const; | |
110 | |
111 bool IsConnectionReused(int pipeline_id) const; | |
112 | |
113 void SetConnectionReused(int pipeline_id); | |
114 | |
115 void GetSSLInfo(int pipeline_id, | |
116 SSLInfo* ssl_info); | |
117 | |
118 void GetSSLCertRequestInfo(int pipeline_id, | |
119 SSLCertRequestInfo* cert_request_info); | |
120 | |
121 private: | |
122 enum StreamState { | |
123 STREAM_CREATED, | |
124 STREAM_BOUND, | |
125 STREAM_SENT, | |
126 STREAM_CLOSED, | |
127 }; | |
128 enum SendRequestState { | |
129 SEND_STATE_NEXT_REQUEST, | |
130 SEND_STATE_COMPLETE, | |
131 SEND_STATE_NONE, | |
132 SEND_STATE_UNUSABLE, | |
133 }; | |
134 enum ReadHeadersState { | |
135 READ_STATE_NEXT_HEADERS, | |
136 READ_STATE_COMPLETE, | |
137 READ_STATE_STREAM_CLOSED, | |
138 READ_STATE_NONE, | |
139 READ_STATE_UNUSABLE, | |
140 }; | |
141 | |
142 struct DeferredSendRequest { | |
143 int pipeline_id; | |
144 std::string request_line; | |
145 HttpRequestHeaders headers; | |
146 UploadDataStream* request_body; | |
147 HttpResponseInfo* response; | |
148 CompletionCallback* callback; | |
149 }; | |
150 | |
151 // Called after the first request is processed, allowing the rest of this | |
152 // pipeline to fill up with any pending requests. | |
153 void FillPipeline(); | |
154 | |
155 int DoSendRequestLoop(int result); | |
156 void OnSendIOCallback(int result); | |
157 int DoSendNextRequest(int result); | |
mmenke
2011/08/03 21:09:39
It'd great to have comments on what these function
James Simonsen
2011/08/05 01:39:00
Done.
| |
158 int DoSendComplete(int result); | |
159 int DoEvictPendingSendRequests(int result); | |
160 | |
161 int DoReadHeadersLoop(int result); | |
162 void OnReadIOCallback(int result); | |
163 int DoReadNextHeaders(int result); | |
164 int DoReadHeadersComplete(int result); | |
165 int DoStreamClosed(); | |
166 int DoEvictPendingReadHeaders(int result); | |
167 | |
168 void FireUserCallback(CompletionCallback* callback, int result); | |
169 | |
170 HttpPipelinedHost* host_; | |
171 scoped_ptr<ClientSocketHandle> connection_; | |
172 SSLConfig used_ssl_config_; | |
173 ProxyInfo used_proxy_info_; | |
174 BoundNetLog net_log_; | |
175 bool was_npn_negotiated_; | |
176 scoped_refptr<GrowableIOBuffer> read_buf_; | |
177 int next_pipeline_id_; | |
178 bool active_; | |
179 bool usable_; | |
180 ScopedRunnableMethodFactory<HttpPipelinedConnection> method_factory_; | |
181 | |
182 typedef std::map<int, StreamState> StreamStateMap; | |
183 StreamStateMap stream_state_map_; | |
184 typedef std::map<int, HttpStreamParser*> ParserMap; | |
185 ParserMap parser_map_; | |
186 | |
187 std::queue<int> request_order_; | |
188 | |
189 std::queue<DeferredSendRequest> deferred_request_queue_; | |
190 SendRequestState send_next_state_; | |
191 CompletionCallbackImpl<HttpPipelinedConnection> send_io_callback_; | |
192 CompletionCallback* send_user_callback_; | |
193 | |
194 ReadHeadersState read_next_state_; | |
195 CompletionCallbackImpl<HttpPipelinedConnection> read_io_callback_; | |
196 CompletionCallback* read_user_callback_; | |
197 typedef std::map<int, CompletionCallback*> CallbackMap; | |
198 CallbackMap callback_map_; | |
199 | |
200 DISALLOW_COPY_AND_ASSIGN(HttpPipelinedConnection); | |
201 }; | |
202 | |
203 } // namespace net | |
204 | |
205 #endif // NET_HTTP_HTTP_PIPELINED_CONNECTION_H_ | |
OLD | NEW |