| OLD | NEW |
| 1 // Copyright (c) 2012 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" |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 60 ClientSocketHandle* connection, | 60 ClientSocketHandle* connection, |
| 61 const SSLConfig& used_ssl_config, | 61 const SSLConfig& used_ssl_config, |
| 62 const ProxyInfo& used_proxy_info, | 62 const ProxyInfo& used_proxy_info, |
| 63 const BoundNetLog& net_log, | 63 const BoundNetLog& net_log, |
| 64 bool was_npn_negotiated, | 64 bool was_npn_negotiated, |
| 65 NextProto protocol_negotiated) { | 65 NextProto protocol_negotiated) { |
| 66 HttpPipelinedHost* host = GetPipelinedHost(key, true); | 66 HttpPipelinedHost* host = GetPipelinedHost(key, true); |
| 67 if (!host) { | 67 if (!host) { |
| 68 return NULL; | 68 return NULL; |
| 69 } | 69 } |
| 70 return host->CreateStreamOnNewPipeline(connection, used_ssl_config, | 70 return host->CreateStreamOnNewPipeline(connection, |
| 71 used_proxy_info, net_log, | 71 used_ssl_config, |
| 72 used_proxy_info, |
| 73 net_log, |
| 72 was_npn_negotiated, | 74 was_npn_negotiated, |
| 73 protocol_negotiated); | 75 protocol_negotiated); |
| 74 } | 76 } |
| 75 | 77 |
| 76 HttpPipelinedStream* HttpPipelinedHostPool::CreateStreamOnExistingPipeline( | 78 HttpPipelinedStream* HttpPipelinedHostPool::CreateStreamOnExistingPipeline( |
| 77 const HttpPipelinedHost::Key& key) { | 79 const HttpPipelinedHost::Key& key) { |
| 78 HttpPipelinedHost* host = GetPipelinedHost(key, false); | 80 HttpPipelinedHost* host = GetPipelinedHost(key, false); |
| 79 if (!host) { | 81 if (!host) { |
| 80 return NULL; | 82 return NULL; |
| 81 } | 83 } |
| 82 return host->CreateStreamOnExistingPipeline(); | 84 return host->CreateStreamOnExistingPipeline(); |
| 83 } | 85 } |
| 84 | 86 |
| 85 bool HttpPipelinedHostPool::IsExistingPipelineAvailableForKey( | 87 bool HttpPipelinedHostPool::IsExistingPipelineAvailableForKey( |
| 86 const HttpPipelinedHost::Key& key) { | 88 const HttpPipelinedHost::Key& key) { |
| 87 HttpPipelinedHost* host = GetPipelinedHost(key, false); | 89 HttpPipelinedHost* host = GetPipelinedHost(key, false); |
| 88 if (!host) { | 90 if (!host) { |
| 89 return false; | 91 return false; |
| 90 } | 92 } |
| 91 return host->IsExistingPipelineAvailable(); | 93 return host->IsExistingPipelineAvailable(); |
| 92 } | 94 } |
| 93 | 95 |
| 94 HttpPipelinedHost* HttpPipelinedHostPool::GetPipelinedHost( | 96 HttpPipelinedHost* HttpPipelinedHostPool::GetPipelinedHost( |
| 95 const HttpPipelinedHost::Key& key, bool create_if_not_found) { | 97 const HttpPipelinedHost::Key& key, |
| 98 bool create_if_not_found) { |
| 96 HostMap::iterator host_it = host_map_.find(key); | 99 HostMap::iterator host_it = host_map_.find(key); |
| 97 if (host_it != host_map_.end()) { | 100 if (host_it != host_map_.end()) { |
| 98 CHECK(host_it->second); | 101 CHECK(host_it->second); |
| 99 return host_it->second; | 102 return host_it->second; |
| 100 } else if (!create_if_not_found) { | 103 } else if (!create_if_not_found) { |
| 101 return NULL; | 104 return NULL; |
| 102 } | 105 } |
| 103 | 106 |
| 104 HttpPipelinedHostCapability capability = | 107 HttpPipelinedHostCapability capability = |
| 105 http_server_properties_->GetPipelineCapability(key.origin()); | 108 http_server_properties_->GetPipelineCapability(key.origin()); |
| 106 if (capability == PIPELINE_INCAPABLE) { | 109 if (capability == PIPELINE_INCAPABLE) { |
| 107 return NULL; | 110 return NULL; |
| 108 } | 111 } |
| 109 | 112 |
| 110 HttpPipelinedHost* host = factory_->CreateNewHost( | 113 HttpPipelinedHost* host = |
| 111 this, key, NULL, capability, force_pipelining_); | 114 factory_->CreateNewHost(this, key, NULL, capability, force_pipelining_); |
| 112 host_map_[key] = host; | 115 host_map_[key] = host; |
| 113 return host; | 116 return host; |
| 114 } | 117 } |
| 115 | 118 |
| 116 void HttpPipelinedHostPool::OnHostIdle(HttpPipelinedHost* host) { | 119 void HttpPipelinedHostPool::OnHostIdle(HttpPipelinedHost* host) { |
| 117 const HttpPipelinedHost::Key& key = host->GetKey(); | 120 const HttpPipelinedHost::Key& key = host->GetKey(); |
| 118 CHECK(ContainsKey(host_map_, key)); | 121 CHECK(ContainsKey(host_map_, key)); |
| 119 host_map_.erase(key); | 122 host_map_.erase(key); |
| 120 delete host; | 123 delete host; |
| 121 } | 124 } |
| 122 | 125 |
| 123 void HttpPipelinedHostPool::OnHostHasAdditionalCapacity( | 126 void HttpPipelinedHostPool::OnHostHasAdditionalCapacity( |
| 124 HttpPipelinedHost* host) { | 127 HttpPipelinedHost* host) { |
| 125 delegate_->OnHttpPipelinedHostHasAdditionalCapacity(host); | 128 delegate_->OnHttpPipelinedHostHasAdditionalCapacity(host); |
| 126 } | 129 } |
| 127 | 130 |
| 128 void HttpPipelinedHostPool::OnHostDeterminedCapability( | 131 void HttpPipelinedHostPool::OnHostDeterminedCapability( |
| 129 HttpPipelinedHost* host, | 132 HttpPipelinedHost* host, |
| 130 HttpPipelinedHostCapability capability) { | 133 HttpPipelinedHostCapability capability) { |
| 131 http_server_properties_->SetPipelineCapability(host->GetKey().origin(), | 134 http_server_properties_->SetPipelineCapability(host->GetKey().origin(), |
| 132 capability); | 135 capability); |
| 133 } | 136 } |
| 134 | 137 |
| 135 base::Value* HttpPipelinedHostPool::PipelineInfoToValue() const { | 138 base::Value* HttpPipelinedHostPool::PipelineInfoToValue() const { |
| 136 base::ListValue* list = new base::ListValue(); | 139 base::ListValue* list = new base::ListValue(); |
| 137 for (HostMap::const_iterator it = host_map_.begin(); | 140 for (HostMap::const_iterator it = host_map_.begin(); it != host_map_.end(); |
| 138 it != host_map_.end(); ++it) { | 141 ++it) { |
| 139 base::Value* value = it->second->PipelineInfoToValue(); | 142 base::Value* value = it->second->PipelineInfoToValue(); |
| 140 list->Append(value); | 143 list->Append(value); |
| 141 } | 144 } |
| 142 return list; | 145 return list; |
| 143 } | 146 } |
| 144 | 147 |
| 145 } // namespace net | 148 } // namespace net |
| OLD | NEW |