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_server_properties_impl.h" | 5 #include "net/http/http_server_properties_impl.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
10 #include "base/message_loop/message_loop.h" | 10 #include "base/message_loop/message_loop.h" |
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
172 const HostPortPair& host_port_pair) { | 172 const HostPortPair& host_port_pair) { |
173 DCHECK(CalledOnValidThread()); | 173 DCHECK(CalledOnValidThread()); |
174 if (host_port_pair.host().empty()) | 174 if (host_port_pair.host().empty()) |
175 return false; | 175 return false; |
176 | 176 |
177 SpdyServerHostPortMap::iterator spdy_host_port = | 177 SpdyServerHostPortMap::iterator spdy_host_port = |
178 spdy_servers_map_.Get(host_port_pair.ToString()); | 178 spdy_servers_map_.Get(host_port_pair.ToString()); |
179 if (spdy_host_port != spdy_servers_map_.end() && spdy_host_port->second) | 179 if (spdy_host_port != spdy_servers_map_.end() && spdy_host_port->second) |
180 return true; | 180 return true; |
181 | 181 |
182 if (!HasAlternateProtocol(host_port_pair)) | 182 const AlternateProtocolInfo info = GetAlternateProtocol(host_port_pair); |
183 return false; | |
184 | |
185 AlternateProtocolInfo info = GetAlternateProtocol(host_port_pair); | |
186 return info.protocol == QUIC; | 183 return info.protocol == QUIC; |
187 } | 184 } |
188 | 185 |
189 void HttpServerPropertiesImpl::SetSupportsSpdy( | 186 void HttpServerPropertiesImpl::SetSupportsSpdy( |
190 const HostPortPair& host_port_pair, | 187 const HostPortPair& host_port_pair, |
191 bool support_spdy) { | 188 bool support_spdy) { |
192 DCHECK(CalledOnValidThread()); | 189 DCHECK(CalledOnValidThread()); |
193 if (host_port_pair.host().empty()) | 190 if (host_port_pair.host().empty()) |
194 return; | 191 return; |
195 | 192 |
(...skipping 25 matching lines...) Expand all Loading... | |
221 http11_servers_.insert(host_port_pair); | 218 http11_servers_.insert(host_port_pair); |
222 } | 219 } |
223 | 220 |
224 void HttpServerPropertiesImpl::MaybeForceHTTP11(const HostPortPair& server, | 221 void HttpServerPropertiesImpl::MaybeForceHTTP11(const HostPortPair& server, |
225 SSLConfig* ssl_config) { | 222 SSLConfig* ssl_config) { |
226 if (RequiresHTTP11(server)) { | 223 if (RequiresHTTP11(server)) { |
227 ForceHTTP11(ssl_config); | 224 ForceHTTP11(ssl_config); |
228 } | 225 } |
229 } | 226 } |
230 | 227 |
231 bool HttpServerPropertiesImpl::HasAlternateProtocol( | |
232 const HostPortPair& server) { | |
233 if (g_forced_alternate_protocol) | |
234 return true; | |
235 AlternateProtocolMap::const_iterator it = | |
236 GetAlternateProtocolIterator(server); | |
237 return it != alternate_protocol_map_.end() && | |
238 it->second.probability >= alternate_protocol_probability_threshold_; | |
239 } | |
240 | |
241 std::string HttpServerPropertiesImpl::GetCanonicalSuffix( | 228 std::string HttpServerPropertiesImpl::GetCanonicalSuffix( |
242 const std::string& host) { | 229 const std::string& host) { |
243 // If this host ends with a canonical suffix, then return the canonical | 230 // If this host ends with a canonical suffix, then return the canonical |
244 // suffix. | 231 // suffix. |
245 for (size_t i = 0; i < canonical_suffixes_.size(); ++i) { | 232 for (size_t i = 0; i < canonical_suffixes_.size(); ++i) { |
246 std::string canonical_suffix = canonical_suffixes_[i]; | 233 std::string canonical_suffix = canonical_suffixes_[i]; |
247 if (EndsWith(host, canonical_suffixes_[i], false)) { | 234 if (EndsWith(host, canonical_suffixes_[i], false)) { |
248 return canonical_suffix; | 235 return canonical_suffix; |
249 } | 236 } |
250 } | 237 } |
251 return std::string(); | 238 return std::string(); |
252 } | 239 } |
253 | 240 |
254 AlternateProtocolInfo | 241 AlternateProtocolInfo HttpServerPropertiesImpl::GetAlternateProtocol( |
255 HttpServerPropertiesImpl::GetAlternateProtocol( | |
256 const HostPortPair& server) { | 242 const HostPortPair& server) { |
257 DCHECK(HasAlternateProtocol(server)); | |
258 | |
259 AlternateProtocolMap::const_iterator it = | 243 AlternateProtocolMap::const_iterator it = |
260 GetAlternateProtocolIterator(server); | 244 GetAlternateProtocolIterator(server); |
261 if (it != alternate_protocol_map_.end()) | 245 if (it != alternate_protocol_map_.end() && |
Bence
2015/02/03 20:43:20
Note that previously GetAlternateProtocol() was ab
| |
246 it->second.probability >= alternate_protocol_probability_threshold_) | |
262 return it->second; | 247 return it->second; |
263 | 248 |
264 // We must be forcing an alternate. | 249 if (g_forced_alternate_protocol) |
265 DCHECK(g_forced_alternate_protocol); | 250 return *g_forced_alternate_protocol; |
266 return *g_forced_alternate_protocol; | 251 |
252 AlternateProtocolInfo uninitialized_alternate_protocol; | |
253 return uninitialized_alternate_protocol; | |
267 } | 254 } |
268 | 255 |
269 void HttpServerPropertiesImpl::SetAlternateProtocol( | 256 void HttpServerPropertiesImpl::SetAlternateProtocol( |
270 const HostPortPair& server, | 257 const HostPortPair& server, |
271 uint16 alternate_port, | 258 uint16 alternate_port, |
272 AlternateProtocol alternate_protocol, | 259 AlternateProtocol alternate_protocol, |
273 double alternate_probability) { | 260 double alternate_probability) { |
274 | 261 |
275 AlternateProtocolInfo alternate(alternate_port, | 262 AlternateProtocolInfo alternate(alternate_port, |
276 alternate_protocol, | 263 alternate_protocol, |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
315 HostPortPair canonical_host(canonical_suffix, server.port()); | 302 HostPortPair canonical_host(canonical_suffix, server.port()); |
316 canonical_host_to_origin_map_[canonical_host] = server; | 303 canonical_host_to_origin_map_[canonical_host] = server; |
317 break; | 304 break; |
318 } | 305 } |
319 } | 306 } |
320 } | 307 } |
321 | 308 |
322 void HttpServerPropertiesImpl::SetBrokenAlternateProtocol( | 309 void HttpServerPropertiesImpl::SetBrokenAlternateProtocol( |
323 const HostPortPair& server) { | 310 const HostPortPair& server) { |
324 AlternateProtocolMap::iterator it = alternate_protocol_map_.Get(server); | 311 AlternateProtocolMap::iterator it = alternate_protocol_map_.Get(server); |
312 const AlternateProtocolInfo alternate = GetAlternateProtocol(server); | |
325 if (it == alternate_protocol_map_.end()) { | 313 if (it == alternate_protocol_map_.end()) { |
326 if (!HasAlternateProtocol(server)) { | 314 if (alternate.protocol == UNINITIALIZED_ALTERNATE_PROTOCOL) { |
327 LOG(DFATAL) << "Trying to mark unknown alternate protocol broken."; | 315 LOG(DFATAL) << "Trying to mark unknown alternate protocol broken."; |
328 return; | 316 return; |
329 } | 317 } |
330 // This server's alternate protocol information is coming from a canonical | 318 // This server's alternate protocol information is coming from a canonical |
331 // server. Add an entry in the map for this server explicitly so that | 319 // server. Add an entry in the map for this server explicitly so that |
332 // it can be marked as broken. | 320 // it can be marked as broken. |
333 it = alternate_protocol_map_.Put(server, GetAlternateProtocol(server)); | 321 it = alternate_protocol_map_.Put(server, alternate); |
334 } | 322 } |
335 it->second.is_broken = true; | 323 it->second.is_broken = true; |
336 int count = ++broken_alternate_protocol_map_[server]; | 324 int count = ++broken_alternate_protocol_map_[server]; |
337 base::TimeDelta delay = | 325 base::TimeDelta delay = |
338 base::TimeDelta::FromSeconds(kBrokenAlternateProtocolDelaySecs); | 326 base::TimeDelta::FromSeconds(kBrokenAlternateProtocolDelaySecs); |
339 BrokenAlternateProtocolEntry entry; | 327 BrokenAlternateProtocolEntry entry; |
340 entry.server = server; | 328 entry.server = server; |
341 entry.when = base::TimeTicks::Now() + delay * (1 << (count - 1)); | 329 entry.when = base::TimeTicks::Now() + delay * (1 << (count - 1)); |
342 broken_alternate_protocol_list_.push_back(entry); | 330 broken_alternate_protocol_list_.push_back(entry); |
343 | 331 |
(...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
535 base::TimeDelta delay = when > now ? when - now : base::TimeDelta(); | 523 base::TimeDelta delay = when > now ? when - now : base::TimeDelta(); |
536 base::MessageLoop::current()->PostDelayedTask( | 524 base::MessageLoop::current()->PostDelayedTask( |
537 FROM_HERE, | 525 FROM_HERE, |
538 base::Bind( | 526 base::Bind( |
539 &HttpServerPropertiesImpl::ExpireBrokenAlternateProtocolMappings, | 527 &HttpServerPropertiesImpl::ExpireBrokenAlternateProtocolMappings, |
540 weak_ptr_factory_.GetWeakPtr()), | 528 weak_ptr_factory_.GetWeakPtr()), |
541 delay); | 529 delay); |
542 } | 530 } |
543 | 531 |
544 } // namespace net | 532 } // namespace net |
OLD | NEW |