OLD | NEW |
1 // Copyright (c) 2011 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/logging.h" | 7 #include "base/logging.h" |
8 #include "base/stl_util.h" | 8 #include "base/stl_util.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" |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
50 void HttpStreamFactoryImpl::Request::SetSpdySessionKey( | 50 void HttpStreamFactoryImpl::Request::SetSpdySessionKey( |
51 const HostPortProxyPair& spdy_session_key) { | 51 const HostPortProxyPair& spdy_session_key) { |
52 DCHECK(!spdy_session_key_.get()); | 52 DCHECK(!spdy_session_key_.get()); |
53 spdy_session_key_.reset(new HostPortProxyPair(spdy_session_key)); | 53 spdy_session_key_.reset(new HostPortProxyPair(spdy_session_key)); |
54 RequestSet& request_set = | 54 RequestSet& request_set = |
55 factory_->spdy_session_request_map_[spdy_session_key]; | 55 factory_->spdy_session_request_map_[spdy_session_key]; |
56 DCHECK(!ContainsKey(request_set, this)); | 56 DCHECK(!ContainsKey(request_set, this)); |
57 request_set.insert(this); | 57 request_set.insert(this); |
58 } | 58 } |
59 | 59 |
60 void HttpStreamFactoryImpl::Request::SetHttpPipeliningKey( | 60 bool HttpStreamFactoryImpl::Request::SetHttpPipeliningKey( |
61 const HostPortPair& http_pipelining_key) { | 61 const HttpPipelinedHost::Key& http_pipelining_key) { |
62 DCHECK(!http_pipelining_key_.get()); | 62 DCHECK(!http_pipelining_key_.get()); |
63 http_pipelining_key_.reset(new HostPortPair(http_pipelining_key)); | 63 http_pipelining_key_.reset(new HttpPipelinedHost::Key(http_pipelining_key)); |
| 64 bool was_new_key = !ContainsKey(factory_->http_pipelining_request_map_, |
| 65 http_pipelining_key); |
64 RequestSet& request_set = | 66 RequestSet& request_set = |
65 factory_->http_pipelining_request_map_[http_pipelining_key]; | 67 factory_->http_pipelining_request_map_[http_pipelining_key]; |
66 DCHECK(!ContainsKey(request_set, this)); | 68 DCHECK(!ContainsKey(request_set, this)); |
67 request_set.insert(this); | 69 request_set.insert(this); |
| 70 return was_new_key; |
68 } | 71 } |
69 | 72 |
70 void HttpStreamFactoryImpl::Request::AttachJob(Job* job) { | 73 void HttpStreamFactoryImpl::Request::AttachJob(Job* job) { |
71 DCHECK(job); | 74 DCHECK(job); |
72 jobs_.insert(job); | 75 jobs_.insert(job); |
73 factory_->request_map_[job] = this; | 76 factory_->request_map_[job] = this; |
74 } | 77 } |
75 | 78 |
76 void HttpStreamFactoryImpl::Request::Complete( | 79 void HttpStreamFactoryImpl::Request::Complete( |
77 bool was_npn_negotiated, | 80 bool was_npn_negotiated, |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
123 DCHECK(jobs_.empty()); | 126 DCHECK(jobs_.empty()); |
124 } | 127 } |
125 delegate_->OnStreamReady(used_ssl_config, used_proxy_info, stream); | 128 delegate_->OnStreamReady(used_ssl_config, used_proxy_info, stream); |
126 } | 129 } |
127 | 130 |
128 void HttpStreamFactoryImpl::Request::OnStreamFailed( | 131 void HttpStreamFactoryImpl::Request::OnStreamFailed( |
129 Job* job, | 132 Job* job, |
130 int status, | 133 int status, |
131 const SSLConfig& used_ssl_config) { | 134 const SSLConfig& used_ssl_config) { |
132 DCHECK_NE(OK, status); | 135 DCHECK_NE(OK, status); |
133 if (!bound_job_.get()) { | 136 // |job| should only be NULL if we're being canceled by a late bound |
| 137 // HttpPipelinedConnection (one that was not created by a job in our |jobs_| |
| 138 // set). |
| 139 if (!job) { |
| 140 DCHECK(!bound_job_.get()); |
| 141 DCHECK(!jobs_.empty()); |
| 142 // NOTE(willchan): We do *NOT* call OrphanJobs() here. The reason is because |
| 143 // we *WANT* to cancel the unnecessary Jobs from other requests if another |
| 144 // Job completes first. |
| 145 } else if (!bound_job_.get()) { |
134 // Hey, we've got other jobs! Maybe one of them will succeed, let's just | 146 // Hey, we've got other jobs! Maybe one of them will succeed, let's just |
135 // ignore this failure. | 147 // ignore this failure. |
136 if (jobs_.size() > 1) { | 148 if (jobs_.size() > 1) { |
137 jobs_.erase(job); | 149 jobs_.erase(job); |
138 factory_->request_map_.erase(job); | 150 factory_->request_map_.erase(job); |
139 delete job; | 151 delete job; |
140 return; | 152 return; |
141 } else { | 153 } else { |
142 bound_job_.reset(job); | 154 bound_job_.reset(job); |
143 jobs_.erase(job); | 155 jobs_.erase(job); |
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
321 RemoveRequestFromHttpPipeliningRequestMap(); | 333 RemoveRequestFromHttpPipeliningRequestMap(); |
322 | 334 |
323 std::set<Job*> tmp; | 335 std::set<Job*> tmp; |
324 tmp.swap(jobs_); | 336 tmp.swap(jobs_); |
325 | 337 |
326 for (std::set<Job*>::iterator it = tmp.begin(); it != tmp.end(); ++it) | 338 for (std::set<Job*>::iterator it = tmp.begin(); it != tmp.end(); ++it) |
327 factory_->OrphanJob(*it, this); | 339 factory_->OrphanJob(*it, this); |
328 } | 340 } |
329 | 341 |
330 } // namespace net | 342 } // namespace net |
OLD | NEW |