Chromium Code Reviews| Index: net/http/http_stream_factory_impl_job.cc |
| diff --git a/net/http/http_stream_factory_impl_job.cc b/net/http/http_stream_factory_impl_job.cc |
| index dcbf1149f24ba7dfa93f43a365c1048c8d851fc6..0046919b954928cc34fdfdf68dd83097b9a9c203 100644 |
| --- a/net/http/http_stream_factory_impl_job.cc |
| +++ b/net/http/http_stream_factory_impl_job.cc |
| @@ -16,9 +16,14 @@ |
| #include "net/base/ssl_cert_request_info.h" |
| #include "net/http/http_basic_stream.h" |
| #include "net/http/http_network_session.h" |
| +#include "net/http/http_pipelined_connection.h" |
| +#include "net/http/http_pipelined_host.h" |
| +#include "net/http/http_pipelined_host_pool.h" |
| +#include "net/http/http_pipelined_stream.h" |
| #include "net/http/http_proxy_client_socket.h" |
| #include "net/http/http_proxy_client_socket_pool.h" |
| #include "net/http/http_request_info.h" |
| +#include "net/http/http_stream_factory.h" |
| #include "net/http/http_stream_factory_impl_request.h" |
| #include "net/socket/client_socket_handle.h" |
| #include "net/socket/client_socket_pool.h" |
| @@ -85,6 +90,7 @@ HttpStreamFactoryImpl::Job::Job(HttpStreamFactoryImpl* stream_factory, |
| was_npn_negotiated_(false), |
| num_streams_(0), |
| spdy_session_direct_(false), |
| + existing_available_pipeline_(NULL), |
| ALLOW_THIS_IN_INITIALIZER_LIST(method_factory_(this)) { |
| DCHECK(stream_factory); |
| DCHECK(session); |
| @@ -580,6 +586,18 @@ int HttpStreamFactoryImpl::Job::DoInitConnection() { |
| } else if (request_ && (using_ssl_ || ShouldForceSpdyWithoutSSL())) { |
| // Update the spdy session key for the request that launched this job. |
| request_->SetSpdySessionKey(spdy_session_key); |
| + } else if (IsRequestEligibleForPipelining()) { |
|
willchan no longer on Chromium
2011/09/03 01:11:06
If we're preconnecting, you may want to choose thi
James Simonsen
2011/09/07 21:20:10
Done.
Yeah, that's an interesting topic. It might
|
| + HttpPipelinedHost* host = session_->http_pipelined_host_pool()-> |
| + GetPipelinedHostIfExists(origin_); |
| + if (host) { |
| + HttpPipelinedConnection* connection = host->FindAvailablePipeline(); |
| + if (connection) { |
| + next_state_ = STATE_CREATE_STREAM; |
| + existing_available_pipeline_ = connection; |
| + return OK; |
| + } |
| + } |
| + request_->SetHttpPipeliningKey(origin_); |
| } |
| // OK, there's no available SPDY session. Let |dependent_job_| resume if it's |
| @@ -757,9 +775,13 @@ int HttpStreamFactoryImpl::Job::DoWaitingUserAction(int result) { |
| } |
| int HttpStreamFactoryImpl::Job::DoCreateStream() { |
| - if (!connection_->socket() && !existing_spdy_session_) |
| + if (!connection_->socket() && !existing_spdy_session_ && |
| + !existing_available_pipeline_) |
| HACKCrashHereToDebug80095(); |
| + DCHECK(connection_->socket() || existing_spdy_session_ || |
| + existing_available_pipeline_); |
| + |
| next_state_ = STATE_CREATE_STREAM_COMPLETE; |
| // We only set the socket motivation if we're the first to use |
| @@ -773,8 +795,22 @@ int HttpStreamFactoryImpl::Job::DoCreateStream() { |
| if (!using_spdy_) { |
| bool using_proxy = (proxy_info_.is_http() || proxy_info_.is_https()) && |
| request_info_.url.SchemeIs("http"); |
| - stream_.reset(new HttpBasicStream(connection_.release(), NULL, |
| - using_proxy)); |
| + // TODO(simonjam): Support proxies. |
| + if (existing_available_pipeline_) { |
| + stream_.reset(existing_available_pipeline_->CreateNewStream()); |
| + } else if (!using_proxy && IsRequestEligibleForPipelining()) { |
| + HttpPipelinedConnection* pipeline = session_->http_pipelined_host_pool()-> |
| + GetOrCreatePipelinedHost(origin_)->CreateNewPipeline( |
| + connection_.release(), |
| + ssl_config_, |
| + proxy_info_, |
| + net_log_, |
| + was_npn_negotiated_); |
| + stream_.reset(pipeline->CreateNewStream()); |
| + } else { |
| + stream_.reset(new HttpBasicStream(connection_.release(), NULL, |
| + using_proxy)); |
| + } |
| return OK; |
| } |
| @@ -1079,6 +1115,19 @@ bool HttpStreamFactoryImpl::Job::IsOrphaned() const { |
| return !IsPreconnecting() && !request_; |
| } |
| +bool HttpStreamFactoryImpl::Job::IsRequestEligibleForPipelining() const { |
| + if (!HttpStreamFactory::http_pipelining_enabled()) { |
| + return false; |
| + } |
| + if (IsPreconnecting() || !request_) { |
| + return false; |
| + } |
| + if (using_ssl_) { |
| + return false; |
| + } |
| + return request_info_.method == "GET" || request_info_.method == "HEAD"; |
| +} |
| + |
| #if defined(OS_WIN) |
| #pragma warning (disable: 4748) |
| #pragma optimize( "", off ) |