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_); | |
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::OnSocketReady( | |
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_->OnSocketReady(used_ssl_config, used_proxy_info, connection); | |
145 } | |
146 | |
147 void HttpStreamFactoryImpl::Request::OnSpdySessionReadyForWS( | |
148 Job* job, | |
149 const SSLConfig& used_ssl_config, | |
150 const ProxyInfo& used_proxy_info, | |
151 scoped_refptr<SpdySession> session) { | |
152 DCHECK(session); | |
153 DCHECK(completed_); | |
154 | |
155 Orphan(job); | |
156 delegate_->OnSpdySessionReady(used_ssl_config, | |
157 used_proxy_info, | |
158 session.get()); | |
159 } | |
160 | |
129 void HttpStreamFactoryImpl::Request::OnStreamFailed( | 161 void HttpStreamFactoryImpl::Request::OnStreamFailed( |
130 Job* job, | 162 Job* job, |
131 int status, | 163 int status, |
132 const SSLConfig& used_ssl_config) { | 164 const SSLConfig& used_ssl_config) { |
133 DCHECK_NE(OK, status); | 165 DCHECK_NE(OK, status); |
134 // |job| should only be NULL if we're being canceled by a late bound | 166 // |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_| | 167 // HttpPipelinedConnection (one that was not created by a job in our |jobs_| |
136 // set). | 168 // set). |
137 if (!job) { | 169 if (!job) { |
138 DCHECK(!bound_job_.get()); | 170 DCHECK(!bound_job_.get()); |
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
273 request_vector.erase(it); | 305 request_vector.erase(it); |
274 break; | 306 break; |
275 } | 307 } |
276 } | 308 } |
277 if (request_vector.empty()) | 309 if (request_vector.empty()) |
278 http_pipelining_request_map.erase(*http_pipelining_key_); | 310 http_pipelining_request_map.erase(*http_pipelining_key_); |
279 http_pipelining_key_.reset(); | 311 http_pipelining_key_.reset(); |
280 } | 312 } |
281 } | 313 } |
282 | 314 |
283 void HttpStreamFactoryImpl::Request::OnSpdySessionReady( | 315 void HttpStreamFactoryImpl::Request::OnSpdySessionReady( |
mmenke
2013/05/15 15:38:20
It looks to me like this path, which I believe is
yhirano
2013/05/16 05:02:35
This function will not be called when for_websocke
| |
284 Job* job, | 316 Job* job, |
285 scoped_refptr<SpdySession> spdy_session, | 317 scoped_refptr<SpdySession> spdy_session, |
286 bool direct) { | 318 bool direct) { |
287 DCHECK(job); | 319 DCHECK(job); |
288 DCHECK(job->using_spdy()); | 320 DCHECK(job->using_spdy()); |
289 | 321 |
290 // The first case is the usual case. | 322 // The first case is the usual case. |
291 if (!bound_job_.get()) { | 323 if (!bound_job_.get()) { |
292 OrphanJobsExcept(job); | 324 OrphanJobsExcept(job); |
293 } else { // This is the case for HTTPS proxy tunneling. | 325 } else { // This is the case for HTTPS proxy tunneling. |
294 DCHECK_EQ(bound_job_.get(), job); | 326 DCHECK_EQ(bound_job_.get(), job); |
295 DCHECK(jobs_.empty()); | 327 DCHECK(jobs_.empty()); |
296 } | 328 } |
297 | 329 |
298 // Cache these values in case the job gets deleted. | 330 // Cache these values in case the job gets deleted. |
299 const SSLConfig used_ssl_config = job->server_ssl_config(); | 331 const SSLConfig used_ssl_config = job->server_ssl_config(); |
300 const ProxyInfo used_proxy_info = job->proxy_info(); | 332 const ProxyInfo used_proxy_info = job->proxy_info(); |
301 const bool was_npn_negotiated = job->was_npn_negotiated(); | 333 const bool was_npn_negotiated = job->was_npn_negotiated(); |
302 const NextProto protocol_negotiated = | 334 const NextProto protocol_negotiated = |
303 job->protocol_negotiated(); | 335 job->protocol_negotiated(); |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
336 RemoveRequestFromHttpPipeliningRequestMap(); | 368 RemoveRequestFromHttpPipeliningRequestMap(); |
337 | 369 |
338 std::set<Job*> tmp; | 370 std::set<Job*> tmp; |
339 tmp.swap(jobs_); | 371 tmp.swap(jobs_); |
340 | 372 |
341 for (std::set<Job*>::iterator it = tmp.begin(); it != tmp.end(); ++it) | 373 for (std::set<Job*>::iterator it = tmp.begin(); it != tmp.end(); ++it) |
342 factory_->OrphanJob(*it, this); | 374 factory_->OrphanJob(*it, this); |
343 } | 375 } |
344 | 376 |
345 } // namespace net | 377 } // namespace net |
OLD | NEW |