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

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: 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 (EndsWith(server.host(), canonical_suffixes_[i], false)) { 314 if (EndsWith(server.host(), canonical_suffixes_[i], false)) {
315 HostPortPair canonical_host(canonical_suffix, server.port()); 315 HostPortPair canonical_host(canonical_suffix, server.port());
316 canonical_host_to_origin_map_[canonical_host] = server; 316 canonical_host_to_origin_map_[canonical_host] = server;
317 break; 317 break;
318 } 318 }
319 } 319 }
320 } 320 }
321 321
322 void HttpServerPropertiesImpl::SetBrokenAlternateProtocol( 322 void HttpServerPropertiesImpl::SetBrokenAlternateProtocol(
323 const HostPortPair& server) { 323 const HostPortPair& server) {
324 const AlternateProtocolInfo alternate = GetAlternateProtocol(server);
324 AlternateProtocolMap::iterator it = alternate_protocol_map_.Get(server); 325 AlternateProtocolMap::iterator it = alternate_protocol_map_.Get(server);
325 if (it == alternate_protocol_map_.end()) { 326 if (it == alternate_protocol_map_.end()) {
326 if (!HasAlternateProtocol(server)) { 327 if (!HasAlternateProtocol(server)) {
327 LOG(DFATAL) << "Trying to mark unknown alternate protocol broken."; 328 LOG(DFATAL) << "Trying to mark unknown alternate protocol broken.";
328 return; 329 return;
329 } 330 }
330 // This server's alternate protocol information is coming from a canonical 331 // 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 332 // server. Add an entry in the map for this server explicitly so that
332 // it can be marked as broken. 333 // it can be marked as broken.
333 it = alternate_protocol_map_.Put(server, GetAlternateProtocol(server)); 334 it = alternate_protocol_map_.Put(server, alternate);
334 } 335 }
335 it->second.is_broken = true; 336 it->second.is_broken = true;
336 int count = ++broken_alternate_protocol_map_[server]; 337 const BrokenAlternateProtocolEntry entry(server, alternate.port,
338 alternate.protocol);
339 int count = ++broken_alternate_protocol_map_[entry];
337 base::TimeDelta delay = 340 base::TimeDelta delay =
338 base::TimeDelta::FromSeconds(kBrokenAlternateProtocolDelaySecs); 341 base::TimeDelta::FromSeconds(kBrokenAlternateProtocolDelaySecs);
339 BrokenAlternateProtocolEntry entry; 342 base::TimeTicks when = base::TimeTicks::Now() + delay * (1 << (count - 1));
340 entry.server = server; 343 broken_alternate_protocol_list_.push_back(
341 entry.when = base::TimeTicks::Now() + delay * (1 << (count - 1)); 344 BrokenAlternateProtocolEntryWithTime(entry, when));
342 broken_alternate_protocol_list_.push_back(entry);
343 345
344 // Do not leave this host as canonical so that we don't infer the other 346 // Do not leave this host as canonical so that we don't infer the other
345 // hosts are also broken without testing them first. 347 // hosts are also broken without testing them first.
346 RemoveCanonicalHost(server); 348 RemoveCanonicalHost(server);
347 349
348 // If this is the only entry in the list, schedule an expiration task. 350 // If this is the only entry in the list, schedule an expiration task.
349 // Otherwise it will be rescheduled automatically when the pending task runs. 351 // Otherwise it will be rescheduled automatically when the pending task runs.
350 if (broken_alternate_protocol_list_.size() == 1) { 352 if (broken_alternate_protocol_list_.size() == 1) {
351 ScheduleBrokenAlternateProtocolMappingsExpiration(); 353 ScheduleBrokenAlternateProtocolMappingsExpiration();
352 } 354 }
353 } 355 }
354 356
355 bool HttpServerPropertiesImpl::WasAlternateProtocolRecentlyBroken( 357 bool HttpServerPropertiesImpl::WasAlternateProtocolRecentlyBroken(
356 const HostPortPair& server) { 358 const HostPortPair& server) {
357 return ContainsKey(broken_alternate_protocol_map_, server); 359 if (!HasAlternateProtocol(server))
Ryan Hamilton 2015/02/03 22:39:35 Looks like this needs to be rebased on top of your
Bence 2015/02/04 14:25:33 Done.
360 return false;
361 const AlternateProtocolInfo alternate_protocol = GetAlternateProtocol(server);
362 const BrokenAlternateProtocolEntry entry(server, alternate_protocol.port,
363 alternate_protocol.protocol);
364 return ContainsKey(broken_alternate_protocol_map_, entry);
358 } 365 }
359 366
360 void HttpServerPropertiesImpl::ConfirmAlternateProtocol( 367 void HttpServerPropertiesImpl::ConfirmAlternateProtocol(
361 const HostPortPair& server) { 368 const HostPortPair& server) {
362 broken_alternate_protocol_map_.erase(server); 369 if (!HasAlternateProtocol(server))
370 return;
371 const AlternateProtocolInfo alternate_protocol = GetAlternateProtocol(server);
372 const BrokenAlternateProtocolEntry entry(server, alternate_protocol.port,
373 alternate_protocol.protocol);
Ryan Hamilton 2015/02/03 22:39:35 might consider adding a 2 arg constructor(server,
Bence 2015/02/04 14:25:33 I was thinking a lot about it, but it turns out Al
374 broken_alternate_protocol_map_.erase(entry);
363 } 375 }
364 376
365 void HttpServerPropertiesImpl::ClearAlternateProtocol( 377 void HttpServerPropertiesImpl::ClearAlternateProtocol(
366 const HostPortPair& server) { 378 const HostPortPair& server) {
367 AlternateProtocolMap::iterator it = alternate_protocol_map_.Peek(server); 379 AlternateProtocolMap::iterator it = alternate_protocol_map_.Peek(server);
368 if (it != alternate_protocol_map_.end()) 380 if (it != alternate_protocol_map_.end())
369 alternate_protocol_map_.Erase(it); 381 alternate_protocol_map_.Erase(it);
370 382
371 RemoveCanonicalHost(server); 383 RemoveCanonicalHost(server);
372 } 384 }
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after
506 518
507 if (!canonical->second.Equals(server)) 519 if (!canonical->second.Equals(server))
508 return; 520 return;
509 521
510 canonical_host_to_origin_map_.erase(canonical->first); 522 canonical_host_to_origin_map_.erase(canonical->first);
511 } 523 }
512 524
513 void HttpServerPropertiesImpl::ExpireBrokenAlternateProtocolMappings() { 525 void HttpServerPropertiesImpl::ExpireBrokenAlternateProtocolMappings() {
514 base::TimeTicks now = base::TimeTicks::Now(); 526 base::TimeTicks now = base::TimeTicks::Now();
515 while (!broken_alternate_protocol_list_.empty()) { 527 while (!broken_alternate_protocol_list_.empty()) {
516 BrokenAlternateProtocolEntry entry = 528 BrokenAlternateProtocolEntryWithTime entry_with_time =
517 broken_alternate_protocol_list_.front(); 529 broken_alternate_protocol_list_.front();
518 if (now < entry.when) { 530 if (now < entry_with_time.when) {
519 break; 531 break;
520 } 532 }
521 533
534 const BrokenAlternateProtocolEntry& entry =
535 entry_with_time.broken_alternate_protocol_entry;
522 ClearAlternateProtocol(entry.server); 536 ClearAlternateProtocol(entry.server);
Ryan Hamilton 2015/02/03 22:39:35 I think this method should now that a BrokenAPEntr
Bence 2015/02/04 14:25:33 A server can still only have one AlternateProtocol
Ryan Hamilton 2015/02/05 17:32:24 Ah,yes, good point.
523 broken_alternate_protocol_list_.pop_front(); 537 broken_alternate_protocol_list_.pop_front();
524 } 538 }
525 ScheduleBrokenAlternateProtocolMappingsExpiration(); 539 ScheduleBrokenAlternateProtocolMappingsExpiration();
526 } 540 }
527 541
528 void 542 void
529 HttpServerPropertiesImpl::ScheduleBrokenAlternateProtocolMappingsExpiration() { 543 HttpServerPropertiesImpl::ScheduleBrokenAlternateProtocolMappingsExpiration() {
530 if (broken_alternate_protocol_list_.empty()) { 544 if (broken_alternate_protocol_list_.empty()) {
531 return; 545 return;
532 } 546 }
533 base::TimeTicks now = base::TimeTicks::Now(); 547 base::TimeTicks now = base::TimeTicks::Now();
534 base::TimeTicks when = broken_alternate_protocol_list_.front().when; 548 base::TimeTicks when = broken_alternate_protocol_list_.front().when;
535 base::TimeDelta delay = when > now ? when - now : base::TimeDelta(); 549 base::TimeDelta delay = when > now ? when - now : base::TimeDelta();
536 base::MessageLoop::current()->PostDelayedTask( 550 base::MessageLoop::current()->PostDelayedTask(
537 FROM_HERE, 551 FROM_HERE,
538 base::Bind( 552 base::Bind(
539 &HttpServerPropertiesImpl::ExpireBrokenAlternateProtocolMappings, 553 &HttpServerPropertiesImpl::ExpireBrokenAlternateProtocolMappings,
540 weak_ptr_factory_.GetWeakPtr()), 554 weak_ptr_factory_.GetWeakPtr()),
541 delay); 555 delay);
542 } 556 }
543 557
544 } // namespace net 558 } // 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