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

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

Powered by Google App Engine
This is Rietveld 408576698