Chromium Code Reviews| Index: net/http/http_pipelined_host.cc |
| diff --git a/net/http/http_pipelined_host.cc b/net/http/http_pipelined_host.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..86e278bc41e60150823fb98a61660e58aefb6dc7 |
| --- /dev/null |
| +++ b/net/http/http_pipelined_host.cc |
| @@ -0,0 +1,93 @@ |
| +// Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "net/http/http_pipelined_host.h" |
| + |
| +#include "base/stl_util.h" |
| +#include "net/http/http_pipelined_connection_impl.h" |
| +#include "net/http/http_pipelined_stream.h" |
| + |
| +namespace net { |
| + |
| +class HttpPipelinedConnectionImplFactory : |
| + public HttpPipelinedConnection::Factory { |
| + public: |
| + HttpPipelinedConnection* CreateNewPipeline( |
|
mmenke
2011/08/23 19:05:25
nit: Indent "public:" 1 space, next line 2 spaces
James Simonsen
2011/08/26 22:19:07
Done.
|
| + ClientSocketHandle* connection, |
| + HttpPipelinedConnection::Owner* owner, |
| + const SSLConfig& used_ssl_config, |
| + const ProxyInfo& used_proxy_info, |
| + const BoundNetLog& net_log, |
| + bool was_npn_negotiated) OVERRIDE { |
| + return new HttpPipelinedConnectionImpl(connection, owner, used_ssl_config, |
| + used_proxy_info, net_log, |
| + was_npn_negotiated); |
| + } |
| +}; |
| + |
| +HttpPipelinedHost::HttpPipelinedHost( |
| + HttpPipelinedHost::Owner* owner, |
| + const HostPortPair& origin, |
| + HttpPipelinedConnection::Factory* factory) |
| + : owner_(owner), |
| + origin_(origin), |
| + factory_(factory) { |
| + if (!factory_) { |
| + factory_ = new HttpPipelinedConnectionImplFactory(); |
| + } |
| +} |
| + |
| +HttpPipelinedHost::~HttpPipelinedHost() { |
| + DCHECK(pipelines_.empty()); |
| +} |
| + |
| +HttpPipelinedConnection* HttpPipelinedHost::CreateNewPipeline( |
| + ClientSocketHandle* connection, |
| + const SSLConfig& used_ssl_config, |
| + const ProxyInfo& used_proxy_info, |
| + const BoundNetLog& net_log, |
| + bool was_npn_negotiated) { |
| + HttpPipelinedConnection* pipeline = factory_->CreateNewPipeline( |
| + connection, this, used_ssl_config, used_proxy_info, net_log, |
| + was_npn_negotiated); |
| + pipelines_.insert(pipeline); |
| + return pipeline; |
| +} |
| + |
| +HttpPipelinedConnection* HttpPipelinedHost::FindAvailablePipeline() { |
| + HttpPipelinedConnection* available_pipeline = NULL; |
| + for (std::set<HttpPipelinedConnection*>::iterator it = pipelines_.begin(); |
| + it != pipelines_.end(); ++it) { |
| + if ((*it)->usable() && |
| + (*it)->active() && |
| + (*it)->depth() < max_pipeline_depth() && |
| + (!available_pipeline || (*it)->depth() < available_pipeline->depth())) { |
| + available_pipeline = *it; |
| + } |
| + } |
| + return available_pipeline; |
| +} |
| + |
| +void HttpPipelinedHost::OnPipelineEmpty(HttpPipelinedConnection* pipeline) { |
| + DCHECK(ContainsKey(pipelines_, pipeline)); |
| + pipelines_.erase(pipeline); |
| + delete pipeline; |
| + if (pipelines_.empty()) { |
| + owner_->OnHostIdle(this); |
| + // WARNING: We'll probably be deleted here. |
| + } |
| +} |
| + |
| +void HttpPipelinedHost::OnPipelineHasCapacity( |
| + HttpPipelinedConnection* pipeline) { |
| + if (pipeline->usable() && pipeline->depth() < max_pipeline_depth()) { |
| + owner_->OnHostHasAdditionalCapacity(this); |
| + } |
| + if (!pipeline->depth()) { |
| + OnPipelineEmpty(pipeline); |
| + // WARNING: We'll probably be deleted here. |
| + } |
| +} |
| + |
| +} // namespace net |