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 209 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
220 SSLConfig* ssl_config) { | 220 SSLConfig* ssl_config) { |
221 if (RequiresHTTP11(server)) { | 221 if (RequiresHTTP11(server)) { |
222 ForceHTTP11(ssl_config); | 222 ForceHTTP11(ssl_config); |
223 } | 223 } |
224 } | 224 } |
225 | 225 |
226 bool HttpServerPropertiesImpl::HasAlternateProtocol( | 226 bool HttpServerPropertiesImpl::HasAlternateProtocol( |
227 const HostPortPair& server) { | 227 const HostPortPair& server) { |
228 if (g_forced_alternate_protocol) | 228 if (g_forced_alternate_protocol) |
229 return true; | 229 return true; |
230 AlternateProtocolMap::const_iterator it = alternate_protocol_map_.Get(server); | 230 AlternateProtocolMap::const_iterator it = |
231 if (it != alternate_protocol_map_.end()) | 231 GetAlternateProtocolIterator(server); |
232 return it->second.probability >= alternate_protocol_probability_threshold_; | 232 return it != alternate_protocol_map_.end() && |
233 | 233 it->second.probability >= alternate_protocol_probability_threshold_; |
234 auto canonical = GetCanonicalHost(server); | |
235 if (canonical == canonical_host_to_origin_map_.end() || | |
236 canonical->second.Equals(server)) { | |
237 return false; | |
238 } | |
239 | |
240 return HasAlternateProtocol(canonical->second); | |
241 } | 234 } |
242 | 235 |
243 std::string HttpServerPropertiesImpl::GetCanonicalSuffix( | 236 std::string HttpServerPropertiesImpl::GetCanonicalSuffix( |
244 const HostPortPair& server) { | 237 const HostPortPair& server) { |
245 // If this host ends with a canonical suffix, then return the canonical | 238 // If this host ends with a canonical suffix, then return the canonical |
246 // suffix. | 239 // suffix. |
247 for (size_t i = 0; i < canonical_suffixes_.size(); ++i) { | 240 for (size_t i = 0; i < canonical_suffixes_.size(); ++i) { |
248 std::string canonical_suffix = canonical_suffixes_[i]; | 241 std::string canonical_suffix = canonical_suffixes_[i]; |
249 if (EndsWith(server.host(), canonical_suffixes_[i], false)) { | 242 if (EndsWith(server.host(), canonical_suffixes_[i], false)) { |
250 return canonical_suffix; | 243 return canonical_suffix; |
251 } | 244 } |
252 } | 245 } |
253 return std::string(); | 246 return std::string(); |
254 } | 247 } |
255 | 248 |
256 AlternateProtocolInfo | 249 AlternateProtocolInfo |
257 HttpServerPropertiesImpl::GetAlternateProtocol( | 250 HttpServerPropertiesImpl::GetAlternateProtocol( |
258 const HostPortPair& server) { | 251 const HostPortPair& server) { |
259 DCHECK(HasAlternateProtocol(server)); | 252 DCHECK(HasAlternateProtocol(server)); |
260 | 253 |
261 // First check the map. | 254 AlternateProtocolMap::const_iterator it = |
262 AlternateProtocolMap::iterator it = alternate_protocol_map_.Get(server); | 255 GetAlternateProtocolIterator(server); |
263 if (it != alternate_protocol_map_.end()) | 256 if (it != alternate_protocol_map_.end()) |
264 return it->second; | 257 return it->second; |
265 | 258 |
266 // Next check the canonical host. | |
267 CanonicalHostMap::const_iterator canonical_host = GetCanonicalHost(server); | |
268 if (canonical_host != canonical_host_to_origin_map_.end()) | |
269 return alternate_protocol_map_.Get(canonical_host->second)->second; | |
270 | |
271 // We must be forcing an alternate. | 259 // We must be forcing an alternate. |
272 DCHECK(g_forced_alternate_protocol); | 260 DCHECK(g_forced_alternate_protocol); |
273 return *g_forced_alternate_protocol; | 261 return *g_forced_alternate_protocol; |
274 } | 262 } |
275 | 263 |
276 void HttpServerPropertiesImpl::SetAlternateProtocol( | 264 void HttpServerPropertiesImpl::SetAlternateProtocol( |
277 const HostPortPair& server, | 265 const HostPortPair& server, |
278 uint16 alternate_port, | 266 uint16 alternate_port, |
279 AlternateProtocol alternate_protocol, | 267 AlternateProtocol alternate_protocol, |
280 double alternate_probability) { | 268 double alternate_probability) { |
281 | 269 |
282 AlternateProtocolInfo alternate(alternate_port, | 270 AlternateProtocolInfo alternate(alternate_port, |
283 alternate_protocol, | 271 alternate_protocol, |
284 alternate_probability); | 272 alternate_probability); |
285 if (HasAlternateProtocol(server)) { | 273 AlternateProtocolMap::const_iterator it = |
286 const AlternateProtocolInfo existing_alternate = | 274 GetAlternateProtocolIterator(server); |
287 GetAlternateProtocol(server); | 275 if (it != alternate_protocol_map_.end()) { |
| 276 const AlternateProtocolInfo existing_alternate = it->second; |
288 | 277 |
289 if (existing_alternate.is_broken) { | 278 if (existing_alternate.is_broken) { |
290 DVLOG(1) << "Ignore alternate protocol since it's known to be broken."; | 279 DVLOG(1) << "Ignore alternate protocol since it's known to be broken."; |
291 return; | 280 return; |
292 } | 281 } |
293 | 282 |
294 if (!existing_alternate.Equals(alternate)) { | 283 if (!existing_alternate.Equals(alternate)) { |
295 LOG(WARNING) << "Changing the alternate protocol for: " | 284 LOG(WARNING) << "Changing the alternate protocol for: " |
296 << server.ToString() | 285 << server.ToString() |
297 << " from [Port: " << existing_alternate.port | 286 << " from [Port: " << existing_alternate.port |
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
471 const ServerNetworkStatsMap& | 460 const ServerNetworkStatsMap& |
472 HttpServerPropertiesImpl::server_network_stats_map() const { | 461 HttpServerPropertiesImpl::server_network_stats_map() const { |
473 return server_network_stats_map_; | 462 return server_network_stats_map_; |
474 } | 463 } |
475 | 464 |
476 void HttpServerPropertiesImpl::SetAlternateProtocolProbabilityThreshold( | 465 void HttpServerPropertiesImpl::SetAlternateProtocolProbabilityThreshold( |
477 double threshold) { | 466 double threshold) { |
478 alternate_protocol_probability_threshold_ = threshold; | 467 alternate_protocol_probability_threshold_ = threshold; |
479 } | 468 } |
480 | 469 |
| 470 AlternateProtocolMap::const_iterator |
| 471 HttpServerPropertiesImpl::GetAlternateProtocolIterator( |
| 472 const HostPortPair& server) { |
| 473 AlternateProtocolMap::const_iterator it = alternate_protocol_map_.Get(server); |
| 474 if (it != alternate_protocol_map_.end()) |
| 475 return it; |
| 476 |
| 477 CanonicalHostMap::const_iterator canonical = GetCanonicalHost(server); |
| 478 if (canonical != canonical_host_to_origin_map_.end()) |
| 479 return alternate_protocol_map_.Get(canonical->second); |
| 480 |
| 481 return alternate_protocol_map_.end(); |
| 482 } |
| 483 |
481 HttpServerPropertiesImpl::CanonicalHostMap::const_iterator | 484 HttpServerPropertiesImpl::CanonicalHostMap::const_iterator |
482 HttpServerPropertiesImpl::GetCanonicalHost(HostPortPair server) const { | 485 HttpServerPropertiesImpl::GetCanonicalHost(HostPortPair server) const { |
483 for (size_t i = 0; i < canonical_suffixes_.size(); ++i) { | 486 for (size_t i = 0; i < canonical_suffixes_.size(); ++i) { |
484 std::string canonical_suffix = canonical_suffixes_[i]; | 487 std::string canonical_suffix = canonical_suffixes_[i]; |
485 if (EndsWith(server.host(), canonical_suffixes_[i], false)) { | 488 if (EndsWith(server.host(), canonical_suffixes_[i], false)) { |
486 HostPortPair canonical_host(canonical_suffix, server.port()); | 489 HostPortPair canonical_host(canonical_suffix, server.port()); |
487 return canonical_host_to_origin_map_.find(canonical_host); | 490 return canonical_host_to_origin_map_.find(canonical_host); |
488 } | 491 } |
489 } | 492 } |
490 | 493 |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
528 base::TimeDelta delay = when > now ? when - now : base::TimeDelta(); | 531 base::TimeDelta delay = when > now ? when - now : base::TimeDelta(); |
529 base::MessageLoop::current()->PostDelayedTask( | 532 base::MessageLoop::current()->PostDelayedTask( |
530 FROM_HERE, | 533 FROM_HERE, |
531 base::Bind( | 534 base::Bind( |
532 &HttpServerPropertiesImpl::ExpireBrokenAlternateProtocolMappings, | 535 &HttpServerPropertiesImpl::ExpireBrokenAlternateProtocolMappings, |
533 weak_ptr_factory_.GetWeakPtr()), | 536 weak_ptr_factory_.GetWeakPtr()), |
534 delay); | 537 delay); |
535 } | 538 } |
536 | 539 |
537 } // namespace net | 540 } // namespace net |
OLD | NEW |