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 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
87 protocol_negotiated_ = protocol_negotiated; | 89 protocol_negotiated_ = protocol_negotiated; |
88 using_spdy_ = using_spdy; | 90 using_spdy_ = using_spdy; |
89 net_log_.AddEvent( | 91 net_log_.AddEvent( |
90 NetLog::TYPE_HTTP_STREAM_REQUEST_BOUND_TO_JOB, | 92 NetLog::TYPE_HTTP_STREAM_REQUEST_BOUND_TO_JOB, |
91 job_net_log.source().ToEventParametersCallback()); | 93 job_net_log.source().ToEventParametersCallback()); |
92 job_net_log.AddEvent( | 94 job_net_log.AddEvent( |
93 NetLog::TYPE_HTTP_STREAM_JOB_BOUND_TO_REQUEST, | 95 NetLog::TYPE_HTTP_STREAM_JOB_BOUND_TO_REQUEST, |
94 net_log_.source().ToEventParametersCallback()); | 96 net_log_.source().ToEventParametersCallback()); |
95 } | 97 } |
96 | 98 |
97 void HttpStreamFactoryImpl::Request::OnStreamReady( | 99 void HttpStreamFactoryImpl::Request::Orphan(Job* job) { |
98 Job* job, | |
99 const SSLConfig& used_ssl_config, | |
100 const ProxyInfo& used_proxy_info, | |
101 HttpStreamBase* stream) { | |
102 DCHECK(stream); | |
103 DCHECK(completed_); | |
104 | |
105 // |job| should only be NULL if we're being serviced by a late bound | 100 // |job| should only be NULL if we're being serviced by a late bound |
106 // SpdySession or HttpPipelinedConnection (one that was not created by a job | 101 // SpdySession or HttpPipelinedConnection (one that was not created by a job |
107 // in our |jobs_| set). | 102 // in our |jobs_| set). |
108 if (!job) { | 103 if (!job) { |
109 DCHECK(!bound_job_.get()); | 104 DCHECK(!bound_job_.get()); |
110 DCHECK(!jobs_.empty()); | 105 DCHECK(!jobs_.empty()); |
111 // NOTE(willchan): We do *NOT* call OrphanJobs() here. The reason is because | 106 // NOTE(willchan): We do *NOT* call OrphanJobs() here. The reason is because |
112 // we *WANT* to cancel the unnecessary Jobs from other requests if another | 107 // we *WANT* to cancel the unnecessary Jobs from other requests if another |
113 // Job completes first. | 108 // Job completes first. |
114 // TODO(mbelshe): Revisit this when we implement ip connection pooling of | 109 // TODO(mbelshe): Revisit this when we implement ip connection pooling of |
115 // SpdySessions. Do we want to orphan the jobs for a different hostname so | 110 // SpdySessions. Do we want to orphan the jobs for a different hostname so |
116 // they complete? Or do we want to prevent connecting a new SpdySession if | 111 // they complete? Or do we want to prevent connecting a new SpdySession if |
117 // we've already got one available for a different hostname where the ip | 112 // we've already got one available for a different hostname where the ip |
118 // address matches up? | 113 // address matches up? |
119 } else if (!bound_job_.get()) { | 114 } else if (!bound_job_.get()) { |
120 // We may have other jobs in |jobs_|. For example, if we start multiple jobs | 115 // We may have other jobs in |jobs_|. For example, if we start multiple jobs |
121 // for Alternate-Protocol. | 116 // for Alternate-Protocol. |
122 OrphanJobsExcept(job); | 117 OrphanJobsExcept(job); |
123 } else { | 118 } else { |
124 DCHECK(jobs_.empty()); | 119 DCHECK(jobs_.empty()); |
125 } | 120 } |
121 } | |
122 | |
123 void HttpStreamFactoryImpl::Request::OnStreamReady( | |
124 Job* job, | |
125 const SSLConfig& used_ssl_config, | |
126 const ProxyInfo& used_proxy_info, | |
127 HttpStreamBase* stream) { | |
128 DCHECK(stream); | |
129 DCHECK(completed_); | |
mmenke
2013/05/23 20:26:20
I'd like a some more DCHECKs on for_websocket_ in
yhirano
2013/05/24 14:11:16
Done.
| |
130 | |
131 Orphan(job); | |
126 delegate_->OnStreamReady(used_ssl_config, used_proxy_info, stream); | 132 delegate_->OnStreamReady(used_ssl_config, used_proxy_info, stream); |
127 } | 133 } |
128 | 134 |
135 void HttpStreamFactoryImpl::Request::OnSocketReadyForWebSocket( | |
136 Job* job, | |
137 const SSLConfig& used_ssl_config, | |
138 const ProxyInfo& used_proxy_info, | |
139 ClientSocketHandle* connection) { | |
140 DCHECK(connection); | |
141 DCHECK(completed_); | |
142 | |
143 Orphan(job); | |
144 delegate_->OnSocketReadyForWebSocket(used_ssl_config, | |
145 used_proxy_info, | |
146 connection); | |
147 } | |
148 | |
149 void HttpStreamFactoryImpl::Request::OnSpdySessionReadyForWebSocket( | |
150 Job* job, | |
151 const SSLConfig& used_ssl_config, | |
152 const ProxyInfo& used_proxy_info, | |
153 scoped_refptr<SpdySession> session) { | |
154 DCHECK(session); | |
155 DCHECK(completed_); | |
156 | |
157 Orphan(job); | |
158 delegate_->OnSpdySessionReadyForWebSocket(used_ssl_config, | |
159 used_proxy_info, | |
160 session.get()); | |
161 } | |
162 | |
129 void HttpStreamFactoryImpl::Request::OnStreamFailed( | 163 void HttpStreamFactoryImpl::Request::OnStreamFailed( |
130 Job* job, | 164 Job* job, |
131 int status, | 165 int status, |
132 const SSLConfig& used_ssl_config) { | 166 const SSLConfig& used_ssl_config) { |
133 DCHECK_NE(OK, status); | 167 DCHECK_NE(OK, status); |
134 // |job| should only be NULL if we're being canceled by a late bound | 168 // |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_| | 169 // HttpPipelinedConnection (one that was not created by a job in our |jobs_| |
136 // set). | 170 // set). |
137 if (!job) { | 171 if (!job) { |
138 DCHECK(!bound_job_.get()); | 172 DCHECK(!bound_job_.get()); |
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
273 request_vector.erase(it); | 307 request_vector.erase(it); |
274 break; | 308 break; |
275 } | 309 } |
276 } | 310 } |
277 if (request_vector.empty()) | 311 if (request_vector.empty()) |
278 http_pipelining_request_map.erase(*http_pipelining_key_); | 312 http_pipelining_request_map.erase(*http_pipelining_key_); |
279 http_pipelining_key_.reset(); | 313 http_pipelining_key_.reset(); |
280 } | 314 } |
281 } | 315 } |
282 | 316 |
283 void HttpStreamFactoryImpl::Request::OnSpdySessionReady( | 317 void HttpStreamFactoryImpl::Request::OnNewSpdySessionReady( |
284 Job* job, | 318 Job* job, |
285 scoped_refptr<SpdySession> spdy_session, | 319 scoped_refptr<SpdySession> spdy_session, |
286 bool direct) { | 320 bool direct) { |
mmenke
2013/05/23 20:26:20
For functions that cannot be called when using web
yhirano
2013/05/24 14:11:16
In PS13 (or newer), OnNewSpdySessionReady is calle
| |
287 DCHECK(job); | 321 DCHECK(job); |
288 DCHECK(job->using_spdy()); | 322 DCHECK(job->using_spdy()); |
289 | 323 |
290 // The first case is the usual case. | 324 // The first case is the usual case. |
291 if (!bound_job_.get()) { | 325 if (!bound_job_.get()) { |
292 OrphanJobsExcept(job); | 326 OrphanJobsExcept(job); |
293 } else { // This is the case for HTTPS proxy tunneling. | 327 } else { // This is the case for HTTPS proxy tunneling. |
294 DCHECK_EQ(bound_job_.get(), job); | 328 DCHECK_EQ(bound_job_.get(), job); |
295 DCHECK(jobs_.empty()); | 329 DCHECK(jobs_.empty()); |
296 } | 330 } |
297 | 331 |
298 // Cache these values in case the job gets deleted. | 332 // Cache these values in case the job gets deleted. |
299 const SSLConfig used_ssl_config = job->server_ssl_config(); | 333 const SSLConfig used_ssl_config = job->server_ssl_config(); |
300 const ProxyInfo used_proxy_info = job->proxy_info(); | 334 const ProxyInfo used_proxy_info = job->proxy_info(); |
301 const bool was_npn_negotiated = job->was_npn_negotiated(); | 335 const bool was_npn_negotiated = job->was_npn_negotiated(); |
302 const NextProto protocol_negotiated = | 336 const NextProto protocol_negotiated = |
303 job->protocol_negotiated(); | 337 job->protocol_negotiated(); |
304 const bool using_spdy = job->using_spdy(); | 338 const bool using_spdy = job->using_spdy(); |
305 const BoundNetLog net_log = job->net_log(); | 339 const BoundNetLog net_log = job->net_log(); |
306 | 340 |
307 Complete(was_npn_negotiated, protocol_negotiated, using_spdy, net_log); | 341 Complete(was_npn_negotiated, protocol_negotiated, using_spdy, net_log); |
308 | 342 |
309 // Cache this so we can still use it if the request is deleted. | 343 // Cache this so we can still use it if the request is deleted. |
310 HttpStreamFactoryImpl* factory = factory_; | 344 HttpStreamFactoryImpl* factory = factory_; |
311 | 345 |
312 bool use_relative_url = direct || url().SchemeIs("https"); | 346 bool use_relative_url = direct || url().SchemeIs("https"); |
313 delegate_->OnStreamReady( | 347 delegate_->OnStreamReady( |
314 job->server_ssl_config(), | 348 job->server_ssl_config(), |
315 job->proxy_info(), | 349 job->proxy_info(), |
316 new SpdyHttpStream(spdy_session, use_relative_url)); | 350 new SpdyHttpStream(spdy_session, use_relative_url)); |
317 // |this| may be deleted after this point. | 351 // |this| may be deleted after this point. |
318 factory->OnSpdySessionReady( | 352 factory->OnNewSpdySessionReady( |
319 spdy_session, direct, used_ssl_config, used_proxy_info, | 353 spdy_session, direct, used_ssl_config, used_proxy_info, |
320 was_npn_negotiated, protocol_negotiated, using_spdy, net_log); | 354 was_npn_negotiated, protocol_negotiated, using_spdy, net_log); |
321 } | 355 } |
322 | 356 |
323 void HttpStreamFactoryImpl::Request::OrphanJobsExcept(Job* job) { | 357 void HttpStreamFactoryImpl::Request::OrphanJobsExcept(Job* job) { |
324 DCHECK(job); | 358 DCHECK(job); |
325 DCHECK(!bound_job_.get()); | 359 DCHECK(!bound_job_.get()); |
326 DCHECK(ContainsKey(jobs_, job)); | 360 DCHECK(ContainsKey(jobs_, job)); |
327 bound_job_.reset(job); | 361 bound_job_.reset(job); |
328 jobs_.erase(job); | 362 jobs_.erase(job); |
329 factory_->request_map_.erase(job); | 363 factory_->request_map_.erase(job); |
330 | 364 |
331 OrphanJobs(); | 365 OrphanJobs(); |
332 } | 366 } |
333 | 367 |
334 void HttpStreamFactoryImpl::Request::OrphanJobs() { | 368 void HttpStreamFactoryImpl::Request::OrphanJobs() { |
335 RemoveRequestFromSpdySessionRequestMap(); | 369 RemoveRequestFromSpdySessionRequestMap(); |
336 RemoveRequestFromHttpPipeliningRequestMap(); | 370 RemoveRequestFromHttpPipeliningRequestMap(); |
337 | 371 |
338 std::set<Job*> tmp; | 372 std::set<Job*> tmp; |
339 tmp.swap(jobs_); | 373 tmp.swap(jobs_); |
340 | 374 |
341 for (std::set<Job*>::iterator it = tmp.begin(); it != tmp.end(); ++it) | 375 for (std::set<Job*>::iterator it = tmp.begin(); it != tmp.end(); ++it) |
342 factory_->OrphanJob(*it, this); | 376 factory_->OrphanJob(*it, this); |
343 } | 377 } |
344 | 378 |
345 } // namespace net | 379 } // namespace net |
OLD | NEW |