Chromium Code Reviews| 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" |
| (...skipping 25 matching lines...) Expand all Loading... | |
| 36 DCHECK(!jobs_.empty()); | 36 DCHECK(!jobs_.empty()); |
| 37 | 37 |
| 38 net_log_.EndEvent(NetLog::TYPE_HTTP_STREAM_REQUEST, NULL); | 38 net_log_.EndEvent(NetLog::TYPE_HTTP_STREAM_REQUEST, NULL); |
| 39 | 39 |
| 40 for (std::set<Job*>::iterator it = jobs_.begin(); it != jobs_.end(); ++it) | 40 for (std::set<Job*>::iterator it = jobs_.begin(); it != jobs_.end(); ++it) |
| 41 factory_->request_map_.erase(*it); | 41 factory_->request_map_.erase(*it); |
| 42 | 42 |
| 43 STLDeleteElements(&jobs_); | 43 STLDeleteElements(&jobs_); |
| 44 | 44 |
| 45 RemoveRequestFromSpdySessionRequestMap(); | 45 RemoveRequestFromSpdySessionRequestMap(); |
| 46 RemoveRequestFromHttpPipeliningRequestMap(); | |
| 46 } | 47 } |
| 47 | 48 |
| 48 void HttpStreamFactoryImpl::Request::SetSpdySessionKey( | 49 void HttpStreamFactoryImpl::Request::SetSpdySessionKey( |
| 49 const HostPortProxyPair& spdy_session_key) { | 50 const HostPortProxyPair& spdy_session_key) { |
| 50 DCHECK(!spdy_session_key_.get()); | 51 DCHECK(!spdy_session_key_.get()); |
| 51 spdy_session_key_.reset(new HostPortProxyPair(spdy_session_key)); | 52 spdy_session_key_.reset(new HostPortProxyPair(spdy_session_key)); |
| 52 RequestSet& request_set = | 53 RequestSet& request_set = |
| 53 factory_->spdy_session_request_map_[spdy_session_key]; | 54 factory_->spdy_session_request_map_[spdy_session_key]; |
| 54 DCHECK(!ContainsKey(request_set, this)); | 55 DCHECK(!ContainsKey(request_set, this)); |
| 55 request_set.insert(this); | 56 request_set.insert(this); |
| 56 } | 57 } |
| 57 | 58 |
| 59 void HttpStreamFactoryImpl::Request::SetHttpPipeliningKey( | |
| 60 const HostPortPair& http_pipelining_key) { | |
| 61 DCHECK(!http_pipelining_key_.get()); | |
| 62 http_pipelining_key_.reset(new HostPortPair(http_pipelining_key)); | |
| 63 RequestSet& request_set = | |
| 64 factory_->http_pipelining_request_map_[http_pipelining_key]; | |
| 65 DCHECK(!ContainsKey(request_set, this)); | |
| 66 request_set.insert(this); | |
| 67 } | |
| 68 | |
| 58 void HttpStreamFactoryImpl::Request::AttachJob(Job* job) { | 69 void HttpStreamFactoryImpl::Request::AttachJob(Job* job) { |
| 59 DCHECK(job); | 70 DCHECK(job); |
| 60 jobs_.insert(job); | 71 jobs_.insert(job); |
| 61 factory_->request_map_[job] = this; | 72 factory_->request_map_[job] = this; |
| 62 } | 73 } |
| 63 | 74 |
| 64 void HttpStreamFactoryImpl::Request::Complete( | 75 void HttpStreamFactoryImpl::Request::Complete( |
| 65 bool was_npn_negotiated, | 76 bool was_npn_negotiated, |
| 66 bool using_spdy, | 77 bool using_spdy, |
| 67 const NetLog::Source& job_source) { | 78 const NetLog::Source& job_source) { |
| 68 DCHECK(!completed_); | 79 DCHECK(!completed_); |
| 69 completed_ = true; | 80 completed_ = true; |
| 70 was_npn_negotiated_ = was_npn_negotiated; | 81 was_npn_negotiated_ = was_npn_negotiated; |
| 71 using_spdy_ = using_spdy; | 82 using_spdy_ = using_spdy; |
| 72 net_log_.AddEvent( | 83 net_log_.AddEvent( |
| 73 NetLog::TYPE_HTTP_STREAM_REQUEST_BOUND_TO_JOB, | 84 NetLog::TYPE_HTTP_STREAM_REQUEST_BOUND_TO_JOB, |
| 74 make_scoped_refptr(new NetLogSourceParameter( | 85 make_scoped_refptr(new NetLogSourceParameter( |
| 75 "source_dependency", job_source))); | 86 "source_dependency", job_source))); |
| 76 } | 87 } |
| 77 | 88 |
| 78 void HttpStreamFactoryImpl::Request::OnStreamReady( | 89 void HttpStreamFactoryImpl::Request::OnStreamReady( |
| 79 Job* job, | 90 Job* job, |
| 80 const SSLConfig& used_ssl_config, | 91 const SSLConfig& used_ssl_config, |
| 81 const ProxyInfo& used_proxy_info, | 92 const ProxyInfo& used_proxy_info, |
| 82 HttpStream* stream) { | 93 HttpStream* stream) { |
| 83 DCHECK(stream); | 94 DCHECK(stream); |
| 84 DCHECK(completed_); | 95 DCHECK(completed_); |
| 85 | 96 |
| 86 // |job| should only be NULL if we're being serviced by a late bound | 97 // |job| should only be NULL if we're being serviced by a late bound |
| 87 // SpdySession (one that was not created by a job in our |jobs_| set). | 98 // SpdySession (one that was not created by a job in our |jobs_| set). |
|
mmenke
2011/08/03 21:09:39
nit: Update comment.
James Simonsen
2011/08/05 01:39:00
Done.
| |
| 88 if (!job) { | 99 if (!job) { |
| 89 DCHECK(!bound_job_.get()); | 100 DCHECK(!bound_job_.get()); |
| 90 DCHECK(!jobs_.empty()); | 101 DCHECK(!jobs_.empty()); |
| 91 // NOTE(willchan): We do *NOT* call OrphanJobs() here. The reason is because | 102 // NOTE(willchan): We do *NOT* call OrphanJobs() here. The reason is because |
| 92 // we *WANT* to cancel the unnecessary Jobs from other requests if another | 103 // we *WANT* to cancel the unnecessary Jobs from other requests if another |
| 93 // Job completes first. | 104 // Job completes first. |
| 94 // TODO(mbelshe): Revisit this when we implement ip connection pooling of | 105 // TODO(mbelshe): Revisit this when we implement ip connection pooling of |
| 95 // SpdySessions. Do we want to orphan the jobs for a different hostname so | 106 // SpdySessions. Do we want to orphan the jobs for a different hostname so |
| 96 // they complete? Or do we want to prevent connecting a new SpdySession if | 107 // they complete? Or do we want to prevent connecting a new SpdySession if |
| 97 // we've already got one available for a different hostname where the ip | 108 // we've already got one available for a different hostname where the ip |
| (...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 218 RequestSet& request_set = | 229 RequestSet& request_set = |
| 219 spdy_session_request_map[*spdy_session_key_]; | 230 spdy_session_request_map[*spdy_session_key_]; |
| 220 DCHECK(ContainsKey(request_set, this)); | 231 DCHECK(ContainsKey(request_set, this)); |
| 221 request_set.erase(this); | 232 request_set.erase(this); |
| 222 if (request_set.empty()) | 233 if (request_set.empty()) |
| 223 spdy_session_request_map.erase(*spdy_session_key_); | 234 spdy_session_request_map.erase(*spdy_session_key_); |
| 224 spdy_session_key_.reset(); | 235 spdy_session_key_.reset(); |
| 225 } | 236 } |
| 226 } | 237 } |
| 227 | 238 |
| 239 void | |
| 240 HttpStreamFactoryImpl::Request::RemoveRequestFromHttpPipeliningRequestMap() { | |
| 241 if (http_pipelining_key_.get()) { | |
| 242 HttpPipeliningRequestMap& http_pipelining_request_map = | |
| 243 factory_->http_pipelining_request_map_; | |
| 244 DCHECK(ContainsKey(http_pipelining_request_map, *http_pipelining_key_)); | |
| 245 RequestSet& request_set = | |
| 246 http_pipelining_request_map[*http_pipelining_key_]; | |
| 247 DCHECK(ContainsKey(request_set, this)); | |
| 248 request_set.erase(this); | |
| 249 if (request_set.empty()) | |
| 250 http_pipelining_request_map.erase(*http_pipelining_key_); | |
| 251 http_pipelining_key_.reset(); | |
| 252 } | |
| 253 } | |
| 254 | |
| 228 void HttpStreamFactoryImpl::Request::OnSpdySessionReady( | 255 void HttpStreamFactoryImpl::Request::OnSpdySessionReady( |
| 229 Job* job, | 256 Job* job, |
| 230 scoped_refptr<SpdySession> spdy_session, | 257 scoped_refptr<SpdySession> spdy_session, |
| 231 bool direct) { | 258 bool direct) { |
| 232 DCHECK(job); | 259 DCHECK(job); |
| 233 DCHECK(job->using_spdy()); | 260 DCHECK(job->using_spdy()); |
| 234 | 261 |
| 235 // The first case is the usual case. | 262 // The first case is the usual case. |
| 236 if (!bound_job_.get()) { | 263 if (!bound_job_.get()) { |
| 237 OrphanJobsExcept(job); | 264 OrphanJobsExcept(job); |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 271 DCHECK(ContainsKey(jobs_, job)); | 298 DCHECK(ContainsKey(jobs_, job)); |
| 272 bound_job_.reset(job); | 299 bound_job_.reset(job); |
| 273 jobs_.erase(job); | 300 jobs_.erase(job); |
| 274 factory_->request_map_.erase(job); | 301 factory_->request_map_.erase(job); |
| 275 | 302 |
| 276 OrphanJobs(); | 303 OrphanJobs(); |
| 277 } | 304 } |
| 278 | 305 |
| 279 void HttpStreamFactoryImpl::Request::OrphanJobs() { | 306 void HttpStreamFactoryImpl::Request::OrphanJobs() { |
| 280 RemoveRequestFromSpdySessionRequestMap(); | 307 RemoveRequestFromSpdySessionRequestMap(); |
| 308 RemoveRequestFromHttpPipeliningRequestMap(); | |
| 281 | 309 |
| 282 std::set<Job*> tmp; | 310 std::set<Job*> tmp; |
| 283 tmp.swap(jobs_); | 311 tmp.swap(jobs_); |
| 284 | 312 |
| 285 for (std::set<Job*>::iterator it = tmp.begin(); it != tmp.end(); ++it) | 313 for (std::set<Job*>::iterator it = tmp.begin(); it != tmp.end(); ++it) |
| 286 factory_->OrphanJob(*it, this); | 314 factory_->OrphanJob(*it, this); |
| 287 } | 315 } |
| 288 | 316 |
| 289 } // namespace net | 317 } // namespace net |
| OLD | NEW |