Chromium Code Reviews| Index: net/http/http_stream_factory_impl.cc |
| diff --git a/net/http/http_stream_factory_impl.cc b/net/http/http_stream_factory_impl.cc |
| index bfc79227c5fdd171d9188ee0019a44988c11f543..4dd455bb96b0ab861ec645c7c6194218a8d6df79 100644 |
| --- a/net/http/http_stream_factory_impl.cc |
| +++ b/net/http/http_stream_factory_impl.cc |
| @@ -12,6 +12,7 @@ |
| #include "net/http/http_network_session.h" |
| #include "net/http/http_server_properties.h" |
| #include "net/http/http_stream_factory_impl_job.h" |
| +#include "net/http/http_stream_factory_impl_job_controller.h" |
| #include "net/http/http_stream_factory_impl_request.h" |
| #include "net/http/transport_security_state.h" |
| #include "net/log/net_log.h" |
| @@ -30,16 +31,7 @@ HttpStreamFactoryImpl::HttpStreamFactoryImpl(HttpNetworkSession* session, |
| HttpStreamFactoryImpl::~HttpStreamFactoryImpl() { |
| DCHECK(request_map_.empty()); |
| DCHECK(spdy_session_request_map_.empty()); |
| - |
| - std::set<const Job*> tmp_job_set; |
| - tmp_job_set.swap(orphaned_job_set_); |
| - STLDeleteContainerPointers(tmp_job_set.begin(), tmp_job_set.end()); |
| - DCHECK(orphaned_job_set_.empty()); |
| - |
| - tmp_job_set.clear(); |
| - tmp_job_set.swap(preconnect_job_set_); |
| - STLDeleteContainerPointers(tmp_job_set.begin(), tmp_job_set.end()); |
| - DCHECK(preconnect_job_set_.empty()); |
| + STLDeleteElements(&job_controller_set_); |
| } |
| HttpStreamRequest* HttpStreamFactoryImpl::RequestStream( |
| @@ -95,48 +87,16 @@ HttpStreamRequest* HttpStreamFactoryImpl::RequestStreamInternal( |
| websocket_handshake_stream_create_helper, |
| HttpStreamRequest::StreamType stream_type, |
| const BoundNetLog& net_log) { |
| - Request* request = new Request(request_info.url, this, delegate, |
| - websocket_handshake_stream_create_helper, |
| - net_log, stream_type); |
| - HostPortPair destination(HostPortPair::FromURL(request_info.url)); |
| - GURL origin_url = ApplyHostMappingRules(request_info.url, &destination); |
| - |
| - Job* job = |
| - new Job(this, session_, request_info, priority, server_ssl_config, |
| - proxy_ssl_config, destination, origin_url, net_log.net_log()); |
| - request->AttachJob(job); |
| - |
| - const AlternativeService alternative_service = |
| - GetAlternativeServiceFor(request_info, delegate, stream_type); |
| - |
| - if (alternative_service.protocol != UNINITIALIZED_ALTERNATE_PROTOCOL) { |
| - // Never share connection with other jobs for FTP requests. |
| - DVLOG(1) << "Selected alternative service (host: " |
| - << alternative_service.host_port_pair().host() |
| - << " port: " << alternative_service.host_port_pair().port() << ")"; |
| - |
| - DCHECK(!request_info.url.SchemeIs("ftp")); |
| - HostPortPair alternative_destination(alternative_service.host_port_pair()); |
| - ignore_result( |
| - ApplyHostMappingRules(request_info.url, &alternative_destination)); |
| - |
| - Job* alternative_job = |
| - new Job(this, session_, request_info, priority, server_ssl_config, |
| - proxy_ssl_config, alternative_destination, origin_url, |
| - alternative_service, net_log.net_log()); |
| - request->AttachJob(alternative_job); |
| - |
| - job->WaitFor(alternative_job); |
| - // Make sure to wait until we call WaitFor(), before starting |
| - // |alternative_job|, otherwise |alternative_job| will not notify |job| |
| - // appropriately. |
| - alternative_job->Start(request); |
| - } |
| + JobController* job_controller = new JobController(this); |
| + job_controller_set_.insert(job_controller); |
| + |
| + Request* request = job_controller->CreatRequest( |
| + request_info, delegate, websocket_handshake_stream_create_helper, net_log, |
| + stream_type); |
| + |
| + job_controller->Start(session_, request_info, priority, server_ssl_config, |
| + proxy_ssl_config, delegate, stream_type, net_log); |
|
Ryan Hamilton
2016/05/06 20:49:01
If this is the only place we call Start and CreatR
Zhongyi Shi
2016/05/12 07:26:23
I have renamed the old public method Start() to pr
|
| - // Even if |alternative_job| has already finished, it will not have notified |
| - // the request yet, since we defer that to the next iteration of the |
| - // MessageLoop, so starting |job| is always safe. |
| - job->Start(request); |
| return request; |
| } |
| @@ -151,29 +111,11 @@ void HttpStreamFactoryImpl::PreconnectStreams( |
| proxy_ssl_config.verify_ev_cert = true; |
| DCHECK(!for_websockets_); |
| - AlternativeService alternative_service = GetAlternativeServiceFor( |
| - request_info, nullptr, HttpStreamRequest::HTTP_STREAM); |
| - HostPortPair destination(HostPortPair::FromURL(request_info.url)); |
| - GURL origin_url = ApplyHostMappingRules(request_info.url, &destination); |
| - if (alternative_service.protocol != UNINITIALIZED_ALTERNATE_PROTOCOL) { |
| - if (session_->params().quic_disable_preconnect_if_0rtt && |
| - alternative_service.protocol == QUIC && |
| - session_->quic_stream_factory()->ZeroRTTEnabledFor(QuicServerId( |
| - alternative_service.host_port_pair(), request_info.privacy_mode))) { |
| - return; |
| - } |
| - destination = alternative_service.host_port_pair(); |
| - ignore_result(ApplyHostMappingRules(request_info.url, &destination)); |
| - } |
| - // Due to how the socket pools handle priorities and idle sockets, only IDLE |
| - // priority currently makes sense for preconnects. The priority for |
| - // preconnects is currently ignored (see RequestSocketsForPool()), but could |
| - // be used at some point for proxy resolution or something. |
| - Job* job = new Job(this, session_, request_info, IDLE, server_ssl_config, |
| - proxy_ssl_config, destination, origin_url, |
| - alternative_service, session_->net_log()); |
| - preconnect_job_set_.insert(job); |
| - job->Preconnect(num_streams); |
| + |
| + JobController* job_controller = new JobController(this); |
| + job_controller_set_.insert(job_controller); |
| + job_controller->Preconnect(num_streams, session_, request_info, |
| + server_ssl_config, proxy_ssl_config); |
| } |
| const HostMappingRules* HttpStreamFactoryImpl::GetHostMappingRules() const { |
| @@ -289,17 +231,6 @@ AlternativeService HttpStreamFactoryImpl::GetAlternativeServiceFor( |
| return first_alternative_service; |
| } |
| -void HttpStreamFactoryImpl::OrphanJob(Job* job, const Request* request) { |
| - DCHECK(ContainsKey(request_map_, job)); |
| - DCHECK_EQ(request_map_[job], request); |
| - DCHECK(!ContainsKey(orphaned_job_set_, job)); |
| - |
| - request_map_.erase(job); |
| - |
| - orphaned_job_set_.insert(job); |
| - job->Orphan(request); |
| -} |
| - |
| void HttpStreamFactoryImpl::OnNewSpdySessionReady( |
| const base::WeakPtr<SpdySession>& spdy_session, |
| bool direct, |
| @@ -331,27 +262,21 @@ void HttpStreamFactoryImpl::OnNewSpdySessionReady( |
| } else if (request->stream_type() == |
| HttpStreamRequest::BIDIRECTIONAL_STREAM) { |
| request->OnBidirectionalStreamImplReady( |
| - nullptr, used_ssl_config, used_proxy_info, |
| + used_ssl_config, used_proxy_info, |
| new BidirectionalStreamSpdyImpl(spdy_session)); |
| } else { |
| bool use_relative_url = direct || request->url().SchemeIs("https"); |
| request->OnStreamReady( |
| - nullptr, used_ssl_config, used_proxy_info, |
| + used_ssl_config, used_proxy_info, |
| new SpdyHttpStream(spdy_session, use_relative_url)); |
| } |
| } |
| // TODO(mbelshe): Alert other valid requests. |
| } |
| -void HttpStreamFactoryImpl::OnOrphanedJobComplete(const Job* job) { |
| - orphaned_job_set_.erase(job); |
| - delete job; |
| -} |
| - |
| -void HttpStreamFactoryImpl::OnPreconnectsComplete(const Job* job) { |
| - preconnect_job_set_.erase(job); |
| - delete job; |
| - OnPreconnectsCompleteInternal(); |
| +void HttpStreamFactoryImpl::OnJobControllerComplete(JobController* controller) { |
| + job_controller_set_.erase(controller); |
| + delete controller; |
| } |
| bool HttpStreamFactoryImpl::IsQuicWhitelistedForHost(const std::string& host) { |