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_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 "net/http/http_pipelined_connection_impl.h" | 8 #include "net/http/http_pipelined_connection_impl.h" |
9 #include "net/http/http_pipelined_stream.h" | 9 #include "net/http/http_pipelined_stream.h" |
10 | 10 |
(...skipping 16 matching lines...) Expand all Loading... |
27 return new HttpPipelinedConnectionImpl(connection, delegate, | 27 return new HttpPipelinedConnectionImpl(connection, delegate, |
28 used_ssl_config, used_proxy_info, | 28 used_ssl_config, used_proxy_info, |
29 net_log, was_npn_negotiated); | 29 net_log, was_npn_negotiated); |
30 } | 30 } |
31 }; | 31 }; |
32 | 32 |
33 HttpPipelinedHostImpl::HttpPipelinedHostImpl( | 33 HttpPipelinedHostImpl::HttpPipelinedHostImpl( |
34 HttpPipelinedHost::Delegate* delegate, | 34 HttpPipelinedHost::Delegate* delegate, |
35 const HostPortPair& origin, | 35 const HostPortPair& origin, |
36 HttpPipelinedConnection::Factory* factory, | 36 HttpPipelinedConnection::Factory* factory, |
37 HttpPipelinedHostCapability capability) | 37 Capability capability) |
38 : delegate_(delegate), | 38 : delegate_(delegate), |
39 origin_(origin), | 39 origin_(origin), |
40 factory_(factory), | 40 factory_(factory), |
41 capability_(capability) { | 41 capability_(capability) { |
42 if (!factory) { | 42 if (!factory) { |
43 factory_.reset(new HttpPipelinedConnectionImplFactory()); | 43 factory_.reset(new HttpPipelinedConnectionImplFactory()); |
44 } | 44 } |
45 } | 45 } |
46 | 46 |
47 HttpPipelinedHostImpl::~HttpPipelinedHostImpl() { | 47 HttpPipelinedHostImpl::~HttpPipelinedHostImpl() { |
48 CHECK(pipelines_.empty()); | 48 CHECK(pipelines_.empty()); |
49 } | 49 } |
50 | 50 |
51 HttpPipelinedStream* HttpPipelinedHostImpl::CreateStreamOnNewPipeline( | 51 HttpPipelinedStream* HttpPipelinedHostImpl::CreateStreamOnNewPipeline( |
52 ClientSocketHandle* connection, | 52 ClientSocketHandle* connection, |
53 const SSLConfig& used_ssl_config, | 53 const SSLConfig& used_ssl_config, |
54 const ProxyInfo& used_proxy_info, | 54 const ProxyInfo& used_proxy_info, |
55 const BoundNetLog& net_log, | 55 const BoundNetLog& net_log, |
56 bool was_npn_negotiated) { | 56 bool was_npn_negotiated) { |
57 if (capability_ == PIPELINE_INCAPABLE) { | 57 if (capability_ == INCAPABLE) { |
58 return NULL; | 58 return NULL; |
59 } | 59 } |
60 HttpPipelinedConnection* pipeline = factory_->CreateNewPipeline( | 60 HttpPipelinedConnection* pipeline = factory_->CreateNewPipeline( |
61 connection, this, used_ssl_config, used_proxy_info, net_log, | 61 connection, this, used_ssl_config, used_proxy_info, net_log, |
62 was_npn_negotiated); | 62 was_npn_negotiated); |
63 PipelineInfo info; | 63 PipelineInfo info; |
64 pipelines_.insert(std::make_pair(pipeline, info)); | 64 pipelines_.insert(std::make_pair(pipeline, info)); |
65 return pipeline->CreateNewStream(); | 65 return pipeline->CreateNewStream(); |
66 } | 66 } |
67 | 67 |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
117 } | 117 } |
118 } | 118 } |
119 | 119 |
120 void HttpPipelinedHostImpl::OnPipelineFeedback( | 120 void HttpPipelinedHostImpl::OnPipelineFeedback( |
121 HttpPipelinedConnection* pipeline, | 121 HttpPipelinedConnection* pipeline, |
122 HttpPipelinedConnection::Feedback feedback) { | 122 HttpPipelinedConnection::Feedback feedback) { |
123 CHECK(ContainsKey(pipelines_, pipeline)); | 123 CHECK(ContainsKey(pipelines_, pipeline)); |
124 switch (feedback) { | 124 switch (feedback) { |
125 case HttpPipelinedConnection::OK: | 125 case HttpPipelinedConnection::OK: |
126 ++pipelines_[pipeline].num_successes; | 126 ++pipelines_[pipeline].num_successes; |
127 if (capability_ == PIPELINE_UNKNOWN) { | 127 if (capability_ == UNKNOWN) { |
128 capability_ = PIPELINE_PROBABLY_CAPABLE; | 128 capability_ = PROBABLY_CAPABLE; |
129 NotifyAllPipelinesHaveCapacity(); | 129 NotifyAllPipelinesHaveCapacity(); |
130 } else if (capability_ == PIPELINE_PROBABLY_CAPABLE && | 130 } else if (capability_ == PROBABLY_CAPABLE && |
131 pipelines_[pipeline].num_successes >= | 131 pipelines_[pipeline].num_successes >= |
132 kNumKnownSuccessesThreshold) { | 132 kNumKnownSuccessesThreshold) { |
133 capability_ = PIPELINE_CAPABLE; | 133 capability_ = CAPABLE; |
134 delegate_->OnHostDeterminedCapability(this, PIPELINE_CAPABLE); | 134 delegate_->OnHostDeterminedCapability(this, CAPABLE); |
135 } | 135 } |
136 break; | 136 break; |
137 | 137 |
138 case HttpPipelinedConnection::PIPELINE_SOCKET_ERROR: | 138 case HttpPipelinedConnection::PIPELINE_SOCKET_ERROR: |
139 case HttpPipelinedConnection::OLD_HTTP_VERSION: | 139 case HttpPipelinedConnection::OLD_HTTP_VERSION: |
140 capability_ = PIPELINE_INCAPABLE; | 140 capability_ = INCAPABLE; |
141 delegate_->OnHostDeterminedCapability(this, PIPELINE_INCAPABLE); | 141 delegate_->OnHostDeterminedCapability(this, INCAPABLE); |
142 break; | 142 break; |
143 | 143 |
144 case HttpPipelinedConnection::MUST_CLOSE_CONNECTION: | 144 case HttpPipelinedConnection::MUST_CLOSE_CONNECTION: |
145 break; | 145 break; |
146 } | 146 } |
147 } | 147 } |
148 | 148 |
149 int HttpPipelinedHostImpl::GetPipelineCapacity() const { | 149 int HttpPipelinedHostImpl::GetPipelineCapacity() const { |
150 int capacity = 0; | 150 int capacity = 0; |
151 switch (capability_) { | 151 switch (capability_) { |
152 case PIPELINE_CAPABLE: | 152 case CAPABLE: |
153 case PIPELINE_PROBABLY_CAPABLE: | 153 case PROBABLY_CAPABLE: |
154 capacity = max_pipeline_depth(); | 154 capacity = max_pipeline_depth(); |
155 break; | 155 break; |
156 | 156 |
157 case PIPELINE_INCAPABLE: | 157 case INCAPABLE: |
158 CHECK(false); | 158 CHECK(false); |
159 | 159 |
160 case PIPELINE_UNKNOWN: | 160 case UNKNOWN: |
161 capacity = 1; | 161 capacity = 1; |
162 break; | 162 break; |
163 | 163 |
164 default: | 164 default: |
165 CHECK(false) << "Unkown pipeline capability: " << capability_; | 165 CHECK(false) << "Unkown pipeline capability: " << capability_; |
166 } | 166 } |
167 return capacity; | 167 return capacity; |
168 } | 168 } |
169 | 169 |
170 bool HttpPipelinedHostImpl::CanPipelineAcceptRequests( | 170 bool HttpPipelinedHostImpl::CanPipelineAcceptRequests( |
171 HttpPipelinedConnection* pipeline) const { | 171 HttpPipelinedConnection* pipeline) const { |
172 return capability_ != PIPELINE_INCAPABLE && | 172 return capability_ != INCAPABLE && |
173 pipeline->usable() && | 173 pipeline->usable() && |
174 pipeline->active() && | 174 pipeline->active() && |
175 pipeline->depth() < GetPipelineCapacity(); | 175 pipeline->depth() < GetPipelineCapacity(); |
176 } | 176 } |
177 | 177 |
178 void HttpPipelinedHostImpl::NotifyAllPipelinesHaveCapacity() { | 178 void HttpPipelinedHostImpl::NotifyAllPipelinesHaveCapacity() { |
179 // Calling OnPipelineHasCapacity() can have side effects that include | 179 // Calling OnPipelineHasCapacity() can have side effects that include |
180 // deleting and removing entries from |pipelines_|. | 180 // deleting and removing entries from |pipelines_|. |
181 PipelineInfoMap pipelines_to_notify = pipelines_; | 181 PipelineInfoMap pipelines_to_notify = pipelines_; |
182 for (PipelineInfoMap::iterator it = pipelines_to_notify.begin(); | 182 for (PipelineInfoMap::iterator it = pipelines_to_notify.begin(); |
183 it != pipelines_to_notify.end(); ++it) { | 183 it != pipelines_to_notify.end(); ++it) { |
184 if (pipelines_.find(it->first) != pipelines_.end()) { | 184 if (pipelines_.find(it->first) != pipelines_.end()) { |
185 OnPipelineHasCapacity(it->first); | 185 OnPipelineHasCapacity(it->first); |
186 } | 186 } |
187 } | 187 } |
188 } | 188 } |
189 | 189 |
190 HttpPipelinedHostImpl::PipelineInfo::PipelineInfo() | 190 HttpPipelinedHostImpl::PipelineInfo::PipelineInfo() |
191 : num_successes(0) { | 191 : num_successes(0) { |
192 } | 192 } |
193 | 193 |
194 } // namespace net | 194 } // namespace net |
OLD | NEW |