Chromium Code Reviews| 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" |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 61 DCHECK(!ContainsKey(request_set, this)); | 61 DCHECK(!ContainsKey(request_set, this)); |
| 62 request_set.insert(this); | 62 request_set.insert(this); |
| 63 } | 63 } |
| 64 | 64 |
| 65 void HttpStreamFactoryImpl::Request::AttachJob(Job* job) { | 65 void HttpStreamFactoryImpl::Request::AttachJob(Job* job) { |
| 66 DCHECK(job); | 66 DCHECK(job); |
| 67 jobs_.insert(job); | 67 jobs_.insert(job); |
| 68 factory_->request_map_[job] = this; | 68 factory_->request_map_[job] = this; |
| 69 } | 69 } |
| 70 | 70 |
| 71 void HttpStreamFactoryImpl::Request::Complete( | 71 void HttpStreamFactoryImpl::Request::Complete(bool was_npn_negotiated, |
| 72 bool was_npn_negotiated, | 72 NextProto protocol_negotiated, |
| 73 NextProto protocol_negotiated, | 73 bool using_spdy) { |
| 74 bool using_spdy, | |
| 75 const BoundNetLog& job_net_log) { | |
| 76 DCHECK(!completed_); | 74 DCHECK(!completed_); |
| 77 completed_ = true; | 75 completed_ = true; |
| 78 was_npn_negotiated_ = was_npn_negotiated; | 76 was_npn_negotiated_ = was_npn_negotiated; |
| 79 protocol_negotiated_ = protocol_negotiated; | 77 protocol_negotiated_ = protocol_negotiated; |
| 80 using_spdy_ = using_spdy; | 78 using_spdy_ = using_spdy; |
| 81 net_log_.AddEvent( | |
| 82 NetLog::TYPE_HTTP_STREAM_REQUEST_BOUND_TO_JOB, | |
| 83 job_net_log.source().ToEventParametersCallback()); | |
| 84 job_net_log.AddEvent( | |
| 85 NetLog::TYPE_HTTP_STREAM_JOB_BOUND_TO_REQUEST, | |
| 86 net_log_.source().ToEventParametersCallback()); | |
| 87 } | 79 } |
| 88 | 80 |
| 89 void HttpStreamFactoryImpl::Request::OnStreamReady( | 81 void HttpStreamFactoryImpl::Request::OnStreamReady( |
| 90 Job* job, | 82 Job* job, |
| 91 const SSLConfig& used_ssl_config, | 83 const SSLConfig& used_ssl_config, |
| 92 const ProxyInfo& used_proxy_info, | 84 const ProxyInfo& used_proxy_info, |
| 93 HttpStream* stream) { | 85 HttpStream* stream) { |
| 94 DCHECK(!factory_->for_websockets_); | 86 DCHECK(!factory_->for_websockets_); |
| 95 DCHECK(stream); | 87 DCHECK(stream); |
| 96 DCHECK(completed_); | 88 DCHECK(completed_); |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 114 } | 106 } |
| 115 | 107 |
| 116 void HttpStreamFactoryImpl::Request::OnStreamFailed( | 108 void HttpStreamFactoryImpl::Request::OnStreamFailed( |
| 117 Job* job, | 109 Job* job, |
| 118 int status, | 110 int status, |
| 119 const SSLConfig& used_ssl_config, | 111 const SSLConfig& used_ssl_config, |
| 120 SSLFailureState ssl_failure_state) { | 112 SSLFailureState ssl_failure_state) { |
| 121 DCHECK_NE(OK, status); | 113 DCHECK_NE(OK, status); |
| 122 DCHECK(job); | 114 DCHECK(job); |
| 123 if (!bound_job_.get()) { | 115 if (!bound_job_.get()) { |
| 124 // Hey, we've got other jobs! Maybe one of them will succeed, let's just | |
| 125 // ignore this failure. | |
| 126 if (jobs_.size() > 1) { | 116 if (jobs_.size() > 1) { |
| 117 // Hey, we've got other jobs! Maybe one of them will succeed, let's just | |
| 118 // ignore this failure. | |
| 127 jobs_.erase(job); | 119 jobs_.erase(job); |
| 128 factory_->request_map_.erase(job); | 120 factory_->request_map_.erase(job); |
| 129 // Notify all the other jobs that this one failed. | 121 // Notify all the other jobs that this one failed. |
| 130 for (std::set<Job*>::iterator it = jobs_.begin(); it != jobs_.end(); ++it) | 122 for (std::set<Job*>::iterator it = jobs_.begin(); it != jobs_.end(); ++it) |
| 131 (*it)->MarkOtherJobComplete(*job); | 123 (*it)->MarkOtherJobComplete(*job); |
| 132 delete job; | 124 delete job; |
| 133 return; | 125 return; |
| 134 } else { | 126 } else { |
| 135 bound_job_.reset(job); | 127 OrphanJobsExcept(job); |
|
mmenke
2015/06/25 23:20:20
This is kind of silly. Can we rename this? "Bind
davidben
2015/06/26 19:16:30
Done. Though in doing that and trying to figure ou
| |
| 136 jobs_.erase(job); | |
| 137 DCHECK(jobs_.empty()); | |
| 138 factory_->request_map_.erase(job); | |
| 139 } | 128 } |
| 140 } else { | 129 } else { |
| 141 DCHECK(jobs_.empty()); | 130 DCHECK(jobs_.empty()); |
| 142 } | 131 } |
| 143 delegate_->OnStreamFailed(status, used_ssl_config, ssl_failure_state); | 132 delegate_->OnStreamFailed(status, used_ssl_config, ssl_failure_state); |
| 144 } | 133 } |
| 145 | 134 |
| 146 void HttpStreamFactoryImpl::Request::OnCertificateError( | 135 void HttpStreamFactoryImpl::Request::OnCertificateError( |
| 147 Job* job, | 136 Job* job, |
| 148 int status, | 137 int status, |
| (...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 289 | 278 |
| 290 // Cache these values in case the job gets deleted. | 279 // Cache these values in case the job gets deleted. |
| 291 const SSLConfig used_ssl_config = job->server_ssl_config(); | 280 const SSLConfig used_ssl_config = job->server_ssl_config(); |
| 292 const ProxyInfo used_proxy_info = job->proxy_info(); | 281 const ProxyInfo used_proxy_info = job->proxy_info(); |
| 293 const bool was_npn_negotiated = job->was_npn_negotiated(); | 282 const bool was_npn_negotiated = job->was_npn_negotiated(); |
| 294 const NextProto protocol_negotiated = | 283 const NextProto protocol_negotiated = |
| 295 job->protocol_negotiated(); | 284 job->protocol_negotiated(); |
| 296 const bool using_spdy = job->using_spdy(); | 285 const bool using_spdy = job->using_spdy(); |
| 297 const BoundNetLog net_log = job->net_log(); | 286 const BoundNetLog net_log = job->net_log(); |
| 298 | 287 |
| 299 Complete(was_npn_negotiated, protocol_negotiated, using_spdy, net_log); | 288 Complete(was_npn_negotiated, protocol_negotiated, using_spdy); |
| 300 | 289 |
| 301 // Cache this so we can still use it if the request is deleted. | 290 // Cache this so we can still use it if the request is deleted. |
| 302 HttpStreamFactoryImpl* factory = factory_; | 291 HttpStreamFactoryImpl* factory = factory_; |
| 303 if (factory->for_websockets_) { | 292 if (factory->for_websockets_) { |
| 304 // TODO(ricea): Re-instate this code when WebSockets over SPDY is | 293 // TODO(ricea): Re-instate this code when WebSockets over SPDY is |
| 305 // implemented. | 294 // implemented. |
| 306 NOTREACHED(); | 295 NOTREACHED(); |
| 307 } else { | 296 } else { |
| 308 delegate_->OnStreamReady(job->server_ssl_config(), job->proxy_info(), | 297 delegate_->OnStreamReady(job->server_ssl_config(), job->proxy_info(), |
| 309 stream.release()); | 298 stream.release()); |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 328 } | 317 } |
| 329 | 318 |
| 330 void HttpStreamFactoryImpl::Request::OrphanJobsExcept(Job* job) { | 319 void HttpStreamFactoryImpl::Request::OrphanJobsExcept(Job* job) { |
| 331 DCHECK(job); | 320 DCHECK(job); |
| 332 DCHECK(!bound_job_.get()); | 321 DCHECK(!bound_job_.get()); |
| 333 DCHECK(ContainsKey(jobs_, job)); | 322 DCHECK(ContainsKey(jobs_, job)); |
| 334 bound_job_.reset(job); | 323 bound_job_.reset(job); |
| 335 jobs_.erase(job); | 324 jobs_.erase(job); |
| 336 factory_->request_map_.erase(job); | 325 factory_->request_map_.erase(job); |
| 337 | 326 |
| 327 net_log_.AddEvent(NetLog::TYPE_HTTP_STREAM_REQUEST_BOUND_TO_JOB, | |
| 328 job->net_log().source().ToEventParametersCallback()); | |
| 329 job->net_log().AddEvent(NetLog::TYPE_HTTP_STREAM_JOB_BOUND_TO_REQUEST, | |
| 330 net_log_.source().ToEventParametersCallback()); | |
| 331 | |
| 338 OrphanJobs(); | 332 OrphanJobs(); |
| 339 } | 333 } |
| 340 | 334 |
| 341 void HttpStreamFactoryImpl::Request::OrphanJobs() { | 335 void HttpStreamFactoryImpl::Request::OrphanJobs() { |
| 342 RemoveRequestFromSpdySessionRequestMap(); | 336 RemoveRequestFromSpdySessionRequestMap(); |
| 343 | 337 |
| 344 std::set<Job*> tmp; | 338 std::set<Job*> tmp; |
| 345 tmp.swap(jobs_); | 339 tmp.swap(jobs_); |
| 346 | 340 |
| 347 for (std::set<Job*>::iterator it = tmp.begin(); it != tmp.end(); ++it) | 341 for (std::set<Job*>::iterator it = tmp.begin(); it != tmp.end(); ++it) |
| (...skipping 27 matching lines...) Expand all Loading... | |
| 375 } | 369 } |
| 376 // We may have other jobs in |jobs_|. For example, if we start multiple jobs | 370 // We may have other jobs in |jobs_|. For example, if we start multiple jobs |
| 377 // for Alternate-Protocol. | 371 // for Alternate-Protocol. |
| 378 OrphanJobsExcept(job); | 372 OrphanJobsExcept(job); |
| 379 return; | 373 return; |
| 380 } | 374 } |
| 381 DCHECK(jobs_.empty()); | 375 DCHECK(jobs_.empty()); |
| 382 } | 376 } |
| 383 | 377 |
| 384 } // namespace net | 378 } // namespace net |
| OLD | NEW |