| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 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 | 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/logging.h" | 7 #include "base/logging.h" |
| 8 #include "base/stl_util-inl.h" | 8 #include "base/stl_util-inl.h" |
| 9 #include "net/http/http_stream_factory_impl_job.h" | 9 #include "net/http/http_stream_factory_impl_job.h" |
| 10 #include "net/spdy/spdy_http_stream.h" | 10 #include "net/spdy/spdy_http_stream.h" |
| 11 #include "net/spdy/spdy_session.h" | 11 #include "net/spdy/spdy_session.h" |
| 12 | 12 |
| 13 namespace net { | 13 namespace net { |
| 14 | 14 |
| 15 HttpStreamFactoryImpl::Request::Request(const GURL& url, | 15 HttpStreamFactoryImpl::Request::Request(const GURL& url, |
| 16 HttpStreamFactoryImpl* factory, | 16 HttpStreamFactoryImpl* factory, |
| 17 HttpStreamRequest::Delegate* delegate, | 17 HttpStreamRequest::Delegate* delegate, |
| 18 const BoundNetLog& net_log) | 18 const BoundNetLog& net_log) |
| 19 : url_(url), | 19 : url_(url), |
| 20 factory_(factory), | 20 factory_(factory), |
| 21 delegate_(delegate), | 21 delegate_(delegate), |
| 22 net_log_(net_log), | 22 net_log_(net_log), |
| 23 completed_(false), | 23 completed_(false), |
| 24 was_alternate_protocol_available_(false), | |
| 25 was_npn_negotiated_(false), | 24 was_npn_negotiated_(false), |
| 26 using_spdy_(false) { | 25 using_spdy_(false) { |
| 27 DCHECK(factory_); | 26 DCHECK(factory_); |
| 28 DCHECK(delegate_); | 27 DCHECK(delegate_); |
| 29 | 28 |
| 30 net_log_.BeginEvent(NetLog::TYPE_HTTP_STREAM_REQUEST, NULL); | 29 net_log_.BeginEvent(NetLog::TYPE_HTTP_STREAM_REQUEST, NULL); |
| 31 } | 30 } |
| 32 | 31 |
| 33 HttpStreamFactoryImpl::Request::~Request() { | 32 HttpStreamFactoryImpl::Request::~Request() { |
| 34 if (bound_job_.get()) | 33 if (bound_job_.get()) |
| (...skipping 21 matching lines...) Expand all Loading... |
| 56 request_set.insert(this); | 55 request_set.insert(this); |
| 57 } | 56 } |
| 58 | 57 |
| 59 void HttpStreamFactoryImpl::Request::AttachJob(Job* job) { | 58 void HttpStreamFactoryImpl::Request::AttachJob(Job* job) { |
| 60 DCHECK(job); | 59 DCHECK(job); |
| 61 jobs_.insert(job); | 60 jobs_.insert(job); |
| 62 factory_->request_map_[job] = this; | 61 factory_->request_map_[job] = this; |
| 63 } | 62 } |
| 64 | 63 |
| 65 void HttpStreamFactoryImpl::Request::Complete( | 64 void HttpStreamFactoryImpl::Request::Complete( |
| 66 bool was_alternate_protocol_available, | |
| 67 bool was_npn_negotiated, | 65 bool was_npn_negotiated, |
| 68 bool using_spdy, | 66 bool using_spdy, |
| 69 const NetLog::Source& job_source) { | 67 const NetLog::Source& job_source) { |
| 70 DCHECK(!completed_); | 68 DCHECK(!completed_); |
| 71 completed_ = true; | 69 completed_ = true; |
| 72 was_alternate_protocol_available_ = was_alternate_protocol_available; | |
| 73 was_npn_negotiated_ = was_npn_negotiated; | 70 was_npn_negotiated_ = was_npn_negotiated; |
| 74 using_spdy_ = using_spdy; | 71 using_spdy_ = using_spdy; |
| 75 net_log_.AddEvent( | 72 net_log_.AddEvent( |
| 76 NetLog::TYPE_HTTP_STREAM_REQUEST_BOUND_TO_JOB, | 73 NetLog::TYPE_HTTP_STREAM_REQUEST_BOUND_TO_JOB, |
| 77 make_scoped_refptr(new NetLogSourceParameter( | 74 make_scoped_refptr(new NetLogSourceParameter( |
| 78 "source_dependency", job_source))); | 75 "source_dependency", job_source))); |
| 79 } | 76 } |
| 80 | 77 |
| 81 void HttpStreamFactoryImpl::Request::OnStreamReady( | 78 void HttpStreamFactoryImpl::Request::OnStreamReady( |
| 82 Job* job, | 79 Job* job, |
| (...skipping 24 matching lines...) Expand all Loading... |
| 107 DCHECK(jobs_.empty()); | 104 DCHECK(jobs_.empty()); |
| 108 } | 105 } |
| 109 delegate_->OnStreamReady(used_ssl_config, used_proxy_info, stream); | 106 delegate_->OnStreamReady(used_ssl_config, used_proxy_info, stream); |
| 110 } | 107 } |
| 111 | 108 |
| 112 void HttpStreamFactoryImpl::Request::OnStreamFailed( | 109 void HttpStreamFactoryImpl::Request::OnStreamFailed( |
| 113 Job* job, | 110 Job* job, |
| 114 int status, | 111 int status, |
| 115 const SSLConfig& used_ssl_config) { | 112 const SSLConfig& used_ssl_config) { |
| 116 DCHECK_NE(OK, status); | 113 DCHECK_NE(OK, status); |
| 117 if (!bound_job_.get()) | 114 if (!bound_job_.get()) { |
| 118 OrphanJobsExcept(job); | 115 // Hey, we've got other jobs! Maybe one of them will succeed, let's just |
| 119 else | 116 // ignore this failure. |
| 117 if (jobs_.size() > 1) { |
| 118 jobs_.erase(job); |
| 119 factory_->request_map_.erase(job); |
| 120 delete job; |
| 121 return; |
| 122 } else { |
| 123 bound_job_.reset(job); |
| 124 jobs_.erase(job); |
| 125 DCHECK(jobs_.empty()); |
| 126 factory_->request_map_.erase(job); |
| 127 } |
| 128 } else { |
| 120 DCHECK(jobs_.empty()); | 129 DCHECK(jobs_.empty()); |
| 130 } |
| 121 delegate_->OnStreamFailed(status, used_ssl_config); | 131 delegate_->OnStreamFailed(status, used_ssl_config); |
| 122 } | 132 } |
| 123 | 133 |
| 124 void HttpStreamFactoryImpl::Request::OnCertificateError( | 134 void HttpStreamFactoryImpl::Request::OnCertificateError( |
| 125 Job* job, | 135 Job* job, |
| 126 int status, | 136 int status, |
| 127 const SSLConfig& used_ssl_config, | 137 const SSLConfig& used_ssl_config, |
| 128 const SSLInfo& ssl_info) { | 138 const SSLInfo& ssl_info) { |
| 129 DCHECK_NE(OK, status); | 139 DCHECK_NE(OK, status); |
| 130 if (!bound_job_.get()) | 140 if (!bound_job_.get()) |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 182 | 192 |
| 183 LoadState HttpStreamFactoryImpl::Request::GetLoadState() const { | 193 LoadState HttpStreamFactoryImpl::Request::GetLoadState() const { |
| 184 if (bound_job_.get()) | 194 if (bound_job_.get()) |
| 185 return bound_job_->GetLoadState(); | 195 return bound_job_->GetLoadState(); |
| 186 DCHECK(!jobs_.empty()); | 196 DCHECK(!jobs_.empty()); |
| 187 | 197 |
| 188 // Just pick the first one. | 198 // Just pick the first one. |
| 189 return (*jobs_.begin())->GetLoadState(); | 199 return (*jobs_.begin())->GetLoadState(); |
| 190 } | 200 } |
| 191 | 201 |
| 192 bool HttpStreamFactoryImpl::Request::was_alternate_protocol_available() const { | |
| 193 DCHECK(completed_); | |
| 194 return was_alternate_protocol_available_; | |
| 195 } | |
| 196 | |
| 197 bool HttpStreamFactoryImpl::Request::was_npn_negotiated() const { | 202 bool HttpStreamFactoryImpl::Request::was_npn_negotiated() const { |
| 198 DCHECK(completed_); | 203 DCHECK(completed_); |
| 199 return was_npn_negotiated_; | 204 return was_npn_negotiated_; |
| 200 } | 205 } |
| 201 | 206 |
| 202 bool HttpStreamFactoryImpl::Request::using_spdy() const { | 207 bool HttpStreamFactoryImpl::Request::using_spdy() const { |
| 203 DCHECK(completed_); | 208 DCHECK(completed_); |
| 204 return using_spdy_; | 209 return using_spdy_; |
| 205 } | 210 } |
| 206 | 211 |
| (...skipping 24 matching lines...) Expand all Loading... |
| 231 if (!bound_job_.get()) { | 236 if (!bound_job_.get()) { |
| 232 OrphanJobsExcept(job); | 237 OrphanJobsExcept(job); |
| 233 } else { // This is the case for HTTPS proxy tunneling. | 238 } else { // This is the case for HTTPS proxy tunneling. |
| 234 DCHECK_EQ(bound_job_.get(), job); | 239 DCHECK_EQ(bound_job_.get(), job); |
| 235 DCHECK(jobs_.empty()); | 240 DCHECK(jobs_.empty()); |
| 236 } | 241 } |
| 237 | 242 |
| 238 // Cache these values in case the job gets deleted. | 243 // Cache these values in case the job gets deleted. |
| 239 const SSLConfig used_ssl_config = job->ssl_config(); | 244 const SSLConfig used_ssl_config = job->ssl_config(); |
| 240 const ProxyInfo used_proxy_info = job->proxy_info(); | 245 const ProxyInfo used_proxy_info = job->proxy_info(); |
| 241 const bool was_alternate_protocol_available = | |
| 242 job->was_alternate_protocol_available(); | |
| 243 const bool was_npn_negotiated = job->was_npn_negotiated(); | 246 const bool was_npn_negotiated = job->was_npn_negotiated(); |
| 244 const bool using_spdy = job->using_spdy(); | 247 const bool using_spdy = job->using_spdy(); |
| 245 const NetLog::Source source = job->net_log().source(); | 248 const NetLog::Source source = job->net_log().source(); |
| 246 | 249 |
| 247 Complete(was_alternate_protocol_available, | 250 Complete(was_npn_negotiated, |
| 248 was_npn_negotiated, | |
| 249 using_spdy, | 251 using_spdy, |
| 250 source); | 252 source); |
| 251 | 253 |
| 252 // Cache this so we can still use it if the request is deleted. | 254 // Cache this so we can still use it if the request is deleted. |
| 253 HttpStreamFactoryImpl* factory = factory_; | 255 HttpStreamFactoryImpl* factory = factory_; |
| 254 | 256 |
| 255 bool use_relative_url = direct || url().SchemeIs("https"); | 257 bool use_relative_url = direct || url().SchemeIs("https"); |
| 256 delegate_->OnStreamReady( | 258 delegate_->OnStreamReady( |
| 257 job->ssl_config(), | 259 job->ssl_config(), |
| 258 job->proxy_info(), | 260 job->proxy_info(), |
| 259 new SpdyHttpStream(spdy_session, use_relative_url)); | 261 new SpdyHttpStream(spdy_session, use_relative_url)); |
| 260 // |this| may be deleted after this point. | 262 // |this| may be deleted after this point. |
| 261 factory->OnSpdySessionReady( | 263 factory->OnSpdySessionReady( |
| 262 spdy_session, direct, used_ssl_config, used_proxy_info, | 264 spdy_session, direct, used_ssl_config, used_proxy_info, |
| 263 was_alternate_protocol_available, was_npn_negotiated, using_spdy, source); | 265 was_npn_negotiated, using_spdy, source); |
| 264 } | 266 } |
| 265 | 267 |
| 266 void HttpStreamFactoryImpl::Request::OrphanJobsExcept(Job* job) { | 268 void HttpStreamFactoryImpl::Request::OrphanJobsExcept(Job* job) { |
| 267 DCHECK(job); | 269 DCHECK(job); |
| 268 DCHECK(!bound_job_.get()); | 270 DCHECK(!bound_job_.get()); |
| 269 DCHECK(ContainsKey(jobs_, job)); | 271 DCHECK(ContainsKey(jobs_, job)); |
| 270 bound_job_.reset(job); | 272 bound_job_.reset(job); |
| 271 jobs_.erase(job); | 273 jobs_.erase(job); |
| 272 factory_->request_map_.erase(job); | 274 factory_->request_map_.erase(job); |
| 273 | 275 |
| 274 OrphanJobs(); | 276 OrphanJobs(); |
| 275 } | 277 } |
| 276 | 278 |
| 277 void HttpStreamFactoryImpl::Request::OrphanJobs() { | 279 void HttpStreamFactoryImpl::Request::OrphanJobs() { |
| 278 RemoveRequestFromSpdySessionRequestMap(); | 280 RemoveRequestFromSpdySessionRequestMap(); |
| 279 | 281 |
| 280 std::set<Job*> tmp; | 282 std::set<Job*> tmp; |
| 281 tmp.swap(jobs_); | 283 tmp.swap(jobs_); |
| 282 | 284 |
| 283 for (std::set<Job*>::iterator it = tmp.begin(); it != tmp.end(); ++it) | 285 for (std::set<Job*>::iterator it = tmp.begin(); it != tmp.end(); ++it) |
| 284 factory_->OrphanJob(*it, this); | 286 factory_->OrphanJob(*it, this); |
| 285 } | 287 } |
| 286 | 288 |
| 287 } // namespace net | 289 } // namespace net |
| OLD | NEW |