Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(129)

Side by Side Diff: net/http/http_stream_factory_impl_job.cc

Issue 1941083002: JobController 1: Adding a new class HttpStreamFactoryImpl::JobController (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: add JobFactory and rewrite test cases Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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_job.h" 5 #include "net/http/http_stream_factory_impl_job.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <string> 8 #include <string>
9 #include <utility> 9 #include <utility>
10 10
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after
147 const std::string* proto, 147 const std::string* proto,
148 NetLogCaptureMode /* capture_mode */) { 148 NetLogCaptureMode /* capture_mode */) {
149 std::unique_ptr<base::DictionaryValue> dict(new base::DictionaryValue()); 149 std::unique_ptr<base::DictionaryValue> dict(new base::DictionaryValue());
150 150
151 dict->SetString("next_proto_status", 151 dict->SetString("next_proto_status",
152 SSLClientSocket::NextProtoStatusToString(status)); 152 SSLClientSocket::NextProtoStatusToString(status));
153 dict->SetString("proto", *proto); 153 dict->SetString("proto", *proto);
154 return std::move(dict); 154 return std::move(dict);
155 } 155 }
156 156
157 HttpStreamFactoryImpl::Job::Job(HttpStreamFactoryImpl* stream_factory, 157 HttpStreamFactoryImpl::Job::Job(Delegate* delegate,
158 JobType job_type,
158 HttpNetworkSession* session, 159 HttpNetworkSession* session,
159 const HttpRequestInfo& request_info, 160 const HttpRequestInfo& request_info,
160 RequestPriority priority, 161 RequestPriority priority,
161 const SSLConfig& server_ssl_config, 162 const SSLConfig& server_ssl_config,
162 const SSLConfig& proxy_ssl_config, 163 const SSLConfig& proxy_ssl_config,
163 HostPortPair destination, 164 HostPortPair destination,
164 GURL origin_url, 165 GURL origin_url,
165 NetLog* net_log) 166 NetLog* net_log)
166 : Job(stream_factory, 167 : Job(delegate,
168 job_type,
167 session, 169 session,
168 request_info, 170 request_info,
169 priority, 171 priority,
170 server_ssl_config, 172 server_ssl_config,
171 proxy_ssl_config, 173 proxy_ssl_config,
172 destination, 174 destination,
173 origin_url, 175 origin_url,
174 AlternativeService(), 176 AlternativeService(),
175 net_log) {} 177 net_log) {}
176 178
177 HttpStreamFactoryImpl::Job::Job(HttpStreamFactoryImpl* stream_factory, 179 HttpStreamFactoryImpl::Job::Job(Delegate* delegate,
180 JobType job_type,
178 HttpNetworkSession* session, 181 HttpNetworkSession* session,
179 const HttpRequestInfo& request_info, 182 const HttpRequestInfo& request_info,
180 RequestPriority priority, 183 RequestPriority priority,
181 const SSLConfig& server_ssl_config, 184 const SSLConfig& server_ssl_config,
182 const SSLConfig& proxy_ssl_config, 185 const SSLConfig& proxy_ssl_config,
183 HostPortPair destination, 186 HostPortPair destination,
184 GURL origin_url, 187 GURL origin_url,
185 AlternativeService alternative_service, 188 AlternativeService alternative_service,
186 NetLog* net_log) 189 NetLog* net_log)
187 : request_(NULL), 190 : request_info_(request_info),
188 request_info_(request_info),
189 priority_(priority), 191 priority_(priority),
190 server_ssl_config_(server_ssl_config), 192 server_ssl_config_(server_ssl_config),
191 proxy_ssl_config_(proxy_ssl_config), 193 proxy_ssl_config_(proxy_ssl_config),
192 net_log_(BoundNetLog::Make(net_log, NetLog::SOURCE_HTTP_STREAM_JOB)), 194 net_log_(BoundNetLog::Make(net_log, NetLog::SOURCE_HTTP_STREAM_JOB)),
193 io_callback_(base::Bind(&Job::OnIOComplete, base::Unretained(this))), 195 io_callback_(base::Bind(&Job::OnIOComplete, base::Unretained(this))),
194 connection_(new ClientSocketHandle), 196 connection_(new ClientSocketHandle),
195 session_(session), 197 session_(session),
196 stream_factory_(stream_factory),
197 next_state_(STATE_NONE), 198 next_state_(STATE_NONE),
198 pac_request_(NULL), 199 pac_request_(NULL),
199 destination_(destination), 200 destination_(destination),
200 origin_url_(origin_url), 201 origin_url_(origin_url),
201 alternative_service_(alternative_service), 202 alternative_service_(alternative_service),
203 delegate_(delegate),
204 job_type_(job_type),
202 blocking_job_(NULL), 205 blocking_job_(NULL),
203 waiting_job_(NULL), 206 waiting_job_(NULL),
204 using_ssl_(false), 207 using_ssl_(false),
205 using_spdy_(false), 208 using_spdy_(false),
206 using_quic_(false), 209 using_quic_(false),
207 quic_request_(session_->quic_stream_factory()), 210 quic_request_(session_->quic_stream_factory()),
208 using_existing_quic_session_(false), 211 using_existing_quic_session_(false),
209 spdy_certificate_error_(OK), 212 spdy_certificate_error_(OK),
210 establishing_tunnel_(false), 213 establishing_tunnel_(false),
211 was_npn_negotiated_(false), 214 was_npn_negotiated_(false),
212 protocol_negotiated_(kProtoUnknown), 215 protocol_negotiated_(kProtoUnknown),
213 num_streams_(0), 216 num_streams_(0),
214 spdy_session_direct_(false), 217 spdy_session_direct_(false),
215 job_status_(STATUS_RUNNING), 218 job_status_(STATUS_RUNNING),
216 other_job_status_(STATUS_RUNNING), 219 other_job_status_(STATUS_RUNNING),
217 stream_type_(HttpStreamRequest::BIDIRECTIONAL_STREAM), 220 stream_type_(HttpStreamRequest::BIDIRECTIONAL_STREAM),
218 ptr_factory_(this) { 221 ptr_factory_(this) {
219 DCHECK(stream_factory);
220 DCHECK(session); 222 DCHECK(session);
221 if (IsQuicAlternative()) { 223 if (IsQuicAlternative()) {
222 DCHECK(session_->params().enable_quic); 224 DCHECK(session_->params().enable_quic);
223 using_quic_ = true; 225 using_quic_ = true;
224 } 226 }
225 } 227 }
226 228
227 HttpStreamFactoryImpl::Job::~Job() { 229 HttpStreamFactoryImpl::Job::~Job() {
228 net_log_.EndEvent(NetLog::TYPE_HTTP_STREAM_JOB); 230 net_log_.EndEvent(NetLog::TYPE_HTTP_STREAM_JOB);
229 231
230 // When we're in a partially constructed state, waiting for the user to 232 // When we're in a partially constructed state, waiting for the user to
231 // provide certificate handling information or authentication, we can't reuse 233 // provide certificate handling information or authentication, we can't reuse
232 // this stream at all. 234 // this stream at all.
233 if (next_state_ == STATE_WAITING_USER_ACTION) { 235 if (next_state_ == STATE_WAITING_USER_ACTION) {
234 connection_->socket()->Disconnect(); 236 connection_->socket()->Disconnect();
235 connection_.reset(); 237 connection_.reset();
236 } 238 }
237 239
238 if (pac_request_) 240 if (pac_request_)
239 session_->proxy_service()->CancelPacRequest(pac_request_); 241 session_->proxy_service()->CancelPacRequest(pac_request_);
240 242
241 // The stream could be in a partial state. It is not reusable. 243 // The stream could be in a partial state. It is not reusable.
242 if (stream_.get() && next_state_ != STATE_DONE) 244 if (stream_.get() && next_state_ != STATE_DONE)
243 stream_->Close(true /* not reusable */); 245 stream_->Close(true /* not reusable */);
244 } 246 }
245 247
246 void HttpStreamFactoryImpl::Job::Start(Request* request) { 248 void HttpStreamFactoryImpl::Job::Start(
247 DCHECK(request); 249 HttpStreamRequest::StreamType stream_type) {
248 request_ = request; 250 stream_type_ = stream_type;
249 // Saves |stream_type_|, since request is nulled when job is orphaned.
250 stream_type_ = request_->stream_type();
251 StartInternal(); 251 StartInternal();
252 } 252 }
253 253
254 int HttpStreamFactoryImpl::Job::Preconnect(int num_streams) { 254 int HttpStreamFactoryImpl::Job::Preconnect(int num_streams) {
255 DCHECK_GT(num_streams, 0); 255 DCHECK_GT(num_streams, 0);
256 base::WeakPtr<HttpServerProperties> http_server_properties = 256 base::WeakPtr<HttpServerProperties> http_server_properties =
257 session_->http_server_properties(); 257 session_->http_server_properties();
258 if (http_server_properties && 258 if (http_server_properties &&
259 http_server_properties->SupportsRequestPriority( 259 http_server_properties->SupportsRequestPriority(
260 url::SchemeHostPort(request_info_.url))) { 260 url::SchemeHostPort(request_info_.url))) {
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
319 // be delayed by the |wait_time_| when it resumes. 319 // be delayed by the |wait_time_| when it resumes.
320 if (next_state_ == STATE_NONE || next_state_ <= STATE_WAIT_FOR_JOB_COMPLETE) 320 if (next_state_ == STATE_NONE || next_state_ <= STATE_WAIT_FOR_JOB_COMPLETE)
321 wait_time_ = delay; 321 wait_time_ = delay;
322 322
323 // We know we're blocked if the next_state_ is STATE_WAIT_FOR_JOB_COMPLETE. 323 // We know we're blocked if the next_state_ is STATE_WAIT_FOR_JOB_COMPLETE.
324 // Unblock |this|. 324 // Unblock |this|.
325 if (next_state_ == STATE_WAIT_FOR_JOB_COMPLETE) 325 if (next_state_ == STATE_WAIT_FOR_JOB_COMPLETE)
326 ResumeAfterDelay(); 326 ResumeAfterDelay();
327 } 327 }
328 328
329 void HttpStreamFactoryImpl::Job::Orphan(const Request* request) { 329 void HttpStreamFactoryImpl::Job::Orphan() {
330 DCHECK_EQ(request_, request);
331 request_ = NULL;
332 net_log_.AddEvent(NetLog::TYPE_HTTP_STREAM_JOB_ORPHANED); 330 net_log_.AddEvent(NetLog::TYPE_HTTP_STREAM_JOB_ORPHANED);
333 if (blocking_job_) { 331 if (blocking_job_) {
334 // We've been orphaned, but there's a job we're blocked on. Don't bother 332 // We've been orphaned, but there's a job we're blocked on. Don't bother
335 // racing, just cancel ourself. 333 // racing, just cancel ourself.
336 DCHECK(blocking_job_->waiting_job_); 334 DCHECK(blocking_job_->waiting_job_);
337 blocking_job_->waiting_job_ = NULL; 335 blocking_job_->waiting_job_ = NULL;
338 blocking_job_ = NULL; 336 blocking_job_ = NULL;
339 if (stream_factory_->for_websockets_ && 337 if (delegate_->for_websockets() && connection_ && connection_->socket()) {
340 connection_ && connection_->socket()) {
341 connection_->socket()->Disconnect(); 338 connection_->socket()->Disconnect();
342 } 339 }
343 stream_factory_->OnOrphanedJobComplete(this); 340 delegate_->OnOrphanedJobComplete(this);
344 } else if (stream_factory_->for_websockets_) { 341 } else if (delegate_->for_websockets()) {
345 // We cancel this job because a WebSocketHandshakeStream can't be created 342 // We cancel this job because a WebSocketHandshakeStream can't be created
346 // without a WebSocketHandshakeStreamBase::CreateHelper which is stored in 343 // without a WebSocketHandshakeStreamBase::CreateHelper which is stored in
347 // the Request class and isn't accessible from this job. 344 // the Request class and isn't retrievable by this job.
348 if (connection_ && connection_->socket()) { 345 if (connection_ && connection_->socket()) {
349 connection_->socket()->Disconnect(); 346 connection_->socket()->Disconnect();
350 } 347 }
351 stream_factory_->OnOrphanedJobComplete(this); 348 delegate_->OnOrphanedJobComplete(this);
352 } 349 }
350 // |this| may be deleted after this call.
353 } 351 }
354 352
355 void HttpStreamFactoryImpl::Job::SetPriority(RequestPriority priority) { 353 void HttpStreamFactoryImpl::Job::SetPriority(RequestPriority priority) {
356 priority_ = priority; 354 priority_ = priority;
357 // TODO(akalin): Propagate this to |connection_| and maybe the 355 // TODO(akalin): Propagate this to |connection_| and maybe the
358 // preconnect state. 356 // preconnect state.
359 } 357 }
360 358
361 bool HttpStreamFactoryImpl::Job::was_npn_negotiated() const { 359 bool HttpStreamFactoryImpl::Job::was_npn_negotiated() const {
362 return was_npn_negotiated_; 360 return was_npn_negotiated_;
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
410 // https (the normal case) or if we're connection to a SPDY proxy. 408 // https (the normal case) or if we're connection to a SPDY proxy.
411 // https://crbug.com/133176 409 // https://crbug.com/133176
412 // TODO(ricea): Add "wss" back to this list when SPDY WebSocket support is 410 // TODO(ricea): Add "wss" back to this list when SPDY WebSocket support is
413 // working. 411 // working.
414 return origin_url_.SchemeIs("https") || 412 return origin_url_.SchemeIs("https") ||
415 proxy_info_.proxy_server().is_https() || IsSpdyAlternative(); 413 proxy_info_.proxy_server().is_https() || IsSpdyAlternative();
416 } 414 }
417 415
418 void HttpStreamFactoryImpl::Job::OnStreamReadyCallback() { 416 void HttpStreamFactoryImpl::Job::OnStreamReadyCallback() {
419 DCHECK(stream_.get()); 417 DCHECK(stream_.get());
420 DCHECK(!IsPreconnecting()); 418 DCHECK(job_type_ != PRECONNECT);
421 DCHECK(!stream_factory_->for_websockets_); 419 DCHECK(!delegate_->for_websockets());
422 420
423 UMA_HISTOGRAM_TIMES("Net.HttpStreamFactoryJob.StreamReadyCallbackTime", 421 UMA_HISTOGRAM_TIMES("Net.HttpStreamFactoryJob.StreamReadyCallbackTime",
424 base::TimeTicks::Now() - job_stream_ready_start_time_); 422 base::TimeTicks::Now() - job_stream_ready_start_time_);
425 423
426 MaybeCopyConnectionAttemptsFromSocketOrHandle(); 424 MaybeCopyConnectionAttemptsFromSocketOrHandle();
427 425
428 if (IsOrphaned()) { 426 delegate_->OnStreamReady(this, server_ssl_config_, proxy_info_);
429 stream_factory_->OnOrphanedJobComplete(this);
430 } else {
431 request_->Complete(was_npn_negotiated(), protocol_negotiated(),
432 using_spdy());
433 request_->OnStreamReady(this, server_ssl_config_, proxy_info_,
434 stream_.release());
435 }
436 // |this| may be deleted after this call. 427 // |this| may be deleted after this call.
437 } 428 }
438 429
439 void HttpStreamFactoryImpl::Job::OnWebSocketHandshakeStreamReadyCallback() { 430 void HttpStreamFactoryImpl::Job::OnWebSocketHandshakeStreamReadyCallback() {
440 DCHECK(websocket_stream_); 431 DCHECK(websocket_stream_);
441 DCHECK(!IsPreconnecting()); 432 DCHECK(job_type_ != PRECONNECT);
442 DCHECK(stream_factory_->for_websockets_); 433 DCHECK(delegate_->for_websockets());
443 // An orphaned WebSocket job will be closed immediately and
444 // never be ready.
445 DCHECK(!IsOrphaned());
446 434
447 MaybeCopyConnectionAttemptsFromSocketOrHandle(); 435 MaybeCopyConnectionAttemptsFromSocketOrHandle();
448 436
449 request_->Complete(was_npn_negotiated(), protocol_negotiated(), using_spdy()); 437 delegate_->OnWebSocketHandshakeStreamReady(
450 request_->OnWebSocketHandshakeStreamReady(this, 438 this, server_ssl_config_, proxy_info_, websocket_stream_.release());
451 server_ssl_config_,
452 proxy_info_,
453 websocket_stream_.release());
454 // |this| may be deleted after this call. 439 // |this| may be deleted after this call.
455 } 440 }
456 441
457 void HttpStreamFactoryImpl::Job::OnBidirectionalStreamImplReadyCallback() { 442 void HttpStreamFactoryImpl::Job::OnBidirectionalStreamImplReadyCallback() {
458 DCHECK(bidirectional_stream_impl_); 443 DCHECK(bidirectional_stream_impl_);
459 444
460 MaybeCopyConnectionAttemptsFromSocketOrHandle(); 445 MaybeCopyConnectionAttemptsFromSocketOrHandle();
461 446
462 if (IsOrphaned()) { 447 delegate_->OnBidirectionalStreamImplReady(this, server_ssl_config_,
463 stream_factory_->OnOrphanedJobComplete(this); 448 proxy_info_);
464 } else { 449 // |this| may be deleted after this call.
465 request_->Complete(was_npn_negotiated(), protocol_negotiated(),
466 using_spdy());
467 request_->OnBidirectionalStreamImplReady(
468 this, server_ssl_config_, proxy_info_,
469 bidirectional_stream_impl_.release());
470 }
471 // |this| may be deleted after this call.
472 } 450 }
473 451
474 void HttpStreamFactoryImpl::Job::OnNewSpdySessionReadyCallback() { 452 void HttpStreamFactoryImpl::Job::OnNewSpdySessionReadyCallback() {
475 DCHECK(stream_.get() || bidirectional_stream_impl_.get()); 453 DCHECK(stream_.get() || bidirectional_stream_impl_.get());
476 DCHECK(!IsPreconnecting()); 454 DCHECK(job_type_ != PRECONNECT);
477 DCHECK(using_spdy()); 455 DCHECK(using_spdy());
478 // Note: an event loop iteration has passed, so |new_spdy_session_| may be 456 // Note: an event loop iteration has passed, so |new_spdy_session_| may be
479 // NULL at this point if the SpdySession closed immediately after creation. 457 // NULL at this point if the SpdySession closed immediately after creation.
480 base::WeakPtr<SpdySession> spdy_session = new_spdy_session_; 458 base::WeakPtr<SpdySession> spdy_session = new_spdy_session_;
481 new_spdy_session_.reset(); 459 new_spdy_session_.reset();
482 460
483 MaybeCopyConnectionAttemptsFromSocketOrHandle(); 461 MaybeCopyConnectionAttemptsFromSocketOrHandle();
484 462
485 // TODO(jgraettinger): Notify the factory, and let that notify |request_|, 463 delegate_->OnNewSpdySessionReady(this, spdy_session, spdy_session_direct_);
486 // rather than notifying |request_| directly. 464
487 if (IsOrphaned()) {
488 if (spdy_session) {
489 stream_factory_->OnNewSpdySessionReady(
490 spdy_session, spdy_session_direct_, server_ssl_config_, proxy_info_,
491 was_npn_negotiated(), protocol_negotiated(), using_spdy(), net_log_);
492 }
493 stream_factory_->OnOrphanedJobComplete(this);
494 } else {
495 if (stream_type_ == HttpStreamRequest::BIDIRECTIONAL_STREAM) {
496 DCHECK(bidirectional_stream_impl_);
497 request_->OnNewSpdySessionReady(this, /*spdy_http_stream=*/nullptr,
498 std::move(bidirectional_stream_impl_),
499 spdy_session, spdy_session_direct_);
500 } else {
501 DCHECK(stream_);
502 request_->OnNewSpdySessionReady(this, std::move(stream_),
503 /** bidirectional_stream_impl=*/nullptr,
504 spdy_session, spdy_session_direct_);
505 }
506 }
507 // |this| may be deleted after this call. 465 // |this| may be deleted after this call.
508 } 466 }
509 467
510 void HttpStreamFactoryImpl::Job::OnStreamFailedCallback(int result) { 468 void HttpStreamFactoryImpl::Job::OnStreamFailedCallback(int result) {
511 DCHECK(!IsPreconnecting()); 469 DCHECK(job_type_ != PRECONNECT);
512 470
513 MaybeCopyConnectionAttemptsFromSocketOrHandle(); 471 MaybeCopyConnectionAttemptsFromSocketOrHandle();
514 472
515 if (IsOrphaned()) { 473 SSLFailureState ssl_failure_state =
516 stream_factory_->OnOrphanedJobComplete(this); 474 connection_ ? connection_->ssl_failure_state() : SSL_FAILURE_NONE;
517 } else { 475
518 SSLFailureState ssl_failure_state = 476 delegate_->OnStreamFailed(this, result, server_ssl_config_,
519 connection_ ? connection_->ssl_failure_state() : SSL_FAILURE_NONE; 477 ssl_failure_state);
520 request_->OnStreamFailed(this, result, server_ssl_config_,
521 ssl_failure_state);
522 }
523 // |this| may be deleted after this call. 478 // |this| may be deleted after this call.
524 } 479 }
525 480
526 void HttpStreamFactoryImpl::Job::OnCertificateErrorCallback( 481 void HttpStreamFactoryImpl::Job::OnCertificateErrorCallback(
527 int result, const SSLInfo& ssl_info) { 482 int result, const SSLInfo& ssl_info) {
528 DCHECK(!IsPreconnecting()); 483 DCHECK(job_type_ != PRECONNECT);
529 484
530 MaybeCopyConnectionAttemptsFromSocketOrHandle(); 485 MaybeCopyConnectionAttemptsFromSocketOrHandle();
531 486
532 if (IsOrphaned()) 487 delegate_->OnCertificateError(this, result, server_ssl_config_, ssl_info);
533 stream_factory_->OnOrphanedJobComplete(this);
534 else
535 request_->OnCertificateError(this, result, server_ssl_config_, ssl_info);
536 // |this| may be deleted after this call. 488 // |this| may be deleted after this call.
537 } 489 }
538 490
539 void HttpStreamFactoryImpl::Job::OnNeedsProxyAuthCallback( 491 void HttpStreamFactoryImpl::Job::OnNeedsProxyAuthCallback(
540 const HttpResponseInfo& response, 492 const HttpResponseInfo& response,
541 HttpAuthController* auth_controller) { 493 HttpAuthController* auth_controller) {
542 DCHECK(!IsPreconnecting()); 494 DCHECK(job_type_ != PRECONNECT);
543 if (IsOrphaned()) 495
544 stream_factory_->OnOrphanedJobComplete(this); 496 delegate_->OnNeedsProxyAuth(this, response, server_ssl_config_, proxy_info_,
545 else 497 auth_controller);
546 request_->OnNeedsProxyAuth(
547 this, response, server_ssl_config_, proxy_info_, auth_controller);
548 // |this| may be deleted after this call. 498 // |this| may be deleted after this call.
549 } 499 }
550 500
551 void HttpStreamFactoryImpl::Job::OnNeedsClientAuthCallback( 501 void HttpStreamFactoryImpl::Job::OnNeedsClientAuthCallback(
552 SSLCertRequestInfo* cert_info) { 502 SSLCertRequestInfo* cert_info) {
553 DCHECK(!IsPreconnecting()); 503 DCHECK(job_type_ != PRECONNECT);
554 if (IsOrphaned()) 504
555 stream_factory_->OnOrphanedJobComplete(this); 505 delegate_->OnNeedsClientAuth(this, server_ssl_config_, cert_info);
556 else
557 request_->OnNeedsClientAuth(this, server_ssl_config_, cert_info);
558 // |this| may be deleted after this call. 506 // |this| may be deleted after this call.
559 } 507 }
560 508
561 void HttpStreamFactoryImpl::Job::OnHttpsProxyTunnelResponseCallback( 509 void HttpStreamFactoryImpl::Job::OnHttpsProxyTunnelResponseCallback(
562 const HttpResponseInfo& response_info, 510 const HttpResponseInfo& response_info,
563 HttpStream* stream) { 511 HttpStream* stream) {
564 DCHECK(!IsPreconnecting()); 512 DCHECK(job_type_ != PRECONNECT);
565 if (IsOrphaned()) 513
566 stream_factory_->OnOrphanedJobComplete(this); 514 delegate_->OnHttpsProxyTunnelResponse(this, response_info, server_ssl_config_,
567 else 515 proxy_info_, stream);
568 request_->OnHttpsProxyTunnelResponse(
569 this, response_info, server_ssl_config_, proxy_info_, stream);
570 // |this| may be deleted after this call. 516 // |this| may be deleted after this call.
571 } 517 }
572 518
573 void HttpStreamFactoryImpl::Job::OnPreconnectsComplete() { 519 void HttpStreamFactoryImpl::Job::OnPreconnectsComplete() {
574 DCHECK(!request_);
575 if (new_spdy_session_.get()) { 520 if (new_spdy_session_.get()) {
576 stream_factory_->OnNewSpdySessionReady(new_spdy_session_, 521 delegate_->OnNewSpdySessionReady(this, new_spdy_session_,
577 spdy_session_direct_, 522 spdy_session_direct_);
578 server_ssl_config_,
579 proxy_info_,
580 was_npn_negotiated(),
581 protocol_negotiated(),
582 using_spdy(),
583 net_log_);
584 } 523 }
585 stream_factory_->OnPreconnectsComplete(this); 524 delegate_->OnPreconnectsComplete(this);
586 // |this| may be deleted after this call. 525 // |this| may be deleted after this call.
587 } 526 }
588 527
589 // static 528 // static
590 int HttpStreamFactoryImpl::Job::OnHostResolution( 529 int HttpStreamFactoryImpl::Job::OnHostResolution(
591 SpdySessionPool* spdy_session_pool, 530 SpdySessionPool* spdy_session_pool,
592 const SpdySessionKey& spdy_session_key, 531 const SpdySessionKey& spdy_session_key,
593 const GURL& origin_url, 532 const GURL& origin_url,
594 const AddressList& addresses, 533 const AddressList& addresses,
595 const BoundNetLog& net_log) { 534 const BoundNetLog& net_log) {
(...skipping 17 matching lines...) Expand all
613 "HttpStreamFactoryImpl::Job::RunLoop"); 552 "HttpStreamFactoryImpl::Job::RunLoop");
614 result = DoLoop(result); 553 result = DoLoop(result);
615 554
616 if (result == ERR_IO_PENDING) 555 if (result == ERR_IO_PENDING)
617 return result; 556 return result;
618 557
619 // If there was an error, we should have already resumed the |waiting_job_|, 558 // If there was an error, we should have already resumed the |waiting_job_|,
620 // if there was one. 559 // if there was one.
621 DCHECK(result == OK || waiting_job_ == NULL); 560 DCHECK(result == OK || waiting_job_ == NULL);
622 561
623 if (IsPreconnecting()) { 562 if (job_type_ == PRECONNECT) {
624 base::ThreadTaskRunnerHandle::Get()->PostTask( 563 base::ThreadTaskRunnerHandle::Get()->PostTask(
625 FROM_HERE, 564 FROM_HERE,
626 base::Bind(&HttpStreamFactoryImpl::Job::OnPreconnectsComplete, 565 base::Bind(&HttpStreamFactoryImpl::Job::OnPreconnectsComplete,
627 ptr_factory_.GetWeakPtr())); 566 ptr_factory_.GetWeakPtr()));
628 return ERR_IO_PENDING; 567 return ERR_IO_PENDING;
629 } 568 }
630 569
631 if (IsCertificateError(result)) { 570 if (IsCertificateError(result)) {
632 // Retrieve SSL information from the socket. 571 // Retrieve SSL information from the socket.
633 GetSSLInfo(); 572 GetSSLInfo();
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
685 } 624 }
686 625
687 case OK: 626 case OK:
688 job_status_ = STATUS_SUCCEEDED; 627 job_status_ = STATUS_SUCCEEDED;
689 MaybeMarkAlternativeServiceBroken(); 628 MaybeMarkAlternativeServiceBroken();
690 next_state_ = STATE_DONE; 629 next_state_ = STATE_DONE;
691 if (new_spdy_session_.get()) { 630 if (new_spdy_session_.get()) {
692 base::ThreadTaskRunnerHandle::Get()->PostTask( 631 base::ThreadTaskRunnerHandle::Get()->PostTask(
693 FROM_HERE, base::Bind(&Job::OnNewSpdySessionReadyCallback, 632 FROM_HERE, base::Bind(&Job::OnNewSpdySessionReadyCallback,
694 ptr_factory_.GetWeakPtr())); 633 ptr_factory_.GetWeakPtr()));
695 } else if (stream_factory_->for_websockets_) { 634 } else if (delegate_->for_websockets()) {
696 DCHECK(websocket_stream_); 635 DCHECK(websocket_stream_);
697 base::ThreadTaskRunnerHandle::Get()->PostTask( 636 base::ThreadTaskRunnerHandle::Get()->PostTask(
698 FROM_HERE, base::Bind(&Job::OnWebSocketHandshakeStreamReadyCallback, 637 FROM_HERE, base::Bind(&Job::OnWebSocketHandshakeStreamReadyCallback,
699 ptr_factory_.GetWeakPtr())); 638 ptr_factory_.GetWeakPtr()));
700 } else if (stream_type_ == HttpStreamRequest::BIDIRECTIONAL_STREAM) { 639 } else if (stream_type_ == HttpStreamRequest::BIDIRECTIONAL_STREAM) {
701 if (!bidirectional_stream_impl_) { 640 if (!bidirectional_stream_impl_) {
702 base::ThreadTaskRunnerHandle::Get()->PostTask( 641 base::ThreadTaskRunnerHandle::Get()->PostTask(
703 FROM_HERE, base::Bind(&Job::OnStreamFailedCallback, 642 FROM_HERE, base::Bind(&Job::OnStreamFailedCallback,
704 ptr_factory_.GetWeakPtr(), ERR_FAILED)); 643 ptr_factory_.GetWeakPtr(), ERR_FAILED));
705 } else { 644 } else {
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
797 CHECK_EQ(STATE_NONE, next_state_); 736 CHECK_EQ(STATE_NONE, next_state_);
798 next_state_ = STATE_START; 737 next_state_ = STATE_START;
799 int rv = RunLoop(OK); 738 int rv = RunLoop(OK);
800 DCHECK_EQ(ERR_IO_PENDING, rv); 739 DCHECK_EQ(ERR_IO_PENDING, rv);
801 return rv; 740 return rv;
802 } 741 }
803 742
804 int HttpStreamFactoryImpl::Job::DoStart() { 743 int HttpStreamFactoryImpl::Job::DoStart() {
805 valid_spdy_session_pool_.reset(new ValidSpdySessionPool( 744 valid_spdy_session_pool_.reset(new ValidSpdySessionPool(
806 session_->spdy_session_pool(), origin_url_, IsSpdyAlternative())); 745 session_->spdy_session_pool(), origin_url_, IsSpdyAlternative()));
746 const BoundNetLog* net_log = delegate_->GetNetLog(this);
807 747
808 net_log_.BeginEvent( 748 if (net_log) {
809 NetLog::TYPE_HTTP_STREAM_JOB, 749 net_log_.BeginEvent(
810 base::Bind(&NetLogHttpStreamJobCallback, 750 NetLog::TYPE_HTTP_STREAM_JOB,
811 request_ ? request_->net_log().source() : NetLog::Source(), 751 base::Bind(&NetLogHttpStreamJobCallback, net_log->source(),
812 &request_info_.url, &origin_url_, &alternative_service_, 752 &request_info_.url, &origin_url_, &alternative_service_,
813 priority_)); 753 priority_));
814 if (request_) { 754 net_log->AddEvent(NetLog::TYPE_HTTP_STREAM_REQUEST_STARTED_JOB,
815 request_->net_log().AddEvent(NetLog::TYPE_HTTP_STREAM_REQUEST_STARTED_JOB, 755 net_log_.source().ToEventParametersCallback());
816 net_log_.source().ToEventParametersCallback());
817 } 756 }
818 757
819 // Don't connect to restricted ports. 758 // Don't connect to restricted ports.
820 if (!IsPortAllowedForScheme(destination_.port(), 759 if (!IsPortAllowedForScheme(destination_.port(),
821 request_info_.url.scheme())) { 760 request_info_.url.scheme())) {
822 if (waiting_job_) { 761 if (waiting_job_) {
823 waiting_job_->Resume(this, base::TimeDelta()); 762 waiting_job_->Resume(this, base::TimeDelta());
824 waiting_job_ = NULL; 763 waiting_job_ = NULL;
825 } 764 }
826 return ERR_UNSAFE_PORT; 765 return ERR_UNSAFE_PORT;
(...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after
1041 // straight to using that. 980 // straight to using that.
1042 if (CanUseExistingSpdySession()) { 981 if (CanUseExistingSpdySession()) {
1043 base::WeakPtr<SpdySession> spdy_session; 982 base::WeakPtr<SpdySession> spdy_session;
1044 int result = valid_spdy_session_pool_->FindAvailableSession( 983 int result = valid_spdy_session_pool_->FindAvailableSession(
1045 spdy_session_key, net_log_, &spdy_session); 984 spdy_session_key, net_log_, &spdy_session);
1046 if (result != OK) 985 if (result != OK)
1047 return result; 986 return result;
1048 if (spdy_session) { 987 if (spdy_session) {
1049 // If we're preconnecting, but we already have a SpdySession, we don't 988 // If we're preconnecting, but we already have a SpdySession, we don't
1050 // actually need to preconnect any sockets, so we're done. 989 // actually need to preconnect any sockets, so we're done.
1051 if (IsPreconnecting()) 990 if (job_type_ == PRECONNECT)
1052 return OK; 991 return OK;
1053 using_spdy_ = true; 992 using_spdy_ = true;
1054 next_state_ = STATE_CREATE_STREAM; 993 next_state_ = STATE_CREATE_STREAM;
1055 existing_spdy_session_ = spdy_session; 994 existing_spdy_session_ = spdy_session;
1056 return OK; 995 return OK;
1057 } 996 }
1058 } 997 }
1059 if (request_ && !request_->HasSpdySessionKey() && using_ssl_) { 998 if (using_ssl_) {
1060 // Update the spdy session key for the request that launched this job. 999 // Ask |delegate_delegate_| to update the spdy session key for the request
1061 request_->SetSpdySessionKey(spdy_session_key); 1000 // that launched this job.
1001 delegate_->SetSpdySessionKey(this, spdy_session_key);
1062 } 1002 }
1063 1003
1064 // OK, there's no available SPDY session. Let |waiting_job_| resume if it's 1004 // OK, there's no available SPDY session. Let |waiting_job_| resume if it's
1065 // paused. 1005 // paused.
1066 if (waiting_job_) { 1006 if (waiting_job_) {
1067 waiting_job_->Resume(this, base::TimeDelta()); 1007 waiting_job_->Resume(this, base::TimeDelta());
1068 waiting_job_ = NULL; 1008 waiting_job_ = NULL;
1069 } 1009 }
1070 1010
1071 if (proxy_info_.is_http() || proxy_info_.is_https()) 1011 if (proxy_info_.is_http() || proxy_info_.is_https())
1072 establishing_tunnel_ = using_ssl_; 1012 establishing_tunnel_ = using_ssl_;
1073 1013
1074 const bool expect_spdy = IsSpdyAlternative(); 1014 const bool expect_spdy = IsSpdyAlternative();
1075 1015
1076 base::WeakPtr<HttpServerProperties> http_server_properties = 1016 base::WeakPtr<HttpServerProperties> http_server_properties =
1077 session_->http_server_properties(); 1017 session_->http_server_properties();
1078 if (http_server_properties) { 1018 if (http_server_properties) {
1079 http_server_properties->MaybeForceHTTP11(destination_, &server_ssl_config_); 1019 http_server_properties->MaybeForceHTTP11(destination_, &server_ssl_config_);
1080 if (proxy_info_.is_http() || proxy_info_.is_https()) { 1020 if (proxy_info_.is_http() || proxy_info_.is_https()) {
1081 http_server_properties->MaybeForceHTTP11( 1021 http_server_properties->MaybeForceHTTP11(
1082 proxy_info_.proxy_server().host_port_pair(), &proxy_ssl_config_); 1022 proxy_info_.proxy_server().host_port_pair(), &proxy_ssl_config_);
1083 } 1023 }
1084 } 1024 }
1085 1025
1086 if (IsPreconnecting()) { 1026 if (job_type_ == PRECONNECT) {
1087 DCHECK(!stream_factory_->for_websockets_); 1027 DCHECK(!delegate_->for_websockets());
1088 return PreconnectSocketsForHttpRequest( 1028 return PreconnectSocketsForHttpRequest(
1089 GetSocketGroup(), destination_, request_info_.extra_headers, 1029 GetSocketGroup(), destination_, request_info_.extra_headers,
1090 request_info_.load_flags, priority_, session_, proxy_info_, expect_spdy, 1030 request_info_.load_flags, priority_, session_, proxy_info_, expect_spdy,
1091 server_ssl_config_, proxy_ssl_config_, request_info_.privacy_mode, 1031 server_ssl_config_, proxy_ssl_config_, request_info_.privacy_mode,
1092 net_log_, num_streams_); 1032 net_log_, num_streams_);
1093 } 1033 }
1094 1034
1095 // If we can't use a SPDY session, don't bother checking for one after 1035 // If we can't use a SPDY session, don't bother checking for one after
1096 // the hostname is resolved. 1036 // the hostname is resolved.
1097 OnHostResolutionCallback resolution_callback = 1037 OnHostResolutionCallback resolution_callback =
1098 CanUseExistingSpdySession() 1038 CanUseExistingSpdySession()
1099 ? base::Bind(&Job::OnHostResolution, session_->spdy_session_pool(), 1039 ? base::Bind(&Job::OnHostResolution, session_->spdy_session_pool(),
1100 spdy_session_key, origin_url_) 1040 spdy_session_key, origin_url_)
1101 : OnHostResolutionCallback(); 1041 : OnHostResolutionCallback();
1102 if (stream_factory_->for_websockets_) { 1042 if (delegate_->for_websockets()) {
1103 // TODO(ricea): Re-enable NPN when WebSockets over SPDY is supported. 1043 // TODO(ricea): Re-enable NPN when WebSockets over SPDY is supported.
1104 SSLConfig websocket_server_ssl_config = server_ssl_config_; 1044 SSLConfig websocket_server_ssl_config = server_ssl_config_;
1105 websocket_server_ssl_config.alpn_protos.clear(); 1045 websocket_server_ssl_config.alpn_protos.clear();
1106 websocket_server_ssl_config.npn_protos.clear(); 1046 websocket_server_ssl_config.npn_protos.clear();
1107 return InitSocketHandleForWebSocketRequest( 1047 return InitSocketHandleForWebSocketRequest(
1108 GetSocketGroup(), destination_, request_info_.extra_headers, 1048 GetSocketGroup(), destination_, request_info_.extra_headers,
1109 request_info_.load_flags, priority_, session_, proxy_info_, expect_spdy, 1049 request_info_.load_flags, priority_, session_, proxy_info_, expect_spdy,
1110 websocket_server_ssl_config, proxy_ssl_config_, 1050 websocket_server_ssl_config, proxy_ssl_config_,
1111 request_info_.privacy_mode, net_log_, connection_.get(), 1051 request_info_.privacy_mode, net_log_, connection_.get(),
1112 resolution_callback, io_callback_); 1052 resolution_callback, io_callback_);
1113 } 1053 }
1114 1054
1115 return InitSocketHandleForHttpRequest( 1055 return InitSocketHandleForHttpRequest(
1116 GetSocketGroup(), destination_, request_info_.extra_headers, 1056 GetSocketGroup(), destination_, request_info_.extra_headers,
1117 request_info_.load_flags, priority_, session_, proxy_info_, expect_spdy, 1057 request_info_.load_flags, priority_, session_, proxy_info_, expect_spdy,
1118 server_ssl_config_, proxy_ssl_config_, request_info_.privacy_mode, 1058 server_ssl_config_, proxy_ssl_config_, request_info_.privacy_mode,
1119 net_log_, connection_.get(), resolution_callback, io_callback_); 1059 net_log_, connection_.get(), resolution_callback, io_callback_);
1120 } 1060 }
1121 1061
1122 int HttpStreamFactoryImpl::Job::DoInitConnectionComplete(int result) { 1062 int HttpStreamFactoryImpl::Job::DoInitConnectionComplete(int result) {
1123 if (using_quic_ && result < 0 && waiting_job_) { 1063 if (using_quic_ && result < 0 && waiting_job_) {
1124 waiting_job_->Resume(this, base::TimeDelta()); 1064 waiting_job_->Resume(this, base::TimeDelta());
1125 waiting_job_ = NULL; 1065 waiting_job_ = NULL;
1126 } 1066 }
1127 if (IsPreconnecting()) { 1067 if (job_type_ == PRECONNECT) {
1128 if (using_quic_) 1068 if (using_quic_)
1129 return result; 1069 return result;
1130 DCHECK_EQ(OK, result); 1070 DCHECK_EQ(OK, result);
1131 return OK; 1071 return OK;
1132 } 1072 }
1133 1073
1134 if (result == ERR_SPDY_SESSION_ALREADY_EXISTS) { 1074 if (result == ERR_SPDY_SESSION_ALREADY_EXISTS) {
1135 // We found a SPDY connection after resolving the host. This is 1075 // We found a SPDY connection after resolving the host. This is
1136 // probably an IP pooled connection. 1076 // probably an IP pooled connection.
1137 SpdySessionKey spdy_session_key = GetSpdySessionKey(); 1077 SpdySessionKey spdy_session_key = GetSpdySessionKey();
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after
1310 1250
1311 // We're always waiting here for the delegate to call us back. 1251 // We're always waiting here for the delegate to call us back.
1312 return ERR_IO_PENDING; 1252 return ERR_IO_PENDING;
1313 } 1253 }
1314 1254
1315 int HttpStreamFactoryImpl::Job::SetSpdyHttpStreamOrBidirectionalStreamImpl( 1255 int HttpStreamFactoryImpl::Job::SetSpdyHttpStreamOrBidirectionalStreamImpl(
1316 base::WeakPtr<SpdySession> session, 1256 base::WeakPtr<SpdySession> session,
1317 bool direct) { 1257 bool direct) {
1318 // TODO(ricea): Restore the code for WebSockets over SPDY once it's 1258 // TODO(ricea): Restore the code for WebSockets over SPDY once it's
1319 // implemented. 1259 // implemented.
1320 if (stream_factory_->for_websockets_) 1260 if (delegate_->for_websockets())
1321 return ERR_NOT_IMPLEMENTED; 1261 return ERR_NOT_IMPLEMENTED;
1322 if (stream_type_ == HttpStreamRequest::BIDIRECTIONAL_STREAM) { 1262 if (stream_type_ == HttpStreamRequest::BIDIRECTIONAL_STREAM) {
1323 bidirectional_stream_impl_.reset(new BidirectionalStreamSpdyImpl(session)); 1263 bidirectional_stream_impl_.reset(new BidirectionalStreamSpdyImpl(session));
1324 return OK; 1264 return OK;
1325 } 1265 }
1326 1266
1327 // TODO(willchan): Delete this code, because eventually, the 1267 // TODO(willchan): Delete this code, because eventually, the
1328 // HttpStreamFactoryImpl will be creating all the SpdyHttpStreams, since it 1268 // HttpStreamFactoryImpl will be creating all the SpdyHttpStreams, since it
1329 // will know when SpdySessions become available. 1269 // will know when SpdySessions become available.
1330 1270
(...skipping 24 matching lines...) Expand all
1355 // need to plumb this through to the connect level. 1295 // need to plumb this through to the connect level.
1356 if (connection_->socket() && !connection_->is_reused()) 1296 if (connection_->socket() && !connection_->is_reused())
1357 SetSocketMotivation(); 1297 SetSocketMotivation();
1358 1298
1359 if (!using_spdy_) { 1299 if (!using_spdy_) {
1360 DCHECK(!IsSpdyAlternative()); 1300 DCHECK(!IsSpdyAlternative());
1361 // We may get ftp scheme when fetching ftp resources through proxy. 1301 // We may get ftp scheme when fetching ftp resources through proxy.
1362 bool using_proxy = (proxy_info_.is_http() || proxy_info_.is_https()) && 1302 bool using_proxy = (proxy_info_.is_http() || proxy_info_.is_https()) &&
1363 (request_info_.url.SchemeIs("http") || 1303 (request_info_.url.SchemeIs("http") ||
1364 request_info_.url.SchemeIs("ftp")); 1304 request_info_.url.SchemeIs("ftp"));
1365 if (stream_factory_->for_websockets_) { 1305 if (delegate_->for_websockets()) {
1366 DCHECK(request_); 1306 DCHECK(job_type_ != PRECONNECT);
1367 DCHECK(request_->websocket_handshake_stream_create_helper()); 1307 DCHECK(delegate_->websocket_handshake_stream_create_helper());
1368 websocket_stream_.reset( 1308 websocket_stream_.reset(
1369 request_->websocket_handshake_stream_create_helper() 1309 delegate_->websocket_handshake_stream_create_helper()
1370 ->CreateBasicStream(std::move(connection_), using_proxy)); 1310 ->CreateBasicStream(std::move(connection_), using_proxy));
1371 } else { 1311 } else {
1372 stream_.reset(new HttpBasicStream(connection_.release(), using_proxy)); 1312 stream_.reset(new HttpBasicStream(connection_.release(), using_proxy));
1373 } 1313 }
1374 return OK; 1314 return OK;
1375 } 1315 }
1376 1316
1377 CHECK(!stream_.get()); 1317 CHECK(!stream_.get());
1378 1318
1379 bool direct = !IsHttpsProxyAndHttpUrl(); 1319 bool direct = !IsHttpsProxyAndHttpUrl();
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
1481 1421
1482 return ReconsiderProxyAfterError(result); 1422 return ReconsiderProxyAfterError(result);
1483 } 1423 }
1484 1424
1485 void HttpStreamFactoryImpl::Job::ReturnToStateInitConnection( 1425 void HttpStreamFactoryImpl::Job::ReturnToStateInitConnection(
1486 bool close_connection) { 1426 bool close_connection) {
1487 if (close_connection && connection_->socket()) 1427 if (close_connection && connection_->socket())
1488 connection_->socket()->Disconnect(); 1428 connection_->socket()->Disconnect();
1489 connection_->Reset(); 1429 connection_->Reset();
1490 1430
1491 if (request_) 1431 delegate_->RemoveRequestFromSpdySessionRequestMapForJob(this);
1492 request_->RemoveRequestFromSpdySessionRequestMap();
1493 1432
1494 next_state_ = STATE_INIT_CONNECTION; 1433 next_state_ = STATE_INIT_CONNECTION;
1495 } 1434 }
1496 1435
1497 void HttpStreamFactoryImpl::Job::SetSocketMotivation() { 1436 void HttpStreamFactoryImpl::Job::SetSocketMotivation() {
1498 if (request_info_.motivation == HttpRequestInfo::PRECONNECT_MOTIVATED) 1437 if (request_info_.motivation == HttpRequestInfo::PRECONNECT_MOTIVATED)
1499 connection_->socket()->SetSubresourceSpeculation(); 1438 connection_->socket()->SetSubresourceSpeculation();
1500 else if (request_info_.motivation == HttpRequestInfo::OMNIBOX_MOTIVATED) 1439 else if (request_info_.motivation == HttpRequestInfo::OMNIBOX_MOTIVATED)
1501 connection_->socket()->SetOmniboxSpeculation(); 1440 connection_->socket()->SetOmniboxSpeculation();
1502 // TODO(mbelshe): Add other motivations (like EARLY_LOAD_MOTIVATED). 1441 // TODO(mbelshe): Add other motivations (like EARLY_LOAD_MOTIVATED).
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
1624 int rv = session_->proxy_service()->ReconsiderProxyAfterError( 1563 int rv = session_->proxy_service()->ReconsiderProxyAfterError(
1625 request_info_.url, request_info_.method, request_info_.load_flags, error, 1564 request_info_.url, request_info_.method, request_info_.load_flags, error,
1626 &proxy_info_, io_callback_, &pac_request_, 1565 &proxy_info_, io_callback_, &pac_request_,
1627 session_->params().proxy_delegate, net_log_); 1566 session_->params().proxy_delegate, net_log_);
1628 if (rv == OK || rv == ERR_IO_PENDING) { 1567 if (rv == OK || rv == ERR_IO_PENDING) {
1629 // If the error was during connection setup, there is no socket to 1568 // If the error was during connection setup, there is no socket to
1630 // disconnect. 1569 // disconnect.
1631 if (connection_->socket()) 1570 if (connection_->socket())
1632 connection_->socket()->Disconnect(); 1571 connection_->socket()->Disconnect();
1633 connection_->Reset(); 1572 connection_->Reset();
1634 if (request_) 1573 delegate_->RemoveRequestFromSpdySessionRequestMapForJob(this);
1635 request_->RemoveRequestFromSpdySessionRequestMap();
1636 next_state_ = STATE_RESOLVE_PROXY_COMPLETE; 1574 next_state_ = STATE_RESOLVE_PROXY_COMPLETE;
1637 } else { 1575 } else {
1638 // If ReconsiderProxyAfterError() failed synchronously, it means 1576 // If ReconsiderProxyAfterError() failed synchronously, it means
1639 // there was nothing left to fall-back to, so fail the transaction 1577 // there was nothing left to fall-back to, so fail the transaction
1640 // with the last connection error we got. 1578 // with the last connection error we got.
1641 // TODO(eroman): This is a confusing contract, make it more obvious. 1579 // TODO(eroman): This is a confusing contract, make it more obvious.
1642 rv = error; 1580 rv = error;
1643 } 1581 }
1644 1582
1645 return rv; 1583 return rv;
(...skipping 30 matching lines...) Expand all
1676 if (ssl_socket->IgnoreCertError(error, load_flags)) 1614 if (ssl_socket->IgnoreCertError(error, load_flags))
1677 return OK; 1615 return OK;
1678 return error; 1616 return error;
1679 } 1617 }
1680 1618
1681 void HttpStreamFactoryImpl::Job::SwitchToSpdyMode() { 1619 void HttpStreamFactoryImpl::Job::SwitchToSpdyMode() {
1682 if (HttpStreamFactory::spdy_enabled()) 1620 if (HttpStreamFactory::spdy_enabled())
1683 using_spdy_ = true; 1621 using_spdy_ = true;
1684 } 1622 }
1685 1623
1686 bool HttpStreamFactoryImpl::Job::IsPreconnecting() const {
1687 DCHECK_GE(num_streams_, 0);
1688 return num_streams_ > 0;
1689 }
1690
1691 bool HttpStreamFactoryImpl::Job::IsOrphaned() const {
1692 return !IsPreconnecting() && !request_;
1693 }
1694
1695 void HttpStreamFactoryImpl::Job::ReportJobSucceededForRequest() { 1624 void HttpStreamFactoryImpl::Job::ReportJobSucceededForRequest() {
1696 if (using_existing_quic_session_) { 1625 if (using_existing_quic_session_) {
1697 // If an existing session was used, then no TCP connection was 1626 // If an existing session was used, then no TCP connection was
1698 // started. 1627 // started.
1699 HistogramAlternateProtocolUsage(ALTERNATE_PROTOCOL_USAGE_NO_RACE); 1628 HistogramAlternateProtocolUsage(ALTERNATE_PROTOCOL_USAGE_NO_RACE);
1700 } else if (IsSpdyAlternative() || IsQuicAlternative()) { 1629 } else if (IsSpdyAlternative() || IsQuicAlternative()) {
1701 // This Job was the alternative Job, and hence won the race. 1630 // This Job was the alternative Job, and hence won the race.
1702 HistogramAlternateProtocolUsage(ALTERNATE_PROTOCOL_USAGE_WON_RACE); 1631 HistogramAlternateProtocolUsage(ALTERNATE_PROTOCOL_USAGE_WON_RACE);
1703 } else { 1632 } else {
1704 // This Job was the normal Job, and hence the alternative Job lost the race. 1633 // This Job was the normal Job, and hence the alternative Job lost the race.
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
1795 return ClientSocketPoolManager::NORMAL_GROUP; 1724 return ClientSocketPoolManager::NORMAL_GROUP;
1796 } 1725 }
1797 1726
1798 // If the connection succeeds, failed connection attempts leading up to the 1727 // If the connection succeeds, failed connection attempts leading up to the
1799 // success will be returned via the successfully connected socket. If the 1728 // success will be returned via the successfully connected socket. If the
1800 // connection fails, failed connection attempts will be returned via the 1729 // connection fails, failed connection attempts will be returned via the
1801 // ClientSocketHandle. Check whether a socket was returned and copy the 1730 // ClientSocketHandle. Check whether a socket was returned and copy the
1802 // connection attempts from the proper place. 1731 // connection attempts from the proper place.
1803 void HttpStreamFactoryImpl::Job:: 1732 void HttpStreamFactoryImpl::Job::
1804 MaybeCopyConnectionAttemptsFromSocketOrHandle() { 1733 MaybeCopyConnectionAttemptsFromSocketOrHandle() {
1805 if (IsOrphaned() || !connection_) 1734 if (!connection_)
1806 return; 1735 return;
1807 1736
1737 ConnectionAttempts socket_attempts = connection_->connection_attempts();
1808 if (connection_->socket()) { 1738 if (connection_->socket()) {
1809 ConnectionAttempts socket_attempts;
1810 connection_->socket()->GetConnectionAttempts(&socket_attempts); 1739 connection_->socket()->GetConnectionAttempts(&socket_attempts);
1811 request_->AddConnectionAttempts(socket_attempts);
1812 } else {
1813 request_->AddConnectionAttempts(connection_->connection_attempts());
1814 } 1740 }
1741
1742 delegate_->AddConnectionAttemptsToRequest(this, socket_attempts);
1815 } 1743 }
1816 1744
1817 } // namespace net 1745 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698