Chromium Code Reviews| 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 286 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 297 std::string canonical_suffix = canonical_suffixes_[i]; | 297 std::string canonical_suffix = canonical_suffixes_[i]; |
| 298 if (EndsWith(server.host(), canonical_suffixes_[i], false)) { | 298 if (EndsWith(server.host(), canonical_suffixes_[i], false)) { |
| 299 HostPortPair canonical_host(canonical_suffix, server.port()); | 299 HostPortPair canonical_host(canonical_suffix, server.port()); |
| 300 canonical_host_to_origin_map_[canonical_host] = server; | 300 canonical_host_to_origin_map_[canonical_host] = server; |
| 301 break; | 301 break; |
| 302 } | 302 } |
| 303 } | 303 } |
| 304 } | 304 } |
| 305 | 305 |
| 306 void HttpServerPropertiesImpl::SetBrokenAlternateProtocol( | 306 void HttpServerPropertiesImpl::SetBrokenAlternateProtocol( |
| 307 const HostPortPair& server) { | 307 const HostPortPair& server) { |
|
Ryan Hamilton
2015/03/06 23:01:12
To be clear, the way |server| is *currently* being
Bence
2015/03/08 18:09:04
Yes, it is exactly the case. It will take an Alte
| |
| 308 AlternateProtocolMap::iterator it = alternate_protocol_map_.Get(server); | 308 AlternateProtocolMap::iterator it = alternate_protocol_map_.Get(server); |
| 309 const AlternateProtocolInfo alternate = GetAlternateProtocol(server); | 309 const AlternateProtocolInfo alternate = GetAlternateProtocol(server); |
| 310 if (it == alternate_protocol_map_.end()) { | 310 if (it == alternate_protocol_map_.end()) { |
| 311 if (alternate.protocol == UNINITIALIZED_ALTERNATE_PROTOCOL) { | 311 if (alternate.protocol == UNINITIALIZED_ALTERNATE_PROTOCOL) { |
| 312 LOG(DFATAL) << "Trying to mark unknown alternate protocol broken."; | 312 LOG(DFATAL) << "Trying to mark unknown alternate protocol broken."; |
| 313 return; | 313 return; |
| 314 } | 314 } |
| 315 // This server's alternate protocol information is coming from a canonical | 315 // This server's alternate protocol information is coming from a canonical |
| 316 // server. Add an entry in the map for this server explicitly so that | 316 // server. Add an entry in the map for this server explicitly so that |
| 317 // it can be marked as broken. | 317 // it can be marked as broken. |
| 318 it = alternate_protocol_map_.Put(server, alternate); | 318 it = alternate_protocol_map_.Put(server, alternate); |
| 319 } | 319 } |
| 320 it->second.is_broken = true; | 320 it->second.is_broken = true; |
| 321 const BrokenAlternateProtocolEntry entry(server, alternate.port, | 321 const AlternativeService altsvc(alternate.protocol, server.host(), |
|
Ryan Hamilton
2015/03/06 23:01:12
same comment here about abbreviations.
Bence
2015/03/08 18:09:04
Same reply here about abbreviations.
| |
| 322 alternate.protocol); | 322 alternate.port); |
| 323 int count = ++broken_alternate_protocol_map_[entry]; | 323 int count = ++broken_alternate_protocol_map_[altsvc]; |
| 324 base::TimeDelta delay = | 324 base::TimeDelta delay = |
| 325 base::TimeDelta::FromSeconds(kBrokenAlternateProtocolDelaySecs); | 325 base::TimeDelta::FromSeconds(kBrokenAlternateProtocolDelaySecs); |
| 326 base::TimeTicks when = base::TimeTicks::Now() + delay * (1 << (count - 1)); | 326 base::TimeTicks when = base::TimeTicks::Now() + delay * (1 << (count - 1)); |
| 327 broken_alternate_protocol_list_.push_back( | 327 broken_alternate_protocol_list_.push_back( |
| 328 BrokenAlternateProtocolEntryWithTime(entry, when)); | 328 BrokenAlternateProtocolEntryWithTime(altsvc, when)); |
| 329 | 329 |
| 330 // Do not leave this host as canonical so that we don't infer the other | 330 // Do not leave this host as canonical so that we don't infer the other |
| 331 // hosts are also broken without testing them first. | 331 // hosts are also broken without testing them first. |
| 332 RemoveCanonicalHost(server); | 332 RemoveCanonicalHost(server); |
| 333 | 333 |
| 334 // If this is the only entry in the list, schedule an expiration task. | 334 // If this is the only entry in the list, schedule an expiration task. |
| 335 // Otherwise it will be rescheduled automatically when the pending task runs. | 335 // Otherwise it will be rescheduled automatically when the pending task runs. |
| 336 if (broken_alternate_protocol_list_.size() == 1) { | 336 if (broken_alternate_protocol_list_.size() == 1) { |
| 337 ScheduleBrokenAlternateProtocolMappingsExpiration(); | 337 ScheduleBrokenAlternateProtocolMappingsExpiration(); |
| 338 } | 338 } |
| 339 } | 339 } |
| 340 | 340 |
| 341 bool HttpServerPropertiesImpl::WasAlternateProtocolRecentlyBroken( | 341 bool HttpServerPropertiesImpl::WasAlternateProtocolRecentlyBroken( |
| 342 const HostPortPair& server) { | 342 const HostPortPair& server) { |
| 343 const AlternateProtocolInfo alternate_protocol = GetAlternateProtocol(server); | 343 const AlternateProtocolInfo alternate_protocol = GetAlternateProtocol(server); |
| 344 if (alternate_protocol.protocol == UNINITIALIZED_ALTERNATE_PROTOCOL) | 344 if (alternate_protocol.protocol == UNINITIALIZED_ALTERNATE_PROTOCOL) |
| 345 return false; | 345 return false; |
| 346 const BrokenAlternateProtocolEntry entry(server, alternate_protocol.port, | 346 const AlternativeService altsvc(alternate_protocol.protocol, server.host(), |
| 347 alternate_protocol.protocol); | 347 alternate_protocol.port); |
| 348 return ContainsKey(broken_alternate_protocol_map_, entry); | 348 return ContainsKey(broken_alternate_protocol_map_, altsvc); |
| 349 } | 349 } |
| 350 | 350 |
| 351 void HttpServerPropertiesImpl::ConfirmAlternateProtocol( | 351 void HttpServerPropertiesImpl::ConfirmAlternateProtocol( |
| 352 const HostPortPair& server) { | 352 const HostPortPair& server) { |
| 353 const AlternateProtocolInfo alternate_protocol = GetAlternateProtocol(server); | 353 const AlternateProtocolInfo alternate_protocol = GetAlternateProtocol(server); |
| 354 if (alternate_protocol.protocol == UNINITIALIZED_ALTERNATE_PROTOCOL) | 354 if (alternate_protocol.protocol == UNINITIALIZED_ALTERNATE_PROTOCOL) |
| 355 return; | 355 return; |
| 356 const BrokenAlternateProtocolEntry entry(server, alternate_protocol.port, | 356 const AlternativeService altsvc(alternate_protocol.protocol, server.host(), |
| 357 alternate_protocol.protocol); | 357 alternate_protocol.port); |
| 358 broken_alternate_protocol_map_.erase(entry); | 358 broken_alternate_protocol_map_.erase(altsvc); |
| 359 } | 359 } |
| 360 | 360 |
| 361 void HttpServerPropertiesImpl::ClearAlternateProtocol( | 361 void HttpServerPropertiesImpl::ClearAlternateProtocol( |
| 362 const HostPortPair& server) { | 362 const HostPortPair& server) { |
| 363 AlternateProtocolMap::iterator it = alternate_protocol_map_.Peek(server); | 363 AlternateProtocolMap::iterator it = alternate_protocol_map_.Peek(server); |
| 364 if (it != alternate_protocol_map_.end()) | 364 if (it != alternate_protocol_map_.end()) |
| 365 alternate_protocol_map_.Erase(it); | 365 alternate_protocol_map_.Erase(it); |
| 366 | 366 |
| 367 RemoveCanonicalHost(server); | 367 RemoveCanonicalHost(server); |
| 368 } | 368 } |
| (...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 504 | 504 |
| 505 void HttpServerPropertiesImpl::ExpireBrokenAlternateProtocolMappings() { | 505 void HttpServerPropertiesImpl::ExpireBrokenAlternateProtocolMappings() { |
| 506 base::TimeTicks now = base::TimeTicks::Now(); | 506 base::TimeTicks now = base::TimeTicks::Now(); |
| 507 while (!broken_alternate_protocol_list_.empty()) { | 507 while (!broken_alternate_protocol_list_.empty()) { |
| 508 BrokenAlternateProtocolEntryWithTime entry_with_time = | 508 BrokenAlternateProtocolEntryWithTime entry_with_time = |
| 509 broken_alternate_protocol_list_.front(); | 509 broken_alternate_protocol_list_.front(); |
| 510 if (now < entry_with_time.when) { | 510 if (now < entry_with_time.when) { |
| 511 break; | 511 break; |
| 512 } | 512 } |
| 513 | 513 |
| 514 const BrokenAlternateProtocolEntry& entry = | 514 const AlternativeService& altsvc = entry_with_time.altsvc; |
| 515 entry_with_time.broken_alternate_protocol_entry; | 515 ClearAlternateProtocol(HostPortPair(altsvc.host, altsvc.port)); |
| 516 ClearAlternateProtocol(entry.server); | |
| 517 broken_alternate_protocol_list_.pop_front(); | 516 broken_alternate_protocol_list_.pop_front(); |
| 518 } | 517 } |
| 519 ScheduleBrokenAlternateProtocolMappingsExpiration(); | 518 ScheduleBrokenAlternateProtocolMappingsExpiration(); |
| 520 } | 519 } |
| 521 | 520 |
| 522 void | 521 void |
| 523 HttpServerPropertiesImpl::ScheduleBrokenAlternateProtocolMappingsExpiration() { | 522 HttpServerPropertiesImpl::ScheduleBrokenAlternateProtocolMappingsExpiration() { |
| 524 if (broken_alternate_protocol_list_.empty()) { | 523 if (broken_alternate_protocol_list_.empty()) { |
| 525 return; | 524 return; |
| 526 } | 525 } |
| 527 base::TimeTicks now = base::TimeTicks::Now(); | 526 base::TimeTicks now = base::TimeTicks::Now(); |
| 528 base::TimeTicks when = broken_alternate_protocol_list_.front().when; | 527 base::TimeTicks when = broken_alternate_protocol_list_.front().when; |
| 529 base::TimeDelta delay = when > now ? when - now : base::TimeDelta(); | 528 base::TimeDelta delay = when > now ? when - now : base::TimeDelta(); |
| 530 base::MessageLoop::current()->PostDelayedTask( | 529 base::MessageLoop::current()->PostDelayedTask( |
| 531 FROM_HERE, | 530 FROM_HERE, |
| 532 base::Bind( | 531 base::Bind( |
| 533 &HttpServerPropertiesImpl::ExpireBrokenAlternateProtocolMappings, | 532 &HttpServerPropertiesImpl::ExpireBrokenAlternateProtocolMappings, |
| 534 weak_ptr_factory_.GetWeakPtr()), | 533 weak_ptr_factory_.GetWeakPtr()), |
| 535 delay); | 534 delay); |
| 536 } | 535 } |
| 537 | 536 |
| 538 } // namespace net | 537 } // namespace net |
| OLD | NEW |