| OLD | NEW |
| 1 // Copyright (c) 2016 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2016 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_controller.h" | 5 #include "net/http/http_stream_factory_impl_job_controller.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 #include <utility> | 8 #include <utility> |
| 9 | 9 |
| 10 #include "base/memory/ptr_util.h" | 10 #include "base/memory/ptr_util.h" |
| (...skipping 430 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 441 | 441 |
| 442 // Cache these values in case the job gets deleted. | 442 // Cache these values in case the job gets deleted. |
| 443 const SSLConfig used_ssl_config = job->server_ssl_config(); | 443 const SSLConfig used_ssl_config = job->server_ssl_config(); |
| 444 const ProxyInfo used_proxy_info = job->proxy_info(); | 444 const ProxyInfo used_proxy_info = job->proxy_info(); |
| 445 const bool was_alpn_negotiated = job->was_alpn_negotiated(); | 445 const bool was_alpn_negotiated = job->was_alpn_negotiated(); |
| 446 const NextProto negotiated_protocol = job->negotiated_protocol(); | 446 const NextProto negotiated_protocol = job->negotiated_protocol(); |
| 447 const bool using_spdy = job->using_spdy(); | 447 const bool using_spdy = job->using_spdy(); |
| 448 const NetLogSource source_dependency = job->net_log().source(); | 448 const NetLogSource source_dependency = job->net_log().source(); |
| 449 | 449 |
| 450 // Cache this so we can still use it if the JobController is deleted. | 450 // Cache this so we can still use it if the JobController is deleted. |
| 451 HttpStreamFactoryImpl* factory = factory_; | 451 SpdySessionPool* spdy_session_pool = session_->spdy_session_pool(); |
| 452 | 452 |
| 453 // Notify |request_|. | 453 // Notify |request_|. |
| 454 if (!is_preconnect_ && !is_job_orphaned) { | 454 if (!is_preconnect_ && !is_job_orphaned) { |
| 455 if (job->job_type() == MAIN && alternative_job_net_error_ != OK) | 455 if (job->job_type() == MAIN && alternative_job_net_error_ != OK) |
| 456 ReportBrokenAlternativeService(); | 456 ReportBrokenAlternativeService(); |
| 457 | 457 |
| 458 DCHECK(request_); | 458 DCHECK(request_); |
| 459 | 459 |
| 460 // The first case is the usual case. | 460 // The first case is the usual case. |
| 461 if (!job_bound_) { | 461 if (!job_bound_) { |
| (...skipping 14 matching lines...) Expand all Loading... |
| 476 used_ssl_config, used_proxy_info, | 476 used_ssl_config, used_proxy_info, |
| 477 bidirectional_stream_impl.release()); | 477 bidirectional_stream_impl.release()); |
| 478 } else { | 478 } else { |
| 479 std::unique_ptr<HttpStream> stream = job->ReleaseStream(); | 479 std::unique_ptr<HttpStream> stream = job->ReleaseStream(); |
| 480 DCHECK(stream); | 480 DCHECK(stream); |
| 481 delegate_->OnStreamReady(used_ssl_config, used_proxy_info, | 481 delegate_->OnStreamReady(used_ssl_config, used_proxy_info, |
| 482 stream.release()); | 482 stream.release()); |
| 483 } | 483 } |
| 484 } | 484 } |
| 485 | 485 |
| 486 // Notify |factory_|. |request_| and |bounded_job_| might be deleted already. | 486 // Notify other requests that have the same SpdySessionKey. |request_| and |
| 487 // |bounded_job_| might be deleted already. |
| 487 if (spdy_session && spdy_session->IsAvailable()) { | 488 if (spdy_session && spdy_session->IsAvailable()) { |
| 488 factory->OnNewSpdySessionReady(spdy_session, direct, used_ssl_config, | 489 spdy_session_pool->OnNewSpdySessionReady( |
| 489 used_proxy_info, was_alpn_negotiated, | 490 spdy_session, direct, used_ssl_config, used_proxy_info, |
| 490 negotiated_protocol, using_spdy, | 491 was_alpn_negotiated, negotiated_protocol, using_spdy, |
| 491 source_dependency); | 492 source_dependency); |
| 492 } | 493 } |
| 493 if (is_job_orphaned) { | 494 if (is_job_orphaned) { |
| 494 OnOrphanedJobComplete(job); | 495 OnOrphanedJobComplete(job); |
| 495 } | 496 } |
| 496 } | 497 } |
| 497 | 498 |
| 498 void HttpStreamFactoryImpl::JobController::OnPreconnectsComplete(Job* job) { | 499 void HttpStreamFactoryImpl::JobController::OnPreconnectsComplete(Job* job) { |
| 499 DCHECK_EQ(main_job_.get(), job); | 500 DCHECK_EQ(main_job_.get(), job); |
| 500 main_job_.reset(); | 501 main_job_.reset(); |
| 501 factory_->OnPreconnectsCompleteInternal(); | 502 factory_->OnPreconnectsCompleteInternal(); |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 596 ResumeMainJobLater(main_job_wait_time_); | 597 ResumeMainJobLater(main_job_wait_time_); |
| 597 return true; | 598 return true; |
| 598 } | 599 } |
| 599 | 600 |
| 600 void HttpStreamFactoryImpl::JobController::SetSpdySessionKey( | 601 void HttpStreamFactoryImpl::JobController::SetSpdySessionKey( |
| 601 Job* job, | 602 Job* job, |
| 602 const SpdySessionKey& spdy_session_key) { | 603 const SpdySessionKey& spdy_session_key) { |
| 603 if (is_preconnect_ || IsJobOrphaned(job)) | 604 if (is_preconnect_ || IsJobOrphaned(job)) |
| 604 return; | 605 return; |
| 605 | 606 |
| 606 if (!request_->HasSpdySessionKey()) { | 607 session_->spdy_session_pool()->AddRequestToSpdySessionRequestMap( |
| 607 RequestSet& request_set = | 608 spdy_session_key, request_); |
| 608 factory_->spdy_session_request_map_[spdy_session_key]; | |
| 609 DCHECK(!base::ContainsKey(request_set, request_)); | |
| 610 request_set.insert(request_); | |
| 611 request_->SetSpdySessionKey(spdy_session_key); | |
| 612 } | |
| 613 } | 609 } |
| 614 | 610 |
| 615 void HttpStreamFactoryImpl::JobController:: | 611 void HttpStreamFactoryImpl::JobController:: |
| 616 RemoveRequestFromSpdySessionRequestMapForJob(Job* job) { | 612 RemoveRequestFromSpdySessionRequestMapForJob(Job* job) { |
| 617 if (is_preconnect_ || IsJobOrphaned(job)) | 613 if (is_preconnect_ || IsJobOrphaned(job)) |
| 618 return; | 614 return; |
| 619 | 615 |
| 620 RemoveRequestFromSpdySessionRequestMap(); | 616 RemoveRequestFromSpdySessionRequestMap(); |
| 621 } | 617 } |
| 622 | 618 |
| 623 void HttpStreamFactoryImpl::JobController:: | 619 void HttpStreamFactoryImpl::JobController:: |
| 624 RemoveRequestFromSpdySessionRequestMap() { | 620 RemoveRequestFromSpdySessionRequestMap() { |
| 625 if (request_->HasSpdySessionKey()) { | 621 // TODO(xunjieli): Use a DCHECK once https://crbug.com/718576 is fixed. |
| 626 const SpdySessionKey& spdy_session_key = request_->GetSpdySessionKey(); | 622 CHECK(request_); |
| 627 SpdySessionRequestMap& spdy_session_request_map = | 623 session_->spdy_session_pool()->RemoveRequestFromSpdySessionRequestMap( |
| 628 factory_->spdy_session_request_map_; | 624 request_); |
| 629 DCHECK(base::ContainsKey(spdy_session_request_map, spdy_session_key)); | |
| 630 RequestSet& request_set = spdy_session_request_map[spdy_session_key]; | |
| 631 DCHECK(base::ContainsKey(request_set, request_)); | |
| 632 request_set.erase(request_); | |
| 633 if (request_set.empty()) | |
| 634 spdy_session_request_map.erase(spdy_session_key); | |
| 635 request_->ResetSpdySessionKey(); | |
| 636 } | |
| 637 } | 625 } |
| 638 | 626 |
| 639 const NetLogWithSource* HttpStreamFactoryImpl::JobController::GetNetLog() | 627 const NetLogWithSource* HttpStreamFactoryImpl::JobController::GetNetLog() |
| 640 const { | 628 const { |
| 641 return &net_log_; | 629 return &net_log_; |
| 642 } | 630 } |
| 643 | 631 |
| 644 void HttpStreamFactoryImpl::JobController::MaybeSetWaitTimeForMainJob( | 632 void HttpStreamFactoryImpl::JobController::MaybeSetWaitTimeForMainJob( |
| 645 const base::TimeDelta& delay) { | 633 const base::TimeDelta& delay) { |
| 646 if (main_job_is_blocked_) { | 634 if (main_job_is_blocked_) { |
| (...skipping 647 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1294 // If ReconsiderProxyAfterError() failed synchronously, it means | 1282 // If ReconsiderProxyAfterError() failed synchronously, it means |
| 1295 // there was nothing left to fall-back to, so fail the transaction | 1283 // there was nothing left to fall-back to, so fail the transaction |
| 1296 // with the last connection error we got. | 1284 // with the last connection error we got. |
| 1297 // TODO(eroman): This is a confusing contract, make it more obvious. | 1285 // TODO(eroman): This is a confusing contract, make it more obvious. |
| 1298 rv = error; | 1286 rv = error; |
| 1299 } | 1287 } |
| 1300 return rv; | 1288 return rv; |
| 1301 } | 1289 } |
| 1302 | 1290 |
| 1303 } // namespace net | 1291 } // namespace net |
| OLD | NEW |