| 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 300 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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 alternative_service(alternate.protocol, |
| 322 alternate.protocol); | 322 server.host(), alternate.port); |
| 323 int count = ++broken_alternate_protocol_map_[entry]; | 323 int count = ++broken_alternate_protocol_map_[alternative_service]; |
| 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(alternative_service, 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 alternative_service( |
| 347 alternate_protocol.protocol); | 347 alternate_protocol.protocol, server.host(), alternate_protocol.port); |
| 348 return ContainsKey(broken_alternate_protocol_map_, entry); | 348 return ContainsKey(broken_alternate_protocol_map_, alternative_service); |
| 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 alternative_service( |
| 357 alternate_protocol.protocol); | 357 alternate_protocol.protocol, server.host(), alternate_protocol.port); |
| 358 broken_alternate_protocol_map_.erase(entry); | 358 broken_alternate_protocol_map_.erase(alternative_service); |
| 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& alternative_service = |
| 515 entry_with_time.broken_alternate_protocol_entry; | 515 entry_with_time.alternative_service; |
| 516 ClearAlternateProtocol(entry.server); | 516 ClearAlternateProtocol( |
| 517 HostPortPair(alternative_service.host, alternative_service.port)); |
| 517 broken_alternate_protocol_list_.pop_front(); | 518 broken_alternate_protocol_list_.pop_front(); |
| 518 } | 519 } |
| 519 ScheduleBrokenAlternateProtocolMappingsExpiration(); | 520 ScheduleBrokenAlternateProtocolMappingsExpiration(); |
| 520 } | 521 } |
| 521 | 522 |
| 522 void | 523 void |
| 523 HttpServerPropertiesImpl::ScheduleBrokenAlternateProtocolMappingsExpiration() { | 524 HttpServerPropertiesImpl::ScheduleBrokenAlternateProtocolMappingsExpiration() { |
| 524 if (broken_alternate_protocol_list_.empty()) { | 525 if (broken_alternate_protocol_list_.empty()) { |
| 525 return; | 526 return; |
| 526 } | 527 } |
| 527 base::TimeTicks now = base::TimeTicks::Now(); | 528 base::TimeTicks now = base::TimeTicks::Now(); |
| 528 base::TimeTicks when = broken_alternate_protocol_list_.front().when; | 529 base::TimeTicks when = broken_alternate_protocol_list_.front().when; |
| 529 base::TimeDelta delay = when > now ? when - now : base::TimeDelta(); | 530 base::TimeDelta delay = when > now ? when - now : base::TimeDelta(); |
| 530 base::MessageLoop::current()->PostDelayedTask( | 531 base::MessageLoop::current()->PostDelayedTask( |
| 531 FROM_HERE, | 532 FROM_HERE, |
| 532 base::Bind( | 533 base::Bind( |
| 533 &HttpServerPropertiesImpl::ExpireBrokenAlternateProtocolMappings, | 534 &HttpServerPropertiesImpl::ExpireBrokenAlternateProtocolMappings, |
| 534 weak_ptr_factory_.GetWeakPtr()), | 535 weak_ptr_factory_.GetWeakPtr()), |
| 535 delay); | 536 delay); |
| 536 } | 537 } |
| 537 | 538 |
| 538 } // namespace net | 539 } // namespace net |
| OLD | NEW |