OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "net/http/http_pipelined_host_pool.h" |
| 6 |
| 7 #include "base/logging.h" |
| 8 #include "base/stl_util.h" |
| 9 #include "net/http/http_pipelined_host.h" |
| 10 #include "net/http/http_stream_factory_impl.h" |
| 11 |
| 12 namespace net { |
| 13 |
| 14 HttpPipelinedHostPool::HttpPipelinedHostPool(HttpStreamFactoryImpl* factory) |
| 15 : factory_(factory) { |
| 16 } |
| 17 |
| 18 HttpPipelinedHostPool::~HttpPipelinedHostPool() { |
| 19 CHECK(host_map_.empty()); |
| 20 } |
| 21 |
| 22 HttpPipelinedStream* HttpPipelinedHostPool::CreateStreamOnNewPipeline( |
| 23 const HostPortPair& origin, |
| 24 ClientSocketHandle* connection, |
| 25 const SSLConfig& used_ssl_config, |
| 26 const ProxyInfo& used_proxy_info, |
| 27 const BoundNetLog& net_log, |
| 28 bool was_npn_negotiated) { |
| 29 HttpPipelinedHost* host = GetPipelinedHost(origin, true); |
| 30 return host->CreateStreamOnNewPipeline(connection, used_ssl_config, |
| 31 used_proxy_info, net_log, |
| 32 was_npn_negotiated); |
| 33 } |
| 34 |
| 35 HttpPipelinedStream* HttpPipelinedHostPool::CreateStreamOnExistingPipeline( |
| 36 const HostPortPair& origin) { |
| 37 HttpPipelinedHost* host = GetPipelinedHost(origin, false); |
| 38 if (!host) { |
| 39 return NULL; |
| 40 } |
| 41 return host->CreateStreamOnExistingPipeline(); |
| 42 } |
| 43 |
| 44 bool HttpPipelinedHostPool::IsExistingPipelineAvailableForOrigin( |
| 45 const HostPortPair& origin) { |
| 46 HttpPipelinedHost* host = GetPipelinedHost(origin, false); |
| 47 if (!host) { |
| 48 return false; |
| 49 } |
| 50 return host->IsExistingPipelineAvailable(); |
| 51 } |
| 52 |
| 53 HttpPipelinedHost* HttpPipelinedHostPool::GetPipelinedHost( |
| 54 const HostPortPair& origin, bool create_if_not_found) { |
| 55 HostMap::iterator it = host_map_.find(origin); |
| 56 if (it != host_map_.end()) { |
| 57 CHECK(it->second); |
| 58 return it->second; |
| 59 } else if (!create_if_not_found) { |
| 60 return NULL; |
| 61 } |
| 62 HttpPipelinedHost* host = new HttpPipelinedHost(this, origin, NULL); |
| 63 host_map_[origin] = host; |
| 64 return host; |
| 65 } |
| 66 |
| 67 void HttpPipelinedHostPool::OnHostIdle(HttpPipelinedHost* host) { |
| 68 const HostPortPair& origin = host->origin(); |
| 69 CHECK(ContainsKey(host_map_, origin)); |
| 70 // TODO(simonjam): We should remember the pipeline state for each host. |
| 71 host_map_.erase(origin); |
| 72 delete host; |
| 73 } |
| 74 |
| 75 void HttpPipelinedHostPool::OnHostHasAdditionalCapacity( |
| 76 HttpPipelinedHost* host) { |
| 77 factory_->OnHttpPipelinedHostHasAdditionalCapacity(host->origin()); |
| 78 } |
| 79 |
| 80 } // namespace net |
OLD | NEW |