| 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_impl.h" | 5 #include "net/http/http_pipelined_host_impl.h" |
| 6 | 6 |
| 7 #include "base/stl_util.h" | 7 #include "base/stl_util.h" |
| 8 #include "base/values.h" | 8 #include "base/values.h" |
| 9 #include "net/http/http_pipelined_connection_impl.h" | 9 #include "net/http/http_pipelined_connection_impl.h" |
| 10 #include "net/http/http_pipelined_stream.h" | 10 #include "net/http/http_pipelined_stream.h" |
| 11 | 11 |
| 12 using base::DictionaryValue; | 12 using base::DictionaryValue; |
| 13 using base::ListValue; | 13 using base::ListValue; |
| 14 using base::Value; | 14 using base::Value; |
| 15 | 15 |
| 16 namespace net { | 16 namespace net { |
| 17 | 17 |
| 18 // TODO(simonjam): Run experiments to see what value minimizes evictions without | 18 // TODO(simonjam): Run experiments to see what value minimizes evictions without |
| 19 // costing too much performance. Until then, this is just a bad guess. | 19 // costing too much performance. Until then, this is just a bad guess. |
| 20 static const int kNumKnownSuccessesThreshold = 3; | 20 static const int kNumKnownSuccessesThreshold = 3; |
| 21 | 21 |
| 22 class HttpPipelinedConnectionImplFactory : | |
| 23 public HttpPipelinedConnection::Factory { | |
| 24 public: | |
| 25 HttpPipelinedConnection* CreateNewPipeline( | |
| 26 ClientSocketHandle* connection, | |
| 27 HttpPipelinedConnection::Delegate* delegate, | |
| 28 const HostPortPair& origin, | |
| 29 const SSLConfig& used_ssl_config, | |
| 30 const ProxyInfo& used_proxy_info, | |
| 31 const BoundNetLog& net_log, | |
| 32 bool was_npn_negotiated, | |
| 33 SSLClientSocket::NextProto protocol_negotiated) OVERRIDE { | |
| 34 return new HttpPipelinedConnectionImpl(connection, delegate, origin, | |
| 35 used_ssl_config, used_proxy_info, | |
| 36 net_log, was_npn_negotiated, | |
| 37 protocol_negotiated); | |
| 38 } | |
| 39 }; | |
| 40 | |
| 41 HttpPipelinedHostImpl::HttpPipelinedHostImpl( | 22 HttpPipelinedHostImpl::HttpPipelinedHostImpl( |
| 42 HttpPipelinedHost::Delegate* delegate, | 23 HttpPipelinedHost::Delegate* delegate, |
| 43 const HostPortPair& origin, | 24 const HttpPipelinedHost::Key& key, |
| 44 HttpPipelinedConnection::Factory* factory, | 25 HttpPipelinedConnection::Factory* factory, |
| 45 HttpPipelinedHostCapability capability) | 26 HttpPipelinedHostCapability capability) |
| 46 : delegate_(delegate), | 27 : delegate_(delegate), |
| 47 origin_(origin), | 28 key_(key), |
| 48 factory_(factory), | 29 factory_(factory), |
| 49 capability_(capability) { | 30 capability_(capability) { |
| 50 if (!factory) { | 31 if (!factory) { |
| 51 factory_.reset(new HttpPipelinedConnectionImplFactory()); | 32 factory_.reset(new HttpPipelinedConnectionImpl::Factory()); |
| 52 } | 33 } |
| 53 } | 34 } |
| 54 | 35 |
| 55 HttpPipelinedHostImpl::~HttpPipelinedHostImpl() { | 36 HttpPipelinedHostImpl::~HttpPipelinedHostImpl() { |
| 56 CHECK(pipelines_.empty()); | 37 CHECK(pipelines_.empty()); |
| 57 } | 38 } |
| 58 | 39 |
| 59 HttpPipelinedStream* HttpPipelinedHostImpl::CreateStreamOnNewPipeline( | 40 HttpPipelinedStream* HttpPipelinedHostImpl::CreateStreamOnNewPipeline( |
| 60 ClientSocketHandle* connection, | 41 ClientSocketHandle* connection, |
| 61 const SSLConfig& used_ssl_config, | 42 const SSLConfig& used_ssl_config, |
| 62 const ProxyInfo& used_proxy_info, | 43 const ProxyInfo& used_proxy_info, |
| 63 const BoundNetLog& net_log, | 44 const BoundNetLog& net_log, |
| 64 bool was_npn_negotiated, | 45 bool was_npn_negotiated, |
| 65 SSLClientSocket::NextProto protocol_negotiated) { | 46 SSLClientSocket::NextProto protocol_negotiated) { |
| 66 if (capability_ == PIPELINE_INCAPABLE) { | 47 if (capability_ == PIPELINE_INCAPABLE) { |
| 67 return NULL; | 48 return NULL; |
| 68 } | 49 } |
| 69 HttpPipelinedConnection* pipeline = factory_->CreateNewPipeline( | 50 HttpPipelinedConnection* pipeline = factory_->CreateNewPipeline( |
| 70 connection, this, origin_, used_ssl_config, used_proxy_info, net_log, | 51 connection, this, key_.origin(), used_ssl_config, used_proxy_info, |
| 71 was_npn_negotiated, protocol_negotiated); | 52 net_log, was_npn_negotiated, protocol_negotiated); |
| 72 PipelineInfo info; | 53 PipelineInfo info; |
| 73 pipelines_.insert(std::make_pair(pipeline, info)); | 54 pipelines_.insert(std::make_pair(pipeline, info)); |
| 74 return pipeline->CreateNewStream(); | 55 return pipeline->CreateNewStream(); |
| 75 } | 56 } |
| 76 | 57 |
| 77 HttpPipelinedStream* HttpPipelinedHostImpl::CreateStreamOnExistingPipeline() { | 58 HttpPipelinedStream* HttpPipelinedHostImpl::CreateStreamOnExistingPipeline() { |
| 78 HttpPipelinedConnection* available_pipeline = NULL; | 59 HttpPipelinedConnection* available_pipeline = NULL; |
| 79 for (PipelineInfoMap::iterator it = pipelines_.begin(); | 60 for (PipelineInfoMap::iterator it = pipelines_.begin(); |
| 80 it != pipelines_.end(); ++it) { | 61 it != pipelines_.end(); ++it) { |
| 81 if (CanPipelineAcceptRequests(it->first) && | 62 if (CanPipelineAcceptRequests(it->first) && |
| (...skipping 11 matching lines...) Expand all Loading... |
| 93 bool HttpPipelinedHostImpl::IsExistingPipelineAvailable() const { | 74 bool HttpPipelinedHostImpl::IsExistingPipelineAvailable() const { |
| 94 for (PipelineInfoMap::const_iterator it = pipelines_.begin(); | 75 for (PipelineInfoMap::const_iterator it = pipelines_.begin(); |
| 95 it != pipelines_.end(); ++it) { | 76 it != pipelines_.end(); ++it) { |
| 96 if (CanPipelineAcceptRequests(it->first)) { | 77 if (CanPipelineAcceptRequests(it->first)) { |
| 97 return true; | 78 return true; |
| 98 } | 79 } |
| 99 } | 80 } |
| 100 return false; | 81 return false; |
| 101 } | 82 } |
| 102 | 83 |
| 103 const HostPortPair& HttpPipelinedHostImpl::origin() const { | 84 const HttpPipelinedHost::Key& HttpPipelinedHostImpl::GetKey() const { |
| 104 return origin_; | 85 return key_; |
| 105 } | 86 } |
| 106 | 87 |
| 107 void HttpPipelinedHostImpl::OnPipelineEmpty(HttpPipelinedConnection* pipeline) { | 88 void HttpPipelinedHostImpl::OnPipelineEmpty(HttpPipelinedConnection* pipeline) { |
| 108 CHECK(ContainsKey(pipelines_, pipeline)); | 89 CHECK(ContainsKey(pipelines_, pipeline)); |
| 109 pipelines_.erase(pipeline); | 90 pipelines_.erase(pipeline); |
| 110 delete pipeline; | 91 delete pipeline; |
| 111 if (pipelines_.empty()) { | 92 if (pipelines_.empty()) { |
| 112 delegate_->OnHostIdle(this); | 93 delegate_->OnHostIdle(this); |
| 113 // WARNING: We'll probably be deleted here. | 94 // WARNING: We'll probably be deleted here. |
| 114 } | 95 } |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 207 OnPipelineHasCapacity(it->first); | 188 OnPipelineHasCapacity(it->first); |
| 208 } | 189 } |
| 209 } | 190 } |
| 210 } | 191 } |
| 211 | 192 |
| 212 Value* HttpPipelinedHostImpl::PipelineInfoToValue() const { | 193 Value* HttpPipelinedHostImpl::PipelineInfoToValue() const { |
| 213 ListValue* list_value = new ListValue(); | 194 ListValue* list_value = new ListValue(); |
| 214 for (PipelineInfoMap::const_iterator it = pipelines_.begin(); | 195 for (PipelineInfoMap::const_iterator it = pipelines_.begin(); |
| 215 it != pipelines_.end(); ++it) { | 196 it != pipelines_.end(); ++it) { |
| 216 DictionaryValue* pipeline_dict = new DictionaryValue; | 197 DictionaryValue* pipeline_dict = new DictionaryValue; |
| 217 pipeline_dict->SetString("host", origin_.ToString()); | 198 pipeline_dict->SetString("host", key_.origin().ToString()); |
| 199 pipeline_dict->SetBoolean("forced", false); |
| 218 pipeline_dict->SetInteger("depth", it->first->depth()); | 200 pipeline_dict->SetInteger("depth", it->first->depth()); |
| 219 pipeline_dict->SetInteger("capacity", GetPipelineCapacity()); | 201 pipeline_dict->SetInteger("capacity", GetPipelineCapacity()); |
| 220 pipeline_dict->SetBoolean("usable", it->first->usable()); | 202 pipeline_dict->SetBoolean("usable", it->first->usable()); |
| 221 pipeline_dict->SetBoolean("active", it->first->active()); | 203 pipeline_dict->SetBoolean("active", it->first->active()); |
| 222 pipeline_dict->SetInteger("source_id", it->first->net_log().source().id); | 204 pipeline_dict->SetInteger("source_id", it->first->net_log().source().id); |
| 223 list_value->Append(pipeline_dict); | 205 list_value->Append(pipeline_dict); |
| 224 } | 206 } |
| 225 return list_value; | 207 return list_value; |
| 226 } | 208 } |
| 227 | 209 |
| 228 HttpPipelinedHostImpl::PipelineInfo::PipelineInfo() | 210 HttpPipelinedHostImpl::PipelineInfo::PipelineInfo() |
| 229 : num_successes(0) { | 211 : num_successes(0) { |
| 230 } | 212 } |
| 231 | 213 |
| 232 } // namespace net | 214 } // namespace net |
| OLD | NEW |