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/bidirectional_stream_impl.h" | 10 #include "net/http/bidirectional_stream_impl.h" |
| 11 #include "net/http/http_stream_factory_impl_job.h" | 11 #include "net/http/http_stream_factory_impl_job.h" |
| 12 #include "net/http/http_stream_factory_impl_job_controller.h" | |
| 12 #include "net/spdy/spdy_http_stream.h" | 13 #include "net/spdy/spdy_http_stream.h" |
| 13 #include "net/spdy/spdy_session.h" | 14 #include "net/spdy/spdy_session.h" |
| 14 | 15 |
| 15 namespace net { | 16 namespace net { |
| 16 | 17 |
| 17 HttpStreamFactoryImpl::Request::Request( | 18 HttpStreamFactoryImpl::Request::Request( |
| 18 const GURL& url, | 19 const GURL& url, |
| 19 HttpStreamFactoryImpl* factory, | 20 JobController* job_controller, |
| 20 HttpStreamRequest::Delegate* delegate, | 21 HttpStreamRequest::Delegate* delegate, |
| 21 WebSocketHandshakeStreamBase::CreateHelper* | 22 WebSocketHandshakeStreamBase::CreateHelper* |
| 22 websocket_handshake_stream_create_helper, | 23 websocket_handshake_stream_create_helper, |
| 23 const BoundNetLog& net_log, | 24 const BoundNetLog& net_log, |
| 24 StreamType stream_type) | 25 StreamType stream_type) |
| 25 : url_(url), | 26 : url_(url), |
| 26 factory_(factory), | 27 job_controller_(job_controller), |
| 27 websocket_handshake_stream_create_helper_( | 28 websocket_handshake_stream_create_helper_( |
| 28 websocket_handshake_stream_create_helper), | 29 websocket_handshake_stream_create_helper), |
| 29 delegate_(delegate), | 30 delegate_(delegate), |
| 30 net_log_(net_log), | 31 net_log_(net_log), |
| 31 completed_(false), | 32 completed_(false), |
| 32 was_npn_negotiated_(false), | 33 was_npn_negotiated_(false), |
| 33 protocol_negotiated_(kProtoUnknown), | 34 protocol_negotiated_(kProtoUnknown), |
| 34 using_spdy_(false), | 35 using_spdy_(false), |
| 35 stream_type_(stream_type) { | 36 stream_type_(stream_type) { |
| 36 DCHECK(factory_); | |
| 37 DCHECK(delegate_); | 37 DCHECK(delegate_); |
| 38 | 38 |
| 39 net_log_.BeginEvent(NetLog::TYPE_HTTP_STREAM_REQUEST); | 39 net_log_.BeginEvent(NetLog::TYPE_HTTP_STREAM_REQUEST); |
| 40 } | 40 } |
| 41 | 41 |
| 42 HttpStreamFactoryImpl::Request::~Request() { | 42 HttpStreamFactoryImpl::Request::~Request() { |
| 43 if (bound_job_.get()) | |
| 44 DCHECK(jobs_.empty()); | |
| 45 | |
| 46 net_log_.EndEvent(NetLog::TYPE_HTTP_STREAM_REQUEST); | 43 net_log_.EndEvent(NetLog::TYPE_HTTP_STREAM_REQUEST); |
| 47 | 44 job_controller_->OnRequestFinish(); |
|
Ryan Hamilton
2016/05/13 20:50:40
nit: s/Finish/Complete/ I think would be a better
Zhongyi Shi
2016/05/13 22:22:22
Done. Renamed to OnRequestComplete
| |
| 48 CancelJobs(); | |
| 49 } | 45 } |
| 50 | 46 |
| 51 void HttpStreamFactoryImpl::Request::SetSpdySessionKey( | 47 void HttpStreamFactoryImpl::Request::SetSpdySessionKey( |
| 52 const SpdySessionKey& spdy_session_key) { | 48 const SpdySessionKey& spdy_session_key) { |
| 53 CHECK(!spdy_session_key_.get()); | |
| 54 spdy_session_key_.reset(new SpdySessionKey(spdy_session_key)); | 49 spdy_session_key_.reset(new SpdySessionKey(spdy_session_key)); |
| 55 RequestSet& request_set = | |
| 56 factory_->spdy_session_request_map_[spdy_session_key]; | |
| 57 DCHECK(!ContainsKey(request_set, this)); | |
| 58 request_set.insert(this); | |
| 59 } | |
| 60 | |
| 61 void HttpStreamFactoryImpl::Request::AttachJob(Job* job) { | |
| 62 DCHECK(job); | |
| 63 jobs_.insert(job); | |
| 64 factory_->request_map_[job] = this; | |
| 65 } | 50 } |
| 66 | 51 |
| 67 void HttpStreamFactoryImpl::Request::Complete(bool was_npn_negotiated, | 52 void HttpStreamFactoryImpl::Request::Complete(bool was_npn_negotiated, |
| 68 NextProto protocol_negotiated, | 53 NextProto protocol_negotiated, |
| 69 bool using_spdy) { | 54 bool using_spdy) { |
| 70 DCHECK(!completed_); | 55 DCHECK(!completed_); |
| 71 completed_ = true; | 56 completed_ = true; |
| 72 was_npn_negotiated_ = was_npn_negotiated; | 57 was_npn_negotiated_ = was_npn_negotiated; |
| 73 protocol_negotiated_ = protocol_negotiated; | 58 protocol_negotiated_ = protocol_negotiated; |
| 74 using_spdy_ = using_spdy; | 59 using_spdy_ = using_spdy; |
| 75 } | 60 } |
| 76 | 61 |
| 77 void HttpStreamFactoryImpl::Request::OnStreamReady( | 62 void HttpStreamFactoryImpl::Request::OnStreamReady( |
| 78 Job* job, | |
| 79 const SSLConfig& used_ssl_config, | 63 const SSLConfig& used_ssl_config, |
| 80 const ProxyInfo& used_proxy_info, | 64 const ProxyInfo& used_proxy_info, |
| 81 HttpStream* stream) { | 65 HttpStream* stream) { |
| 82 DCHECK(!factory_->for_websockets_); | |
| 83 DCHECK_EQ(HttpStreamRequest::HTTP_STREAM, stream_type_); | |
| 84 DCHECK(stream); | |
| 85 DCHECK(completed_); | 66 DCHECK(completed_); |
| 86 | |
| 87 OnJobSucceeded(job); | |
| 88 delegate_->OnStreamReady(used_ssl_config, used_proxy_info, stream); | 67 delegate_->OnStreamReady(used_ssl_config, used_proxy_info, stream); |
| 89 } | 68 } |
| 90 | 69 |
| 91 void HttpStreamFactoryImpl::Request::OnBidirectionalStreamImplReady( | 70 void HttpStreamFactoryImpl::Request::OnBidirectionalStreamImplReady( |
| 92 Job* job, | |
| 93 const SSLConfig& used_ssl_config, | 71 const SSLConfig& used_ssl_config, |
| 94 const ProxyInfo& used_proxy_info, | 72 const ProxyInfo& used_proxy_info, |
| 95 BidirectionalStreamImpl* stream_job) { | 73 BidirectionalStreamImpl* stream_job) { |
| 96 DCHECK(!factory_->for_websockets_); | |
| 97 DCHECK_EQ(HttpStreamRequest::BIDIRECTIONAL_STREAM, stream_type_); | |
| 98 DCHECK(stream_job); | |
| 99 DCHECK(completed_); | 74 DCHECK(completed_); |
| 100 | |
| 101 OnJobSucceeded(job); | |
| 102 delegate_->OnBidirectionalStreamImplReady(used_ssl_config, used_proxy_info, | 75 delegate_->OnBidirectionalStreamImplReady(used_ssl_config, used_proxy_info, |
| 103 stream_job); | 76 stream_job); |
| 104 } | 77 } |
| 105 | 78 |
| 106 void HttpStreamFactoryImpl::Request::OnWebSocketHandshakeStreamReady( | 79 void HttpStreamFactoryImpl::Request::OnWebSocketHandshakeStreamReady( |
| 107 Job* job, | |
| 108 const SSLConfig& used_ssl_config, | 80 const SSLConfig& used_ssl_config, |
| 109 const ProxyInfo& used_proxy_info, | 81 const ProxyInfo& used_proxy_info, |
| 110 WebSocketHandshakeStreamBase* stream) { | 82 WebSocketHandshakeStreamBase* stream) { |
| 111 DCHECK(factory_->for_websockets_); | |
| 112 DCHECK_EQ(HttpStreamRequest::HTTP_STREAM, stream_type_); | |
| 113 DCHECK(stream); | |
| 114 DCHECK(completed_); | 83 DCHECK(completed_); |
| 115 | |
| 116 OnJobSucceeded(job); | |
| 117 delegate_->OnWebSocketHandshakeStreamReady( | 84 delegate_->OnWebSocketHandshakeStreamReady( |
| 118 used_ssl_config, used_proxy_info, stream); | 85 used_ssl_config, used_proxy_info, stream); |
| 119 } | 86 } |
| 120 | 87 |
| 121 void HttpStreamFactoryImpl::Request::OnStreamFailed( | 88 void HttpStreamFactoryImpl::Request::OnStreamFailed( |
| 122 Job* job, | |
| 123 int status, | 89 int status, |
| 124 const SSLConfig& used_ssl_config, | 90 const SSLConfig& used_ssl_config, |
| 125 SSLFailureState ssl_failure_state) { | 91 SSLFailureState ssl_failure_state) { |
| 126 DCHECK_NE(OK, status); | |
| 127 DCHECK(job); | |
| 128 if (!bound_job_.get()) { | |
| 129 if (jobs_.size() > 1) { | |
| 130 // Hey, we've got other jobs! Maybe one of them will succeed, let's just | |
| 131 // ignore this failure. | |
| 132 jobs_.erase(job); | |
| 133 factory_->request_map_.erase(job); | |
| 134 // Notify all the other jobs that this one failed. | |
| 135 for (std::set<Job*>::iterator it = jobs_.begin(); it != jobs_.end(); ++it) | |
| 136 (*it)->MarkOtherJobComplete(*job); | |
| 137 delete job; | |
| 138 return; | |
| 139 } else { | |
| 140 BindJob(job); | |
| 141 } | |
| 142 } else { | |
| 143 DCHECK(jobs_.empty()); | |
| 144 } | |
| 145 delegate_->OnStreamFailed(status, used_ssl_config, ssl_failure_state); | 92 delegate_->OnStreamFailed(status, used_ssl_config, ssl_failure_state); |
| 146 } | 93 } |
| 147 | 94 |
| 148 void HttpStreamFactoryImpl::Request::OnCertificateError( | 95 void HttpStreamFactoryImpl::Request::OnCertificateError( |
| 149 Job* job, | |
| 150 int status, | 96 int status, |
| 151 const SSLConfig& used_ssl_config, | 97 const SSLConfig& used_ssl_config, |
| 152 const SSLInfo& ssl_info) { | 98 const SSLInfo& ssl_info) { |
| 153 DCHECK_NE(OK, status); | |
| 154 if (!bound_job_.get()) | |
| 155 BindJob(job); | |
| 156 else | |
| 157 DCHECK(jobs_.empty()); | |
| 158 delegate_->OnCertificateError(status, used_ssl_config, ssl_info); | 99 delegate_->OnCertificateError(status, used_ssl_config, ssl_info); |
| 159 } | 100 } |
| 160 | 101 |
| 161 void HttpStreamFactoryImpl::Request::OnNeedsProxyAuth( | 102 void HttpStreamFactoryImpl::Request::OnNeedsProxyAuth( |
| 162 Job* job, | |
| 163 const HttpResponseInfo& proxy_response, | 103 const HttpResponseInfo& proxy_response, |
| 164 const SSLConfig& used_ssl_config, | 104 const SSLConfig& used_ssl_config, |
| 165 const ProxyInfo& used_proxy_info, | 105 const ProxyInfo& used_proxy_info, |
| 166 HttpAuthController* auth_controller) { | 106 HttpAuthController* auth_controller) { |
| 167 if (!bound_job_.get()) | |
| 168 BindJob(job); | |
| 169 else | |
| 170 DCHECK(jobs_.empty()); | |
| 171 delegate_->OnNeedsProxyAuth( | 107 delegate_->OnNeedsProxyAuth( |
| 172 proxy_response, used_ssl_config, used_proxy_info, auth_controller); | 108 proxy_response, used_ssl_config, used_proxy_info, auth_controller); |
| 173 } | 109 } |
| 174 | 110 |
| 175 void HttpStreamFactoryImpl::Request::OnNeedsClientAuth( | 111 void HttpStreamFactoryImpl::Request::OnNeedsClientAuth( |
| 176 Job* job, | |
| 177 const SSLConfig& used_ssl_config, | 112 const SSLConfig& used_ssl_config, |
| 178 SSLCertRequestInfo* cert_info) { | 113 SSLCertRequestInfo* cert_info) { |
| 179 if (!bound_job_.get()) | |
| 180 BindJob(job); | |
| 181 else | |
| 182 DCHECK(jobs_.empty()); | |
| 183 delegate_->OnNeedsClientAuth(used_ssl_config, cert_info); | 114 delegate_->OnNeedsClientAuth(used_ssl_config, cert_info); |
| 184 } | 115 } |
| 185 | 116 |
| 186 void HttpStreamFactoryImpl::Request::OnHttpsProxyTunnelResponse( | 117 void HttpStreamFactoryImpl::Request::OnHttpsProxyTunnelResponse( |
| 187 Job *job, | |
| 188 const HttpResponseInfo& response_info, | 118 const HttpResponseInfo& response_info, |
| 189 const SSLConfig& used_ssl_config, | 119 const SSLConfig& used_ssl_config, |
| 190 const ProxyInfo& used_proxy_info, | 120 const ProxyInfo& used_proxy_info, |
| 191 HttpStream* stream) { | 121 HttpStream* stream) { |
| 192 if (!bound_job_.get()) | |
| 193 BindJob(job); | |
| 194 else | |
| 195 DCHECK(jobs_.empty()); | |
| 196 delegate_->OnHttpsProxyTunnelResponse( | 122 delegate_->OnHttpsProxyTunnelResponse( |
| 197 response_info, used_ssl_config, used_proxy_info, stream); | 123 response_info, used_ssl_config, used_proxy_info, stream); |
| 198 } | 124 } |
| 199 | 125 |
| 200 int HttpStreamFactoryImpl::Request::RestartTunnelWithProxyAuth( | 126 int HttpStreamFactoryImpl::Request::RestartTunnelWithProxyAuth( |
| 201 const AuthCredentials& credentials) { | 127 const AuthCredentials& credentials) { |
| 202 DCHECK(bound_job_.get()); | 128 return job_controller_->RestartTunnelWithProxyAuth(credentials); |
| 203 return bound_job_->RestartTunnelWithProxyAuth(credentials); | |
| 204 } | 129 } |
| 205 | 130 |
| 206 void HttpStreamFactoryImpl::Request::SetPriority(RequestPriority priority) { | 131 void HttpStreamFactoryImpl::Request::SetPriority(RequestPriority priority) { |
| 207 for (std::set<HttpStreamFactoryImpl::Job*>::const_iterator it = jobs_.begin(); | 132 job_controller_->SetPriority(priority); |
| 208 it != jobs_.end(); ++it) { | |
| 209 (*it)->SetPriority(priority); | |
| 210 } | |
| 211 if (bound_job_) | |
| 212 bound_job_->SetPriority(priority); | |
| 213 } | 133 } |
| 214 | 134 |
| 215 LoadState HttpStreamFactoryImpl::Request::GetLoadState() const { | 135 LoadState HttpStreamFactoryImpl::Request::GetLoadState() const { |
| 216 if (bound_job_.get()) | 136 return job_controller_->GetLoadState(); |
| 217 return bound_job_->GetLoadState(); | |
| 218 DCHECK(!jobs_.empty()); | |
| 219 | |
| 220 // Just pick the first one. | |
| 221 return (*jobs_.begin())->GetLoadState(); | |
| 222 } | 137 } |
| 223 | 138 |
| 224 bool HttpStreamFactoryImpl::Request::was_npn_negotiated() const { | 139 bool HttpStreamFactoryImpl::Request::was_npn_negotiated() const { |
| 225 DCHECK(completed_); | 140 DCHECK(completed_); |
| 226 return was_npn_negotiated_; | 141 return was_npn_negotiated_; |
| 227 } | 142 } |
| 228 | 143 |
| 229 NextProto HttpStreamFactoryImpl::Request::protocol_negotiated() | 144 NextProto HttpStreamFactoryImpl::Request::protocol_negotiated() |
| 230 const { | 145 const { |
| 231 DCHECK(completed_); | 146 DCHECK(completed_); |
| 232 return protocol_negotiated_; | 147 return protocol_negotiated_; |
| 233 } | 148 } |
| 234 | 149 |
| 235 bool HttpStreamFactoryImpl::Request::using_spdy() const { | 150 bool HttpStreamFactoryImpl::Request::using_spdy() const { |
| 236 DCHECK(completed_); | 151 DCHECK(completed_); |
| 237 return using_spdy_; | 152 return using_spdy_; |
| 238 } | 153 } |
| 239 | 154 |
| 240 const ConnectionAttempts& HttpStreamFactoryImpl::Request::connection_attempts() | 155 const ConnectionAttempts& HttpStreamFactoryImpl::Request::connection_attempts() |
| 241 const { | 156 const { |
| 242 return connection_attempts_; | 157 return connection_attempts_; |
| 243 } | 158 } |
| 244 | 159 |
| 245 void | 160 void HttpStreamFactoryImpl::Request::ResetSpdySessionKey() { |
| 246 HttpStreamFactoryImpl::Request::RemoveRequestFromSpdySessionRequestMap() { | |
| 247 if (spdy_session_key_.get()) { | 161 if (spdy_session_key_.get()) { |
| 248 SpdySessionRequestMap& spdy_session_request_map = | |
| 249 factory_->spdy_session_request_map_; | |
| 250 DCHECK(ContainsKey(spdy_session_request_map, *spdy_session_key_)); | |
| 251 RequestSet& request_set = | |
| 252 spdy_session_request_map[*spdy_session_key_]; | |
| 253 DCHECK(ContainsKey(request_set, this)); | |
| 254 request_set.erase(this); | |
| 255 if (request_set.empty()) | |
| 256 spdy_session_request_map.erase(*spdy_session_key_); | |
| 257 spdy_session_key_.reset(); | 162 spdy_session_key_.reset(); |
| 258 } | 163 } |
| 259 } | 164 } |
| 260 | 165 |
| 261 bool HttpStreamFactoryImpl::Request::HasSpdySessionKey() const { | 166 bool HttpStreamFactoryImpl::Request::HasSpdySessionKey() const { |
| 262 return spdy_session_key_.get() != NULL; | 167 return spdy_session_key_.get() != NULL; |
| 263 } | 168 } |
| 264 | 169 |
| 265 // TODO(jgraettinger): Currently, HttpStreamFactoryImpl::Job notifies a | |
| 266 // Request that the session is ready, which in turn notifies it's delegate, | |
| 267 // and then it notifies HttpStreamFactoryImpl so that /other/ requests may | |
| 268 // be woken, but only if the spdy_session is still okay. This is tough to grok. | |
| 269 // Instead, see if Job can notify HttpStreamFactoryImpl only, and have one | |
| 270 // path for notifying any requests waiting for the session (including the | |
| 271 // request which spawned it). | |
| 272 void HttpStreamFactoryImpl::Request::OnNewSpdySessionReady( | |
| 273 Job* job, | |
| 274 std::unique_ptr<HttpStream> stream, | |
| 275 std::unique_ptr<BidirectionalStreamImpl> bidirectional_stream_impl, | |
| 276 const base::WeakPtr<SpdySession>& spdy_session, | |
| 277 bool direct) { | |
| 278 DCHECK(job); | |
| 279 DCHECK(job->using_spdy()); | |
| 280 | |
| 281 // Note: |spdy_session| may be NULL. In that case, |delegate_| should still | |
| 282 // receive |stream| so the error propagates up correctly, however there is no | |
| 283 // point in broadcasting |spdy_session| to other requests. | |
| 284 | |
| 285 // The first case is the usual case. | |
| 286 if (!bound_job_.get()) { | |
| 287 BindJob(job); | |
| 288 } else { // This is the case for HTTPS proxy tunneling. | |
| 289 DCHECK_EQ(bound_job_.get(), job); | |
| 290 DCHECK(jobs_.empty()); | |
| 291 } | |
| 292 | |
| 293 // Cache these values in case the job gets deleted. | |
| 294 const SSLConfig used_ssl_config = job->server_ssl_config(); | |
| 295 const ProxyInfo used_proxy_info = job->proxy_info(); | |
| 296 const bool was_npn_negotiated = job->was_npn_negotiated(); | |
| 297 const NextProto protocol_negotiated = | |
| 298 job->protocol_negotiated(); | |
| 299 const bool using_spdy = job->using_spdy(); | |
| 300 const BoundNetLog net_log = job->net_log(); | |
| 301 | |
| 302 Complete(was_npn_negotiated, protocol_negotiated, using_spdy); | |
| 303 | |
| 304 // Cache this so we can still use it if the request is deleted. | |
| 305 HttpStreamFactoryImpl* factory = factory_; | |
| 306 if (factory->for_websockets_) { | |
| 307 // TODO(ricea): Re-instate this code when WebSockets over SPDY is | |
| 308 // implemented. | |
| 309 NOTREACHED(); | |
| 310 } else if (stream_type_ == HttpStreamRequest::BIDIRECTIONAL_STREAM) { | |
| 311 DCHECK(bidirectional_stream_impl); | |
| 312 DCHECK(!stream); | |
| 313 delegate_->OnBidirectionalStreamImplReady( | |
| 314 job->server_ssl_config(), job->proxy_info(), | |
| 315 bidirectional_stream_impl.release()); | |
| 316 } else { | |
| 317 DCHECK(!bidirectional_stream_impl); | |
| 318 DCHECK(stream); | |
| 319 delegate_->OnStreamReady(job->server_ssl_config(), job->proxy_info(), | |
| 320 stream.release()); | |
| 321 } | |
| 322 // |this| may be deleted after this point. | |
| 323 if (spdy_session && spdy_session->IsAvailable()) { | |
| 324 factory->OnNewSpdySessionReady(spdy_session, | |
| 325 direct, | |
| 326 used_ssl_config, | |
| 327 used_proxy_info, | |
| 328 was_npn_negotiated, | |
| 329 protocol_negotiated, | |
| 330 using_spdy, | |
| 331 net_log); | |
| 332 } | |
| 333 } | |
| 334 | |
| 335 void HttpStreamFactoryImpl::Request::AddConnectionAttempts( | 170 void HttpStreamFactoryImpl::Request::AddConnectionAttempts( |
| 336 const ConnectionAttempts& attempts) { | 171 const ConnectionAttempts& attempts) { |
| 337 for (const auto& attempt : attempts) | 172 for (const auto& attempt : attempts) |
| 338 connection_attempts_.push_back(attempt); | 173 connection_attempts_.push_back(attempt); |
| 339 } | 174 } |
| 340 | 175 |
| 341 void HttpStreamFactoryImpl::Request::BindJob(Job* job) { | |
| 342 DCHECK(job); | |
| 343 DCHECK(!bound_job_.get()); | |
| 344 DCHECK(ContainsKey(jobs_, job)); | |
| 345 bound_job_.reset(job); | |
| 346 jobs_.erase(job); | |
| 347 factory_->request_map_.erase(job); | |
| 348 | |
| 349 net_log_.AddEvent(NetLog::TYPE_HTTP_STREAM_REQUEST_BOUND_TO_JOB, | |
| 350 job->net_log().source().ToEventParametersCallback()); | |
| 351 job->net_log().AddEvent(NetLog::TYPE_HTTP_STREAM_JOB_BOUND_TO_REQUEST, | |
| 352 net_log_.source().ToEventParametersCallback()); | |
| 353 | |
| 354 OrphanJobs(); | |
| 355 } | |
| 356 | |
| 357 void HttpStreamFactoryImpl::Request::OrphanJobs() { | |
| 358 RemoveRequestFromSpdySessionRequestMap(); | |
| 359 | |
| 360 std::set<Job*> tmp; | |
| 361 tmp.swap(jobs_); | |
| 362 | |
| 363 for (Job* job : tmp) | |
| 364 factory_->OrphanJob(job, this); | |
| 365 } | |
| 366 | |
| 367 void HttpStreamFactoryImpl::Request::CancelJobs() { | |
| 368 RemoveRequestFromSpdySessionRequestMap(); | |
| 369 | |
| 370 std::set<Job*> tmp; | |
| 371 tmp.swap(jobs_); | |
| 372 | |
| 373 for (Job* job : tmp) { | |
| 374 factory_->request_map_.erase(job); | |
| 375 delete job; | |
| 376 } | |
| 377 } | |
| 378 | |
| 379 void HttpStreamFactoryImpl::Request::OnJobSucceeded(Job* job) { | |
| 380 // |job| should only be NULL if we're being serviced by a late bound | |
| 381 // SpdySession (one that was not created by a job in our |jobs_| set). | |
| 382 if (!job) { | |
| 383 DCHECK(!bound_job_.get()); | |
| 384 DCHECK(!jobs_.empty()); | |
| 385 // NOTE(willchan): We do *NOT* call OrphanJobs() here. The reason is because | |
| 386 // we *WANT* to cancel the unnecessary Jobs from other requests if another | |
| 387 // Job completes first. | |
| 388 // TODO(mbelshe): Revisit this when we implement ip connection pooling of | |
| 389 // SpdySessions. Do we want to orphan the jobs for a different hostname so | |
| 390 // they complete? Or do we want to prevent connecting a new SpdySession if | |
| 391 // we've already got one available for a different hostname where the ip | |
| 392 // address matches up? | |
| 393 CancelJobs(); | |
| 394 return; | |
| 395 } | |
| 396 if (!bound_job_.get()) { | |
| 397 if (jobs_.size() > 1) | |
| 398 job->ReportJobSucceededForRequest(); | |
| 399 // Notify all the other jobs that this one succeeded. | |
| 400 for (std::set<Job*>::iterator it = jobs_.begin(); it != jobs_.end(); ++it) { | |
| 401 if (*it != job) { | |
| 402 (*it)->MarkOtherJobComplete(*job); | |
| 403 } | |
| 404 } | |
| 405 // We may have other jobs in |jobs_|. For example, if we start multiple jobs | |
| 406 // for Alternate-Protocol. | |
| 407 BindJob(job); | |
| 408 return; | |
| 409 } | |
| 410 DCHECK(jobs_.empty()); | |
| 411 } | |
| 412 | |
| 413 } // namespace net | 176 } // namespace net |
| OLD | NEW |