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

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

Issue 888943003: Add AlternateProtocol to broken_altproto_list_ and map_. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase. Created 5 years, 10 months 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
« no previous file with comments | « net/http/http_server_properties_impl.h ('k') | no next file » | 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) 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 303 matching lines...) Expand 10 before | Expand all | Expand 10 after
314 if (alternate.protocol == UNINITIALIZED_ALTERNATE_PROTOCOL) { 314 if (alternate.protocol == UNINITIALIZED_ALTERNATE_PROTOCOL) {
315 LOG(DFATAL) << "Trying to mark unknown alternate protocol broken."; 315 LOG(DFATAL) << "Trying to mark unknown alternate protocol broken.";
316 return; 316 return;
317 } 317 }
318 // This server's alternate protocol information is coming from a canonical 318 // This server's alternate protocol information is coming from a canonical
319 // 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
320 // it can be marked as broken. 320 // it can be marked as broken.
321 it = alternate_protocol_map_.Put(server, alternate); 321 it = alternate_protocol_map_.Put(server, alternate);
322 } 322 }
323 it->second.is_broken = true; 323 it->second.is_broken = true;
324 int count = ++broken_alternate_protocol_map_[server]; 324 const BrokenAlternateProtocolEntry entry(server, alternate.port,
325 alternate.protocol);
326 int count = ++broken_alternate_protocol_map_[entry];
325 base::TimeDelta delay = 327 base::TimeDelta delay =
326 base::TimeDelta::FromSeconds(kBrokenAlternateProtocolDelaySecs); 328 base::TimeDelta::FromSeconds(kBrokenAlternateProtocolDelaySecs);
327 BrokenAlternateProtocolEntry entry; 329 base::TimeTicks when = base::TimeTicks::Now() + delay * (1 << (count - 1));
328 entry.server = server; 330 broken_alternate_protocol_list_.push_back(
329 entry.when = base::TimeTicks::Now() + delay * (1 << (count - 1)); 331 BrokenAlternateProtocolEntryWithTime(entry, when));
330 broken_alternate_protocol_list_.push_back(entry);
331 332
332 // Do not leave this host as canonical so that we don't infer the other 333 // Do not leave this host as canonical so that we don't infer the other
333 // hosts are also broken without testing them first. 334 // hosts are also broken without testing them first.
334 RemoveCanonicalHost(server); 335 RemoveCanonicalHost(server);
335 336
336 // If this is the only entry in the list, schedule an expiration task. 337 // If this is the only entry in the list, schedule an expiration task.
337 // Otherwise it will be rescheduled automatically when the pending task runs. 338 // Otherwise it will be rescheduled automatically when the pending task runs.
338 if (broken_alternate_protocol_list_.size() == 1) { 339 if (broken_alternate_protocol_list_.size() == 1) {
339 ScheduleBrokenAlternateProtocolMappingsExpiration(); 340 ScheduleBrokenAlternateProtocolMappingsExpiration();
340 } 341 }
341 } 342 }
342 343
343 bool HttpServerPropertiesImpl::WasAlternateProtocolRecentlyBroken( 344 bool HttpServerPropertiesImpl::WasAlternateProtocolRecentlyBroken(
344 const HostPortPair& server) { 345 const HostPortPair& server) {
345 return ContainsKey(broken_alternate_protocol_map_, server); 346 const AlternateProtocolInfo alternate_protocol = GetAlternateProtocol(server);
347 if (alternate_protocol.protocol == UNINITIALIZED_ALTERNATE_PROTOCOL)
348 return false;
349 const BrokenAlternateProtocolEntry entry(server, alternate_protocol.port,
350 alternate_protocol.protocol);
351 return ContainsKey(broken_alternate_protocol_map_, entry);
346 } 352 }
347 353
348 void HttpServerPropertiesImpl::ConfirmAlternateProtocol( 354 void HttpServerPropertiesImpl::ConfirmAlternateProtocol(
349 const HostPortPair& server) { 355 const HostPortPair& server) {
350 broken_alternate_protocol_map_.erase(server); 356 const AlternateProtocolInfo alternate_protocol = GetAlternateProtocol(server);
357 if (alternate_protocol.protocol == UNINITIALIZED_ALTERNATE_PROTOCOL)
358 return;
359 const BrokenAlternateProtocolEntry entry(server, alternate_protocol.port,
360 alternate_protocol.protocol);
361 broken_alternate_protocol_map_.erase(entry);
351 } 362 }
352 363
353 void HttpServerPropertiesImpl::ClearAlternateProtocol( 364 void HttpServerPropertiesImpl::ClearAlternateProtocol(
354 const HostPortPair& server) { 365 const HostPortPair& server) {
355 AlternateProtocolMap::iterator it = alternate_protocol_map_.Peek(server); 366 AlternateProtocolMap::iterator it = alternate_protocol_map_.Peek(server);
356 if (it != alternate_protocol_map_.end()) 367 if (it != alternate_protocol_map_.end())
357 alternate_protocol_map_.Erase(it); 368 alternate_protocol_map_.Erase(it);
358 369
359 RemoveCanonicalHost(server); 370 RemoveCanonicalHost(server);
360 } 371 }
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after
494 505
495 if (!canonical->second.Equals(server)) 506 if (!canonical->second.Equals(server))
496 return; 507 return;
497 508
498 canonical_host_to_origin_map_.erase(canonical->first); 509 canonical_host_to_origin_map_.erase(canonical->first);
499 } 510 }
500 511
501 void HttpServerPropertiesImpl::ExpireBrokenAlternateProtocolMappings() { 512 void HttpServerPropertiesImpl::ExpireBrokenAlternateProtocolMappings() {
502 base::TimeTicks now = base::TimeTicks::Now(); 513 base::TimeTicks now = base::TimeTicks::Now();
503 while (!broken_alternate_protocol_list_.empty()) { 514 while (!broken_alternate_protocol_list_.empty()) {
504 BrokenAlternateProtocolEntry entry = 515 BrokenAlternateProtocolEntryWithTime entry_with_time =
505 broken_alternate_protocol_list_.front(); 516 broken_alternate_protocol_list_.front();
506 if (now < entry.when) { 517 if (now < entry_with_time.when) {
507 break; 518 break;
508 } 519 }
509 520
521 const BrokenAlternateProtocolEntry& entry =
522 entry_with_time.broken_alternate_protocol_entry;
510 ClearAlternateProtocol(entry.server); 523 ClearAlternateProtocol(entry.server);
511 broken_alternate_protocol_list_.pop_front(); 524 broken_alternate_protocol_list_.pop_front();
512 } 525 }
513 ScheduleBrokenAlternateProtocolMappingsExpiration(); 526 ScheduleBrokenAlternateProtocolMappingsExpiration();
514 } 527 }
515 528
516 void 529 void
517 HttpServerPropertiesImpl::ScheduleBrokenAlternateProtocolMappingsExpiration() { 530 HttpServerPropertiesImpl::ScheduleBrokenAlternateProtocolMappingsExpiration() {
518 if (broken_alternate_protocol_list_.empty()) { 531 if (broken_alternate_protocol_list_.empty()) {
519 return; 532 return;
520 } 533 }
521 base::TimeTicks now = base::TimeTicks::Now(); 534 base::TimeTicks now = base::TimeTicks::Now();
522 base::TimeTicks when = broken_alternate_protocol_list_.front().when; 535 base::TimeTicks when = broken_alternate_protocol_list_.front().when;
523 base::TimeDelta delay = when > now ? when - now : base::TimeDelta(); 536 base::TimeDelta delay = when > now ? when - now : base::TimeDelta();
524 base::MessageLoop::current()->PostDelayedTask( 537 base::MessageLoop::current()->PostDelayedTask(
525 FROM_HERE, 538 FROM_HERE,
526 base::Bind( 539 base::Bind(
527 &HttpServerPropertiesImpl::ExpireBrokenAlternateProtocolMappings, 540 &HttpServerPropertiesImpl::ExpireBrokenAlternateProtocolMappings,
528 weak_ptr_factory_.GetWeakPtr()), 541 weak_ptr_factory_.GetWeakPtr()),
529 delay); 542 delay);
530 } 543 }
531 544
532 } // namespace net 545 } // namespace net
OLDNEW
« no previous file with comments | « net/http/http_server_properties_impl.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698