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 Capability capability) | 37 HttpPipelinedHostCapability 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_ == INCAPABLE) { | 57 if (capability_ == PIPELINE_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 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
106 if (pipelines_.empty()) { | 106 if (pipelines_.empty()) { |
107 delegate_->OnHostIdle(this); | 107 delegate_->OnHostIdle(this); |
108 // WARNING: We'll probably be deleted here. | 108 // WARNING: We'll probably be deleted here. |
109 } | 109 } |
110 } | 110 } |
111 | 111 |
112 void HttpPipelinedHostImpl::OnPipelineHasCapacity( | 112 void HttpPipelinedHostImpl::OnPipelineHasCapacity( |
113 HttpPipelinedConnection* pipeline) { | 113 HttpPipelinedConnection* pipeline) { |
114 CHECK(ContainsKey(pipelines_, pipeline)); | 114 CHECK(ContainsKey(pipelines_, pipeline)); |
115 if (pipeline->usable() && | 115 if (pipeline->usable() && |
116 capability_ != INCAPABLE && | 116 capability_ != PIPELINE_INCAPABLE && |
117 pipeline->depth() < GetPipelineCapacity()) { | 117 pipeline->depth() < GetPipelineCapacity()) { |
118 delegate_->OnHostHasAdditionalCapacity(this); | 118 delegate_->OnHostHasAdditionalCapacity(this); |
119 } | 119 } |
120 if (!pipeline->depth()) { | 120 if (!pipeline->depth()) { |
121 OnPipelineEmpty(pipeline); | 121 OnPipelineEmpty(pipeline); |
122 // WARNING: We might be deleted here. | 122 // WARNING: We might be deleted here. |
123 } | 123 } |
124 } | 124 } |
125 | 125 |
126 void HttpPipelinedHostImpl::OnPipelineFeedback( | 126 void HttpPipelinedHostImpl::OnPipelineFeedback( |
127 HttpPipelinedConnection* pipeline, | 127 HttpPipelinedConnection* pipeline, |
128 HttpPipelinedConnection::Feedback feedback) { | 128 HttpPipelinedConnection::Feedback feedback) { |
129 CHECK(ContainsKey(pipelines_, pipeline)); | 129 CHECK(ContainsKey(pipelines_, pipeline)); |
130 switch (feedback) { | 130 switch (feedback) { |
131 case HttpPipelinedConnection::OK: | 131 case HttpPipelinedConnection::OK: |
132 ++pipelines_[pipeline].num_successes; | 132 ++pipelines_[pipeline].num_successes; |
133 if (capability_ == UNKNOWN) { | 133 if (capability_ == PIPELINE_UNKNOWN) { |
134 capability_ = PROBABLY_CAPABLE; | 134 capability_ = PIPELINE_PROBABLY_CAPABLE; |
135 for (PipelineInfoMap::iterator it = pipelines_.begin(); | 135 for (PipelineInfoMap::iterator it = pipelines_.begin(); |
136 it != pipelines_.end(); ++it) { | 136 it != pipelines_.end(); ++it) { |
137 OnPipelineHasCapacity(it->first); | 137 OnPipelineHasCapacity(it->first); |
138 } | 138 } |
139 } else if (capability_ == PROBABLY_CAPABLE && | 139 } else if (capability_ == PIPELINE_PROBABLY_CAPABLE && |
140 pipelines_[pipeline].num_successes >= | 140 pipelines_[pipeline].num_successes >= |
141 kNumKnownSuccessesThreshold) { | 141 kNumKnownSuccessesThreshold) { |
142 capability_ = CAPABLE; | 142 capability_ = PIPELINE_CAPABLE; |
143 delegate_->OnHostDeterminedCapability(this, CAPABLE); | 143 delegate_->OnHostDeterminedCapability(this, PIPELINE_CAPABLE); |
144 } | 144 } |
145 break; | 145 break; |
146 | 146 |
147 case HttpPipelinedConnection::PIPELINE_SOCKET_ERROR: | 147 case HttpPipelinedConnection::PIPELINE_SOCKET_ERROR: |
148 case HttpPipelinedConnection::OLD_HTTP_VERSION: | 148 case HttpPipelinedConnection::OLD_HTTP_VERSION: |
149 capability_ = INCAPABLE; | 149 capability_ = PIPELINE_INCAPABLE; |
150 delegate_->OnHostDeterminedCapability(this, INCAPABLE); | 150 delegate_->OnHostDeterminedCapability(this, PIPELINE_INCAPABLE); |
151 break; | 151 break; |
152 | 152 |
153 case HttpPipelinedConnection::MUST_CLOSE_CONNECTION: | 153 case HttpPipelinedConnection::MUST_CLOSE_CONNECTION: |
154 break; | 154 break; |
155 } | 155 } |
156 } | 156 } |
157 | 157 |
158 int HttpPipelinedHostImpl::GetPipelineCapacity() const { | 158 int HttpPipelinedHostImpl::GetPipelineCapacity() const { |
159 int capacity = 0; | 159 int capacity = 0; |
160 switch (capability_) { | 160 switch (capability_) { |
161 case CAPABLE: | 161 case PIPELINE_CAPABLE: |
162 case PROBABLY_CAPABLE: | 162 case PIPELINE_PROBABLY_CAPABLE: |
163 capacity = max_pipeline_depth(); | 163 capacity = max_pipeline_depth(); |
164 break; | 164 break; |
165 | 165 |
166 case INCAPABLE: | 166 case PIPELINE_INCAPABLE: |
167 CHECK(false); | 167 CHECK(false); |
168 | 168 |
169 case UNKNOWN: | 169 case PIPELINE_UNKNOWN: |
170 capacity = 1; | 170 capacity = 1; |
171 break; | 171 break; |
172 | 172 |
173 default: | 173 default: |
174 CHECK(false) << "Unkown pipeline capability: " << capability_; | 174 CHECK(false) << "Unkown pipeline capability: " << capability_; |
175 } | 175 } |
176 return capacity; | 176 return capacity; |
177 } | 177 } |
178 | 178 |
179 HttpPipelinedHostImpl::PipelineInfo::PipelineInfo() | 179 HttpPipelinedHostImpl::PipelineInfo::PipelineInfo() |
180 : num_successes(0) { | 180 : num_successes(0) { |
181 } | 181 } |
182 | 182 |
183 } // namespace net | 183 } // namespace net |
OLD | NEW |