Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(293)

Side by Side Diff: net/http/http_pipelined_host_impl.cc

Issue 8770035: Save pipelining capabilities for the most used hosts between sessions. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Merged Created 9 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « net/http/http_pipelined_host_impl.h ('k') | net/http/http_pipelined_host_impl_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
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_ == UNKNOWN) { 127 if (capability_ == PIPELINE_UNKNOWN) {
128 capability_ = PROBABLY_CAPABLE; 128 capability_ = PIPELINE_PROBABLY_CAPABLE;
129 NotifyAllPipelinesHaveCapacity(); 129 NotifyAllPipelinesHaveCapacity();
130 } else if (capability_ == PROBABLY_CAPABLE && 130 } else if (capability_ == PIPELINE_PROBABLY_CAPABLE &&
131 pipelines_[pipeline].num_successes >= 131 pipelines_[pipeline].num_successes >=
132 kNumKnownSuccessesThreshold) { 132 kNumKnownSuccessesThreshold) {
133 capability_ = CAPABLE; 133 capability_ = PIPELINE_CAPABLE;
134 delegate_->OnHostDeterminedCapability(this, CAPABLE); 134 delegate_->OnHostDeterminedCapability(this, PIPELINE_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_ = INCAPABLE; 140 capability_ = PIPELINE_INCAPABLE;
141 delegate_->OnHostDeterminedCapability(this, INCAPABLE); 141 delegate_->OnHostDeterminedCapability(this, PIPELINE_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 CAPABLE: 152 case PIPELINE_CAPABLE:
153 case PROBABLY_CAPABLE: 153 case PIPELINE_PROBABLY_CAPABLE:
154 capacity = max_pipeline_depth(); 154 capacity = max_pipeline_depth();
155 break; 155 break;
156 156
157 case INCAPABLE: 157 case PIPELINE_INCAPABLE:
158 CHECK(false); 158 CHECK(false);
159 159
160 case UNKNOWN: 160 case PIPELINE_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_ != INCAPABLE && 172 return capability_ != PIPELINE_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
OLDNEW
« no previous file with comments | « net/http/http_pipelined_host_impl.h ('k') | net/http/http_pipelined_host_impl_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698