| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "base/values.h" | 9 #include "base/values.h" |
| 10 #include "net/http/http_pipelined_host_capability.h" | 10 #include "net/http/http_pipelined_host_capability.h" |
| 11 #include "net/http/http_pipelined_host_forced.h" |
| 11 #include "net/http/http_pipelined_host_impl.h" | 12 #include "net/http/http_pipelined_host_impl.h" |
| 12 #include "net/http/http_server_properties.h" | 13 #include "net/http/http_server_properties.h" |
| 13 | 14 |
| 14 using base::ListValue; | 15 using base::ListValue; |
| 15 using base::Value; | 16 using base::Value; |
| 16 | 17 |
| 17 namespace net { | 18 namespace net { |
| 18 | 19 |
| 19 class HttpPipelinedHostImplFactory : public HttpPipelinedHost::Factory { | 20 class HttpPipelinedHostImplFactory : public HttpPipelinedHost::Factory { |
| 20 public: | 21 public: |
| 21 virtual HttpPipelinedHost* CreateNewHost( | 22 virtual HttpPipelinedHost* CreateNewHost( |
| 22 HttpPipelinedHost::Delegate* delegate, const HostPortPair& origin, | 23 HttpPipelinedHost::Delegate* delegate, |
| 24 const HttpPipelinedHost::Key& key, |
| 23 HttpPipelinedConnection::Factory* factory, | 25 HttpPipelinedConnection::Factory* factory, |
| 24 HttpPipelinedHostCapability capability) OVERRIDE { | 26 HttpPipelinedHostCapability capability, |
| 25 return new HttpPipelinedHostImpl(delegate, origin, factory, capability); | 27 bool force_pipelining) OVERRIDE { |
| 28 if (force_pipelining) { |
| 29 return new HttpPipelinedHostForced(delegate, key, factory); |
| 30 } else { |
| 31 return new HttpPipelinedHostImpl(delegate, key, factory, capability); |
| 32 } |
| 26 } | 33 } |
| 27 }; | 34 }; |
| 28 | 35 |
| 29 HttpPipelinedHostPool::HttpPipelinedHostPool( | 36 HttpPipelinedHostPool::HttpPipelinedHostPool( |
| 30 Delegate* delegate, | 37 Delegate* delegate, |
| 31 HttpPipelinedHost::Factory* factory, | 38 HttpPipelinedHost::Factory* factory, |
| 32 HttpServerProperties* http_server_properties) | 39 HttpServerProperties* http_server_properties, |
| 40 bool force_pipelining) |
| 33 : delegate_(delegate), | 41 : delegate_(delegate), |
| 34 factory_(factory), | 42 factory_(factory), |
| 35 http_server_properties_(http_server_properties) { | 43 http_server_properties_(http_server_properties), |
| 44 force_pipelining_(force_pipelining) { |
| 36 if (!factory) { | 45 if (!factory) { |
| 37 factory_.reset(new HttpPipelinedHostImplFactory); | 46 factory_.reset(new HttpPipelinedHostImplFactory); |
| 38 } | 47 } |
| 39 } | 48 } |
| 40 | 49 |
| 41 HttpPipelinedHostPool::~HttpPipelinedHostPool() { | 50 HttpPipelinedHostPool::~HttpPipelinedHostPool() { |
| 42 CHECK(host_map_.empty()); | 51 CHECK(host_map_.empty()); |
| 43 } | 52 } |
| 44 | 53 |
| 45 bool HttpPipelinedHostPool::IsHostEligibleForPipelining( | 54 bool HttpPipelinedHostPool::IsKeyEligibleForPipelining( |
| 46 const HostPortPair& origin) { | 55 const HttpPipelinedHost::Key& key) { |
| 47 HttpPipelinedHostCapability capability = | 56 HttpPipelinedHostCapability capability = |
| 48 http_server_properties_->GetPipelineCapability(origin); | 57 http_server_properties_->GetPipelineCapability(key.origin()); |
| 49 return capability != PIPELINE_INCAPABLE; | 58 return capability != PIPELINE_INCAPABLE; |
| 50 } | 59 } |
| 51 | 60 |
| 52 HttpPipelinedStream* HttpPipelinedHostPool::CreateStreamOnNewPipeline( | 61 HttpPipelinedStream* HttpPipelinedHostPool::CreateStreamOnNewPipeline( |
| 53 const HostPortPair& origin, | 62 const HttpPipelinedHost::Key& key, |
| 54 ClientSocketHandle* connection, | 63 ClientSocketHandle* connection, |
| 55 const SSLConfig& used_ssl_config, | 64 const SSLConfig& used_ssl_config, |
| 56 const ProxyInfo& used_proxy_info, | 65 const ProxyInfo& used_proxy_info, |
| 57 const BoundNetLog& net_log, | 66 const BoundNetLog& net_log, |
| 58 bool was_npn_negotiated, | 67 bool was_npn_negotiated, |
| 59 SSLClientSocket::NextProto protocol_negotiated) { | 68 SSLClientSocket::NextProto protocol_negotiated) { |
| 60 HttpPipelinedHost* host = GetPipelinedHost(origin, true); | 69 HttpPipelinedHost* host = GetPipelinedHost(key, true); |
| 61 if (!host) { | 70 if (!host) { |
| 62 return NULL; | 71 return NULL; |
| 63 } | 72 } |
| 64 return host->CreateStreamOnNewPipeline(connection, used_ssl_config, | 73 return host->CreateStreamOnNewPipeline(connection, used_ssl_config, |
| 65 used_proxy_info, net_log, | 74 used_proxy_info, net_log, |
| 66 was_npn_negotiated, | 75 was_npn_negotiated, |
| 67 protocol_negotiated); | 76 protocol_negotiated); |
| 68 } | 77 } |
| 69 | 78 |
| 70 HttpPipelinedStream* HttpPipelinedHostPool::CreateStreamOnExistingPipeline( | 79 HttpPipelinedStream* HttpPipelinedHostPool::CreateStreamOnExistingPipeline( |
| 71 const HostPortPair& origin) { | 80 const HttpPipelinedHost::Key& key) { |
| 72 HttpPipelinedHost* host = GetPipelinedHost(origin, false); | 81 HttpPipelinedHost* host = GetPipelinedHost(key, false); |
| 73 if (!host) { | 82 if (!host) { |
| 74 return NULL; | 83 return NULL; |
| 75 } | 84 } |
| 76 return host->CreateStreamOnExistingPipeline(); | 85 return host->CreateStreamOnExistingPipeline(); |
| 77 } | 86 } |
| 78 | 87 |
| 79 bool HttpPipelinedHostPool::IsExistingPipelineAvailableForOrigin( | 88 bool HttpPipelinedHostPool::IsExistingPipelineAvailableForKey( |
| 80 const HostPortPair& origin) { | 89 const HttpPipelinedHost::Key& key) { |
| 81 HttpPipelinedHost* host = GetPipelinedHost(origin, false); | 90 HttpPipelinedHost* host = GetPipelinedHost(key, false); |
| 82 if (!host) { | 91 if (!host) { |
| 83 return false; | 92 return false; |
| 84 } | 93 } |
| 85 return host->IsExistingPipelineAvailable(); | 94 return host->IsExistingPipelineAvailable(); |
| 86 } | 95 } |
| 87 | 96 |
| 88 HttpPipelinedHost* HttpPipelinedHostPool::GetPipelinedHost( | 97 HttpPipelinedHost* HttpPipelinedHostPool::GetPipelinedHost( |
| 89 const HostPortPair& origin, bool create_if_not_found) { | 98 const HttpPipelinedHost::Key& key, bool create_if_not_found) { |
| 90 HostMap::iterator host_it = host_map_.find(origin); | 99 HostMap::iterator host_it = host_map_.find(key); |
| 91 if (host_it != host_map_.end()) { | 100 if (host_it != host_map_.end()) { |
| 92 CHECK(host_it->second); | 101 CHECK(host_it->second); |
| 93 return host_it->second; | 102 return host_it->second; |
| 94 } else if (!create_if_not_found) { | 103 } else if (!create_if_not_found) { |
| 95 return NULL; | 104 return NULL; |
| 96 } | 105 } |
| 97 | 106 |
| 98 HttpPipelinedHostCapability capability = | 107 HttpPipelinedHostCapability capability = |
| 99 http_server_properties_->GetPipelineCapability(origin); | 108 http_server_properties_->GetPipelineCapability(key.origin()); |
| 100 if (capability == PIPELINE_INCAPABLE) { | 109 if (capability == PIPELINE_INCAPABLE) { |
| 101 return NULL; | 110 return NULL; |
| 102 } | 111 } |
| 103 | 112 |
| 104 HttpPipelinedHost* host = factory_->CreateNewHost( | 113 HttpPipelinedHost* host = factory_->CreateNewHost( |
| 105 this, origin, NULL, capability); | 114 this, key, NULL, capability, force_pipelining_); |
| 106 host_map_[origin] = host; | 115 host_map_[key] = host; |
| 107 return host; | 116 return host; |
| 108 } | 117 } |
| 109 | 118 |
| 110 void HttpPipelinedHostPool::OnHostIdle(HttpPipelinedHost* host) { | 119 void HttpPipelinedHostPool::OnHostIdle(HttpPipelinedHost* host) { |
| 111 const HostPortPair& origin = host->origin(); | 120 const HttpPipelinedHost::Key& key = host->GetKey(); |
| 112 CHECK(ContainsKey(host_map_, origin)); | 121 CHECK(ContainsKey(host_map_, key)); |
| 113 host_map_.erase(origin); | 122 host_map_.erase(key); |
| 114 delete host; | 123 delete host; |
| 115 } | 124 } |
| 116 | 125 |
| 117 void HttpPipelinedHostPool::OnHostHasAdditionalCapacity( | 126 void HttpPipelinedHostPool::OnHostHasAdditionalCapacity( |
| 118 HttpPipelinedHost* host) { | 127 HttpPipelinedHost* host) { |
| 119 delegate_->OnHttpPipelinedHostHasAdditionalCapacity(host->origin()); | 128 delegate_->OnHttpPipelinedHostHasAdditionalCapacity(host); |
| 120 } | 129 } |
| 121 | 130 |
| 122 void HttpPipelinedHostPool::OnHostDeterminedCapability( | 131 void HttpPipelinedHostPool::OnHostDeterminedCapability( |
| 123 HttpPipelinedHost* host, | 132 HttpPipelinedHost* host, |
| 124 HttpPipelinedHostCapability capability) { | 133 HttpPipelinedHostCapability capability) { |
| 125 http_server_properties_->SetPipelineCapability(host->origin(), capability); | 134 http_server_properties_->SetPipelineCapability(host->GetKey().origin(), |
| 135 capability); |
| 126 } | 136 } |
| 127 | 137 |
| 128 Value* HttpPipelinedHostPool::PipelineInfoToValue() const { | 138 Value* HttpPipelinedHostPool::PipelineInfoToValue() const { |
| 129 ListValue* list = new ListValue(); | 139 ListValue* list = new ListValue(); |
| 130 for (HostMap::const_iterator it = host_map_.begin(); | 140 for (HostMap::const_iterator it = host_map_.begin(); |
| 131 it != host_map_.end(); ++it) { | 141 it != host_map_.end(); ++it) { |
| 132 Value* value = it->second->PipelineInfoToValue(); | 142 Value* value = it->second->PipelineInfoToValue(); |
| 133 list->Append(value); | 143 list->Append(value); |
| 134 } | 144 } |
| 135 return list; | 145 return list; |
| 136 } | 146 } |
| 137 | 147 |
| 138 } // namespace net | 148 } // namespace net |
| OLD | NEW |