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" |
(...skipping 25 matching lines...) Expand all Loading... |
36 HttpPipelinedStream* HttpPipelinedHostImpl::CreateStreamOnNewPipeline( | 36 HttpPipelinedStream* HttpPipelinedHostImpl::CreateStreamOnNewPipeline( |
37 ClientSocketHandle* connection, | 37 ClientSocketHandle* connection, |
38 const SSLConfig& used_ssl_config, | 38 const SSLConfig& used_ssl_config, |
39 const ProxyInfo& used_proxy_info, | 39 const ProxyInfo& used_proxy_info, |
40 const BoundNetLog& net_log, | 40 const BoundNetLog& net_log, |
41 bool was_npn_negotiated, | 41 bool was_npn_negotiated, |
42 NextProto protocol_negotiated) { | 42 NextProto protocol_negotiated) { |
43 if (capability_ == PIPELINE_INCAPABLE) { | 43 if (capability_ == PIPELINE_INCAPABLE) { |
44 return NULL; | 44 return NULL; |
45 } | 45 } |
46 HttpPipelinedConnection* pipeline = factory_->CreateNewPipeline( | 46 HttpPipelinedConnection* pipeline = |
47 connection, this, key_.origin(), used_ssl_config, used_proxy_info, | 47 factory_->CreateNewPipeline(connection, |
48 net_log, was_npn_negotiated, protocol_negotiated); | 48 this, |
| 49 key_.origin(), |
| 50 used_ssl_config, |
| 51 used_proxy_info, |
| 52 net_log, |
| 53 was_npn_negotiated, |
| 54 protocol_negotiated); |
49 PipelineInfo info; | 55 PipelineInfo info; |
50 pipelines_.insert(std::make_pair(pipeline, info)); | 56 pipelines_.insert(std::make_pair(pipeline, info)); |
51 return pipeline->CreateNewStream(); | 57 return pipeline->CreateNewStream(); |
52 } | 58 } |
53 | 59 |
54 HttpPipelinedStream* HttpPipelinedHostImpl::CreateStreamOnExistingPipeline() { | 60 HttpPipelinedStream* HttpPipelinedHostImpl::CreateStreamOnExistingPipeline() { |
55 HttpPipelinedConnection* available_pipeline = NULL; | 61 HttpPipelinedConnection* available_pipeline = NULL; |
56 for (PipelineInfoMap::iterator it = pipelines_.begin(); | 62 for (PipelineInfoMap::iterator it = pipelines_.begin(); |
57 it != pipelines_.end(); ++it) { | 63 it != pipelines_.end(); |
| 64 ++it) { |
58 if (CanPipelineAcceptRequests(it->first) && | 65 if (CanPipelineAcceptRequests(it->first) && |
59 (!available_pipeline || | 66 (!available_pipeline || |
60 it->first->depth() < available_pipeline->depth())) { | 67 it->first->depth() < available_pipeline->depth())) { |
61 available_pipeline = it->first; | 68 available_pipeline = it->first; |
62 } | 69 } |
63 } | 70 } |
64 if (!available_pipeline) { | 71 if (!available_pipeline) { |
65 return NULL; | 72 return NULL; |
66 } | 73 } |
67 return available_pipeline->CreateNewStream(); | 74 return available_pipeline->CreateNewStream(); |
68 } | 75 } |
69 | 76 |
70 bool HttpPipelinedHostImpl::IsExistingPipelineAvailable() const { | 77 bool HttpPipelinedHostImpl::IsExistingPipelineAvailable() const { |
71 for (PipelineInfoMap::const_iterator it = pipelines_.begin(); | 78 for (PipelineInfoMap::const_iterator it = pipelines_.begin(); |
72 it != pipelines_.end(); ++it) { | 79 it != pipelines_.end(); |
| 80 ++it) { |
73 if (CanPipelineAcceptRequests(it->first)) { | 81 if (CanPipelineAcceptRequests(it->first)) { |
74 return true; | 82 return true; |
75 } | 83 } |
76 } | 84 } |
77 return false; | 85 return false; |
78 } | 86 } |
79 | 87 |
80 const HttpPipelinedHost::Key& HttpPipelinedHostImpl::GetKey() const { | 88 const HttpPipelinedHost::Key& HttpPipelinedHostImpl::GetKey() const { |
81 return key_; | 89 return key_; |
82 } | 90 } |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
161 break; | 169 break; |
162 | 170 |
163 default: | 171 default: |
164 CHECK(false) << "Unkown pipeline capability: " << capability_; | 172 CHECK(false) << "Unkown pipeline capability: " << capability_; |
165 } | 173 } |
166 return capacity; | 174 return capacity; |
167 } | 175 } |
168 | 176 |
169 bool HttpPipelinedHostImpl::CanPipelineAcceptRequests( | 177 bool HttpPipelinedHostImpl::CanPipelineAcceptRequests( |
170 HttpPipelinedConnection* pipeline) const { | 178 HttpPipelinedConnection* pipeline) const { |
171 return capability_ != PIPELINE_INCAPABLE && | 179 return capability_ != PIPELINE_INCAPABLE && pipeline->usable() && |
172 pipeline->usable() && | 180 pipeline->active() && pipeline->depth() < GetPipelineCapacity(); |
173 pipeline->active() && | |
174 pipeline->depth() < GetPipelineCapacity(); | |
175 } | 181 } |
176 | 182 |
177 void HttpPipelinedHostImpl::NotifyAllPipelinesHaveCapacity() { | 183 void HttpPipelinedHostImpl::NotifyAllPipelinesHaveCapacity() { |
178 // Calling OnPipelineHasCapacity() can have side effects that include | 184 // Calling OnPipelineHasCapacity() can have side effects that include |
179 // deleting and removing entries from |pipelines_|. | 185 // deleting and removing entries from |pipelines_|. |
180 PipelineInfoMap pipelines_to_notify = pipelines_; | 186 PipelineInfoMap pipelines_to_notify = pipelines_; |
181 for (PipelineInfoMap::iterator it = pipelines_to_notify.begin(); | 187 for (PipelineInfoMap::iterator it = pipelines_to_notify.begin(); |
182 it != pipelines_to_notify.end(); ++it) { | 188 it != pipelines_to_notify.end(); |
| 189 ++it) { |
183 if (pipelines_.find(it->first) != pipelines_.end()) { | 190 if (pipelines_.find(it->first) != pipelines_.end()) { |
184 OnPipelineHasCapacity(it->first); | 191 OnPipelineHasCapacity(it->first); |
185 } | 192 } |
186 } | 193 } |
187 } | 194 } |
188 | 195 |
189 base::Value* HttpPipelinedHostImpl::PipelineInfoToValue() const { | 196 base::Value* HttpPipelinedHostImpl::PipelineInfoToValue() const { |
190 base::ListValue* list_value = new base::ListValue(); | 197 base::ListValue* list_value = new base::ListValue(); |
191 for (PipelineInfoMap::const_iterator it = pipelines_.begin(); | 198 for (PipelineInfoMap::const_iterator it = pipelines_.begin(); |
192 it != pipelines_.end(); ++it) { | 199 it != pipelines_.end(); |
| 200 ++it) { |
193 base::DictionaryValue* pipeline_dict = new base::DictionaryValue; | 201 base::DictionaryValue* pipeline_dict = new base::DictionaryValue; |
194 pipeline_dict->SetString("host", key_.origin().ToString()); | 202 pipeline_dict->SetString("host", key_.origin().ToString()); |
195 pipeline_dict->SetBoolean("forced", false); | 203 pipeline_dict->SetBoolean("forced", false); |
196 pipeline_dict->SetInteger("depth", it->first->depth()); | 204 pipeline_dict->SetInteger("depth", it->first->depth()); |
197 pipeline_dict->SetInteger("capacity", GetPipelineCapacity()); | 205 pipeline_dict->SetInteger("capacity", GetPipelineCapacity()); |
198 pipeline_dict->SetBoolean("usable", it->first->usable()); | 206 pipeline_dict->SetBoolean("usable", it->first->usable()); |
199 pipeline_dict->SetBoolean("active", it->first->active()); | 207 pipeline_dict->SetBoolean("active", it->first->active()); |
200 pipeline_dict->SetInteger("source_id", it->first->net_log().source().id); | 208 pipeline_dict->SetInteger("source_id", it->first->net_log().source().id); |
201 list_value->Append(pipeline_dict); | 209 list_value->Append(pipeline_dict); |
202 } | 210 } |
203 return list_value; | 211 return list_value; |
204 } | 212 } |
205 | 213 |
206 HttpPipelinedHostImpl::PipelineInfo::PipelineInfo() | 214 HttpPipelinedHostImpl::PipelineInfo::PipelineInfo() : num_successes(0) { |
207 : num_successes(0) { | |
208 } | 215 } |
209 | 216 |
210 } // namespace net | 217 } // namespace net |
OLD | NEW |