| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 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 | 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_pipelined_host_pool.h" | 5 #include "net/http/http_pipelined_host_pool.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "base/stl_util.h" | 8 #include "base/stl_util.h" |
| 9 #include "net/http/http_pipelined_host_capability.h" |
| 9 #include "net/http/http_pipelined_host_impl.h" | 10 #include "net/http/http_pipelined_host_impl.h" |
| 11 #include "net/http/http_server_properties.h" |
| 10 | 12 |
| 11 namespace net { | 13 namespace net { |
| 12 | 14 |
| 13 // TODO(simonjam): Run experiments with different values of this to see what | |
| 14 // value is good at avoiding evictions without eating too much memory. Until | |
| 15 // then, this is just a bad guess. | |
| 16 static const int kNumHostsToRemember = 200; | |
| 17 | |
| 18 class HttpPipelinedHostImplFactory : public HttpPipelinedHost::Factory { | 15 class HttpPipelinedHostImplFactory : public HttpPipelinedHost::Factory { |
| 19 public: | 16 public: |
| 20 virtual HttpPipelinedHost* CreateNewHost( | 17 virtual HttpPipelinedHost* CreateNewHost( |
| 21 HttpPipelinedHost::Delegate* delegate, const HostPortPair& origin, | 18 HttpPipelinedHost::Delegate* delegate, const HostPortPair& origin, |
| 22 HttpPipelinedConnection::Factory* factory, | 19 HttpPipelinedConnection::Factory* factory, |
| 23 HttpPipelinedHost::Capability capability) OVERRIDE { | 20 HttpPipelinedHostCapability capability) OVERRIDE { |
| 24 return new HttpPipelinedHostImpl(delegate, origin, factory, capability); | 21 return new HttpPipelinedHostImpl(delegate, origin, factory, capability); |
| 25 } | 22 } |
| 26 }; | 23 }; |
| 27 | 24 |
| 28 HttpPipelinedHostPool::HttpPipelinedHostPool( | 25 HttpPipelinedHostPool::HttpPipelinedHostPool( |
| 29 Delegate* delegate, | 26 Delegate* delegate, |
| 30 HttpPipelinedHost::Factory* factory) | 27 HttpPipelinedHost::Factory* factory, |
| 28 HttpServerProperties* http_server_properties) |
| 31 : delegate_(delegate), | 29 : delegate_(delegate), |
| 32 factory_(factory), | 30 factory_(factory), |
| 33 known_capability_map_(kNumHostsToRemember) { | 31 http_server_properties_(http_server_properties) { |
| 34 if (!factory) { | 32 if (!factory) { |
| 35 factory_.reset(new HttpPipelinedHostImplFactory); | 33 factory_.reset(new HttpPipelinedHostImplFactory); |
| 36 } | 34 } |
| 37 } | 35 } |
| 38 | 36 |
| 39 HttpPipelinedHostPool::~HttpPipelinedHostPool() { | 37 HttpPipelinedHostPool::~HttpPipelinedHostPool() { |
| 40 CHECK(host_map_.empty()); | 38 CHECK(host_map_.empty()); |
| 41 } | 39 } |
| 42 | 40 |
| 43 bool HttpPipelinedHostPool::IsHostEligibleForPipelining( | 41 bool HttpPipelinedHostPool::IsHostEligibleForPipelining( |
| 44 const HostPortPair& origin) { | 42 const HostPortPair& origin) { |
| 45 HttpPipelinedHost::Capability capability = GetHostCapability(origin); | 43 HttpPipelinedHostCapability capability = |
| 46 return capability != HttpPipelinedHost::INCAPABLE; | 44 http_server_properties_->GetPipelineCapability(origin); |
| 45 return capability != PIPELINE_INCAPABLE; |
| 47 } | 46 } |
| 48 | 47 |
| 49 HttpPipelinedStream* HttpPipelinedHostPool::CreateStreamOnNewPipeline( | 48 HttpPipelinedStream* HttpPipelinedHostPool::CreateStreamOnNewPipeline( |
| 50 const HostPortPair& origin, | 49 const HostPortPair& origin, |
| 51 ClientSocketHandle* connection, | 50 ClientSocketHandle* connection, |
| 52 const SSLConfig& used_ssl_config, | 51 const SSLConfig& used_ssl_config, |
| 53 const ProxyInfo& used_proxy_info, | 52 const ProxyInfo& used_proxy_info, |
| 54 const BoundNetLog& net_log, | 53 const BoundNetLog& net_log, |
| 55 bool was_npn_negotiated) { | 54 bool was_npn_negotiated) { |
| 56 HttpPipelinedHost* host = GetPipelinedHost(origin, true); | 55 HttpPipelinedHost* host = GetPipelinedHost(origin, true); |
| (...skipping 26 matching lines...) Expand all Loading... |
| 83 HttpPipelinedHost* HttpPipelinedHostPool::GetPipelinedHost( | 82 HttpPipelinedHost* HttpPipelinedHostPool::GetPipelinedHost( |
| 84 const HostPortPair& origin, bool create_if_not_found) { | 83 const HostPortPair& origin, bool create_if_not_found) { |
| 85 HostMap::iterator host_it = host_map_.find(origin); | 84 HostMap::iterator host_it = host_map_.find(origin); |
| 86 if (host_it != host_map_.end()) { | 85 if (host_it != host_map_.end()) { |
| 87 CHECK(host_it->second); | 86 CHECK(host_it->second); |
| 88 return host_it->second; | 87 return host_it->second; |
| 89 } else if (!create_if_not_found) { | 88 } else if (!create_if_not_found) { |
| 90 return NULL; | 89 return NULL; |
| 91 } | 90 } |
| 92 | 91 |
| 93 HttpPipelinedHost::Capability capability = GetHostCapability(origin); | 92 HttpPipelinedHostCapability capability = |
| 94 if (capability == HttpPipelinedHost::INCAPABLE) { | 93 http_server_properties_->GetPipelineCapability(origin); |
| 94 if (capability == PIPELINE_INCAPABLE) { |
| 95 return NULL; | 95 return NULL; |
| 96 } | 96 } |
| 97 | 97 |
| 98 HttpPipelinedHost* host = factory_->CreateNewHost( | 98 HttpPipelinedHost* host = factory_->CreateNewHost( |
| 99 this, origin, NULL, capability); | 99 this, origin, NULL, capability); |
| 100 host_map_[origin] = host; | 100 host_map_[origin] = host; |
| 101 return host; | 101 return host; |
| 102 } | 102 } |
| 103 | 103 |
| 104 void HttpPipelinedHostPool::OnHostIdle(HttpPipelinedHost* host) { | 104 void HttpPipelinedHostPool::OnHostIdle(HttpPipelinedHost* host) { |
| 105 const HostPortPair& origin = host->origin(); | 105 const HostPortPair& origin = host->origin(); |
| 106 CHECK(ContainsKey(host_map_, origin)); | 106 CHECK(ContainsKey(host_map_, origin)); |
| 107 host_map_.erase(origin); | 107 host_map_.erase(origin); |
| 108 delete host; | 108 delete host; |
| 109 } | 109 } |
| 110 | 110 |
| 111 void HttpPipelinedHostPool::OnHostHasAdditionalCapacity( | 111 void HttpPipelinedHostPool::OnHostHasAdditionalCapacity( |
| 112 HttpPipelinedHost* host) { | 112 HttpPipelinedHost* host) { |
| 113 delegate_->OnHttpPipelinedHostHasAdditionalCapacity(host->origin()); | 113 delegate_->OnHttpPipelinedHostHasAdditionalCapacity(host->origin()); |
| 114 } | 114 } |
| 115 | 115 |
| 116 void HttpPipelinedHostPool::OnHostDeterminedCapability( | 116 void HttpPipelinedHostPool::OnHostDeterminedCapability( |
| 117 HttpPipelinedHost* host, | 117 HttpPipelinedHost* host, |
| 118 HttpPipelinedHost::Capability capability) { | 118 HttpPipelinedHostCapability capability) { |
| 119 CapabilityMap::iterator known_it = known_capability_map_.Get(host->origin()); | 119 http_server_properties_->SetPipelineCapability(host->origin(), capability); |
| 120 if (known_it == known_capability_map_.end() || | |
| 121 known_it->second != HttpPipelinedHost::INCAPABLE) { | |
| 122 known_capability_map_.Put(host->origin(), capability); | |
| 123 } | |
| 124 } | |
| 125 | |
| 126 HttpPipelinedHost::Capability HttpPipelinedHostPool::GetHostCapability( | |
| 127 const HostPortPair& origin) { | |
| 128 HttpPipelinedHost::Capability capability = HttpPipelinedHost::UNKNOWN; | |
| 129 CapabilityMap::const_iterator it = known_capability_map_.Get(origin); | |
| 130 if (it != known_capability_map_.end()) { | |
| 131 capability = it->second; | |
| 132 } | |
| 133 return capability; | |
| 134 } | 120 } |
| 135 | 121 |
| 136 } // namespace net | 122 } // namespace net |
| OLD | NEW |