OLD | NEW |
---|---|
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 #include "net/http/http_stream_factory_impl_request.h" | 5 #include "net/http/http_stream_factory_impl_request.h" |
6 | 6 |
7 #include "base/callback.h" | 7 #include "base/callback.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "base/stl_util.h" | 9 #include "base/stl_util.h" |
10 #include "net/http/http_stream_factory_impl_job.h" | 10 #include "net/http/http_stream_factory_impl_job.h" |
11 #include "net/spdy/spdy_http_stream.h" | 11 #include "net/spdy/spdy_http_stream.h" |
12 #include "net/spdy/spdy_session.h" | 12 #include "net/spdy/spdy_session.h" |
13 | 13 |
14 namespace net { | 14 namespace net { |
15 | 15 |
16 HttpStreamFactoryImpl::Request::Request(const GURL& url, | 16 HttpStreamFactoryImpl::Request::Request(const GURL& url, |
17 HttpStreamFactoryImpl* factory, | 17 HttpStreamFactoryImpl* factory, |
18 HttpStreamRequest::Delegate* delegate, | 18 HttpStreamRequest::Delegate* delegate, |
19 const BoundNetLog& net_log) | 19 const BoundNetLog& net_log, |
20 bool for_websocket) | |
20 : url_(url), | 21 : url_(url), |
21 factory_(factory), | 22 factory_(factory), |
22 delegate_(delegate), | 23 delegate_(delegate), |
23 net_log_(net_log), | 24 net_log_(net_log), |
24 completed_(false), | 25 completed_(false), |
25 was_npn_negotiated_(false), | 26 was_npn_negotiated_(false), |
26 protocol_negotiated_(kProtoUnknown), | 27 protocol_negotiated_(kProtoUnknown), |
27 using_spdy_(false) { | 28 using_spdy_(false), |
29 for_websocket_(for_websocket) { | |
28 DCHECK(factory_); | 30 DCHECK(factory_); |
29 DCHECK(delegate_); | 31 DCHECK(delegate_); |
30 | 32 |
31 net_log_.BeginEvent(NetLog::TYPE_HTTP_STREAM_REQUEST); | 33 net_log_.BeginEvent(NetLog::TYPE_HTTP_STREAM_REQUEST); |
32 } | 34 } |
33 | 35 |
34 HttpStreamFactoryImpl::Request::~Request() { | 36 HttpStreamFactoryImpl::Request::~Request() { |
35 if (bound_job_.get()) | 37 if (bound_job_.get()) |
36 DCHECK(jobs_.empty()); | 38 DCHECK(jobs_.empty()); |
37 else | 39 else |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
119 } else if (!bound_job_.get()) { | 121 } else if (!bound_job_.get()) { |
120 // We may have other jobs in |jobs_|. For example, if we start multiple jobs | 122 // We may have other jobs in |jobs_|. For example, if we start multiple jobs |
121 // for Alternate-Protocol. | 123 // for Alternate-Protocol. |
122 OrphanJobsExcept(job); | 124 OrphanJobsExcept(job); |
123 } else { | 125 } else { |
124 DCHECK(jobs_.empty()); | 126 DCHECK(jobs_.empty()); |
125 } | 127 } |
126 delegate_->OnStreamReady(used_ssl_config, used_proxy_info, stream); | 128 delegate_->OnStreamReady(used_ssl_config, used_proxy_info, stream); |
127 } | 129 } |
128 | 130 |
131 void HttpStreamFactoryImpl::Request::OnSocketReady( | |
132 Job* job, | |
133 const SSLConfig& used_ssl_config, | |
134 const ProxyInfo& used_proxy_info, | |
135 ClientSocketHandle* connection) { | |
136 DCHECK(connection); | |
137 DCHECK(completed_); | |
138 | |
139 // |job| should only be NULL if we're being serviced by a late bound | |
140 // SpdySession or HttpPipelinedConnection (one that was not created by a job | |
141 // in our |jobs_| set). | |
142 if (!job) { | |
143 DCHECK(!bound_job_.get()); | |
144 DCHECK(!jobs_.empty()); | |
145 // NOTE(willchan): We do *NOT* call OrphanJobs() here. The reason is because | |
146 // we *WANT* to cancel the unnecessary Jobs from other requests if another | |
147 // Job completes first. | |
148 // TODO(mbelshe): Revisit this when we implement ip connection pooling of | |
149 // SpdySessions. Do we want to orphan the jobs for a different hostname so | |
150 // they complete? Or do we want to prevent connecting a new SpdySession if | |
151 // we've already got one available for a different hostname where the ip | |
152 // address matches up? | |
153 } else if (!bound_job_.get()) { | |
154 // We may have other jobs in |jobs_|. For example, if we start multiple jobs | |
155 // for Alternate-Protocol. | |
156 OrphanJobsExcept(job); | |
157 } else { | |
158 DCHECK(jobs_.empty()); | |
159 } | |
tyoshino (SeeGerritForStatus)
2013/05/15 07:48:52
factor out common part?
yhirano
2013/05/15 08:21:28
Done.
| |
160 delegate_->OnSocketReady(used_ssl_config, used_proxy_info, connection); | |
161 } | |
162 | |
163 void HttpStreamFactoryImpl::Request::OnSpdySessionReadyForWS( | |
164 Job* job, | |
165 const SSLConfig& used_ssl_config, | |
166 const ProxyInfo& used_proxy_info, | |
167 scoped_refptr<SpdySession> session) { | |
168 DCHECK(session); | |
169 DCHECK(completed_); | |
170 | |
171 // |job| should only be NULL if we're being serviced by a late bound | |
172 // SpdySession or HttpPipelinedConnection (one that was not created by a job | |
173 // in our |jobs_| set). | |
174 if (!job) { | |
175 DCHECK(!bound_job_.get()); | |
176 DCHECK(!jobs_.empty()); | |
177 // NOTE(willchan): We do *NOT* call OrphanJobs() here. The reason is because | |
178 // we *WANT* to cancel the unnecessary Jobs from other requests if another | |
179 // Job completes first. | |
180 // TODO(mbelshe): Revisit this when we implement ip connection pooling of | |
181 // SpdySessions. Do we want to orphan the jobs for a different hostname so | |
182 // they complete? Or do we want to prevent connecting a new SpdySession if | |
183 // we've already got one available for a different hostname where the ip | |
184 // address matches up? | |
185 } else if (!bound_job_.get()) { | |
186 // We may have other jobs in |jobs_|. For example, if we start multiple jobs | |
187 // for Alternate-Protocol. | |
188 OrphanJobsExcept(job); | |
189 } else { | |
190 DCHECK(jobs_.empty()); | |
191 } | |
192 delegate_->OnSpdySessionReady(used_ssl_config, | |
193 used_proxy_info, | |
194 session.get()); | |
195 } | |
196 | |
129 void HttpStreamFactoryImpl::Request::OnStreamFailed( | 197 void HttpStreamFactoryImpl::Request::OnStreamFailed( |
130 Job* job, | 198 Job* job, |
131 int status, | 199 int status, |
132 const SSLConfig& used_ssl_config) { | 200 const SSLConfig& used_ssl_config) { |
133 DCHECK_NE(OK, status); | 201 DCHECK_NE(OK, status); |
134 // |job| should only be NULL if we're being canceled by a late bound | 202 // |job| should only be NULL if we're being canceled by a late bound |
135 // HttpPipelinedConnection (one that was not created by a job in our |jobs_| | 203 // HttpPipelinedConnection (one that was not created by a job in our |jobs_| |
136 // set). | 204 // set). |
137 if (!job) { | 205 if (!job) { |
138 DCHECK(!bound_job_.get()); | 206 DCHECK(!bound_job_.get()); |
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
283 void HttpStreamFactoryImpl::Request::OnSpdySessionReady( | 351 void HttpStreamFactoryImpl::Request::OnSpdySessionReady( |
284 Job* job, | 352 Job* job, |
285 scoped_refptr<SpdySession> spdy_session, | 353 scoped_refptr<SpdySession> spdy_session, |
286 bool direct) { | 354 bool direct) { |
287 DCHECK(job); | 355 DCHECK(job); |
288 DCHECK(job->using_spdy()); | 356 DCHECK(job->using_spdy()); |
289 | 357 |
290 // The first case is the usual case. | 358 // The first case is the usual case. |
291 if (!bound_job_.get()) { | 359 if (!bound_job_.get()) { |
292 OrphanJobsExcept(job); | 360 OrphanJobsExcept(job); |
293 } else { // This is the case for HTTPS proxy tunneling. | 361 } else { // This is the case for HTTPS proxy tunneling. |
294 DCHECK_EQ(bound_job_.get(), job); | 362 DCHECK_EQ(bound_job_.get(), job); |
295 DCHECK(jobs_.empty()); | 363 DCHECK(jobs_.empty()); |
296 } | 364 } |
297 | 365 |
298 // Cache these values in case the job gets deleted. | 366 // Cache these values in case the job gets deleted. |
299 const SSLConfig used_ssl_config = job->server_ssl_config(); | 367 const SSLConfig used_ssl_config = job->server_ssl_config(); |
300 const ProxyInfo used_proxy_info = job->proxy_info(); | 368 const ProxyInfo used_proxy_info = job->proxy_info(); |
301 const bool was_npn_negotiated = job->was_npn_negotiated(); | 369 const bool was_npn_negotiated = job->was_npn_negotiated(); |
302 const NextProto protocol_negotiated = | 370 const NextProto protocol_negotiated = |
303 job->protocol_negotiated(); | 371 job->protocol_negotiated(); |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
336 RemoveRequestFromHttpPipeliningRequestMap(); | 404 RemoveRequestFromHttpPipeliningRequestMap(); |
337 | 405 |
338 std::set<Job*> tmp; | 406 std::set<Job*> tmp; |
339 tmp.swap(jobs_); | 407 tmp.swap(jobs_); |
340 | 408 |
341 for (std::set<Job*>::iterator it = tmp.begin(); it != tmp.end(); ++it) | 409 for (std::set<Job*>::iterator it = tmp.begin(); it != tmp.end(); ++it) |
342 factory_->OrphanJob(*it, this); | 410 factory_->OrphanJob(*it, this); |
343 } | 411 } |
344 | 412 |
345 } // namespace net | 413 } // namespace net |
OLD | NEW |